Inspired by the Romans

Roman inspirations

Rome

After two and a half weeks in Italy visiting the sites in Rome as well as Pompeii and Herculaneum, I have been reminded how impressive the Romans were. I still can’t really understand how the whole thing collapsed given how advanced they were.

With Trump in anti Muslim mode, perhaps we need to make contingency plans for getting rid of our politically incorrect Arabic numerals. Despite the impracticality of Roman numerals, the recent Brexit vote tells us that politics can easily override rational thinking. So in preparation (and perhaps in the spirit of the summer silly season), here’s a bit of Swift code for doing the necessary translations:

Meanwhile, I hope everyone is enjoying the MMXVI Olympics. Currently, the UK is number II in the medal table, which is amazing!

A Swift update

A Swift update

A Swift update

Once again, I failed to live up to my good intentions to update this blog more in 2015. So as a new year starts, I thought I would do a few “catch up” posts covering events from last year.

The first one of these is a catch up on the coding front. I’d been playing with Swift right from the beginning, but early attempts at rewriting some parts of my Mac Finances application in Swift rapidly convinced me that Swift just wasn’t ready and I reverted to Objective C. However, I continued to play with Swift on the side as I do really like the language.

The advent of Swift 2.0 prompted me to ‘take the plunge’. I decided to completely rewrite the application in Swift – not because this is a good idea, but because I felt this would be the best way to really learn the language. I took me about 5 weeks to rewrite 12,700 lines of Objective C, working in my not very large amount of spare time, which is either a long time or surprisingly quick, depending on your perspective. It probably took me another couple of weeks to squash the final bugs that I had inadvertently introduced during the process. Overall, I’d say the experience was quite positive.

One of the things that I was intrigued to discover was whether Swift would produce more compact code, so I keep track of things as I converted things over. The outcome was a 13.6% reduction with a resulting Swift code base of 11,000 lines. I did make a few functional changes and refactored some of my earliest code along the way, so I can’t guarantee that this was all due to the language, but I kept track of the reduction as I went and it did seem pretty consistent. The reduction was only a little larger than number of lines of code in the objective C header files, so I think that elimination of these is probably the main saving. But what struck me the most was that the final Swift code was much cleaner and more elegant than the Objective C version and the “proof of the pudding” is that I would be really unhappy to have to switch back now.

Confessions of a closet coder

My first computer

My first computer

I promised myself to post more regularly on this blog in 2014 and after a good start, I’ve let things slide a bit recently. Laziness apart, one of the main reasons is that I’ve been busy on other projects, most notably learning to write Mac and iOS applications. “Why on earth have you been doing that?”, I hear you ask. Well if you want to know the answer, read on. However, I should warn that things are going to get a little geeky, so look away now if you are not into that kind of thing. You have been warned!

I’ve always loved programming. My first experiences, as for many others of my generation was with BASIC. In my case, it involved typing programmes into a teletype machine at school, dialling into the local council mainframe. Back in those days, “saving” your programme meant punching holes in a roll of paper tape.

Ease of use regressed further when I got my first personal computer, a Sinclair MK14. Not only did I have to assemble the machine myself, it had to be programmed in machine code, and I don’t mean assembler. I mean inputting the hexadecimal numbers that represent each instruction. Initially, there was no way to save your programmes at all – you had to type them in again after each reboot, no small task using a 20 key membrane keyboard. The only plus point was that with only 256 bytes of RAM to play with, that’s a maximum of 516 hexadecimal digits to type in.

Over the years, I’ve always tried to keep my hand in and I’ve used PASCAL, Visual Basic, Javascript, PHP, Applescript, BASH and Python. I dabbled at times with C, the low level nature of the language appealing to the machine code hacker in me. But until recently, I’ve never attempted to produce any real world programmes using the language as it was all just a bit too much hard work.

About 6 months ago, I decided to learn Objective C – an object oriented version of C that is used by Apple to develop Mac and iOS applications. I was driven by a mixture of intellectual curiosity and a desire to be able to write real Mac and iOS applications for my own use. Specifically, to replace the 45 sheet Excel spreadsheet that I use to manage my personal finances with something easier to use and maintain (I’ve tried but never liked any of the personal finance apps available in the market).

Objective C and Apple’s Cocoa frameworks have a steep learning curve, even for someone with experience of other languages. The learning resources that I found invaluable were the books from Big Nerd Ranch, video tutorials by Simon Allardice on Lynda.com and the Q&As on Stack Overflow. However, despite this learning curve, after six months my personal finances spreadsheet has been retired. The new Mac app has advanced to the point where it does the job much better. I’m not saying that you’ll be able to buy it on the app store any time soon, since it’s definitely an app targetted at a one person niche market segment. But overall I find it quite amazing that the development tools have now advanced to a point where a hobbyist like me, coding in my spare time, can learn how to build a functional Mac application in such a relatively short space of time.

The world of technology being what it is, just as soon as I’d “finished” learning Objective C (in as much as you can ever finish learning anything), Apple duly announced at this month’s WWDC developer conference that they were replacing Objective C with a new language, Swift. Having spent a couple of weeks playing with it, including experimenting with rewriting some parts of my finances application in Swift, I can say that there is much to like about the new language. To me, it brings many of the ease of use attractions of the Python language, whilst retaining the speed advantages of a low level language built on C. It solves many of the “WTF” moments I had when learning Objective C. To give one example, to add two decimal numbers A & B together in Objective C you have to use the syntax [A decimalNumberByAdding: B]. Swift has operator overloading so even for non primitive data types like NSDecimalNumber, you can use the syntax A+B. They’ve also brought across one of the great things about Python – an interactive mode where you can type commands and get an immediate response without needing to compile and run your code first, a real benefit when learning a language.

So all in all I think Swift will make it even easier to get into Mac and iOS application development. However, just at the moment it presents some additional challenges. Swift is still in beta and you still need to learn Objective C if you want to write apps today. It will take some time for the books, training videos and online Q&As that I found so useful to catch up. It has also given me a new language to learn. It’s a good job I like learning new things!