Don’t be THAT Programmer – Syntax Sins Vol. 1

CAUTION: This blog post contains traumatizing coding styles. Please proceed carefully!

Whether you work for a company, contribute to an open source project or study, eventually you will have to collaborate on projects and deal with another programmer’s source code.
It’s easy to point out mistakes, design flaws and coding style abominations, but have you ever thought about being judged yourself? What do other’s think about your code and coding behaviour?

Here are some of my favourite (or should I say most hated?) syntax sins I have encountered or committed myself.

spacebar==broken

Every now and then I encounter this kind of coding style:

if(x>=2){console.log(condition?'okay:'+condition:'not okay')}

This is just a short example, but imagine the lack of spaces in a longer file. Readability drops down towards zero, debugging becomes tedious as hell. You will probably go bald trying to read such code.

White Space

Some people call programming “art”. If programming is art, this code is a 2yr old’s finger painting.

What is version control?

If you encounter this kind of bad habit, teach people how to use Git:

// function doSomething(x) {
function doSomething(x, y) {
  /*
  if(x >= y) {
    console.log("last week's output");
  }
  */
  if(x == y) {
    // console.log("yesterday's output");
    console.log("today's output");
  }
  // console.log("initial output");
}

Developers who do this probably also make copies of project folders and rename them “project v1”, “project v2” and so on. GodGit, please help us all.

Tabulator vs. Space

function doSomething(x, y) {
    if(x == y) {
        console.log("Told you so.");
      console.log("Didn't I?");
        }
        if(x == 3) {
          anotherMethod();
    }
 console.log("The end.");
}

Ever opened a file just to look at a completely messed up indentation? Yeah, probably a case of “Space vs. Tabulator”. People use different IDEs with different settings, so this is pretty common among new collaborators.

A good practice is to use EditorConfig and/or ESLint in projects to counter this kind of behaviour. This also applies to other points.

spellingIsKing()

Yes. I get easily triggered by spelling mistakes and typos. Especially if it’s variable or class names.

var incrorrectlySplledFunctoin = function () {
 console.log("Hi mum! I'm in your browser.");
};

This code would get me mad almost instantly. For the sake of my OCD, just don’t do it. Please. T_T

Copy. Paste.

I don’t know a single developer who hasn’t used StackOverflow or example code in the past and present. On the other hand I know some, who solely rely on other’s code and copy code left and right without even putting at least some thought into it.

Imagine finding a function called loadIngredients in your project about maintaining heavy machinery. Or a subtle “sortBy: calories” in your vehicle listing.
I even saw a name being declared as a numeric, because someone wasn’t particularly careful when changing copied example code.

Copying code is fine, as long as you understand what it does and what you are allowed to do with it in terms of licensing.

Do you plead guilty?

Did you encounter or even commit some of those sins yourself? Probably everyone does or did at some point – encounter and commit.
Apart from triggering some people, these coding style mistakes decrease productivity by reducing readability and making it harder to debug code.

So don’t be that programmer. Learn from your mistakes. Help others in and by avoiding them.