What is the iPad for?


So Apple's fabled Tablet, the iPad, has finally been unveiled. While many of the rumours turned out to be spot on, at least as many more missed the mark. Inevitably there will be a section of the community who feel disappointed with the reality. After all no single device could live up to every expectation. I mean it doesn't even have sharks with frickin' lasers!

However, while Apple have made clear what they think this device is initially going to be used for I think ultimately it's going to be the developer community that proves whether this really is a new device category. Can you imagine the iPhone now still being just a phone that does email, music and internet? Certainly they are still very much core to the iPhone experience, but what really sets the iPhone apart are the apps that have taken it in directions that Apple would never even have thought of. Of course Apple know that too and have already released a new SDK for developers.

This is what makes this time especially exciting to me, as I am part of that developer community. I have one iPhone app out there at the moment, vConqr, a turns-based strategy game somewhat based on the board game, Risk. vConqr should work quite nicely on the new device as is, and of course I have plans to tweak it to take advantage of the new form factor and features. But I have other apps in the pipeline, including one idea that I have been brewing for about five years now. In fact, back in 2005 I was shopping around for tablet computers, looking for a platform to do my app idea justice, but I never found anything compelling. I had initially planned to write a desktop version, which I did start work on, and when the iPhone came out I put it on my queue for an iPhone version. But when I started hearing that rumours of an Apple tablet device where gaining momentum I realised this could be the ideal home platform. Today's unveiling has turned that hope into reality and I can confirm that I am now fully committed to bringing this product to market.

I hope you'll forgive me for not describing exactly what my idea entails just yet, although I have mentioned it to some people in the past. I'll go as far as saying that it is a productivity app that is largely a synergy of two existing app concepts - both of which I fully expect to see numerous implementations of becoming available, individually, for the tablet (as, indeed, they already are for the iPhone). My offering would not simply be a tool that provided both functions - or even a way of seamlessly switching between the two. I believe the integration of the two concepts leads to a sum that is greater than its parts, and throwing in some extra factors (think "cloud") leads to something that, for the last five years, I've wished I already had almost daily and I'm very excited about finally following through on.

Of course, I'm not suggesting that my app will be the saviour of the iPad! In context my point is that, as a developer, I have ideas for this device that would not work so well on any other platform yet. I'm sure I'm not the only one. What the iPad ultimately becomes associated with is something that will not fully emerge until time has allowed the developer community to provide that answer.

As I start to work on Two Blue [Dacted] I'll post a little more information - just to keep you in suspense. You can also follow me on Twitter as phil_nash where I may say more from time to time.

Technorati Tags: , , ,


Code formatting in C++ Part Three

In this article I am going to present my recommendation for a C++ code formatting style (although it applies to most free-formatted languages, especially those that are C/C++ like).

I have covered the background to most of my choices in some detail (some would say too much - but I invoke Blaise Pascal here) in the first two articles of this series, the rather consistently named:

Code formatting in C++ Part One
Code formatting in C++ Part Two
Since the style I am about to present is a little unusual in places, and arbitrary in others, I encourage you to take a look a the previous articles if you have not already done so. Also, where arbitrary looking numbers are used, follow the spirit of the rule rather than the letter (or, in this case, number).

Page width

The proposals below refer often to page width, and by this I mean the number of characters that you would normally expect to be visible while reading and writing code in an editor. For example, it used to be common to keep within 80 characters (or less) due to text mode screen sizes. These days windows can easily be sized to much greater character widths, but I would still recommend adopting a page width of between 80-100 characters. It is not a hard limit, although it is more important in some areas than others. Personally I still try to stick to 80.

Proposal 1: Formatting variable declaration blocks

char*          txt = "hello";
int            i = 7;
std::string    txt2 = "world";
std::vector<std::string>            v;
std::map<std::string, std::string>  m;

Variable declarations should be grouped together where possible (without violating the principle of locality - ie, keeping them close to first use) in "islands" of no more than 16 lines at a time. If there are more than 16 variable declarations in a group then use single lines of whitespace to break them up. Try to keep variables of similar length in the same block.

Within each block, align the variable names as much as possible. Where there is a large variation in type name length, sub-group longer names and shorter names together and align variable names in sub-group blocks instead (note how the vector and map, above, are separated out this way)

This proposal applies both in function body code and within class declarations (and at global scope, if you must).

Proposal 2: Formatting function signatures

Function signatures come in two forms, and we make a distinction here. The first form is the prototype, usually found in a header file, if at all. The second form is part of the definition and is followed by the function body (if applying this to a language without the separate prototype stage, the first form does not exist, of course). We shall start with that:

Function definition signatures

void ClassName::MethodName
	char*          txt = "hello",
	int            i = 7,
	std::string    txt2 = "world",
	std::vector<std::string>            v,
	std::map<std::string, std::string>  m
	// ... method body

