Even for someone who thinks code, like art, is a form of expression and should reflect the characters of its creator, there is no denying that coding convention is a necessary evil for effective collaboration, especially for shipping production code. So far, my practice has been to cheery pick what makes sense from a number of recommendations, some of which are listed below:
Somehow I get the occasional feeling that my output lacked organization and discipline. Take this class for example, should those init logic really be crammed inside viewDidLoad? And certainly there must be a way to organize initViews into smaller, more manageable chunks? A coding convention I began to follow in the past month, introduced by @samgrossberg and @kompfner, turned out to be a great help.
While yet to be convinced about avoiding NIBs and using AutolayoutShorthand over VFL, code written to this convention does *read* much better. At first glance, the nitty gritty suggestions in the document border on OCD (case in point – import statements sorted alphabetically, really?), but the up side is, while reading through a project’s worth of code written in this style, you find yourself getting into the gist of the code much faster as your brain gets quickly accustomed to the pattern. This consistency surely does have great productivity yields down the road and makes it worth the effort during coding.
I’ll put up a before and after comparison of code written in my old style and this new one to illustrate the difference. Meanwhile, do take a moment to read through the convention below. It’s available as a public gist on https://gist.github.com/kenshin03/7963568.
Do you have a favorite Objective-C coding convention? Much appreciated if you could share them here or via @kenshin03 on twitter.