5 ms·
> the fact that if tabs are allowed in source code, people will mix them with spaces, resulting in code that looks bad unless you have the exact same tab width
by cup-of-tea 8y ago
> the fact that if tabs are allowed in source code, people will mix them with spaces, resulting in code that looks bad unless you have the exact same tab width preferences as the author.
Every bit of go code shows you are wrong. If a codebase uses tabs for indentation (which is the only place they should ever be allowed) then it's a mistake to use spaces for indentation. My first ever contribution to a free software project (when I was about 15) used the wrong whitespace for indentation. They made me fix the patch and that is how I learnt about whitespace. The example you've shown is just an example of bad code standards, not tabs being bad.
- tom_mellior 8y agoThe problem with the code in question is a problem of alignment, not indentation. Edit: Ah, no, there are some indentation problems too. But it's the alignment that I first noticed because it's so jarring.
- lomnakkus 8y agoWow, yeah, that's why should never change tab width to anything other than 8 unless you're very sure that you've got things set up exactly right tooling-wise.
- ricardobeat 8y agoIf you open it in an editor, you'll see no indentation problems: https://monosnap.com/direct/cSBUU3ik31upjfdxpc8p9RJjLyVtda https://monosnap.com/direct/cSBUU3ik31upjfdxpc8p9RJjLyVtda This is a result of using 'elastic tabs' which GitHub is not able to display correctly (and also the reason people will use spaces for alignment in a tab-indented project).
- tom_mellior 8y agoIf you open it in an editor and have the same tab width configured as the author, you'll see no indentation and alignment problems. If you set a different tab width (the purported advantage of tabs), the code will be messed up (the actual disadvantage of tabs). Not sure why you blame this on GitHub. Emacs with a tab width of 2 or vim with a tab width of 8 will also show this code with broken formatting.
- cup-of-tea 8y agoYep. It's not a github problem, it is a problem with the code mixing tabs and spaces for indentation. It never ceases to amaze me just how many programmers don't understand tabs. I guess it's because they look like spaces Or because every programmer at some point got bitten by the issue but instead of learning how to use tabs correctly learnt that tabs are evil. The tabs vs spaces war is all just a massive misunderstanding due to some people (the spaces people) not understanding tabs (and not understanding that nobody is advocating using tabs for alignment purposes).
- tom_mellior 8y ago> not understanding that nobody is advocating using tabs for alignment purposes It's not about advocating, it's about actual use as in the example above. Tab fans get confused about what they are doing and put hard tabs where there shouldn't be any. If tab users were actually perfectly consistent about using only tabs only for indentation but not alignment, things would be fine. In practice most of them don't understand the issues and even those that do understand them apparently fail to be consistent in practice. Which is not surprising, since tabs are just as invisible as spaces in most environments. I've said it before, I'll say it again: I've worked on several projects that were halfway through a painful tabs-to-spaces transition period, and they all said "no tabs in new code, never again a project where we allow tabs". I've never had the opposite experience. In practice, as used by actual humans that need to work together, tabs don't work well.
- cup-of-tea 8y agoYeah, I guess that is also my experience and it correlates with what I do. I think that tabs for indentation and spaces for alignment is correct, but in practice I use spaces and have done for most of my career (apart from go).
- jasonkostempski 8y agoTabs polute an otherwise perfectly simple concept, fixed width fonts. If they had't existed out of the gate, no one would have ever considered asking for it, especially if the reason was "I want to be able to pick my own indentation level". They'd be laughed out of the industry. You want the whole world to worry about your prefered indentation level every single time they start a new line? Thats never going happen. Take the indentaion level your given and burden yourself with the task of writting a feature for your editor that lets you pick what you like instead. Oh, and have fun fighting with it every time you open a file you didn't write.
- vthriller 8y agouint32_t<3 tabs>pc; double<4 tabs>time; That's not how elastic tabstops work. With elastic tabs you only put one tab between each and every field. (Besides, not all editors support elastic tabstops, not even with plugins.)
- petre 8y agoPerl best practices understandably has a problem with this type of tab usage. It only allows for tabs after a newline and before any actual code but not inside code (for alignment).
- lomnakkus 8y agoAll the world is not golang. Go is actually one of the few exceptions in the world due to having had "go fix" baked into the compiler/ecosystem from the start. That makes a huge difference. It's also quite a simple language and is pretty easy to auto-format reasonably. Few other languages are that easy to auto-format or have that kind of culture where auto-formatting is accepted as a matter of course.
- skybrian 8y agoNit: you probably mean "go fmt". "go fix" is a different tool. (Though "go fix" does also run the formatter.)
- conradev 8y agoRust is working on this: $ rustup component add rustfmt-preview $ cargo fmt
- steveklabnik 8y ago(And rustfix for the “go fix” equivalent.)
- hota_mazi 8y agoGo is actually extremely hard to format automatically: http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/ http://journal.stuffwithstuff.com/2015/09/08/the-hardest-pro...
- self 8y agoThat article is about Dart, not Go.
- andrewflnr 8y agoFurthermore, the difficulties it mentions are pretty much universal across languages.