The example here is for a method of a class, but the formatting would be the same for a free function

The return value and function or method name (along with any modifier prefixes - e.g. static, or namespace prefixes) appear on their own line.
Next are the parentheses - both of which appear on their own line - indented to the same level as the preceding line.
Within the parentheses, each on their own lines, are the arguments - formatted according to Proposal 1. Any post-fix modifiers (just const, in this case) appear on their own line, followed by the function or method body.

This is almost certainly the most controversial proposal and I will take up my additional rationale in the next article

If a comment block does not already precede the signature, use a line of forward slashes for about a page width (e.g. I run them up to the 80th column).

An additional point worth mentioning here is that this style lends itself well to being used with the Doxygen "inline comment" method of documenting function and method arguments.

Function prototype signatures

void MethodName
	(	char*          txt,
		int            i,
		std::string    txt2,
		std::vector<std::string>            v,
		std::map<std::string, std::string>  m ) const;

If a separate prototype is required there are some differences to the formatting. This might seem a little odd but I'll provide the rationale in the following article.

First, the parentheses appear in-line with the arguments block, rather than on their own lines. Furthermore the whole block itself is indented with respect to the function name. Finally, any post-fix modifiers (which may include the pure virtual marker here) appear on the same line as the closing parenthesis.

Note that no line of comment characters precedes the signature. Ideally functions and methods would be fully documented at the implementation site and the documentation extracted from comments using a tool such as Doxygen. There are reasons to consider keeping the prototypes clear of too many comments, but obviously you can put them here if you are sure that is best for you

Proposal 3: Function calls

If a function call fits within a normal page width then write it on one line. Long lines should be split across lines according to one of the following two examples:
LongMethodCall1( "some text",
                  anotherArgument );
string returnVal = ReallyLongMethodNameCall
		( "some text",
		  anotherArgument );

In both cases the arguments are aligned, one line each, with parentheses on the first and last lines. The first line should share the line with the function or method name itself, unless that would push the argument list across such that any of the arguments end up beyond the page width

General Principles

The proposals above are deliberately narrow in focus, concentrating on those areas that are often left out of standards, or not sufficiently described, and where using an ad-hoc approach is often less than satisfactory. However there are some simple emergent themes that can be carried through to other areas of code:

  • Types and identifier names are separated into columns through alignment
  • Code is kept within a page width where possible. This is especially significant for code that you need to refer to at a glance, such as function prototypes - and is often where it is most overlooked!
  • For "structural" code, such as function signatures, consistency is especially important, even in places where it seems unnecessary (e.g. splitting short function signatures across multiple lines - even empty constructors). For implementation code the choice of when to split can be guided by the page width.

I have made some recommendations in these proposals that are not specifically backed by the discussion in the previous articles. I will attempt to cover these in the next, and final, article in this series.


Apple's "Magic Mouse" - just sleight of hand?

Magic Mouse

Apple recently released their latest mouse. It's a smooth, minimal design, connected via bluetooth, but of particular significance it claims to be "the world's first Multi-Touch mouse". But how good is it in practice. Do the multi-touch features enhance usability? Does it break Apple's curse when it comes to mouse designs (historically they tend to suck)?

There are many reviews of the Magic Mouse springing up over the internet already - on both professional and personal sites, as you would expect. However using a mouse is such a subjective experience that I feel there is still some value in presenting my own experience so far with it. Not least becausea fair amount of controversy surrounds it

One button to rule them all

Apple are often criticised, if not ridiculed, for only supporting a single mouse button. In fact that is not true and Macs have supported multi-button mice by default since at least the mid-90s, and through third-party drivers since long before then. What they have continued to do until only relatively recently is to ship with only a single button mouse, and advocate that all features should be accessible with only the single button.

In 2005 Apple released the Mighty Mouse, first in wired form, then a year later with a Bluetooth variant. This added not just one extra button - but three (for a total of four)! Unfortunately this mouse had problems - most notably in the very area that it appeared to have finally caught up in! To perform a right click you had to lift your left finger, or else the click was interpreted as a left click! There were also other criticisms, such as the ball clogging with dirt frequently.

Since it was Apple who first popularised the use of a mouse for personal computing, it seems odd that for many years now most discerning Mac users eschew Apple's own mice for third-party devices - usually Logitech. Originally the main reason was the lack of extra buttons, but more recently the implementation of multiple buttons has been badly executed. So the release of the Magic Mouse has been met with much hope that Apple have finally got it right - but have they?

Almost but not quite

Sadly the right-click problem is still there. If your left finger is touching the mouse during a right click then a left click event is fired. If, having read this you are ready to give up in disgust, please read on. Personally I have found this to be not as much of an issue as I thought it would be, and by getting past this sticking point I have been able to enjoy the nicer features this new device has to offer.

