6 ms·
I can see this is probably a calm point that will definitely not escalate, programmers don't really care about tabs and spaces that much, right???
by robbick 4y ago
I can see this is probably a calm point that will definitely not escalate, programmers don't really care about tabs and spaces that much, right???
- bnt 4y agoTabs
- Accacin 4y agoHeh, I always wondered what the big deal was. I'll just use whatever the company I'm working for uses and not even think about it. To be honest, that's why I love auto formatting cause I never need to think about that stuff, I can just write code.
- spartanatreyu 4y ago"Tabs vs spaces" is often misunderstood (and falsely reported) as a problem of preference. The real problem is that using spaces for indentation is an accessibility issue. The solution is to use tabs for indentation, and spaces for alignment.
- shepherdjerred 4y ago> The real problem is that using spaces for indentation is an accessibility issue. Not this again https://github.com/prettier/prettier/issues/7475#issuecomment-1296955779 https://github.com/prettier/prettier/issues/7475#issuecommen... > Blind programmers have no problems with it.
- bragr 4y agoNot everyone with vision or vision processing issues is blind. Being able to configure custom tab stops is an easy way to control what level of indentation is useful and clear.
- Dylan16807 4y agoThere are perfectly good tools for that which don't require text changes.
- shadowgovt 4y agoAs with all other types of data: the right approach is for model and presentation to be separable concerns. We're struggling with the wrong problem if we aren't asking why the editor can't treat blocks as entities that are displayed however we want.
- LanternLight83 4y agohttps://nickgravgaard.com/elastic-tabstops/ https://nickgravgaard.com/elastic-tabstops/
- dotancohen 4y ago> why the editor can't treat blocks as entities That might with with C, but won't work with e.g. Python.
- int_19h 4y agoPython has syntactic blocks as well, and editors totally can (and do) muck around with their formatting. I don't see any reason why they couldn't handle customizable indentation.
- shepherdjerred 4y agoThe primary accessibility argument is that spaces waste precious space on braille displays.
- Aeolun 4y agoWhy would you ever mix them?! Even when I started programming 15 years ago it was already accepted wisdom that that was a terrible idea.
- Beltalowda 4y agoThis is one of those things that started out as good advice, and then got turned in to an oversimplified parody of the original argument. If you have something like: var ( x = foo other = bar ) Then clearly you should use spaces to align those "="s, no matter if you use spaces or tabs for indentation. Similarly, "hanging indents" like: coolFun(arg1, arg2) Can only be done correctly with spaces, and it doesn't really matter if you use tabs or spaces for indentation; this will still align correct no matter the tabstop size: ->coolFun(arg1, -> arg2) --->coolFun(arg1, ---> arg2) ------->coolFun(arg1, -------> arg2) If you had used tabs, changing the tab size would make it align all wrong. The problem is when you start doing stuff like: if (one) { ------>if (two) bar(); ------>else xxx(); } And then, depending on the tabstop size, things can start looking very misaligned and confusing; this is why Python 3 forbids mixing tabs and spaces in the same function, because it's so easy to make something appear wrong and there are no braces to clarify things. That's what people mean with "don't mix tabs and spaces", not "if you use tabs then the space shall never appear in the file under any condition".
- sublinear 4y ago> If you had used tabs, changing the tab size would make it align all wrong. This is clearly false. You said this after giving a perfect example of how it's done with tabs.
- Beltalowda 4y agoSo you are saying that using a tabstop of eight to align this: -------->coolFun(arg1, -------->------->arg2) Would still look nicely aligned with a tabstop of 4? and 2? Clearly that will not look right.
- mathstuf 4y agoWhile that may be true, "spaces for alignment" is nigh unsupported by all editors I've seen. They insist on replacing 8 (or N) spaces with tab even if in an alignment region. int foobar(int a, ___________int b) // should only ever have spaces (using _ here because HTML) But good luck finding an editor that won't insert a tab when you use the tab key here (willing to be wrong). The other issue I have is that diffs break alignment between undented code and anything with tabs because the tabs "eat" the leading space, but unindented lines are offset by one.
- CoastalCoder 4y agoI'm curious what editors you've experienced that with. I've had some editors that made tab-space conversion an option, but it was never mandatory.
- mathstuf 4y agoWhen I'm working in Git, Go, or Linux code, Vim (and NeoVim) uses `expandtab` in conjunction with `softtabstop` and converts any `tabstop` spaces into a tab (with `noexpandtab`) regardless of whether or not it is "alignment". I've not done lots of development with other editors, but Kate didn't do it and the few times I used Visual Studio, it also had similar behaviors (I'm assuming VSCode inherited that stuff).
- charsi 4y agoWith a .editorconfig[1] file with the correct configs you can get most code editors to insert spaces instead of tabs. [1] https://editorconfig.org/ https://editorconfig.org/
- mathstuf 4y agoWhat configuration is necessary for editors to insert spaces in code like this: https://lore.kernel.org/keyrings/20221109025019.1855-2-linux@weissschuh.net/T/#Z2e.:..:20221109025019.1855-3-linux::40weissschuh.net:1include:linux:key.h https://lore.kernel.org/keyrings/20221109025019.1855-2-linux... If HN mangles the link, it is the addition of the `key_create` function in this thread: https://lore.kernel.org/keyrings/20221109025019.1855-2-linux@weissschuh.net/T/#u https://lore.kernel.org/keyrings/20221109025019.1855-2-linux...
- LanternLight83 4y agoI used to tout "tabs for indentation, spaces for alignment" until I started working primarily woth lisps. Idiomatic lisp indention isn't compatible with regular tab-stops, so the only solution is to go with spaces (maybe losing accessability) or, preferably, to go elastic. https://nickgravgaard.com/elastic-tabstops/ https://nickgravgaard.com/elastic-tabstops/
- brianzelip 4y ago> The solution is to use tabs for indentation, and spaces for alignment. It's the second step that drives me nuts. Why can't/doesn't alignment happen at first step? The inconsistencies of alignment using true tabs, in a monospace plain text environment, grosses me out and decrements my faith in the underlying systems. I appreciate editors w/ settings like `insert spaces when pressing tab` and `the number of spaces a tab is equal to`.
- kazinator 4y ago> The real problem is that using spaces for indentation is an accessibility issue. The problem of leading spaces not changing their size can be solved through programming. Those programmers who have such a problem and need leading space to be rubbery, if those programmers are worthy, will solve that problem instead of complaining that everyone should adapt to them. The use of tabs is detrimental to code bases. Whenever tabs creep in, invariably people use different tab settings and make a dog's breakfast out of the code. Code exhibits indented sub-structures that are internally indented, but not themselves not aligned to a tab stop, but aligned with something. One kind of example is something like: function_name_of_random_length(lambda (a, b) { if (a < b) { indented(); } }, arg2);
- Dylan16807 4y agoSometimes it can make sense to align arguments but I strongly disagree with pushing over a multi-line lambda that way. So I'm not convinced the problem you're describing should ever happen.
- eyegor 4y agoIn soviet python, runtime cares (if you accidentally use a tab in a file that otherwise uses spaces, you get a runtime exception, or vise versa)