Resource: Defensive Programming

http://www.mikeash.com/pyblog/friday-qa-2009-10-09-defensive-programming.html

This is an article about programming strategy and error handling on an abstract level.

I am still very much in the ‘trying to make it work’ stage of programming, but this article has made me consider a stage in application development that I hadn’t, if I’m honest, given much thought to.

I am very much at the ‘trying to make it work’ stage of programming. Or rather, for the most part, I am at the ‘deciding what I want to design’ stage. I am working from the user side of things, for the most part: I know want thumbnails of individual records displayed in a grid so I can reorder information and drag things around, and the next step was to work out how such a thing might be implemented. The _actual implementation_ is still a fair way away, but I have a good idea of what I need to do.

Failing gracefully goes beyond that. (At this point in time I have no idea how much error handling OS X will provide or how the whole thign works – it honestly isn’t something I’ve looked into.) I think that asking yourself ‘what if it fails’ at every stage of the application might easily lead to paranoia – but on the other hand, when things go wrong, you’ll be able to at least display a useful message to the user.

The trick will be, I think, to anticipate high-level errors. You cannot possibly think of every way in which [open file] can fail (and a good number of them are listed in the article, some of which I hadn’t thought of), but you _can_ test whether your application was able to read the kind of information it expected, and put up an error otherwise.

Posted in Culture of Programming, Error Handling, Resources | Tagged | Leave a comment

Resource: Application Design Chart

On Cocoa with Love, which I should read more often anyway, I came across the following:

http://cocoawithlove.com/2010/06/design-of-every-mac-application.html

This article goes a long way towards explaining how a complex application works and helps to bridge the gap between MyFirstCalculator and the kind of thing that I eventually want to write – it is based, not on theory, but on _practical experience developing working applications_ and it shows. I was, for instance, reassured by the mentioning of 400 classes in a large-ish project – not that I intend to have that many, but the little buggers are multiplying like kudzu, so it’s reassuring to hear that this is normal.

This is the rare article that I want to print out and keep next to my desk and refer to again; I am the sort of person who needs to have an overview over what they’re doing – a Gestalt learner – and who needs to see how whatever I’m doing – a model here, a function there – fits into the application as a whole; I can’t just develop things sequentially and eventually fit them together, I need to know how whatever I am working on fits into the application as a whole.

I don’t have much to say about the article itself. I have just enough competence to recognise _it’s_ competence. As me in a year or two whether it was helpful.

Posted in Resources | Tagged | Leave a comment

Platform Independence: a critical view

The other day, the hours I have spent learning Objective C and messing with Cocoa paid off: I was able, without too much effort, to identify an application as Not-Cocoa and to spot a long list of things that would have been better (in some cases, *much* better) if the programmer had used Cocoa to write it.

It was that rare beast, an application that had been ported to Mac from other platforms without being rewritten from scratch.

Specific software and general musings

Posted in Culture of Programming | Tagged , | Leave a comment

Sorry about the hiatus

Life intervened. I haven’t spent a lot of time thinking about programming (and managed to lock myself out of this account, which took a little work to resolve).
This is interesting in that the difference between things I had understood (they only need a little activation for me to go ‘oh, yes, of course’) and things I had mistakenly thought I had understood (‘huh?’) is becoming very obvious, so I am, in a way, starting again, but at a different level.

Posted in EC meta | Leave a comment

The peril of hidden assumptions

This is something I run into all the time in various programming-related fields: the assumption that everybody knows how to do technique x, or that nobody will ever do y, and they therefore do not need to be referred to.

Examples that I’ve come across recently are:

 

Detailed Examples

Posted in Culture of Programming, Teaching Programming | Tagged , | Leave a comment

One aspect in which Cocoa is definitely not welcoming

What the heck, I’ve already got a ‘rantage’ tag.

OS X owes a fair amount to the Next computer system. Cocoa – and the various frameworks that make up its functionality – owes a lot to the old NextStep programming environment. (Whatever it was precisely, I played with Next for a few minutes about fifteen years back.)

This means that almost everyhing – other than a couple InterfaceBuilder items and the iPhone UI classes is prefixed with ‘NS’.

