by inanutshellus · 9y ago · 0 comments
* Joe likes 4-space tabs, I like 2-space tabs, and Jane is old-school with 8-space tabs.
* All goes well until someone aligns something visually, like so:
[tab]void someNiceMethod(int myParamA,
[tab][tab][tab][tab][space][space]int myParamB...);
(What you should do--if you're going to visually align at all--of course, is [tab]void someNiceMethod(int myParamA,
[tab] int myParamB...);
... but humans are humans and IDEs aren't created equal, so this doesn't happen consistently.)* Now it aligns perfectly on my machine, looks mostly ok on Joe's machine, and is ON MARS on Jane's machine.
Thus one-or-more of three futures happens:
* Someone implements a code re-formatter into version control
* Someone re-aligns the code, starting the process over again.
* Someone calls a meeting and demands we all switch to spaces AND IDEs that let you treat spaces like tabs.
[1]: This came up last week (https://news.ycombinator.com/item?id=14560042) and this comment is shamelessly copied from that discussion (https://news.ycombinator.com/item?id=14561223).
[tab]void someNiceMethod(
[tab][tab]int myParamA,
[tab][tab]int myParamB,
[tab][tab]...
[tab]);After talking to several people, I've realised this is very subjective though (what isn't!). I certainly prefer indenting only, without worrying about alignment.
Alignment is what makes ASCII art possible. Without alignment, we might as well be using modern proportional fonts rather than old-fashioned type writer fixed-width fonts (ducks).
var something =
[tab]someReallyLongCallThatWouldExceedMargin()
someObject
[tab].call()
[tab].otherCall(param)
[tab].yetAnother(
[tab][tab]withLong,
[tab][tab]parameters);
I use four literal spaces, but I think this approach would work well with literal tabs. The only problem is most IDEs do not have an expressive enough configuration to do this, nor do I think I could make it easily happen out of the box with tools like indent or gofmt.But using alignment doesn't mean you are childish. It's just a bad habit that leads to many problems.
A couple of examples from the Servo source code, whose coding standard at one time required column alignment:
let construction_item = ConstructionItem::TableColumnFragment(Fragment::new(node,
specific));
self.set_flow_construction_result(&kid,
ConstructionResult::Flow(kid_flow,
Descendants::new()))
There's no good reason for these lines to be so long. If they were formatted with indentation as shown in hawski's example, they would be much shorter.Another example from an earlier version of the code:
ConstructionResult::ConstructionItem(ConstructionItem::Whitespace(whitespace_node,
whitespace_style,
whitespace_damage)) => {
...
}
Wait, is this aligned or not? What happened? Most likely it was aligned at one time, and then some names were changed and it became misaligned.If you use indentation instead of alignment, these problems never happen. And in fact, the Servo coding standard finally allows the use of indentation, and this particular call has been changed to use it.
Now back to the question of tabs and spaces. If you use tabs and only use indentation with no alignment, then it doesn't matter what anyone uses for their tab width. The code will always look perfect whether someone likes their tabs rendered as 2, 4, 8, or any number of spaces.
The code will also look fine for someone like me who prefers proportional fonts. In fact, I think every developer should try using a proportional font for a while. It's a good way to get over the bad habit of column alignment.
A similar issue is formatting for 80 columns. In general, this is a good idea, because long lines can be hard to read and hard to edit. That doesn't mean that you should contort the formatting of your code in bizarre ways to avoid an 85 character line.
[1] not columns. Bitmapped displays don't have columns, and it's objectively measurable that humans read fixed-pitch fonts more slowly.
Problem solved and it works for them
Shoot, just myself using a single IDE I always end up with spaces and tabs and missing indents and oddities. When I have something that's nested and I copy/paste it into another file, some of the spaces/tabs get preserved, some don't, and I end up having to either reformat it or ignore it, and then I forget which div closes which and it's just a headache.
~Humanity
(╯°□°)╯︵ ┻━┻