3 ms·
The reason is that when sharing code use of tabs can lead to confusion, subtle, and not so subtle errors, especially in Python, where consistent indentation is
by cutie 14y ago
The reason is that when sharing code use of tabs can lead to confusion, subtle, and not so subtle errors, especially in Python, where consistent indentation is most important.
For example, one person has tabs set to the size of 8 chars and writes a lengthy script. A second person comes along with tabs set to 5 chars and makes changes. The indentation could well be wrong because they see the same file differently. Sometimes you get lucky and you get errors immediately, but other bugs can lurk... like the second statement under an if block for example. Should it be included in the if or not? Bug.
Therefore, tabs aren't worth the trouble they can potentially cause. Never mix them with spaces either.
Also, using spaces is not difficult in a modern editor. You don't have to actually type four spaces each level. You set tabs as 4 spaces in the prefs and then every time you hit the tab key you get 4 spaces instead, and when you hit the backspace it removes 4 spaces (geany does this).
Whatever you use, I suggest turning on the display of whitespace in your editor. It will then show tabs as "--->" and spaces as a dot. Change the color in the highlighting preferences to be very subtle so it does not overwhelm the code. It will help you keep every file you work on consistent and such errors a thing of the past.
- codegeek 14y agoWell explained. I get it now. Thanks
- Rust 14y agoIn your example, if both developers are using TABs instead of spaces, why would it matter that one sees it as 5 spaces and the other as 8? It's still just a single TAB character either way. Plus, each developer has the freedom to choose how many spaces a TAB is - I like 8 when I'm using my big monitor, but I prefer 4 on my laptop. With TABs, I can see it both ways depending on the machine. On the off chance that I'm ever actually editing in a smaller window, I can even set it to 2 characters instead, but when I open that file again on another machine, I can see it as 4 or 8 characters.
- cutie 14y agoYes, there's an error there, conflating two ideas. I think tabs-only can still cause a problem, say when lining up comments on the end of a line because there might be a different amount needed per line depending on its length. Still, you can't be sure what other people will have, so for interop spaces it is. It might not be the case for everyone, but my laptop screen is 1920x1080 and has more room for text than I can use. In a three way merge your strategy could help me perhaps.