First, the USP for the new mouse is its multi-touch ability. Now this is not as fully featured as an iPhone screen, or the newest Macbook Pro/Air trackpads, but since this is in addition to traditional mouse features it's a good first step. At it's most basic it replaces the scroll-ball of the Mighty Mouse, offering full 360 degree scrolling by dragging or flicking (just like on an iPhone screen). Scroll-ball diehards fail to see what the fuss is about, but if you've never liked scroll-balls much, and if you're already used to the iPhone way of doing things, this new surface is very nice indeed. In addition to basic scrolling a two finger swipe left or right invokes the back and forward buttons of a browser, respectively. These gestures are a little more awkward at first, but are still useable. It would have been nice if pinch-to-zoom had been available too, but I suspect that would require a more advanced touch surface to work reliably.

Size matters

What about the form factor. This is another highly individual area. If you're used to the ergonomic styles of many of the Logitech mice, which fill the cup of your hand, you may find the Magic Mouse to be small and cramped. Moving from such a Logitech device myself I did notice the difference, but don't find it a problem. I think the differentiating factor is how long you tend to be tied to the mouse. I can imagine that if you are a graphics designer, or someone who spends the majority of their time with their hand on the mouse, the advantage of an ergonomic design become significant. As a developer I'm generally more keyboard oriented. Switching from mouse to keyboard frequently, if anything, is easier with the smaller design as I only tend to touch the mouse with my finger-tips.

Despite being much smaller than my Logitech, the Magic Mouse is roughly the same weight. This is not unusual since the Logitech I have is a wired mouse. As a wireless device, the Magic is probably at the lighter end of the spectrum - but not so light that it feels flimsy. The weight seems just about right - any lighter and the multi-touch gestures would likely knock the mouse around.

Batteries included

Another criticism of the Magic Mouse is that it takes AA batteries, with no integral charging facility. Obviously rechargeable batteries can be used but then it is up to you to take them out and charge them separately. For a mouse with this form factor I think it would be tricky to get the charging circuitry in too - but I could be wrong. It remains to be seen whether this is a real issue or not. I've had battery powered mice before they've been a minor inconvenience, but then so have those with their own chargers - remembering to dock them all the time. Again this is a very subjective experience

Magic or curse?

So is this the Apple mouse that's finally worth getting? Well it seems this question is tougher to answer than before. It still has the right-click problem, and it has a number of other possible downsides too. However the extent and merits of each are highly subjective, and you may be surprised yourself at the experience. Therefore the only conclusion is to try it for yourself. Fortunately they are readily available for testing out in Apple stores around the world.

Personally I'm really enjoying the experience. The scrolling works well and it feels good for my usage patterns. The right-click problem is less of an issue than I thought it would be. Your Magic May Vary.


DevDays slides


Stackoverflow DevDays London

Yesterday I attended, and presented at, the Stackoverflow London DevDays event.

For various reasons I missed a chunk of the conference, and as my mind was on my own presentation I wasn't quite as attentive to the rest as I would normally like to be.

Nonetheless the highlight for me, and I think most attendees, was Jon Skeet's entertaining, yet thought-provoking, foray into how we can't even get the most fundamental aspects of software right: numbers, text and dates - all accompanied by a sock puppet called Tony. I also enjoyed Christian Heilmann's coverage of the Yahoo YUI web toolkit, and especially the little known YQL. From the twitter back-chat it seems I am not alone in both being blown away by YQL and not having heard of it before!

Divided Opinions

As for my own presentation, one of the points I brought out was that people tend to either love or hate Objective-C.

Objective-C as Marmite

It seems this dichotomy extended to my presentation as well, so I feel it's worthwhile to fill in here some of the things I had to leave out of the talk. Trying to fit an introduction to an "alien" language, a sampling of the SDK, and a coding demo into a 50 minute presentation was always going to be a challenge. Some things had to go. A lot had to go! In the end it was a case of following the adage, adopted by the iPhone community, of do just one thing but do it well. At least the first part worked out.

Why the focus on Objective-C?

There is more to iPhone development than Objective-C. Even if you leave Monotouch out, the bulk of what you need to learn is actually the libraries and platform. Then there's the IDE, Interface Builder (more on that in a moment), the headache of submitting your application to Apple, the review process etc etc.

However, these are all things you can readily read about on the internet or in books. In the case of the libraries learning them is actually pretty easy - it just takes the time to read the docs. Knowing what to look for takes a bit more effort, but even that is usually just a case of googling around. So the value of trying to cover just a fraction of that in the time allotted is questionable. I did try to show a little of XCode and the APIs in my code demo - just enough, I hope, to show that you can get a lot done with a few lines of descriptive code.

