D versus Objective C Comparison

bearophile bearophileHUGS at lycos.com
Wed Feb 4 01:13:38 PST 2009


Chris R Miller:
> As you can see, I added important functionality to the class NSString 
> without going through all the trouble to make a new class and type cast 
> between NSString and MyDerivedString all over the place.  It's more 
> transparent, and it's far better than a global function, or placing this 
> kind of code into an unrelated class, or worse yet, a "kitchen-sink" class.

Instead of using a "kitchen-sink" class, in D you can put such functionality into a module, like the string module of Phobos or similar libs.

I don't know Object-C, what you have done looks like the "monkey patching" done sometimes in Ruby. Is this the same thing?
"monkey patching" as done in Ruby has several disadvantages and dangers. Time ago I have read that there's a simple enough way to remove most of the dangers from monkey patching: make it scoped. So the changes to the classes can be seen just inside a scope (and its subscopes) and not outside it.

Bye,
bearophile



More information about the Digitalmars-d mailing list