Things have been quiet here in this blog. Too quiet. As such, I’m keeping the name-five-things-you-hate-about-a-language-you-like ball rolling, having seen it rolled with zest and vigor by brian d foy, Titus, Jacob Kaplan-Moss and Vincent.
Without further ado:
Five Things that Suck About Objective-C/Cocoa:
- Syntax for NSString literals. For the uninitiated, in Objective-C code enclosing
"insomnia"in simple double-quotes creates a C-style char[] string; if you wish to use the far more powerful and versatile Objective-C NSString class, you must add an @ (making@"insomnia"). Backwards-compatibility with C is a good and useful thing, but why require more keystrokes to do the most commonly-used thing? I myself last weekend puzzled over a wonderfully non-specific “invalid reciever” error for a long time before realizing that I forgot an @ when sending strings to anarrayWithObjects:method. Aside from that, why use the @-sign as a prefix for NSStrings when it’s used in a plethora of other places, such as@interface,@implementation,@endand@selector? Though 90% of my @-key-presses in Textmate are prefixes to NSStrings, I can’t have a keypress of @ automatically expand to @”” – there are too many other things to do with the poor little @-sign. The oft-neglected | (pipe or vertical bar, I’ve heard both) character is far less disruptive to the flow of typing. - reallyLongAndCamelCasedMethodNamesGetAnnoying. I refer specifically to the lovely
NSWorkspacemethodopenURLs: withAppBundleIdentifier: options: additionalEventParamDescriptor: launchIdentifiers:
And ObjC method names can be concise yet informative – take for example NSString’scompare: options: range: locale:. I must admit, this complaint is not entirely valid, especially considering Textmate/XCode’s fancy code completion. - No operator overloading. Come on, guys – why reject this crucial part of Smalltalk heritage? I, for one, am sick of writing
objectAtIndexandobjectForKey:as compared to Python’s []. Though Smalltalk allows one to define new operators, I’d be perfectly happy to settle for a few overloadable operators (string concatenation is desperately needed). - Mysterious helper methods. I didn’t know of the existence of
NSHomeDirectory(),NSTemporaryDirectory(), orNSClassFromString()until very recently. True, this is my fault, but I think that F-Script’s idea of storing all of these methods in a singleton System object is excellent, and much more in line with Objective-C’s Smalltalk heritage. (Actually, I have a half-finished ObjC class that makesNSBeep()and all those other miscellaneous C functions into class methods; if there’s any interest, I’ll finish and release it. I suppose that makes this complaint invalid. Oh well.) - File management is a mess. Essential code is scattered throughout
NSWorkspace(in all its brain-dead glory),NSFileManager,NSFileHandle,NSPipe,NSDirectoryEnumerator, andNSData– few things are as infuriating as hunting down the correct class that does exactly what I want. (Actually, no. Finding a better solution after thirty minutes of hacking around some perceived inadequacy is worse.
So there you have it. To be honest, it took me quite a while to write this, mainly because Objective-C is such a great language and Cocoa is such a great set of libraries. I suppose that the imperfections in a consistently useful and friendly toolkits stand out, and in retrospect I sort of feel guilty for my picky attitude. After all, it could be much, much worse.