5 ms·
I use 2 spaces. The argument stands, though. Code is meant to be read by programmers. If the code you write is unreadable (because of too many spaces), then
by coreyp_1 9y ago
I use 2 spaces.
The argument stands, though. Code is meant to be read by programmers. If the code you write is unreadable (because of too many spaces), then it is wrong, too. Full stop.
I work with a lot of beginners. That is, I teach University programming classes (C/C++), and have for several years. Tabs confuse beginners to no end, because they are different everywhere. Their code looks different from their lab partner's. Their code looks different from the person sitting next to them. They think that they're doing something wrong. Then, when they try to look at someone else's code, it doesn't look right, either, because they don't know how to adjust the tab width setting in whatever editor they are using (it could be Sublime, Notepad++, Vim, Nano, Emacs, etc.). It's just another hurdle for them to think through, and more time lost in a lecture trying to explain it. I have learned my lesson. As a teacher, I teach them to use spaces. When I was an industry developer, I used spaces, too.
When I have to read code that forces a 3 space tab in order for everything to align and to be read clearly, or any other size (which means that I have to adjust my editor's settings just to read that 1 file), then the programmer, IMO, is doing it wrong.
You may prefer tabs, and I abhor them. We can agree on that. I took issue with the tone of the blog post, however, which completely ignores issues that to me are painfully obvious, and then claims that his opinion is rational (implying that an opposing view is not). I very much disagree with his interpretation of the issue, as well as his conclusion.
- flukus 9y ago> When I have to read code that forces a 3 space tab in order for everything to align and to be read clearly, or any other size (which means that I have to adjust my editor's settings just to read that 1 file), then the programmer, IMO, is doing it wrong. You see what you've done though? You've defined everything that is not your personal preference of 2 spaces (I could live with this one at least) to be wrong. > Code is meant to be read by programmers. If the code you write is unreadable (because of too many spaces), then it is wrong, too. Full stop. Oh please tell me this universal definition of readability you've come up with, because the industry standard is 4 spaces that you apparently find unreadable. What you find readable I do not and that's what tabs are for, we both get the readability we desire. > Tabs confuse beginners to no end, because they are different everywhere. Their code looks different from their lab partner's. Their code looks different from the person sitting next to them. They think that they're doing something wrong. Having a class standard makes perfect sense, just like having a company standard does. But they're going to run into much bigger issues than tab sizes. There will be different fonts, different font sizes, different line wrapping, different colors and different screen sizes. All of those will produce different looking code, but I don't see anyone standardizing on those things.
- coreyp_1 9y ago"You see what you've done though? You've defined everything that is not your personal preference of 2 spaces (I could live with this one at least) to be wrong." No, I've stated that making me change my tab settings to read your code is wrong. If you want to use 3 spaces, then that's perfectly fine with me. Just don't make me change my settings in order to understand what you have written. "Oh please tell me this universal definition of readability..." My universal definition is that code should be understandable. Not obfuscated. Not verbose. Whitespace is the issue that we are talking about here (but it is definitely not the only issue), and 4 spaces is fine if the code allows it. But if you have 11 levels of indentation, then 4 spaces is silly. Some languages lend themselves to a heavily-indented structure (especially object-oriented class definitions), and 4 spaces make them unreadable. As for the last point, I agree, but I disagree that the variations in fonts and colors are of the same impact as having the wrong tab width. Again, I refer to my teaching experience. Colors, fonts, font sizes, line wrapping, screen sizes, etc., do not confuse beginners. Tabs do. They are invisible (unless you know the magic setting to make them visible in your particular editor) and they hide spaces (a space followed by a tab aligns with a single tab), which causes problems in a language like Python. [edit: adding this paragraph] The best parallel to the preceding argument is if you wrote code that required a specific font, color, etc., in order to read it clearly, then that would be bad programming, IMO. This is not the case, however, with any IDE that I have seen. That is also why I do not consider these variations to be of the same level as tabs vs. spaces. I get it. Spaces are explicit; tabs are variable. You consider it a feature. I consider it a liability.
- flukus 9y ago> No, I've stated that making me change my tab settings to read your code is wrong. If you want to use 3 spaces, then that's perfectly fine with me. Just don't make me change my settings in order to understand what you have written. That's exactly what tabs do and exactly what spaces don't do. If the code is tabbed then it will use the editors tab width and no one has to change settings. I can open the code on my computer and get a tab width of 4, you can open it on yours and get a tab width of 2, it'll show whatever tab width your editor is set to. Everyone is happy. With spaces on the other hand, if I decide I want 4 spaces for indentation then you're going to get 4 spaces when you read the file. You'd have to reformat the whole file to be able to read it. > I get it. Spaces are explicit; tabs are variable. You consider it a feature. I consider it a liability. But you seem to want the variability, you don't want to be subjected to my setting of 4 spaces because you find it unreadable.