Hacker News new | past | comments | ask | show | jobs | submit login

I wasn't criticizing your code, per-se.

I did fair bit of Smalltalk development back in school, so I know exactly where Obj-C/Cocoa naming conventions and 'message' syntax comes from. The problem is this: that naming convention doesn't make any sense in a statically typed language. It made sense in Smalltalk because the parameters sent to a message could be anything. It was a convention to avoid common erros. In Obj-C, on the other hand, it doesn't make any sense. Sure, it might sound like saying "message withBananaParameter: banana andCoconutParameter: coconut" is clearer and 'self documenting', but it's a waste of your time typing it (even when you use autocomplete) and the compiler parsing it. Let alone people reading your code in the future.

The indentation is arguable. I don't know whether that's the standard or not, but I dislike the fact that you are pushing stuff to the right, basically forcing yourself to break the parameter list a lot because you get closer to the "right margin". It looks like that indentation convention was specifically invented to make long parameters list harder to read (ironically, considering long parameter lists are an artifact of Smalltalk-like message/parameter convention.)

I've programmed in a bunch of languages and platforms over the yeas, and only three languages always keep bugging me when reading them: Obj-C (specially Cocoa code), Perl and very complex Javascript. There's something about them that just feels off.




Since Obj-C messaging supports duck typing, I'm not sure I understand the argument you're making against the syntax.


I believe dguaraglia is talking about the types of arguments, which are often included in the method name. So you get things like [guy eatFood:food withHand:hand usingEatingStyle:eatingStyle]. Overall, it lends itself to exceptionally long lines of code, such that Objective-C message sends are often broken into multiple lines with lots of info on the right side of the window. For example, instead of:

  NSWindow *window = [[NSWindow alloc] initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen];
people will often write write:

  NSWindow *window = [[NSWindow alloc] initWithContentRect: desiredRect
                                                 styleMask: windowStyle
                                                   backing: NSBackingStoreBuffered
                                                     defer: YES
                                                    screen: [NSScreen mainScreen]];
The length of the selector requires us to choose how we're going to write this line of code.


I might have talked out of my ass? Wouldn't be the first time, and I apologize if I did.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: