Theocacao
Leopard
Design Element
Comment on "CocoaHeads: Objective-C 2.0"
by Nicko — Sep 21
@Scott
You can certainly provide supporting evidence for either side, but ultimately the point is moot because Objective-C does not have operator overloading.
Well, the topic of the thread is a future release of the language which benefits from newly added features, has changes which makes currently erroneous code legal and is still only in beta, so discussion of what Objective C either might or should have seems appropriate. Furthermore, I'm actively considering building a patch to gcc to add support for it!

In the example you give, you talk about the ease of writing code with operator overloading. In my opinion, ease of reading code is more important in most cases.
I talked about both, and I think that both are important. The question I asked of you was which was more readable but the deeper question is "Which makes the programmer's intent clearer to the reader?" My most common frustration with coding complex applications in Objective C is that the intent of the code is all to often obscured by the detail.

The more layers you have, the more you have to dig to find out what's going on.
That is certainly true in some cases, but in many others, if the programmer is doing his or her job, there should be no need to dig. If I've got three variables called "startTime", "delay" and "endTime" then when the heck do you think that the "+" operator is going to do in this context? The exact same thing could be said for adding two NSString objects, ORing one NSSet with another or even adding an NSView subclasss to an NSTabView. Unless the programmer is actively trying to deceive the reader it is almost always going to be the case that a succinct representation of the intent is going to be more meaningful to others, precisely because you don't need to dig. That's one of the main benefits of abstraction.

Redefining the basic meaning of a C operator is much different that creating a shim method over several smaller ones.
True, but there is also a huge difference between redefining an operator and overloading it. I'm not supporting trying to redefine the basic meaning of an operator, I'm arguing that the concepts like "addition" and "OR" have a natural meaning contexts other than int or double, that programmers know what it means to subtract, for instance, an object from a set, and that allowing the extension of these natural meanings into other types of object makes it easier to represent your programming goals.
Back to "CocoaHeads: Objective-C 2.0"
Design Element

Copyright © Scott Stevenson 2004-2015