Christian Heilmann

The endless talk about code syntax standards and an idea to get there quicker

Tuesday, August 14th, 2007 at 10:12 pm

As the readers of this blog know, I am currently working in a new team that defines the code standards, best practices and methodologies to follow for the European web development in our company. We’re trying to achieve that using a mixture of commonly regarded best practices and findings in different projects after analyzing their outcome.

There are several things that are a no-brainer, like web standards compliance, unobtrusive scripting, namespacing and so on and so forth. Where it starts to get tricky is defining code syntax standards to follow. Tabs or Spaces? Curly braces on the same line or on the next? Spaces around equal signs or not? Many a religious debate and many a working hour has been held and wasted over these.

A big portion of the endless debate is because code syntax means personal style and people are ready to defend their solution to the issue to the bitter end. A lot of times the solution does not get justified by arguments either but gets sold as “this is how I always did it”.

However, there are several arguments that speak for following a certain code syntax:

  • Code can be easily handed over to other developers
  • Version control works without false positives (a tab changed to a space is a change, but it really isn’t, now is it?)

Now, what can be done about this dilemma? Either you find a concensus and make it mandatory, or you try another option:

  • You define a standardized way of coding
  • You make sure that people create valid code
  • You also make sure that the code can be minified (all whitespace removed) as that should be done with live code to save on file size anyway.
  • You collect the different desired syntax styles
  • You offer plugins for the different editing tools in place (notepad++, dreamweaver, eclipse, textmate…) that can convert the code between the different styles by minifying and re-styling (code beautification).
  • You make it mandatory for developers to run the beautifier that creates the standard syntax before submitting the code to the version control.

It is a bit of work up-front, but it means that:

  • People can code the way they want to
  • Code will be ready to be minified for the live system
  • Developers who buy into the agreed standard won’t have to do anything extra.
  • Other developers have tools at their disposal for quick conversion

What are your thoughts? Worth persuing and sharing the plugins?

Share on Mastodon (needs instance)

Share on Twitter

My other work: