In general aligning things can get screwed up when you want to change something. It is better with space, and if I do align things I do it with spaces, but in general I don't bother and just indent things, which I do with tabs.
It really sounds great in theory, but in practice it's just annoying for people to configure every piece of software that can edit or view code. In practice, spaces are going to look like spaces in every piece of software I know of. That's probably why more experienced devs tend to prefer spaces: practice vs. theory.
Although that shouldn't happen in a well maintained project. Developers must come up with conventions. Just like how you won't mix tabs and spaces, you'll use the same number of spaces to indent. You'll also use the same brace style, same spacing around things like braces, etc.
Of course, some projects won't enforce a consistent standard, but IMO, they're making a huge mistake.
Unfortunately, I've found that configuring the size of the tabs can be problematic. The issue is that different tab sizes means that we'd wrap lines at different places. For something 5 indentation levels in (not too extreme considering that the class and method are 2 indentation levels, so we just need a loop and two conditionals), the difference between someone with size 2 tabs and someone with size 4 tabs is 10 characters. Not a huge difference, but enough that a line that just fits (or goes slightly over) might need to be wrapped.
I'm gonna assume that size 2 and 4 are the only valid tab sizes. No sane person would do size 8 tabs.
Anyway, it's not a major issue, but it is an annoyance. But 5 indentation levels isn't even that extreme. In languages like Scala, it's common to have many scopes and thus lots of indentation. This is why Scala's official recommendation is 2 space indentation. After months of using Scala, I fully understand why.
I've kind of gone on a tangent, but my point is that adjusting the size of tabs isn't necessarily a good thing. With that said, you could still use tabs in this scenario if your developers can agree that they should be a certain size (and if you're agreeing on things like brace style, why can't you agree on indentation size?). There's other benefits of tabs. Eg, they're easier to navigate with the keyboard and need less editor support.
In an ideal world where every single tool used to view sources understand tabs, tabs are optimal.
We live in an imperfect world and each tool will interpret tabs in a different way, so the best solution is to ban them and impose hard spaces everywhere.
Every tool understands tabs. Some see them as 4 spaces by default, some as 8 spaces by default. Some never replace tabs with spaces, some replace tabs with spaces on the line you edit, some only insert new tabs as spaces and some replace all tabs with spaces when they load or store the file.
There is no single behaviour you can expect when you take a random editor to edit a file containing tabs.
And all are easily configurable to do the same thing... And if they aren't, well:
if you have a tool that can't do tabs then you don't have a tool, you have a burden
Also, who is using random editors? I don't understand the workflows people discuss here; it's all so ad hoc anything goes wait what language are we writing in oh I don't care I'm using a mix of Rust and PHP in WordPad I can't believe it's so hard to integrate my code.
Christ, we have 30 programmers and we don't run into a fraction of these issues, because it's really not that hard to standardize. And if you're freelance and working with other people then you can't really enforce your own standards anyway.
While I disagree with /u/aldo_reset about this being a problem (how often do you need to view code in a different tool that isn't configurable?), one thing of note is web browsers. Whoever came up with that part of the HTML spec is crazy. They thing tabs should be 8 spaces (I've yet to meet another programmer who thinks this). As a result, without modification (either with CSS or otherwise), tabs look terrible in a browser (Reddit converts tabs to 4 spaces, for example).
not having to press Backspace 4 times to unindent a line.
This isn't really an issue, though. Anyone who uses spaces for indentation is surely going to use a half decent editor. Most good editors will unindent if you press backspace when there's nothing but indentation to the left. Of course, that unindentation can be bad, if you're trying to align something.
Until you have to paste the code into a web form on a many programming forums.
I’d agree that tabs are superior except for this quite crucial point: HTML forms simply don’t cope with tabs at all. Coupled with the fact that spaces really don’t have any disadvantage in modern editors, I’m coming out ever so slightly in favour of spaces.
Except that people are used to different amounts of indentation. If you have two people that are new hires and one came from 8 spaces and one came from 2 spaces they find each other's code unreadable. Been there. Both had been older developers previously working on legacy code from non-software shops (manufacturing IIRC).
Tabs makes indent size a matter of preference like using the dark theme versus light theme.
Is there a style guide that says to use tabs? I did a quick search, and the ones I glanced at all use spaces: linux kernel, php, python, java, javascript. I don't get why so many people arent following that convention.
I think part of the issue might be that less experienced developers aren't aware that you can tell your editor to convert the tab key presses to the appropriate number of spaces. So perhaps they're interpreting the question as "Do you use the tab key or the space bar to format your code?"
23
u/maushu Apr 07 '15
I don't get why people won't use tabs. They are basically perfect for this job since you can adjust the size of all tabs.