13 ms·
What's the deal with tab size (8 spaces) in the GitHub UI?
- est31 5y agoWhat the linked thread doesn't mention is that github respects editorconfig files. If you create one in your repo and set the number of spaces a tab should represent, it uses that as default for the repo. Maybe the feature hadn't been launched yet in 2018? https://editorconfig.org/ https://editorconfig.org/
- soraminazuki 5y agoWow, the linked discussion turned toxic pretty fast for something so trivial. It's surprising no one in that thread mentioned that there is a good reason to keep it the way it is, namely to avoid screwing up the formatting of files on GitHub by sticking to an ages-old, well-known default.
- ncann 5y agoLooks like this thread is devolving into a tab vs space war again, an eternal holy war without end except at local level where some VP of engineering put down a decree one way or another and the plebs begrudgingly follow.
- toast0 5y agoThe ideal tabbing scheme is fibonacci. If you can't do that, 8 will do.
- falcolas 5y ago1, 1, 2, 3? Seems like too small an increment scheme. Minor /s here. Inaccuracy in specifications lead to inaccuracies in code.
- toast0 5y agoThe first couple indents don't really need much anyway... Especially if you're writing something like the C# example elsewhere in the thread. if (CompareTag("Player")) in that example is 24 characters in from the side, but four would really feel better. If you're using a language that's less indenty, maybe you want to start further on in the sequence. Although, in all honesty, I've never used fibonacci tabs, it's just something to suggest to move the discussion elsewhere. :D
- FiggyPudding 5y agoFibonacci? Never! Golden ratio with fractional spaces. With fibonacci someone is always going to screwup the whitespace. :p
- jen20 5y agoA useful time for a quote from the Linux Kernel coding standards [1] - exactly the first item in fact: "Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3. Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations. Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program. In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning." [1]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html#indentation https://www.kernel.org/doc/html/v4.10/process/coding-style.h...
- omegalulw 5y ago4 character indents are already too big. 8 character indented code is vomit inducing. 2 character indents and any modern monospace font is enough for readability. I concede that reading 2 indented is hard when you begin braces on a new line - but then your problem is beginning braces on a new line, not the indent.
- SmooL 5y agoI've heard this "no more than 3 levels of indentation" thing before, but isn't that somewhat language specific? If in coding in python, I have 1 level for being inside a class, 1 level for being inside a function, and that gives me only 1 level to write actual program flow with. I find it hard to believe that a double nested for loop, having 4 levels of indentation, is in-itself a sign that I have to "fix my program".
- smnrchrds 5y agoList comprehensions in Python allow you to avoid having to add another level of indentation. If the feature did not exist, a lot of Python code would be one more level deep. Language features definitely have an effect on the number of indentation levels you need. Map and reduce reduce the number, Node-style callbacks increase it, etc. Although I suppose a Linux kernel developer would consider having to write Node JS code as 'being screwed'.
- DiabloD3 5y agoAt least most people are agreeing on using tabs, as opposed to putting spaces in and trying to hardcode their preference. If we use tabs, then we can just have whatever tab stop we personally want, and nobody else is the wiser.
- djur 5y agoThis suggests that spaces are more popular. https://hoffa.medium.com/400-000-github-repositories-1-billion-files-14-terabytes-of-code-spaces-or-tabs-7cfe0b5dd7fd https://hoffa.medium.com/400-000-github-repositories-1-billi... The only exceptions being C, where tabs are slightly more common, and Go, where tabs are the official style.
- BeetleB 5y agoIt's amusing to see this on HN. I always preferred TABs, but for most of my SW programming life I've been told to prefer spaces. I'm actually surprised to hear folks here preferring TABs - I first read your comment as humor. Perhaps the pendulum has shifted (again)?
- forrestthewoods 5y agoHuh? I have never worked anywhere that used tabs.
- encryptluks2 5y agoTruly scary honestly. I cringe whenever I see spaces hardcoded. I feel the same way about line width with hard stops too though. There is no longer a need for line limits and is the whole point of linewraps.
- 83457 5y agoHuh? I have never worked anywhere that uses spaces.
- pasquinelli 5y agoi've never understood why spaces are used for indentation, bit i've ended up adopting it because if everyone else is using spaces, i can't very well use tabs. there's, like, a message in there about life and society.
- edflsafoiewq 5y agoIt's awfully useful for detecting indentation errors. Everyone uses 4, so anything that uses something else will make it obvious when someone has borked up the whitespace (which always seems to happen on projects that use tabs).
- mark-r 5y agoBack when the Tab character was first invented, the indentation was always to a multiple of the 8th column; there was no option for anything else. Not sure why anyone thinks living 50 years in the past is a good idea.
- kazinator 5y agoBecause, the tab being fixed at some specific, agreed-upon value is better than it being a moving target. If you use tabs in a plain text document, you know what they are going to do because of the 8 space tab de facto standard. You could also know what tabs are going to do in a plain text document, if plain text had a standard way to program the tab size. To say, okay, in this line, we have 4 space tabs. Or these specific tab stops at these columns. But here is no such standard thing; therefore, any tab size option ends up being something that is outside of the representation of the text. It's a setting in the text editor, or terminal or rendering software (e.g. monospaced text to ps/pdf). The user has to somehow find out what tab size the text "wants", and then configure it. And that tab size fiddling is a sucky waste of time everyone hates; why can't the text just assume 8 so the default works?
- TJSomething 5y agoThe best reason I've seen for tabs is this one [0], where there were two people working on the same code base with different visual impairments, where one person needed 1 space tabs with a very large font and the other had to use 8 space tabs with a very wide monitor. You can't get that functionality if you assume any tab width. [0] https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/ https://www.reddit.com/r/javascript/comments/c8drjo/nobody_t...
- kazinator 5y agoI read that bit about the two developers also. It was never explained what the 8-space indent person's visual impairment might be; I suspect that it's a field of vision problem: difficulty tracking vertically between distant elements that are expected to be at the same indentation level. Editors can help here by rendering some vertical lines to guide the eyesight. Nobody should have to resort to huge tabs because of a vertical tracking problem. I really think solving the adaptive indentation problem with tabs is a nonstarter. You have to adapt the tools to the reams of existing code, not vice versa. The editor, in combination with recognizing the syntax of the language to some extent, could treat leading indentation spaces in a flexible "tab like" way. Indentation that is excessive to the visually impaired developer could be reduced by assigning fractional widths to just leading spaces, like 1/8, 1/4 or 1/2 a cell. The editor has to separate indentation spaces from alignment spaces for this purpose. Another approach could be that, quite simply: the editor groks the indentation and renders it flexibly. It deduces that a certain line of code is three levels indented and then renders that however the user wants, regardless of whether the three levels come from three tabs, 24 spaces, or a mixture of tabs or spaces or whatever. If the editor knows that two space indentation is in effect, and some line with 30 spaces is deduced to be at four indentation levels, then it knows that eight spaces of that line are rendered as abstract indentation, and the remaining spaces are literal, for alignment. This is not some Hard Problem in software where we have to throw our hands in the air and conclude that the only way is to achieve the requirements is to have tabs in the data.
- lioeters 5y agoThis is why I don't use tabs, and instead use 2 spaces for indentation like a sane and reasonable person.
- LanternLight83 5y agoI haven't seen any poll results (yet!), but I bet we're in a pretty small minority. Two spaces is jist what i find most aesthetically pleasing. Four seems to be the standard among my peers, and the apparent fact that the standard is historically eight boggles my mind.
- lioeters 5y agoWell, it was (kind of) a joke about "sane and reasonable" because everyone seems to have their favorite reasons for preferring one way or another. I agree about it being aesthetically pleasing. For me it's the easiest spacing to read and scan code horizontally and diagonally. And apparently: > using spaces instead of tabs is associated with as high a salary difference as an extra 2.4 years of experience. https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/ https://stackoverflow.blog/2017/06/15/developers-use-spaces-...
- FiggyPudding 5y agoI cowardly use tabs viewed as 2 spaces so if needed in the future some quick lazy code like sed can convert it to 4 spaces or something if someone demands.
- chrisweekly 5y agoThe choice isn't really "tabs vs spaces", it's "(tabs and spaces) vs (spaces)". And 8 char indentation is ludicrous.
- smcameron 5y agoLudicrous, nope, it's the standard. See: linux kernel. To quote from the coding style: "Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3."[1] If it works for a multi-million line C code base like the linux kernel withou any real problem, then it's definitely not ludicrous. If you find yourself indenting too much, then write some helper functions. [1] https://www.kernel.org/doc/html/v4.10/process/coding-style.html https://www.kernel.org/doc/html/v4.10/process/coding-style.h...