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

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?

8 Responses to “The endless talk about code syntax standards and an idea to get there quicker”

  1. Karen Says:

    At my company, we use git for version control and while it normally does a great job on merging whitespace changes, sometimes it creates conflicts. Cogito (our previous system), which is a set of wrappers around git, used to choke on file permission differences, it was that bad.

    I’d say it’s worth pursuing. If you haven’t already, check out Perl Best Practices by Damian Conway (O’Reilly); even as a PHP developer, the syntax principles have made my code much more readable. It might give justification for some of your standards and provides a third party to blame for giving up favored syntax styles :)

  2. Adam Patten Says:

    I think setting a syntax standard is a great thing, especially if one of the big guys like Yahoo shares their standards with the rest of us. The tab vs space issue is enough to frustrate me when working with others code. If this goes anywhere, please share!

  3. Ross Bruniges Says:

    I guess its the kind of thing that could really piss off a number of employee’s (especially if it forces them to change a life-long habit) but the benefits do seem to be there.

    If you manage to save your developers valuable work time I wouldn’t think many would argue with that!!

  4. Arjan Eising Says:

    I think it is the best way to do it by software. Code your way, and when you save it automatically will be standardized. Won’t be very difficult for a good software programmer I think.

    The code editor I use can automatically insert X spaces when I use tab (X is a variable you can change). Now that is a start, but I think it would be nice if just when file opening and saving a convertion between you preferences and the standard is used. Same goes for HTML I think. I prefer to use tabs and whitelines in my code, but why can’t Tidy make it tidy when I save it.

    By the way, if there is such an code editor, please notify me. I use Programmers Notepad at the moment.

  5. Ara Pehlivanian Says:

    Having just inherited a larger team myself, I’ve been thinking along the same lines too. I’ve never had much luck with beautifying plug-ins/tools though. If anyone can share any good ones (in particular for Eclipse and DreamWeaver), I’d really appreciate it.

  6. David Joseph Says:

    A Plug-in like that for Eclipse and Notepad++ would be ideal :)

  7. Jeff L Says:

    Yeah, I think plugins like that would be a great idea.

  8. Gilles Ruppert Says:

    We have the same debate at our company. We have been sitting together for a while now trying to standardise code formatting. Even if people compromise and agree, there is always stuff coming back that isn’t formatted in the right way. Old habits die hard and different editors do different things in autocomplete.
    I really like your suggestion of using plugins (even more if you share them with the public! we need some for textmate, aptana, topstyle and dreamweaver ;-)
    Really hope to see that happening!

Leave a Reply

@mediaAjax
Scripting Enabled - hacking the web to be more accessible - London, England 19th and 20th of September 2008
Wait till I come! is the blog of , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).