Archive for April, 2010

Pure Heart, Clean Code

Tuesday, April 13th, 2010

A month or two ago while processing through a lot of old code, particularly a lot that I didn’t originally write (or at least I’m claiming I didn’t write), it dawned on me how pleasant a world it would be if I could quickly reformat the code – to make the code bend to my will… curly braces on their own line as God intended them… whitespaces where they belonged, and not where they aren’t, etc. So, the adventure began.

From many years with other languages and editors and IDEs, the concept that this would not only be missing from Xcode, but somewhat difficult to obtain was a bit foreign. Nonetheless, with a bit of Internet research, an external tool called Uncrustify, and some experimenting, I coerced Xcode to do my bidding. Oh, before I get started – the Edit->Format->Re-Indent option in Xcode is worthless, so we’ll just ignore it for this outing.

To note, I tinkered with multiple external formatters and the weak internal xcode formatter before I finally settled with uncrustify. Uncrustify has fairly good Objective-C support, can easily be integrated with xcode as a user script, and provides a centralized formatter for pretty much all languages that xcode natively supports.

First stop, acquire Uncrustify. I built mine from source, but if you want an easier route, it can easily be installed by using MacPorts.

Edit User Scripts in Xcode

Once you’ve verified that you have a functional version of uncrustify (uncrustify –version at the terminal command prompt should do the trick – I’m currently using 0.55), the next step is to integrate uncrustify’s usage into Xcode. We need to add a custom script, so open up Xcode, head to the Scripts menu (look for the funky little scroll-like icon) and choose Open Scripts Folder. We need to create a new script with the following:


#!/bin/sh
echo -n "%%%{PBXSelection}%%%"
/usr/local/bin/uncrustify -q -c ~/uncrustify.cfg -l oc+
echo -n "%%%{PBXSelection}%%%"

Input will be Entire Document. Directory will be Selection. Output will be Replace Document Contents. Errors will be Merge with Script Output. I set this script to have a key combination action of Shift-Command-P (P for Pretty).

The only thing left to do is to configure uncrustify to format our code in the specific dialect of style that we prefer. This task is actually quite a bit more difficult than expected. Uncrustify uses a very simple but daunting configuration file. My recommendation, take one of the supplied sample configs (ben2.cfg is very good), merge in the objc.cfg sample, and tweak as necessary. Once you’re done, place the configuration file where specified in your script (above, I used ~/uncrustify.cfg). For those interested, I’ve attached my uncrustify.cfg. I’m still tweaking it here and there, so it’s definitely a work in progress, but it does the job for the most part.

Now, any time my cursor is an editor, a simple Shift-Command-P will reformat my code quickly and to my liking. I find myself now often typing code very hastily without regards to style and formatting and following up with a Shift-Command-P to make it nice and readable.

Hypocritical Rancor

Sunday, April 11th, 2010

The last week has seen quite the bristling of a hypocritical and vociferous group of “developers” and technical pundits. The best recapping of this whole situation can be found at John Gruber’s blog: initial discovery and assessment. The two loudest crowds seem to be the Adobe Flash fans and the C# Mono folks.

Let’s just leave the actual “rule” from Apple aside for a moment and just speak from a user experience perspective.

First, let’s talk performance… The fact that you can make a good performing app with an intermediary language certainly isn’t proof that it isn’t much more likely to have a performant application that is written in a more native language. I mean, if hardware had not gotten faster, we would all be programming in assembly (or C). Abstractions are great for developers but not great for machines. There is a reason Java and C# haven’t taken over the desktop or game development – and the examples that can be given of the few sparse games in those two languages / platforms doesn’t change the fact that other than casual web games and a few Xbox toys, they aren’t used seriously by professional game studios. With mobile platforms, the hardware is going in the opposite direction from desktop hardware. Not to mention, I’m curious about the incongruities of a cross-compiler from a managed memory model to one that isn’t, but hey – maybe they’ve figured it out.

As for user experience, Gruber nailed it. The Kindle application is a very good example of the problem with many cross-platform libraries…. I’ve never seen an application for the Mac written in a language / library other than Objective-C / Cocoa that felt right – and that includes applications written in the Apple approved C / Carbon libraries (which are slowly being deprecated)… If MonoTouch is that good at traversing the paradigms between .NET and Cocoa, that’s damn impressive, but I don’t believe it… The problem is, that on every other platform, interface incongruities are just the norm – expected, so cross-platform libraries are not abhorred as greatly – the users aren’t as discerning. On the Mac and it’s derivatives, consistency of behavior and user experience are tightly defined. I haven’t seen people getting up in arms about the HIG (human interface guidelines). Did you know that you can be rejected from the app store from not complying with the HIG? Now, most would say that’s just more Apple restrictive behavior, but it’s not – it’s protecting the user experience and the platform. Obviously, most didn’t see the HIG requirements as offensive though, although these new requirements are truly enforcing the same thing.

