5 ms·
> admit it, tabs are fragile and a pretty weak implementation Could you elaborate? I don't have a personal opinion here and have only worked in orgs that requi
by wutbrodo 5y ago
> admit it, tabs are fragile and a pretty weak implementation
Could you elaborate? I don't have a personal opinion here and have only worked in orgs that require spaces, but I'm not familiar with the criticisms of tabs.
- gregmac 5y agoFor me the problem happens as soon as tabs are used for alignment, instead of just indent. The benefit of tabs is custom tabstop. If anyone does anything that undermines that benefit, you might as well use spaces to avoid all the problems caused. Consider the following code: if (x) { SomeMethod(paramater1, paramater2, parameter3); } If done "properly", it is: if (x) { <tab>SomeMethod(paramater1, <tab><spaces...>paramater2, <tab><spaces...>parameter3); } What I often see, that totally breaks the entire point of tabs: if (x) { <tab>SomeMethod(paramater1, <tab><tab><tab><space><space>paramater2, <tab><tab><tab><space><space>parameter3); } The same thing happens if you are trying to align table-style code: var badMixedTypeArrayExample = [ [ "some", true, 128, x ], [ "long strings", true, 8, someLongVariable ], [ "and", false, 16384, x ], [ "short", true, 12345678, anotherVariable ], ]; If tabs are used between fields, it will look like a hot mess to anyone with a different tabstop than the author.
- cool_scatter 5y agoWhich is the reason for the very common stance "tabs for indentation, spaces for alignment".
- nybble41 5y agoWhich is easy to say, but hard to make everyone do correctly. First you need to ensure that everyone uses an editor with a "visible whitespace" option, and turns it on, so they can see whether they have the right whitespace. Then you get to spend precious programming time turning one kind of whitespace into another since most editors will get it wrong when they auto-indent. Either use spaces everywhere so you have total control over the layout or forego alignment (other than block indentation). Mixing tabs and spaces is a path to madness.
- PaulDavisThe1st 5y agoThis is part of the reason why editors for programmers and editors for general text editing are not the right thing. I have F11 in emacs bound to whitespace-cleanup, which takes care of it all for me. And supertabs mode in general works just the way it should with tabs-indent/spaces-align. Then there's also clang-fmt, possibley used as a post-receive hook in git (and some other VCS) which makes irrelevant what the programmer's editor did, mostly.
- comex 5y agoCan whitespace-cleanup really differentiate between places where you want a tab for indentation, and places where you want spaces for alignment, where the number of spaces may be greater than the tab width? After all, the only way to differentiate is to guess what you might be trying to align to by looking at surrounding lines… but from a quick search, whitespace.el looks less complex than that.
- PaulDavisThe1st 5y agoYou're entirely correct. Sorry, i forget, whitespace-cleanup is there so that I can remove dangling whitespace from the end of lines. supertab mode is the tab-to-indent/space-to-align magic.
- zkldi 5y agoif (x) { SomeMethod(paramater1, paramater2, parameter3); } You simply should not write this code. It's unclear, and performs nonsense indentation. You could do: if (x) { SomeMethod( paramater1, paramater2, parameter3 ); } If you need your function to use line breaks.
- gregmac 5y agoI totally agree; I personally hate this style of code! However, people still write it (in the same way they screw up tabs+spaces), and in some code bases it's "the style" they use. I've also seen a lot of SQL and LINQ (C#) written in this way, as well as things like: var longString = "Line 1\n" + "Line 2\n" + "Line 3";
- zkldi 5y agoPersonally, I'd go as far to say that `alignment` is an anti-pattern. Setting up an automatic formatter and using tabs is personally the best for all worlds. Space-like alignments like var someReallyLongVar = 5; var x = 10; Are the worst!
- jcranmer 5y agoThe main supposed advantage of tabs is that everyone can set their own custom preferred tab-width and be done with it, but this advantage doesn't actually play out in practice: * There's usually a maximum line length restriction as well, so you need to know what the tab-width is to figure out if a line needs to be broken into multiple lines. * There are also cases where you need exact-column alignment, even across multiple indent widths. A simple example is as follows: module whatever { fn long_function_name_whatever(arg1: type1, arg2: type2, arg3: type3, etc: etc4, do: you, get: my, point: now); } So in practice, tab width for a project is actually fixed to a particular value. And then you discover that wrong-tab-width code becomes quite annoying to read. I hate reading GNU style guide code, which uses 8-space-tabs but indent-width of 4, because the indenting is unreadable unless I mess with the tab spacing for an individual file I'm reading.
- Asraelite 5y agoAlignment can just be done with spaces. This can then be enforced by a style checker. But the maximum line length problem is real. I would be 100% for tabs if it wasn't for this issue and imo it's the only real criticism you can make that doesn't have a good solution.
- zerocrates 5y agoThe alignment in the comment above doesn't work with tabs: your initial line is going to be tab-indented, which means if you want those next lines to align with it you don't have any options for it to work. Now, I tend to find it's better to just avoid that kind of alignment in your code style completely (just push the first arg to a new line so you're not space-ing everything out a mile to match the function call open paren) but if that's your style then you can't really do it with actually variable tab widths.
- rossy 5y ago"Alignment done with spaces" would look like this for that code. module whatever { ->fn long_function_name_whatever(arg1: type1, ->...............................arg2: type2, ->...............................arg3: type3); } It works just fine - tabs for indentation and spaces for alignment.
- convolvatron 5y agoit only works for initial indentation, so people that like columnar layouts are kinda screwed. auto-tabbing tools will take n-spaces and turn them into a tab, which screws up stuff. lets just take the whole idea one step further and either use tools that reformat based on agreed upon styles (meaning a developer could reasonably take the source, preject it into their preferred style and project it back out again). or store the canonical version as structured data in a database and always project it into some text for viewing. broader adoption of formatters has drastically reduced the number of pointless and emotional formatting arguments I've gotten into. lets push that further.