Quantcast
Channel: Dereferenced.com » PHP
Viewing all articles
Browse latest Browse all 2

Stamp Out Tab-Stops! (An Unsung Holy War)

0
0

At $DAY_JOB, I have for the first time encountered a coding style that I have problems adapting to. It’s not that I can’t do it; I easily re-configured my editors and IDE settings to accomodate it. It just leaves a bad taste in my mouth every time I commit code with tab characters still present.

It’s a quiet holy war, nowhere nearly as loudly fought as Perl vs. Python (Perl, naturally) or Emacs vs. Vi/Vim (I take the Switzerland stance and use both while advocating neither). Do you expand your tabs to spaces? Do you even have tabs at all, have you instead configured your editor-of-choice to bypass them entirely? Do you prefer to retain tabs? Or do you, like the author of these styling guidelines, advocate mixing spaces and tabs together?

To me, that’s the worst of the options– even though you’re using spaces to make sure that sub-elements of a statement still line up, it only takes a few missed lines and a viewer (such as “less”, or converted-printing such as “enscript”) with tab settings that are different than yours. Then, you have source code whose flow is so much harder to read than it needs to be.

And what are the arguments for even using tabs? They’re a hold-over from the days of mechanical typewriters, and some cool steampunk hacks notwithstanding, we don’t use those anymore. Non-software-professional office workers don’t even use them anymore! The closest they come is in word-processing software such as OpenOffice.org or Microsoft Word. Neither of which, last I checked, were popular as source-code editors.

My coding style has evolved over the years, and the way I code now doesn’t always match what I wrote 15 years ago. Sometimes when I look at my older code it can be painful to see stylistic shortcomings. But when I look at code that uses tabs, let alone that mixes tabs and spaces, it’s often outright jarring. Block structures in Java, Perl, even PHP can be all over the place if the author wasn’t careful. And if there were multiple authors, it’s almost guaranteed to be that much worse.

I’ve heard people say, fairly-recently even, that a tab-stop saves bytes over using spaces for the same indentation. Why is this even remotely an argument when terabyte disks are under $200? Is the savings of a few bytes here and there worth the headache of reading code who’s format is skewed by inconsistent tab layout?

I’ve also heard that it’s a matter of keeping people to a consistent style, and that not everyone has their editors set up to convert tabs. That’s an even weaker argument, since even as I started re-learning Vi/Vim, it took me mere minutes to find the proper option to make it always use spaces in place of tabs (that would be “expandtab”, in case you were wondering). In Emacs you can also configure it (because really, what can’t you configure in Emacs?), and likewise it is trivial to set up in Eclipse, Padre, jEdit, etc., whichever editor is your favorite. And consistency in style is so much more than just tabs versus spaces, it seems like an insult to the question of stylistic guidelines to reduce them to this argument. And with tools such as pertidy, there’s no reason to be that concerned about the relationship between editing and style-adherence.

So help me in my goal of stamping out every last tab-stop in source code that you find! End the tyranny of the mechanical typewriter!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images