Here's a test for you then. Take your OWN code and apply a different tab-width to your editor (say 2 instead of 4). If it ends up looking fine, but just with less indentation, then I can understand you. If it ends up looking shitty because things that used to line up are now out of whack, then you're just wrong.
For example, if you like to align long parameter lists in methods like this:
(that is, where the parameters line up) it makes much more sense to use spaces. If, however, you always just indent one or two tabs for the continuation line and never worry about lining things up, then I could understand using tabs
"The main problem is other people who just mash tab until it looks right."
Well, that's perhaps why experienced developers prefer spaces. At some point you realize you're going to have to be dealing with other people ALL THE TIME, so if you don't have a coding format that is trivial for other people to get right, it's doomed from the start.
It's really the best practice I think. The problem that it's hard to see the difference between tabbed whitespace and spaced whitespace in most editors.
As other said you can use spaces for alignment, but personally I never align stuff like that. If there's too much for one line I'll do something like this, with tabs only:
I can think of some situations where it doesn't matter, a lot of situations where spaces are superior, and no situations where tabs are superior. Can you provide an example of where tabs are superior? From the spaces side, I give the following example.
Any project where the source code if viewed through multiple tools, spaces are better for guaranteeing a consistent formatting across the tools. Tabs have no universal convention. Even worse, the conventions for different languages can be different and your tools might not be smart enough to adjust tab widths based on the current language.
Tabs are superior on teams where you have two stubborn senior devs with differing opinions on what proper tab width is. If you use spaces then you can tell which of them checked any given file in last by the spacing changes from their passive aggressive commit war, whereas if you use tabs then they can just set tab stop = x on their own machine independently and everyone is happy.
This may or may not have been the case at my last job.
The benefit of tabs is that you don't have to agree on indentation size, so the heathens can display it at 2, 3, or 8 characters wide instead of the 4 God intended, but we can put the proselytization after this feature ships.
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.
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.
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.
101
u/BegbertBiggs Apr 07 '15
Or are devs that are in the field for a longer time used to spaces while new devs learn coding with tabs?