Four things I wish I knew about Objective-C six months ago (and three things I'm sure in six months I will wish I knew now)

Gosh, I really haven’t kept this as up-to-date as I’d hoped. Nonetheless, slow and constant improvement is better than five entries and then silence for a year, right?

My project since, well, before the beginning of this year, has been to learn Cocoa/Objective-C. Partly, I like making things I can use, but it could also be helpful for the whole CV thing, if I decide to take that avenue. I hear diversification is good and all.

It’s been a relatively steep learning curve. I’m not primarily a programmer, so I don’t have quite the inclination to learn one language a year or whatever the recommended dosage is. There’s been a few techniques that I haven’t had to worry about programming in ruby. But overall it’s been a mind-stretching experience, and those are always good.

There are a few things that I glossed over originally, thinking “I’ll learn that later, when the project is up and running as it stands”. It turns out that a lot of those things would have saved me time and effort if I’d learned them back in January or whenever. I thought I might document them for posterity’s sake, perhaps.

Git

When I first learned git, it was so I could grab stuff from the internet. (Isn’t that the case for all of us?) It took several projects before I worked out that – hold on, version control could be really hard! Of course, there’s a few commands in git, and while it’s easy enough to remember git add and git commit, I tend to forget some of the more advanced/complex ones. Plus, I just haven’t found a GUI for git that I particularly love.

So I printed out a cheat sheet:

This sits next to my computer and has every git command on it (well, every git command I need – no conflicts so far). It’s pretty handy knowing I can screw with my source as much as I want and, if I break it, I can just revert to my last commit. It effectively gives me permission to try weird crazy things without having to worry too much. Additionally, it forces me to solve issues one-at-a-time, rather than trying to give one class a big re-haul in the middle of another project. All good things.

Bindings

I briefly discussed bindings with a friend of mine who actually knows Objective-C, and while they sounded interesting I decided that I’d wait for a bit before learning them. I planned to get everything working and then replace what code I could with said bindings.

Turns out, bindings are awesome.

I ended up learning how to implement bindings from CocoaDevCentre: I found that their tutorial on actually getting them working was a bit more concise than Apple’s documentation. Still, I think I’m better off for knowing how they work as opposed to just draging objects around on a canvas. The amount of glue code they eliminate, however, and the amount of time they save, is excellent. Not having to deal with a whole heap of new methods for changing text boxes and clicking buttons in my controller is bliss.

Which handily leads us to…

Code organisation

Classes get out of hand very quickly, and for a while I just had a file full of methods with no rhyme or reason to them. Which is fine when what you want to do of an evening is get method x completed: you don’t want to spend half an hour refactoring your code. However, halfway through my project I started refactoring as I went, dividing the class into segments, alphabetically ordering methods within said segments, and liberally sprinling pragma marks throughout. Now it looks a lot cleaner - especially from the dropdown.

There’s one other big advantage: peace of mind. Being somewhat of a clean freak, having my code organised nicely, so nothing will get lost, has something of a calming effect. Which lets me focus on what I’m doing now, even if it bears no relation to the nice clean code sitting on either side.

XCode 4

For a while I was running Snow Leopard with XCode 3. My coding friend looked at the interface and immediately told me to upgrade. I resisted.

Eventually I gave in and installed Lion. Some of the “features” I’m not incredibly pleased about, but XCode 4 is such an improvement. While it has trouble fitting on my 11" screen, the additional features offered (assistant editor, integration with source control, what seems to be improved error spotting, etc. etc.) are well worth the upgrade. I’m pretty sure it’s sped up code production by a significant factor.

There’s still a lot of things I need to learn. Eventually I plan on having some software up on here, but in the meantime, I’m learning. Here’s some things I imagine in six months I wished I had learned right now, instead of waiting for a lull in coding:

Unit tests

I’m aware they exist for Objective-C, I just haven’t got around to them yet. I’m interested as to how they’ll work regarding UI (button clicks, etc.), but at least for the code it’ll be handy to have automated tests so I know when things break.

Core Data

I ended up skimming a tutorial for this, and it looks amazing. I imagine that once I get to grips with it, I’ll be shaving as much glue code off my application as I did with bindings, and it’ll make everything incredibly maintainable. I just have to put in the time and either find a good article or bribe a friend.

???

Half the problem I have is that there’s not really anything I can check out for a list of topics to learn. I have some books (but Objective-C books seem to fall out-of-date pretty fast), and I have a friend or two I can call on, but there is no well-established community here for asking “what should I do now?”

I’m getting better at this - browsing websites and checking out lists of tutorials - but for someone who’s moved from hobbyist programming in ruby to learning Objective-C/Cocoa, it’s a relatively big step. If I re-write this in six months, I imagine there’ll be another few things on this list, things I don’t even know I don’t know, that I’m glad I picked up.

Comments

Leave a comment

Sorry, you need to enable javascript for commenting. That’s one of the drawbacks of having a static site blog I guess.