Spot any errors? let me know, but Unleash your pedant politely please.

Friday 1 April 2016

Tabs, spaces and alignment.

I just read this...
http://cocoawithlove.com/blog/2016/04/01/neither-tabs-nor-spaces.html

I agree with it all completely, except the parts I disagree with.

I agree that I t doesn't matter whether you tabs or spaces as long as you and your team are consistent.

I think my preferences come from coding on actual VT100s an VT220s in the 80s. Physically 80/132x24 monochrome. 

I prefer spaces. A space is a fixed unit and a tab is unpredictable. You need spaces in your code, but you don't need tabs. It makes sense to pick just one, and that can't be tabs. 

Where I really disagree though, is that manually formatting and aligning to make the code pretty is a waste of time and effort.  Readability is really fucking important. Code is read far more than it is written. To not make the code pretty will annoy or inconvenience readers, including future me. The most valuable tool in making code readable is space. We see this most obviously in left indentation implying or defining scope. It's also good for indicating arbitrary blocks. Or giving a complex line room to breath. 

The other thing that really, really bugs me about this drive for efficiency while coding. I'm not 100% creative coding at full speed the whole time. It's more like crafting or interval training. There's a creative burst, then a period of recuperation. This is when I prettify the code I've just written. There's low cognitive load, pride in a job well done, and I'm ready for the next creative burst. 

In monochrome, there's no syntax highlighting. Keys and values, formal parameters and their default values or actual values, names and literals. They all look the same. Maybe pretty code yields more readability in that context.

While I'm at it… Comments that add value are fine. Yeah, yeah, they can atrophy, and code should be self-documenting, but a little explanation can make skimming the code a lot easier. Anyone maintaining or reviewing code needs to take responsibility for the comments.

Lastly, I was intrigued by this post, in which an editor would present code like an outliner rather than just text: http://inessential.com/2015/12/21/how_to_solve_tabs_vs_spaces_forever





No comments:

Post a Comment