C Double Sharp

In both fiction and reality, some partners have wonderfully deep emotional responses to certain languages.

Without giving any bedroom secrets away, I suspect that most of us find French at least mildly erotic, so it is unsurprisingly dubbed ‘the language of love’. The term ‘romance’ for an amorous affair is the same ‘Romance’ used for languages descended from Latin, prominent among them being French.

Even to the most diehard nerd, programming languages are the antithesis of love, whether erotic or platonic; but they also impart their characteristics to what you express in them. Fortran remains forever numeric, Basic belongs in the classroom, and Prolog is for artificial intelligence – although each is capable of much more.

Apple has long recognised the importance of language standards in software development. With the development of the first Mac, Larry Tesler called in the inventor of Pascal, Niklaus Wirth, to implement Object Pascal, which became almost obligatory for Mac development until OS X. As architect of the Newton PDA, Tesler later oversaw development of two new languages, Dylan (from Lisp) and NewtonScript (based on Self), for that platform.

OS X brought from NeXT the Objective-C language, one of the two object-oriented descendants of C, which had originated with Unix. In common with C, C++, and C Sharp (Microsoft’s C derivative), Objective-C is equipped to go low-down and ‘dirty’ as well as for high-level application and interface code.

They all support one of the biggest strengths and weaknesses in the C family of languages, the ability to address memory using ‘pointers’. In the early days of computing this was all but essential, as a ‘pointer’ pointed to the physical address of a block of memory. When accessed through pointers and pointer arithmetic, most code ran far quicker than when accessing memory more safely. Unfortunately this double-edged sword has opened up a long and rich succession of bugs and security holes.

The C family is also fiddly in its syntax. Omit a semi-colon and your code can do something very different from what you intended. As we saw in last year’s flaw in iOS and OS X, inadvertent duplication of a line of code can be hard to spot, and readily opened a hole in the security of SSL/TLS (see here).

Probably the most significant announcement of WWDC last year was the release of Swift, Apple’s next standard language. For the first time Apple has launched a new language before a new platform, and Swift begs questions as to whether, what and when its associated new hardware will be. But for the moment, sticking with official explanations, this looks like a big step forward for both iOS and OS X as we know them.

Swift does away with some of the worst excesses of the C family, particularly those associated with bugs. There is no such thing as a pointer: programmers are denied direct access to memory. The goto control, deprecated almost as soon as it was introduced, has gone, and with it the danger of the mistake underlying that SSL/TLS security hole. Memory management is a lot smarter, with Automatic Reference Counting a good way of combatting memory leaks, but is still far from being as simple in some languages.

Apple refers to Swift as both a general purpose programming and scripting language: a high ambition indeed. Ultimately Swift’s test will come in its implementation, and adoption by developers, which has been encouraging so far.

This could be the start of a new and exciting romance. I hope that it is not an opportunistic one-night stand that we will both regret in the morning.

Updated from the original, which was first published in MacUser volume 30 issue 09, 2014.