But here's the bigger problem: just to be able to demo those few lines of code I needed to explain enough the syntax of Objective-C for the demo to make sense. Learning Objective-C for the first time is not easy right at the start, but that's exactly where I needed to be!

So for my 10 minute code demo to make sense, all the slides preceding that were the minimum that seemed necessary just to get to that point. Just writing the code and hoping people will follow it wouldn't cut it!

But why use Objective-C at all? With Monotouch gaining traction - and just the day before the presentation getting full debugger support - isn't it easier to just use that? Well, I'm not entirely qualified to answer that as I have yet to try it for myself - but it certainly looks very good. In the U.S. my counterpart for the iPhone sessions was Rory Blyth and he seems to be all over Monotouch.

In my presentation I brought out a few points that I believe show that at least a basic understanding of Objective-C is necessary to be an effective iPhone developer - for now, anyway. From what I have heard Rory made similar points in his presentations. They are:

  • Documentation - all Apple docs for the iPhone APIs (except those that are pure C APIs) describe the Objective-C usage.
  • Books and web articles - similarly the majority of these also assume Objective-C
  • Debugging - this was an obstacle, but, as mentioned, has now been addressed in the latest release. Again I do not have first hand experience
  • Not all the APIs have been exposed to Monotouch yet, although it's getting pretty darn close. Notably Core-Data is currently missing and there are other limitations that may or may not be of relevance

Of course all of these will change, although - as with Mono itself - there will always be a certain amount of catch-up as the raw APIs evolve.

Another potential obstacle is that Monotouch has a price associated with it. It's not an unreasonable price, but it may put off those just looking to casually tinker with it. One point that I forgot to mention in the talk (there were a few - due to technical difficulties I did not have access to my notes) was that, even with Monotouch you still need to be running on a Mac! One or two Twitter comments seemed to imply otherwise so it's worth clearing that up. Also, to run on the device or submit to the app store you still need to join Apple's developer programmer at the same cost ($99/ year for a non enterprise membership). Therefore the cost of Monotouch really is an additional cost.

So the premise of my presentation was that, if you still want to pursue iPhone development, whether or not you plan to use Monotouch at some point, you'll need some Objective-C fundamentals and that has a steep initial learning curve. I attempted to temper that by observing that the curve flattens out quite quickly the other side, and that the iPhone APIs are quite sensible, easy to use, and fairly self-documenting (even if this leads to quite a verbose naming style at times).

What I wasn't saying

As often happens when you put yourself out there, some of my motivations appear to have been misconstrued. I did not give this presentation to try and convince anyone to take up iPhone development, nor to dissuade them from doing so. If some have decided that, having seen Objective-C, they want nothing to with it, then hopefully that just means that I saved them some time, rather than doing them any injustice.

My objective (pun partly intended) was really to say that, if you have already decided that you want to have a go at developing for the iPhone, don't be too put off by the initial difficulty - it gets much easier. Beyond that I hope that I clarified some things. If you never intended to do it in the first place I believe it's always beneficial to look at other ways of doing things - regardless of whether you consider them to be better or worse. That was the theme of the conference, after all.

Why didn't I show Interface Builder

This was probably the number one question posed to me directly, or on Twitter. For this I have two answers. Whether they are good answers I make no claim to:

  1. My focus, as I've said, was on Objective-C. Having gone to some lengths to try to give an accessible crash course in the language basics in a small amount of time it didn't seem logical to then almost completely ignore it and use a GUI builder tool. Several people posted on twitter that my demo would have been simpler if I'd used Interface Builder to do it That may or may not be true but that wouldn't have supported what I was trying to do. I do concede that I should have pointed out, at least, that it could have been done using IB.
  2. Not everyone thinks that Interface Builder is worth using for building iPhone apps. Personally I think it's fine for some things, if you're already familiar with it. For many tasks, especially if you'll have to customise the controls a lot anyway, it can add as much complexity as it removes. That is all IMHO, of course, and others are welcome to disagree with it - as they will. My purpose here is just to explain my own motivation in largely excluding it from the presentation

Was it really that bad?


If you didn't see my presentation you may conclude from the above that the whole thing was a disaster! Actually I was pleasantly surprised at the volume of positive chatter on the Twitter back-channel, as well as from people who approached me personally. Obviously I was pleased that they enjoyed the session and that I didn't completely suck, but more than that I was pleased that what I set out to do did reach a good number of people. Thanks to everyone that gave me feedback, good and bad, directly and indirectly. This has certainly been a challenge and I've enjoyed the opportunity of helping people to think along new lines.


I know that I'll have picked up a few extra readers of this blog as a result of the conference, and that they will largely be reading it for iPhone related material. I'm not a prolific blogger, but I have been posting a little more frequently of late, and intend to keep the momentum going. I don't just blog about iPhone development, however. I also cover C# and C++ as well as more general themes. See the archive links on the side for more.