Coding Standards that ain’t one

Developer Quiz: What are coding standards that do not get applied?

  1. More free-time on weekends.
  2. A non maneuvering ship on the Atlantic Ocean.
  3. A present for president.

Well, probably it might be any of these. But what you can say for sure is, that a coding standard that does not gets applied is not a coding standard at all. That simple it is.

And if the age of code is the excuse for not having it following the standards, then this is just a very lame excuse for being lazy/not having a coding standard.

Automated Testing or not?

The coding standard example is one of those simple but aching misuse of programming tools and techniques. Another good example is the broken testsuite. Having a broken testsuite is more bad than having none. That simple it is.

Spare your project the overhead if you really can not manage an automated testsuite properly. Throw it in the bin. I can understand that this is a hard step as it implies to question all efforts already done in testing. But it only introduces code and work while not giving you anything but a whole bunch of unanswerable questions. And – surprise, surprise – broken testuites just do not attract any developers to write new tests. Writing patches for a testsuite that throws more fails then you can count is just a very unthankful; not to say foolish job.

Example: WordPress Automated Testing results over time

Date Tests Assertions Failures Errors Skipped
3. Nov 2010 505
15. May 2010 489 2919
22. Feb 2010 489 2879 128 54 18

Source: hakre on wordpress, see also.

So when a project is not able to run a testsuite then it should not create the image that it is doing so. That’s just counter productive, even if testing is a well accepted thing in development. Just don’t do it for the others, do it or don’t do it for yourself.

Live with your coding style and your non-test-driven development and be proud of it. Otherwise you’re just introducing complexity that hinders you learing about the real problemstm your project has.

Coding Standards FAQ Style

When does it make sense to have coding standards? — It makes sense to have coding standards from the moment there is more then one coderette handling the chunks, so any project with more than a single developer. You normally automatically create a sort of coding standard when you first-time share the code with another developer and he shares his impressions on coding style with you.

Must coding standards be complicated? — Not at all! In fact, the standards should be very easy to adopt. Like when a new developer looks into a file of a project for the first time it should be immediately clear to her what the coding standards are because the code is properly formatted.

Is it okay to use tools to follow the standards? — Absolutely. There is no rule that every single char has to be written manually and it does not make the coding standard less better if a developer uses a tool like a code formatter. Just keep in mind that if it is a need to follow the coding standard to use specific tools all the time you might have the wrong coding standard because it is a too complicated thing.

Should Coding Standards be written down? — The code should already show the coding standard which normally means it’s documented. If you experience unclear cases in your project, you can write those down giving examples of how to do / not to do things. But keep things simple, it’s a tool that should be accessible for developers and not a complicated science to deal with.

How can I find out if the coding standards are followed in my project? — There are tools and utilities that can be automated to constantly check your codebase and report back to you if there is a glitch or everything is still in order. That spares you a lot of time to check the code manually. This is something useful to have when your project has about five or more developers. For PHP such a tool is the PHP Code Sniffer.

Image Credits: Tower of Babel by Lucas van Valckenborch; 1594; via KoS

Read on:

This entry was posted in Hacking The Core, PHP Development, Pressed and tagged , , , , , , , . Bookmark the permalink.

3 Responses to Coding Standards that ain’t one

  1. Denis says:

    Use Symfony. 😉

    • hakre says:

      Sure, and a bunch of other libs and frameworks. Unfortunately I take a look into the codebase of a very known package as well from time to time by chance ;-). And next to how it looks this bigoted attitude is the cherry on top. This is sort of misleading for new developers who might use it as an entry-point.

      So this article is more about when you start a new project what you can do wrong with coding and development style. It’s somehow a summary what I’ve learned over the last weeks while kicking-off some new development project. Just don’t do it that way 🙂

  2. shazarre says:

    I totally agree with you that not applying even a single convention implies not following a standard at all. That, as you wrote, really simple as that 😉 Then we create standard only based on the previous one. Let’s call it a “parent” standard…

    I think that the truth is, every developers team should develop their own coding standard, based on compromise between each other (and they can, of course, choose some existing standard as a base for their discussion).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.