Code

My bromance with the Clang Static Analyzer

As I was building our first iPhone application for MuchMusic, my new best friend the “Clang Static Analyzer” came to the rescue many times, watching my back and offering sound advice.

Well, we’ve finally wrapped up version 1.0 of our first iPhone app. The good people at MuchMusic decided we were the guys to bring their concert listings app, Much Concerts, to life. And we couldn’t be happier.

Throughout the adventure of making our first real-deal app we took many wrong turns and hit plenty of walls and dead ends, but that’s what learning a new platform is all about. As long as you learn from your mistakes and are willing to rethink your strategies you’ll be ok. Oh and you have to do a lot of reading, and I mean a lot!

One thing I read about, which is absolutely invaluable, is my new best friend, the Clang Static Analyzer. Like a good friend, it watches your back, lets you know when you’re doing something stupid, and gives you sound advice. Beyond the metaphor, it analyses your code and gives a detailed report of all the problems you would otherwise discover through runtime testing. It tells you about memory leaks, missing dealloc methods, over releasing objects and all the other wonderful things an Objective-C programmer is forced to cope with. It’s especially good for new Objective-C programmers like myself.

Like a good friend, it watches your back, lets you know when you’re doing something stupid, and gives you sound advice.

Now I’m not going to explain how to use it. This has been done by some very capable people already, however, I will share the resources I found most useful for getting up and running.

http://clang-analyzer.llvm.org/ - Home of Clang. Here you’ll find everything you need to get going.

http://iphonedevelopment.blogspot.com/2009/02/clang-static-analyzer.html - Here Jeff LaMarche provides a very detailed tutorial on how to get started with Clang on the command-line (Yes, it is a command-line tool).

http://www.karppinen.fi/analysistool/ - If you’d rather use a GUI, try out AnalysisTool. For one, it’s got the most accurate no-frills application name I’ve ever come across, and secondly, it makes using Clang extremely straightforward. Just give it the path of your project and hit run. It’s that simple. My only issue with it is the additional checks they added that deal more with coding convention than actual bugs, but thankfully you can filter those results out if you find them unnecessary.

Again, like any good friend, Clang makes the occasional mistake. It’s a work-in-progress so its output isn’t one hundred percent reliable. It does mark false bugs sometimes, aka false positives, so remain diligent. If you’re sure that you’re right and the tool is wrong, report it to the dev team at their bug/feature request page; they’d surely love to hear from you.
In sum, this tool saved me countless hours of testing. Not only does it keep you from ripping your hair out, it helps you develop a more stable, and therefore better, product. With this logic in mind, I encourage you to get to know my friend…the friendship will last forever.

LEAVE YOUR COMMENTS HERE






BACK

CONTACT US

135 Liberty St, Suite 200
Toronto, ON, M6K 1A7
.(JavaScript must be enabled to view this email address)
(416) 840 - 0545
Copyright © 2009 Indusblue, Inc.