6 ms·
Would someone mind explaining the argument for spaces over tabs? Possibly naive young dev here.
by felixmc 11y ago
Would someone mind explaining the argument for spaces over tabs? Possibly naive young dev here.
- sdegutis 11y agoSpaces work better with my preferred IDE setup. Therefore spaces are inherently and objectively superior to tabs.
- andrezsanchez 11y agoI personally like the idea of tabs better, but prefer spaces because it makes navigating the text less awkward when traversing tabs. It may sound stupid, but for my own stuff it's just more comfortable.
- ktRolster 11y agoHow many spaces do you like to indent your code? Some people like 3 space indentations, some like 8 spaces, and some like 5. It's very personal (but anyone who doesn't use 3 is a reeky brazen-faced mammet). A simple solution is to use tabs, because then every developer can set the tab distance however they like, and they are happy. It breaks down when you have code that is aligned beyond the indent, like this: if(a && b && c && d && e && f ) { In that case, increasing (or decreasing) the tab distance will ruin the intention. The best solution is to use tabs to the point of indentation, and then spaces thereafter, but a lot of code editors don't support that, so in practice it's hard to implement, so people use spaces to preserve their formatting when it gets uploaded to github.
- pcora 11y agoOMG! 3 spaces? EVEN number? 2 or 4. Never even.
- ktRolster 11y agoYou sir, are a reeky, brazen faced mammet!
- collyw 11y agoMixing sounds like the worst option.Its what has cause horrendous looking code in the past when you open someone elses code and they are mixed. Python and spaces for me.
- ktRolster 11y ago> Python and spaces for me. Sounds like you are a very open-minded individual. Not.
- collyw 11y agoI say this from experience, not narrow mindedness. Open a file where it is all spaces, and it looks the same on every machine. Open a file with a mix of spaces and tabs, and it often turns out an absolute mess.
- xorcist 11y agoShort version: spaces doesn't break over time. Longer version: First understand that there is no tabs vs. space. There is only tabs + spaces vs. only spaces. (Because not all indentation line up with tab spaces, and someone may wish to line up assignments, lists, etc.) Only one developer in the history of your project that uses another tab stop standard is then enough to mess up your indentation. And that's just one way to mess it up, in a sufficiently large project some creative developer will find another. Spaces just work and ensures your guidelines are followed. The only downside is a few wasted bytes. It might have been a religious debate in a long distant past when someone actually counted bytes, but today it's mostly young developers who don't know better who engage in it (with a few exceptions). Linus uses spaces. OpenSSL changed to spaces as part of cleaning up their codebase. It's the default behaviour of GNU indent. It is a good idea.
- slavik81 11y agoSpaces always have the same width, so it's harder to screw up formatting and easier to enforce stuff like maximum line width. Tabs width can be set to whatever you want, so everyone can use the spacing they prefer.