Thursday, 10 July 2008

Cocoa: Starting to Learn

As I said previously I'm attempting to teach myself Cocoa and Objective-C programming. My starting point was the advice on the website of the authors of my favourite journal article management system. really isn't that difficult to learn actually. Of course a basic knowledge of C is a prerequisite, but once you have that experience things can go fast. Really fast! Remember we didn't have any programming experience when we started only a few years ago.

...many terrific books for beginners have become available since then. From personal experience we can absolutely recommend these four that will help you take the large hurdle at the beginning, and get you going in no time.

...One of the first things we urge you to do is sign up with Apple's Developer Connection (ADC) for a free (!) online account....

So, I signed up for the basic, free Apple Developer Connection membership and installed the dev tools from the discs that came with my MacBook. My next step was trying to get a clue about how to actually write programs.

I started out reading Stephen Prata's C Primer and learnt some useful basics like putting a semicolon at the end of every statement, declaring variables and where to put the braces to enclose functions. It also covers stuff about how code works, what compilers do and things like that - I to have an understanding of the basic stuff that happens in the background. However, I only got about three chapters into the book when a detailed discussion about the different variable types and the number of bytes of memory that they require completely derailed my interest. This was far too hardcore computer science for me. I understood it but had a feeling that I might not need to know stuff in such insane detail - Cocoa struck me as being too friendly for that kind of knowledge. I closed the C Primer. If I ever have an urge to write code for embedded systems (maybe washing machine engineering will call to me later in life) I might come back and carry on with the rest of the book1.

Next I ventured into Learning Cocoa with Objective-C from O'Reilly. This was considerably better. The writing was much more accessible and it covered some useful basic points of the objective-C language and introduced me to what object oriented programming is. Problems staretd when they started to explain the creation of GUI-based applications rather than command-line tools. The book was published in 2005 and, in the intervening three years, Apple have made a lot of changes to their development tools. 'Project Builder' is now called XCode and both it and Interface Builder have undergone plenty of tweaks to their layout. All of the examples in Learning Cocoa... are based in Project Builder and so it took a considerable amount of time to work out what the hell was going on when told to click a button that had been moved or no longer existed. That wasn't fun. I'd also heard a lot about these cool new features in Leopard to handle data and graphics etc - I really wanted to learn about these because I reckon they'll be useful in the app I want to write.

Whilst thinking about the most appropriate book for my needs I saw an interview with Aaron Hillegass, author of Cocoa Programming for Objective C. In a piece of excellent, fortuitous timing a new edition of the book had just been released that was fully up to date with the most recent release of XCode and all of the new Leopard features. Great news. I've bought a copy and it looks promising.

So, I've found a book. I'll detail my progress with it later...

  1. Anyone who just tutted, sighed and thought "How can you even think about writing code without a full understanding of C?" will be ignored. Life's too short. I'll understand what I need and not a thing more.

Tuesday, 8 July 2008

On the Design of this Blog

You've probably noticed (because you're sharp like that) that this blog uses one of the standard Blogger templates. Having noticed this you might be thinking "But Mike, you bang on about how you care about good, interesting design. How can you use a tedious, common Blogger layout? You big hypocrite". Well, fair point. I'd love to be able to use a beautiful layout that I'd designed from scratch and that encapsulated my entire personality in a few well-chosen lines, boxes and fonts. That's not going to happen. Mainly because I know nothing about the actual process of web-design. I could draw a pleasing simulation of a page in Adobe Illustrator or InDesign but actually getting that into someone's browser is currently beyond me.

That's not to say I don't want to learn. I'd love to get to grips with HTML, CSS and other fancy web-design techniques. In fact, I'm sure that the cool kids aren't using HTML or CSS to do anything any more and I've probably just demonstrated how little I know. Oh well.

The problem is that learning web-design would take time. I know that I'm sufficiently obsessive that if I started to learn I'd have to get to a stage where I knew a lot about the techniques. I would then spend a loooong time tweaking my web page to get it just as I wanted and making sure that the site was compatible with all available browsers and looked equally beautiful in all of them. This would not be time that I spent producing content for this blog or actually learning Cocoa. Between work, seeing my fiancee, interacting with the outside world and watching House my time for the blog and coding is somewhat limited. It's probably best that I don't squeeze that time any more by developing an obsession with web design.

Hello World

I am a scientist. I am also very very bored.

I have become frustrated with my job. I'll go into the reasons for this creeping disillusionment in later posts but recently I've found during work that my mind wanders. I take up hobbies (photography, golf, cycling, plenty more) and spend far longer reading and thinking about those than I do thinking about my day-to-day science. I also spend a lot of time wishing that I could do more activities that actually create something physical. In an ideal world i would be a chef or, in a world where I had any artistic talent at all I would spend my days sculpting, making furniture or being an architect. It's a bit late for some of those changes now (at least it is without a massive source of cash to support me while I sort myself out) so I've decided on something else.

