Fun with Objective C
To try and find some fun coding projects outside of work, I’ve spent a little time at home trying to get back into Mac development. It’s been about three years since I last did anything targeted at the Mac platform (rather than using a Mac to write generic code for many platforms), and since then a lot has changed. Thankfully, it’s for the better – what used to be good has only improved in my absence.
One thing that’s struck me this time around is how coding with Cocoa and Objective-C is much more like writing Python code than C++ or Java. Many of the idioms are the same – a lack of emphasis on subclassing and instead using helper objects, and some nice syntactic sugar to help with things like array processing. For example, today I wrote the following code to show the contents of a directory, and I think it gives you an idea of both how nice the library interface is and how similar to Python it can all be at times:
NSFileManager* manager = [NSFileManager defaultManager]; NSArray* dir_list = [manager directoryContentsAtPath: path_of_interest]; NSLog(@"Directory contents:"); for (NSString* name in dir_list) NSLog(name);
Here I’m using part of the vast, but at the same time actually useful, Cocoa library to quickly look up a directory listing into an array and then printing it out in a very similar fashion to how I would in Python.
The nice thing about Objective C is that it is still C at heart, so I can both interface quickly with lots of C/C++ libraries and system interfaces, whilst still having a nice high level view of the world for writing application code (which is something I don’t think C’s typically good at).
- Next: The illusion of decay
- Previous: Finding new music
- Tags: Geek