DEV Community

loading...

Discussion on: Who Killed The Tab?

Collapse
bytebodger profile image
Adam Nathaniel Davis Author

I'm gonna pick on you a bit, just because you spelled out this particular sentiment (that I loathe in programming). I don't mean it as anything personal. But here's your quote:

I know (for sure) that the way I see my code is the same way you or anyone else will see it because there's only one way to render a space; with tabs, i don't know if you will have a good experience or not, because it depends on all your tools being set up to handle tabs sensibly

This is what really drives me bonkers sometimes about those who advocate spaces. They're not content to see things with, say, a 2-space indent in their IDE. They must ensure that everyone else is looking at the code with a 2-space indent. We now have these amazingly sophisticated IDEs that can do so much to format code however a particular dev wants to see it. But when you use spaces, you basically undercut all of that functionality.

It's quite possible that you prefer 2-space indents, and Mary prefers 1-space indents, and Joe prefers 9-space indents. And with tabs, everyone can view the code in the way that's most comfortable for them. But I've run into soooo many coders who feel it's imperative that I read code in the way that is most comfortable for them. IMHO, it's one of the most nonsensical forms of control that I've witnessed in dev. I'm sorry, but it's just sorta silly to imply that, if you see the code in your IDE with 2-space indentation, that there's anything wrong if I view that same code with 3-space indentation.

The key here is that you shouldn't be responsible for whether or not I "have a good experience or not". I'm a big boy. I can configure my IDE. If the tabs in the code are too wide or narrow for my taste, I can fix it. And it's not like you have to do a bunch of work to get an IDE to "handle tabs sensibly". It's 2020. As far as I've seen, every IDE handles tabs "sensibly" out-of-the-box. You may want to adjust them to your liking. But it's not as though opening a code file with tabs will blow up an IDE unless it's been heavily pre-configured.

But when you peg everything to a 2-space indent, you're basically saying, "Are those indents too narrow for you? Does it make it harder for you to read the code? Well, guess what?? I don't friggin care. Because I wrote the code with 2-space indents on my monitor. And therefore, everyone else should have to look at it in the exact same way!"

And worst case (pre-lintinters) someone invariably mixes spaces in with tabs (in my experience) . It looks fine to them because they have the same number of spaces as their tab-width, but to anyone else it's downright horrible.

I totally agree with this. Although I would prefer tabs if it were my choice (usually, it's not), I do understand that you need to pick tabs-or-spaces. Because if you start mixing them up in the same project, files start to become a mess when others open them.

Collapse
kallmanation profile image
Nathan Kallman

Thanks for picking on me! :P

I want to agree with you; and I don't want to "control" how you view the code. I'll clarify that I really am focused on the "worst case" of mixed tabs and spaces in my opinion on "know[ing] that the way I see my code is the same way you or anyone else will see it". Which some styles of coding would essentially require mixing tabs and spaces; see this multilined example of a validation in ruby on rails (borrowed from real examples I've seen in production code):

validates :something,
          :presence => true,
          :inclusion => { :in => ALLOWABLE_VALUES }
Enter fullscreen mode Exit fullscreen mode

(We can have a separate discussion on if this is a good style or not, but) How would I write that with tabs? should I have 2 tabs and 2 spaces? 4 tabs and 2 spaces? 10 spaces? Now I have mixed indention that will be subtly broken for everyone who isn't me.

We now have these amazingly sophisticated IDEs that can do so much to format code however a particular dev wants to see it

Just as a counterpoint; not all code is written and read in IDEs. They also appear in command lines; in git clients; in GitHub (or GitLab or BitBucket etc.); in CodePen's; in StackOverflow; in DEV posts and comments :) ...


To be honest, it shouldn't be that difficult for these "sophisticated" IDEs to solve this problem by treating groups of 2 or 4 (or whatever) spaces as something to be rendered with a different width (same width as tab would be). This solves the problem of always being forced to see unaccessible indentation with the problem of getting all the various places code appears to render tabs "correctly".


So, semantically I want tabs; but for historical reasons I see why spaces were chosen.

Thread Thread
defman profile image
Sergey Kislyakov πŸ‡·πŸ‡Ί πŸ‡ΊπŸ‡Έ • Edited

If everyone used tabs, your code example would probably look something like this:

validates
[tab]:something,
[tab]:presense => true,
[tab]:inclusion => { :in => ALLOWABLE_VALUES }
Enter fullscreen mode Exit fullscreen mode

It seems logical to me (a statement with the arguments being a nested thing (thus the indentation)). This would not introduce the problem you described (mixing tabs and spaces), though it might not be liked by some people because there's one line that could be gone.