Things I Prefer Not Be in My Code Style Guides

Spaces for indentation and cuddled elses.

JavaScript is getting a wider audience at the office lately so I found myself searching around for JavaScript style guides. With more people very new to writing code maybe some guidelines would help establish good habits? Ultimately I realized the answer was no. Leading horses to water and all that. These things have to come organically from the bottom up and I eventually remembered that suggesting them tends to do the opposite.

But reading through a few prominent guides made me think. You can tell a lot about a community through its rules, reasonings and how they present them. Not surprisingly, I didn’t find one that fit my personal style. Since that’s what personal internet sites are all about…​

Of all the nit picky things that show up in style guides the two that stood out for me where how often spaces are preferred for indentation and all the else cuddling.

Lea Verou covers TABs versus spaces nicely. Spot on.

The cuddling thing? It’s interesting that most places you see talking about bracing show simple if/else examples and nobody is talking about "cuddled else ifs". I prefer the line start with the else if or else. Just like the line starts with the if.

1 2 3 4 5 6 7 8 9
if(inYourHouse) { // do what you like } else if (inSomeoneElsesHouse) { // follow their rules } else { // follow the community's social norms (and the law) }

Much easier for my brain to see the blocks that way.

Of course, "match what’s there" wins over all of this. If you’re in somebody elses' home play by their rules. But when I build my own they use TABs and else is on its own line.