If you’re a thinking person, particularly European or with a knowledge of history, you’ll hopefully have winced just now.

I’m a historian. I’ve curated a small exhibition about life in the Third Reich, and every time I see and type ‘NSSomething’ I feel uncomfortable. There’s no way to get around it – if I want to write applications for my Mac I will have to use this term, but it’s an example of cultural insensitivity, and I hope that Apple will move to a different prefix at some point.

Posted in Culture of Programming | Tagged , | Leave a comment

Catalogue of resources

I’ve briefly talked about two resources that do not work for me: books that attempt to teach you by showing you how to create an example application (here) and relying on other programmers (very briefly touched upon here.)

In this post, I want to talk about the resources I *do* have. How much they’ll ultimately contribute to my goal remains to be seen – I am yet at the beginning of my journey – but there are quite a few.
Resource List

Posted in Teaching Programming | Tagged | Leave a comment

A different view on learning to program

While looking around for articles on how to learn programming from a more abstract point of view, I came across the following article:
Teach yourself programming in ten years.
Go and read it, it’s thought-provoking.

It’s nine years old, and it’s every bit as relevant as if it had been written yesterday, and *that* is the scary part. The individual books have changed, and I’m sure that he’d add a few more ‘must read’ books to his resources, but other than that, it’s still extraordinarily relevant.
Discussion

Posted in Culture of Programming, Teaching Programming | Tagged , , | Leave a comment

Programming books as learning resource