Again, languages and frameworks are not difficult for any experienced developer to pick up. For most programmers, the basics of Objective-C and Cocoa can easily be picked up in days… proficiency can be attained in a couple weeks. Once proficient, why would you choose the targeted platform over another? .NET is a bit a richer than Cocoa, but certainly not worth forsaking the native platform, the tools, the documentation, etc. provided? Flash has no real benefits for a traditionally trained programmer.

As an aside, I think Mono outside of Novell is pretty much dead anyway. I can’t imagine it will ever make major inroads outside of certain niches – folks who need to develop for Linux but have a lot of .NET experience. Many couldn’t be doing Mono right now if they weren’t also Novell partners. Microsoft’s threats have gone a long way in making corporate lawyers nervous, and it’s only through the negotiated protections offered by the Novell / Microsoft partnership that have allowed some to move forward.

As much as everyone has belabored this iPhone OS issue, the rancor towards Microsoft and their general destruction of C# and .NET has never reached similar fervor. The real reason Microsoft has stifled these technologies is often applied to Apple – an anti-competitive bent of protectionism. I don’t deny – I’m sure there is a significant element of this in Apple’s intentions as well – but at least they have a pretty good logical and conceivably more benevolent reason as well.

Even Icaza said it:

“The most important part is that Microsoft has shot the .NET ecosystem in the foot because of the constant thread of patent infringement that they have cast on the ecosystem. Unlike the Java world that is blossoming with dozens of vibrant Java virtual machine implementations, the .NET world has suffered by this meme spread by Ballmer that they would come after people that do not license patents from them.”

Of course, Google is our angel – savior from the capitalistic bastards facing us in Cupertino and Redmond. If anyone thinks Google is any more noble and less evil, keep dreaming. Why aren’t they releasing all their new apps for platforms other than Android? Why did they buy AdMobile (which they knew would be a problem with the SEC) in a move to block Apple from acquiring it? To think that Google is any different is naiveté at its extreme.

In the end, I would rather the new iPhone/iPad platform be more open – or at least have more than one pathway to sale and deployment. But, the raucous rancor and fervor exhibited over the last week is nothing but hypocrisy. Bitter hypocrisy…

A New Day

Saturday, April 3rd, 2010

April 3rd arrives, and with it, the delivery of a new paradigm of end-user computing. Mine happened to be delivered by the UPS woman, all the way from Shenzen, China, molded and formed in the bowels of Cupertino at the bidding of one Steve Jobs. Even as I opined mere months ago in an attempt of prophetic speech, it could not have been anticipated by anyone who’s finger had not laid presence on the device how significant this day would be etched in the computing annals of some future era.

The future is now, and I have seen, nay, caressed it.

Ok, I wax dramatic. It’s some freaking glass, silicon and metal – a small computer with a 9″ screen. This isn’t a technological miracle – this is not some technical innovation that breaks all new barriers of speed, power or even size. What has been brought into this world is a design – albeit an incredible design, that breaks the mold of current end-user computing. After spending a half-day marveling at this device, all I can say is that it truly is a new way of approaching the end-user computing experience, and in every way I have experienced, a vastly superior one.

As of today, 95% of all end-user computing tasks, and probably 100% of most folks typical computer needs, are met with this single device. Not only met, but improved in ways I thought unlikely. This is the first real computer that my parents will ever own that will perform magical incantations of computing without getting in the way. This will be the only computer they will ever need (well, they both will need their own, actually). Amazingly, very few tasks are yet unattainable through this device, and most are external hardware related. Other than software development and some multimedia content creation, I can see even myself almost completely satisfied with this single device. I have no doubt a wave of innovation will appear as the masses explore the capabilities and potential of this device.

No doubt, the iPad has a laundry list of needed improvements and years of maturation, but even in this initial release, it exceeds any and all expectations that I had conceived. It needs a camera (maybe two). It needs some form of 3rd-party application multitasking. It needs better integrated cloud synchronization of data. It would be really swell if the homogeneous application conduit was more open and equitable. Most of the flaws will be fixed, functionality will be amended and increased, and the last vestiges of end-user computing yet attainable by today’s iPad will fall with it, leaving the era of personal computing changed forever.