| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On Aug 23, 2006, at 5:09 PM, Wagner Truppel wrote:
Delegation can be easily implemented using interfaces, and as far as I understand, is not a feature of the language itself, but of the Cocoa frameworks.
With Obj-C poorly named variable names don't prevent code readability. With Java (and plain old C on which the Java syntax was based) calling the method doesn't make it clear what each argument is for, so you're constantly having to look at the docs. With Obj-C's syntax, the purpose of each argument can be very clear.
I respectfully disagree. Here's an example, using yours as a starting point:
- (void) configureObject:(MyObject *)arg1 :(NSString *)arg2 : (NSString *)arg3 :(int)arg4;
which would be called as follows: [self configureObject:arg1:arg2:arg3:arg4];
Your point would be a strong one if Obj-C *forced* the programmer to add "explanatory" pieces to each argument. As it is, it's equally as easy to write unreadable code in Obj-C as it is in Java.
The runtime features are also great, since messages to nil objects don't throw NullPointerExceptions as they do in Java, which means you don't have to put in if(obj!=null) checking code everywhere.
I happen to think that forcing me to explicitly test for a possible null pointer is a good thing. It makes me a lot more conscious about the runtime behavior of my programs. Not having to test for it opens up the possibility of unexpected and undesirable runtime behavior which may be difficult to debug. Moreover, nil objects not complaining when you send them messages doesn't translate necessarily into better code or better-behaved programs. Try releasing an object and then sending it a message.
With Objective-C if it doesn't directly handle a message, it can have a delegate object handle the message. The responder chain is probably the most powerful feature of the AppKit & it relies on message capabilities of Objective-C to do that.
Again, the responder chain and the delegation mechanism are, as far as I know, aspects of the Cocoa frameworks and not of the language itself. As such, they could equally as easily be incorporated into a Java version of Cocoa.
A few things I'd like to add in favor of Java which you haven't touched on:
a) in Java you don't have an interface file separate from its implementation, which I happen to like
b) in Java you can have static variables and static methods with their own visibility modifiers; in Obj-C, as far as I know, there are no static variables in the sense of class variables (you have to fake them)
c) it's a lot easier (with much less typing) to define private methods in Java than in Obj-C
d) Java automatically supports forward class declarations; in Obj-C you need to use the @class directive
e) the whole pointer notation is so outdated... granted, it's not a terribly complicated concept to grasp (first-year CS students might disagree), but why impose on programmers another layer of thinking when the language can take care of it for them? How many times have you accidentally typed foo.x rather than foo->x?
To summarize, I won't deny that Obj-C is more dynamic than Java (mainly because of the 'id' data type), but I think it would be equally as easy, from a technical perspective alone, to implement Cocoa in Java as it was in Obj-C. Then, again, I'm not an Apple engineer faced with that prospect, so it's easy for me to make that claim...
| References: | |
| >Re: Re: Apple should get behind Cocoa Java (From: Wagner Truppel <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.