After staring at things like this in Java for 12 years:
…it can be a little odd when you find yourself typing things like this in objc:
[[[reference objectA] objectB] objectC];
But in Objective-C 2.0 there’s the so-called “dot notation”:
As a Java programmer, that makes me squirm. We’re taught from day one that good object oriented design is about encapsulation, encapsulation and then encapsulation. i.e. do not allow direct access to fields within an object, give your users accessor methods (aka getters and setters). This isn’t just “convention” for the sake of readability, it’s absolutely required from the point of view of the JavaBeans specification. And as an extension of that, APIs such as Hibernate won’t work at all if it cannot introspect your class and find accessor methods to match the fields you’ve mapped into the database. “Dot notation” looks like lazy coding…someone couldn’t be bothered to create accessors, and also didn’t care that some has direct access to their fields.
For me the “message passing” approach is more natural than the “dot notation”. Keeping this fire burning is made easier by the notion of properties in objc. For any field described in the .h file, you can quickly create accessors out of thin air like this:
@property (retain) NSObject objectA;
In the implementation:
Luckily, both dot notation and message passing use the setter, regardless of whether it is synthesized or hand written. Read more »
Although I legitimately own the various books I mentioned in the previous post, I came across an electronic version of a few of them. They are much nicer for working with on the train. And of course you’ve got copy/paste if you’re feeling lazy.
One in particular was encapsulated in a CHM file. This is apparently a Microsoft format containing an entire ‘website’ but compressed into an archive (probably a zip file). The first reader for this file format is called ‘Chmox‘ and is available as an open source project. Fantastic!
However once I downloaded a binary from the Sourceforge site I found it ran very slowly with few clues as to why. I then decided to download the source and build it myself.
Using Xcode’s repository management I was able to download the full source and build my own version on 10.5.8. And this fixed the problem! Now of course it’s early days as to me discovering exactly why my local build ran so much faster than the download, but who cares?
I am having an issue with the Deployment build…there’s a script that prepares a DMG file for release, but it fails. Once I fix that, i’ll post a link to my own Leopard build.
In recent weeks I have acquired a most usable laptop to compliment my 24″ iMac. Although that is indeed a lovely machine, it won’t do for code expeditions on the train. So I bought a Lenovo S12, and installed a dubious copy of Leopard on it. It must be said, it works like a charm. And especially so as it fits between my large geek-gut and the seat in front of me.
So with an install of the latest Xcode 3.* I am up and running in mobile form.
Books I am reading:
C Programming Language – Kernigham and Ritchie
“The classic K&R”, right? I decide to get this as it’s a return to fundamentals. I managed to skirt C entirely during my career, so it’s about time.
The Hillegass Book – Aaron Hillegass
Some might offer this up as the Cocoa K&R…so far it’s excellent. I’ll have some more comment on various ‘discoveries’ in the context of coming from Java.
iPhone Cookbook – Erica Sadun
Snippets of crafty code to get some iphone apps written quickly. I’ve played around in this book, and got some good stuff going, but I’ll finish Hillegass prior to really delving into it.
iPhone SDK Development – Dudney & Adamson
This one isn’t quite out yet, but i’ve been following it via their exceptionally useful beta program. I’ve been able to read it as either a PDF or via the Stanza Reader on my iPhone (yes, very recursive). They’re reworking some parts to include iPhone SDK 3.*, so i’m not sure it’ll be out for a few weeks. Great nonetheless.
My coding life began by messing around with BASIC on my ZX Spectrum, and then doing Active Server Pages (just an acronym for ‘some crappy Microsoft scripting thing’), before moving on to Java. So my training could be referred to as ‘informal’.
And now that I’m reading all kinds of stuff about Cocoa and Objective-C, there’s a voice in my head that says “learn the fundamentals!”. And what better way to do that than with C:
UPDATE: Years ago my friend and mentor John Hollis gave me a book titled “ANSI C”. At the time (I think this was about 15 years ago) I was almost entirely bewildered by it. I had an Atari ST and no development tools, so I didn’t get far. I really ought to try and find that book.
I’ve been writing Java for many years now. I bought my first “Learn Java in 24 hours”-type book back in 1996 (at a bookshop near St Andrews golf course of all places). Since then I’ve been lucky enough to make a career of it, and it’s been very good to me.
But times change, and as all other IT folk know, “new stuff” in the form of a gadget or some cool piece of technology is always out there tempting you. My gadget-du-jour has to be my iPhone. Since I bought one (a 1st generation device off a friend) I’ve been jonesing to write code for it. I registered as a developer and downloaded all the tools, and even bought a few books, but I haven’t yet fully immersed myself in all that’s required to actually get something done. But I feel like I must make a concerted effort soon, and why not use this kind of venue to document my experiences along the way.
So hopefully this will serve as a guide to learning Cocoa Touch (and eventually regular Cocoa) from the point of view of a die-hard Java programmer who does not know C, C++ or any other useful language for that matter.