A few months ago a very generous uncle gave me some money to buy a new computer and I decided to switch from PCs to a Macbook Pro. I have a soft spot for Macs nurtured by using them in my Apple-centric department at University and I've been attached to my iPod ever since the second-generation one that I had in 2001 (even though it was a brick compared to models that came later). I love the design of the hardware and software, the fact that the company seems to care about the user experience and, if I'm honest, the slight feeling of superiority that I get from owning one. The main problem was that I couldn't afford a Mac - despite all of the convincing evidence that the total cost of ownership is the same or lower for Macs vs PCs I didn't ever have the free, disposable capital available to start to actually OWN one. Now I do and I'm infatuated with it.

I've spent some time getting used to OS X instead of Windows and exploring the software available for the platform. I've been blown away by the quality of applications available. Anyone who's ever looked for Windows software to achieve a specific task will be familiar with the experience of finding a million different programs that all seem to do the same thing and that all look like they were designed by a blind idiot who actively hates the users of his program. Rarely do they work well. Lots of people before me have noticed that this experience is somewhat different on the Mac - the quantity of software is somewhat reduced BUT what is available is worlds ahead in terms of quality. It feels like it's been designed rather than hacked together and is way more pleasant to use.

I guess this is due to the desire of developers to continue the experience of the OS into their software because mac people complain vociferously if programs feel "wrong". Whatever the reasons, the users all win. I think that developers win too - I've found myself massively more willing to buy software for the Mac than I was for the PC. If everything available is horrible to use why would you buy something if there's an equally unpleasant freeware alternative? Or, if the only option requires payment why would you buy it when it's easily available via t3h torrentz for free (not that i'd ever do that....)? I'm more than willing to pay for software if it works, looks good, is nice to use and solves a problem that I have.

One of the best pieces of Mac-only software that I've found is Papers. A large part of science (especially when doing a PhD) is the reading of journal articles. These papers are where scientists publish their work for others to read (eg in Nature,Science or other much smaller, more specific journals). When writing up one's own work for a paper or a PhD thesis it's incredibly important to reference the articles that one has read to back up statements and demonstrate an awareness of the field. You can probably guess that having a system to organise your papers is rather useful to save time and effort. Most journals are now available online (often requiring a heart-stoppingly expensive institutional subscription) and so a collection of papers is usually a load of PDFs rather an a pile of print-outs. When I was using Windows I followed most other academics and used EndNote. This ticks the boxes mentioned earlier of looking nasty and being difficult to use - it *is* good for inserting citations into a Word document but otherwise used to suck the life out of me on a regular basis. I had a look at the Mac version but it is equally unpleasant to use and, since Microsoft decided they couldn't be arsed to implement VBA in Office 2008 for Mac, doesn't even insert references into Word. Some searching around coupled with a well-timed Ars Technica reviewpointed me at Papers. It's written by two guys (Mekentosj) who did it during their PhDs and it's a revelation. Nice to use and look at, it makes all of my article-management tasks quick and easy and uses the excellent PDFKit in OS X to allow reading of articles from within the program. In short, it's great.

So, finally, the reason for this blog. Whilst browsing around the Mekentosj website I found this page about how they write their software.

...we had no programming skills whatsoever. Being interested, and having tried to start a few times, we had desperately failed each time, stumbling upon this utterly steep learning curve. But somehow, the release of Mac OS X in combination with all the talking about this great Cocoa programming environment and free tools made us feel that now was the time to really go for it. We bought a great book on the C programming language just to learn the basics. Soon after, we downloaded the developer tools, and made the switch to Objective-C with help of O'Reilly's Cocoa book. After the obligatory "Hello world" and "Currency Converter" samples, things really started to take off, and soon after we finished our first program. LabAssistant was launched in the summer of 2001, only a few months after the C programming book was bought. If you have ever thought to start programming, now is the time!

This started to fire some inspiration in me. I have never properly written programs. As a geeky teenager I played around with Basic and OPLon my Psion 3a (told you I was a geek!). More recently I've had to write some moderately complicated VBA macros to automate tasks in Excel and Word for work. I've discovered that I really enjoy the challenge (even if it's pretty simple) of bending a computer to my will and making it do my bidding. I like the fact that getting a program to work is basically just a big puzzle to be solved - this pleases my slightly obsessive-compulsive brain. So I've decided to teach myself how to write software in Cocoa and Objective-C for Mac OS X. I have some ideas for what I want to write but it's going to be a long time before I'm proficient enough to even attempt those so I won't go into them yet.

I also want to do some more (non-scientific) writing so I've started a blog. Hopefully this will enable me to document some of the process of learning Cocoa and Objective-C which will help crystallise the ideas in my head but, maybe, also be of use to anyone in a similar position who stumbles across my posts. I won't only be writing about programming but also about anything else that might be interesting. Maybe people other than me will read this - who knows? If you are reading this and you're not me, please leave a comment so I know that I'm not just shouting into an empty room.