11 ms·
looking at code like this in github always reminds me why I prefer spaces over tabs, look at all that broken alignment: https://github.com/id-Software/Quake-II
by zorkw4rg 9y ago
looking at code like this in github always reminds me why I prefer spaces over tabs, look at all that broken alignment:
https://github.com/id-Software/Quake-III-Arena/blob/master/code/ui/ui_players.c https://github.com/id-Software/Quake-III-Arena/blob/master/c...
- IshKebab 9y agoExcept in a few cases that code is pretty well formatted I would say. Anyway this is game engine code and very old. I doubt you would find perfect formatting if it were spaces either.
- SquareWheel 9y agoAnd the counter-argument remains that you can customize tabs to whatever length you want. Set "tab-size: 4;" in CSS.
- zorkw4rg 9y agoI'm pretty sure its perfectly aligned if you have the correct tab size that was used for the whole project. Which is the stupidest thing about using tabs over spaces.
- SquareWheel 9y agoIt looks fine to me at even 8, so I'm not sure what you mean.
- zorkw4rg 9y agoexample: https://github.com/id-Software/Quake-III-Arena/blob/master/code/ui/ui_players.c#L700 https://github.com/id-Software/Quake-III-Arena/blob/master/c...
- SquareWheel 9y agoOkay, I can see the issue there. Though it's worth keeping in mind that tabs are for indentation and not alignment. Even people that use tabs would agree that is a poor use.
- martin-t 9y agoTabs for indentation, spaces for alignment. You wouldn't need to customize anything, it would look good at all tab widths and people who prefer 2 space sized indents would be able to use that in their editors. Actually, it could be even better, we could use tabs for aligning to tables too if editors supported elastic tabstops [0]. Unfortunately, the only ones that do don't support other essential features like saving when they lose focus. Please note that i disagree with how the example aligns function params. The space/tab there looks bad and params should be aligned with spaces using a formatting tool (which every sane language should have). Or, y'know, scratch that, why don't we commit the AST (enhanced to include comments and other hints like blank lines) to git and let everyone use their formatting. </rant> [0]: http://nickgravgaard.com/elastic-tabstops/ http://nickgravgaard.com/elastic-tabstops/
- simias 9y agoOnly works if people use tabs for indentation and spaces for alignment which I've never seen anybody maintain successfully on a big project. The code the parent linked is not indentation, it's alignment so it should be formatted using spaces regardless otherwise it breaks that way. If you have to impose tab width to have proper readability then what's the point? Try hacking the linux kernel with tabs != 8 spaces and see how long you last before all the broken alignment drives you crazy. Furthermore if your coding style imposes some kind of width restriction you also have to commit to a certain tab width anyway. Beyond that if you really value configurability it's a bit odd to limit yourself to "I want to configure tab width". How about bracket positions, spacing between operators, variable names etc... ? All these seems are arguably more important for readability and code understanding than indentation. Ideally programming languages would be stored as abstract syntax trees that you can display however you like but we're still using dumb all ASCII text files. In theory tabs are mildly superior to spaces, pragmatically it's spaces all day every day as far as I'm concerned.
- coldtea 9y ago>Only works if people use tabs for indentation and spaces for alignment which I've never seen anybody maintain successfully on a big project. It shouldn't be left to the devs. All languages should have something like Go's gofmt -- or even better, mandatory whitespacing/tabs rules. If you don't respect them (which the auto format tool could help you automatically do), the program shouldn't compile.
- warmwaffles 9y ago> All languages should have something like Go's gofmt -- or even better, mandatory whitespacing/tabs rules. If you don't respect them (which the auto format tool could help you automatically do), the program shouldn't compile. It exists `clang-format`
- coldtea 9y agoFormatters / indent do exist. But they're not widely accepted by most languages devs (like gofmt is by Go programmers), nor is their use enforced by the compiler (even in Go).
- taneq 9y agoThat's the problem, though. People do that, and then to indent 12 spaces, your guy who uses 4-space tabs will put three tabs, your girl who uses 8-space tabs will put a tab and four spaces, and your ace who uses only spaces will put twelve spaces. And after a year of sharing code doing this, your formatting will be farked and you'll spend half your time fixing other peoples' "broken" indentation. I have no issue whatsoever with using tabs in an editor, as long as it saves them as spaces on disk.
- iforgotpassword 9y agoYou do not "indent 12 spaces", you have levels of indentation. If you indent code only using tabs it doesn't matter whether you set your tab width to 4, 8 or 20, it will always display properly. Feel free to change your tab width hourly, still no problem. The only valid argument is that mixing spaces and tabs for indentation messes things up, but that argument works both ways so doesn't support either side in this never ending argument.
- esrauch 9y agoIt is trivial both to ban tabs and to bulk convert tabs to spaces in a codebase or presubmit hook. The other direction seems impossible. That means that if you want to avoid a mixed codebase it is far easier to get to and stay at spaces only than tabs-for-indent, spaces-for-alignment.
- deleted 9y ago[deleted]
- taneq 9y agoStill messes with alignment if you want to do things like keep your comments aligned at the right of the page.
- tinus_hn 9y agoThe solution is to have the repository refuse checkins with bad indentation. Anyone who can program can follow indentation rules, many people just can’t be bothered. But they can if there is no alternative.
- snarfy 9y agoAh yes tab, the only ascii character where the rendering is user configurable.
- dTal 9y agoNot at all. ASCII 0x07 ("BEL") can do anything as long as it notifies the user. Traditionally it makes a beep (volume, duration, and frequency unspecified, settable on X Windows with 'xset b') but implementations vary - OSX Terminal plays the system warning sound, while my Zipit Z2 frenetically blinks an LED. Of course you can also configure all the alphanumeric characters by changing your terminal font. I'm only half joking - it's not supposed to be important what the letters look like, only what they mean. ASCII art is not guaranteed to look good, whether or not it uses tabs.
- SquareWheel 9y agoNot to mention monospace vs proportional fonts. Cool example on BEL.
- nhaehnle 9y agoThis is why you use tabs for indentation and spaces for alignment. Too bad most editors don't have good support for that.
- imron 9y ago> Too bad most editors don't have good support for that. And this is why you use spaces for everything.
- abritinthebay 9y ago... and get the worst possible experience? No thanks.
- recursive 9y agoIt can't be the worst experience if things actually line up.
- abritinthebay 9y agoI was being flippant but... things actually line up if you force everything to tabs too (or “smart tabs” if you really really want alignment for some reason). Except with tabs everyone gets whatever width they want. Tab width is configurable system wide (and even in GitHub’s terrible web view). Spaces are objectively worse in every possible way and require workarounds and editor hacks to make them behave like tabs. Skip a step & just use tabs: much better.
- recursive 9y agoIt's only objective if you're controlling the objectives. Here's my counter-example. Go here in a browser: https://github.com/id-Software/Quake-III-Arena/blob/master/code/ui/ui_players.c#L28 https://github.com/id-Software/Quake-III-Arena/blob/master/c... Note that the use of tabs has caused un-alignment. You've claimed that tab width is configurable in git's web view, but I can't figure out how to do it. And further, if it requires me to configure in a certain way, then it's not really true that "everyone can configure tabs how they want". Spaces. Set it and forget it. Works everywhere, every time. Objectively better.
- hungerstrike 9y agoIf it's so remarkable that you were reminded why you prefer spaces over tabs, presumably since the thing you're doing doesn't happen very often, maybe you shouldn't prefer spaces over tabs. I edit code in an editor way, way more often than look at it on GitHub. Every day when I edit code indented with spaces and my various editors don't correctly handle every edge-case for backspacing, de-denting, etc. I am reminded why I prefer tabs over spaces. It's such a common event for me that I probably wouldn't remark on it without some prompting.
- AdmiralAsshat 9y agoOr just have your tabs converted to equivalent spaces.
- dkonofalski 9y agoBut then anyone else who doesn't also use that same number of spaces is SOL. With tabs, each user can set the display to whatever they want.