With two exceptions – I’ve reviewed PHP Programming Solutions and shall review Cocoa Design Patterns later – the books I’ve seen on Cocoa/Objective C (and a number of other languages/topics) follow the same pattern.

  • Introduction
  • Taster Project
  • Projects of Increasing Difficulty
  • That’s it. The Intro can – if Objective C is covered in detail – be quite long. The taster used to be Hello World; these days most introductory Cocoa text skip the command line output and let you build a real, live, mini-application, just so you can et a taste for Interface Builder and how easy it is to hook things up.
    After that, the pattern tends to be that you are taken through projects in increasing difficulty – sometimes a single application, sometimes several.

    I’m not disputing that this can be enormously helpful. Anyone who sees the ease with which Cocoa allows you to build a fully-functioning Mac application with very little effort will be hooked – should be hooked, and it is wonderful to work through a more complex project and see what -it – and you – can do.
    However…

    Posted in Culture of Programming, Teaching Programming | Tagged , , , , | Leave a comment

    Why accessibility matters

    So there’s no easy way to learn how to program. [1] Why should you care? Particularly, why should you care if you’re one of the people for whom the process works?

    Personally, I feel that fairness and making things accessible to people are goals in themselves, goals that do not need justification. Whenever you begin to justify a goal not because of some intrinsic humanitarian quality (women should have the same rights as men, nobody should beat up a child) you at the same time make it easier to convince people of an argument’s validity and take away part of its fundamental truth. Doing something worthwhile because you can see the economic or social advantage isn’t the same as doing it because it’s _right_.

    But anyway, a few arguments

    Posted in Culture of Programming | Tagged , , | Leave a comment

    Review: PHP Programming Solutions

    Vikram Vaswani: PHP Programming Solutions. New York et.al 2007 (McGraw-Hill)

    The observant reader will notice that this is not a book about Cocoa. It is, however, a book that gets it right, and of all the computer books I’ve read and attempted to read, it is handsdown my favorite.

    This is a reference work, split into twelve chapters, each dealing with an area of problems programmers encounter again and again. Working with strings, functions, files, HTML…

    If ever you find yourself wondering ‘how do I do X’ this is the book to consult: once you have defined your problem (I want to include a header, I want to send e-mail, I want to split content into pages) you can find a solution. And not only does the solution come with code printed where you can see it, this book gives you comments, warnings about what you need to consider, quite often giving you ways of extending the functionality, mentioning alternatives, comparing the PHP behaviour to other languages… in short, you don’t just get a function, you get its context, too.

    I would not *quite* sell my firstborn to get a similar book for Cocoa – I have an acute shortage of firstborns – but that kind of resource would be invaluable.

    I’m reviewing this book – and reviewing it first – to prove that providing useful resources is possible and has, in fact, been done for other languages. Since Cocoa programming is not _just_ about the Objective C language but also about using Cocoa-specific design patterns, a Cocoa equivalent would take a different form, but the first step has been made: after someone worked out how to efficiently present information so users can speed up their programming tenfold, ‘all’ that is left now is to fill in the gaps with actual information.

    Posted in Resources, Teaching Programming | Tagged , | Leave a comment

    Should programming be difficult?

    When I’ve complained about the difficulties in learning how to program, one of the sentiments I heard repeatedly was ‘Programming is insanely difficult’ or words to that effect. Don’t expect to find it easy.

    I’m having difficulties accepting that.

    There *is* a dimension of programming that is ‘insanely difficult’ by most people’s standards. There are people who develop operating systems and programming languages; who optimise millions of datasets and computer instructions into smoother, more efficient units, who write drivers for devices that have not yet been finalized-

    Those people don’t use Cocoa in their line of work. I have every inch of respect for them, but I don’t want to join their ranks.

    Programming levels

    Posted in Culture of Programming, EC meta, Teaching Programming | Tagged , , | Leave a comment

    Code Formatting test

    I’m using this post to test code formatting, so the function blow was hastily written and might not work, but it was a good test to see whether I had understood basic functions well enough to make one up on the spot.

    @implementation Tiger
    - (int) countStripes
    {
    int i;
    int stripecount;
    for (i=0, i<[stripes count];i++)
    stripecount=i;
    return stripecount;
    }
    

    This is, admittedly, a rather silly function, and I have no idea whether [something count] works – it loops through the number of stripes on a tiger and returns a variable. You could have set it directly by using stripecount=[stripes count];, but it should be a valid example of a loop.

    Posted in Virtual Zoo | Tagged , | Leave a comment

    Welcome to Extelligent Cocoa!

    April 2011: I have finally identified the main reason for my frustration with the process of learning how to program Cocoa applications: most resources appear to cater to procedural learners. This has left me – a Gestalt learner – frustrated and wondering how *anyone* could learn like this; with hindsight I must admit that there probably *are* people who learn like that, I’m just not one of them. I’ve felt excluded from a community that mostly says ‘this is what you need to learn’ without considering that maybe I need to learn something completely different first, so one of the things I’ll be doing on this blog is to provide a completely different approach.

    What you will find here:

    • Examination of resources available for Cocoa programmers
    • Talk (ok, rantage) about the ‘programming is insanely difficult’ culture
    • Discussion of learning styles and how to develop better resources for Gestalt learners
    • Adventures in coding where I chronicle my personal journey
    • The Virtual Jungle, or rather, -Zoo. Instead of piecemeal applets like Hello World and calculators I plan to be talking about the programming challenges involved in an application of real-world complexity. I’ve settled on programming a virtual zoo because you can show both simple and high-level problems, and since no example exists, I’ll have to _develop_ it. Following examples is very well; but the step from there to creating proper applications is largely uncharted territory.
    • A resource Wiki. More often than anything else, I find myself looking for answers to ‘how do I [open a window/add an image from a filepath/use a dropdown menu with Core Data]‘. Some of these answers take days to hunt down… and they shouldn’t. I want to put them in a public place so that the next time I look for something I’ve already worked out, I’ll find it; and I hope it will be useful to others, too.
    • Snippet Posts. I am still dithering how to implement this feature. I would prefer to keep them off the front page, and have experimented with custom post features; but right now those don’t work very well (no honouring the ‘more’ tag, title does not get turned into a post link, hence no ability to address a post directly), and I’m thinking of folding them back together after all – I already spent an insane amount of time trying to figure it out, and it’s not really worth the hassle.

    Unless things change drastically, this blog will be Objective C only. I’m sure there are weird and wonderful things you can do with Java, or by mixing Objective C and other variants, but life is complicated enough that I don’t want to complicate it further.

    Posted in EC meta | Leave a comment