6 ms·
At 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
by DiabloD3 5y ago
At 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.
- ModernMech 5y agoI think it’s as simple as the fact that spaces are easy to hit with your thumb, and tabs are hard to hit with your pinky. At least that’s why I do it!
- gpsx 5y agoI think the role of a tab in a code editor is different from the role of a tab in a document editor. I have always used dedicated code editors and prefer tabs (but like you, I use and specify spaces for code style). I think people who use editors that are multi-purpose generally see these alternate usages of tab as problematic or even illogical. I think this is often the linux people, and they are often the most experienced and influential coders. I think that is why spaces are generally seen as the preferred method.
- toddh 5y agoBecause everyone has tabs set differently, so code always looks wrong, even if you use the same editor. A space is a space is a space.
- kevincox 5y ago> always looks wrong Only if you are mixing tabs and spaces in a strange way. If you use tabs reasonably then it looks right to each user's preferences. I think the reason that spaces are popular are that it is more obvious when done wrong. We should probably just have better code review tools that highlight when tabs are used for anything but initial indentation. It is as simple as /[^\t]\t/. The other downside of tabs is that you don't have a well defined line width, but IMHO line limits are a fairly silly lint anyways, you should make the code look reasonable. I find that formatters based on line length limits tend to make code very awkward to read.
- lmm 5y agoWhich fails silently - someone will make a change that looks good to them, but messes up indentation for anyone else with a different tabstop. Indeed two people looking at the same code might disagree about which block some statements were part of. If you want to use tabs for indentation then you absolutely must enforce that they are used consistently, and I've never seen any organisation succeed at that. Whereas if you use spaces then you can simply ban the tab character from all source files (which organisations do enforce), and then at least you guarantee that everyone will see the same thing when they look at a given piece of code.
- gilgoomesh 5y agoWhat you're describing isn't messed up indentation but messed up column alignment (trying to align content on multiple lines). Indent only using tabs, based only on scoped, and there's no possibility of problems. It's super simple to enforce via linting. People who love column alignment are really painting their code on a grid of characters and expect to be able to paint any coordinate. There are even editors that let you click past the end of the line and they'll fill in all the spaces to that point. It's madness, I tells ya.
- lmm 5y ago> What you're describing isn't messed up indentation but messed up column alignment (trying to align content on multiple lines). It's still indentation - the point is lining up the start of a line with some point on the line above. > It's super simple to enforce via linting. And yet I've never seen anywhere manage to actually enforce it in practice.
- fastball 5y agoRelevant Silicon Valley scene: https://www.youtube.com/watch?v=SsoOG6ZeyUI https://www.youtube.com/watch?v=SsoOG6ZeyUI
- torstenvl 5y agoI hate that scene. "I run a compression company" but apparently he doesn't know that spaces are trivially compressible and that both HFS+ and APFS have built-in file compression?
- kazinator 5y agoNo you can't, because material that is aligned between lines that have different indentation gets screwed. struct foo { /* nicely aligned int x; * comment or whatever int y; * designed for two-space tab */ }; struct foo { /* nicely aligned int x; * comment or whatever int y; * designed for two space tab */ }; Only the x and y lines moved when the tab size changed, so the comment is screwed. This is a nonstarter. If you use tabs, assume 8, or don't use tabs. If you want flexible tabs, you must rigidly adhere to formatting rules which ban internal alignment between lines that are at different indentation levels. Problem with this banning is that whereas it reasonably applies to comments like what I showed, those comments are a strawman example of internal alignment. Here is a less of a strawman example: { function(arg, arg, arg, arg); } OK, this will work if we use exactly one tab for both lines, and then spaces for aligning the arguments: { [Tab]function(arg, arg, [Tab] arg, arg); } I'm not sure how good the editor support is for this; on a team of 15, you will easily find two who will mess this up often enough that the team's adjustable tab dream will crumble. If you want code that looks good with different tab sizes, that's a goal. Goals have to be verified and enforced, or they fall apart. You need a well-written commit filter which detects situations where moving tabs will wreck apparent alignment, or else team members need to waste their time policing this in reviews. The most productive thing is to just ban tabs. The code looks one way, modulo your local font setting, and that's it.
- bikeshaving 5y agoAn alternative is to use soft tabs for anything that needs to be aligned, especially if the things appears after other code which is already indented. An even better alternative is to not use align code like this, as it invariably leads to soul crushing diffs and merge conflicts when you have to change the size of the longest line.
- rattlesnakedave 5y agoJust tab in under the function definition on a new line. Done. >The most productive thing is to just ban tabs. There are valid accessibility reasons to prefer tabs to spaces.