Tuesday, June 9, 2009

Objective-C

I'm learning Objective-C and I am really stewing over a few things:

First, there's a lot of punctuation in Objective-C.

Second, I don't like that the annoyance of writing header files is extended by having to write @interface et al. We should know by know how to write implementations and have a tool to create the header files from publicly visible methods. I get really annoyed when I'm writing things twice. #import is a nice improvement over #include though.

Third, I don't like that the word @interface is used for the declarations in the header file. Because the header files don't do anything for the programmer, we have a new word @protocol to describe the same thing that "interface" does in Java. But at least Objective-C has its @protocol word, because that's a really useful programming technique.

Fourth, I don't like the way are declared on classes and variables. It looks awkward to be in a class declaration after the parent class, and it looks extraneous in a variable declaration. I like the Java way better, where I can just clearly write "class ... implements ..." and declare variables with the interface as data type so that both me and the compiler know what they can and can't do. After all, when they conform to an interface, it doesn't matter to the programmer what type they really are.

Fifth, I don't like the arrangement of functionality in the Foundation framework. The NSString class has methods for handling file paths and that seems out of place. I guess that because it's so much more cumbersome for the programmer to create new instances in Objective-C with the alloc/init/release formula, the Objective-C guys found it more convenient to stick a bunch of methods into related using objects so they can be accessed directly instead of in a package where the functionality is grouped together. At first I thought it might have been added with a category (mix-in... neat) but the documentation for NSString doesn't mention that so I think it really is built-in.