5 ms·
There's only two ways to write code where the lines of text stay legible regardless of tab size configuration: 1. Use all spaces 2. Use tabs for indentation a
by andrewmcwatters 3y ago
There's only two ways to write code where the lines of text stay legible regardless of tab size configuration:
1. Use all spaces
2. Use tabs for indentation and spaces for alignment
Unfortunately, only individual developers seem competent on their own to do #2, so everyone who cares about readability inevitably practices #1 by default.
You can never use only tabs.
- saghm 3y ago> Use tabs for indentation and spaces for alignment I'm not surprised that this isn't something that projects have been able to adopt successfully very often because I've never found it very intuitive that those are separate things. In what way is "indentation" not also a form of "alignment"?
- deleted 3y ago[deleted]
- zarzavat 3y agoThe other problem with it is that it assumes that people have visible whitespace on, and that their tools even have that option to show whitespace, otherwise it’s like navigating the Fuchsia Gym. I don’t mind if people use tabs but mixing the two is not great.
- yetihehe 3y agoThe worst mixing I've seen: aligning on 4 spaces, but using tabs as a placeholder for 8 spaces. So first stop is 4 spaces, then tab, then tab and 4 spaces. Chaotic evil version of tabs vs spaces battle.
- yencabulator 3y agoWhy would you care about the whitespace? Formatting is a job for computers, not humans. I'm practically unable to `git add` unformatted Go or Rust code, and very happy with the setup: .config/git/attributes: *.go filter=gofmt *.cgo filter=gofmt *.rs filter=rustfmt .config/git/config: [filter "gofmt"] clean = "gofmt" [filter "rustfmt"] clean = "rustfmt --edition=2021"
- zarzavat 3y agoI’m not sure what relevance this has to files that use a mix of tabs and spaces because I’m not aware of any formatting tool that can reproduce that convention. Knowing whether a space in a space-formatted document is for alignment or indentation is AI complete.
- yencabulator 3y agoThe relevance is that I the human don't bother and the tools do it right. Go code uses both tabs and spaces...
- apelapan 3y agoWith a variable width font you can't use spaces for alignment...
- MiddleEndian 3y agoIf you program in a variable-width font, you're on your own!
- GoblinSlayer 3y agoThat is, people using alignment only care that it works on their machine.
- yencabulator 3y agoMonospace is weird legacy technology and a path dependency that people are holding on to for not so great reasons. If monospace was actually a good idea and not a technical limitation of computers from the 80s, books, newspapers, and your comment on this website would be displayed in monospace.
- MiddleEndian 3y agoI dunno man, sometimes things are good in different contexts. Monospace makes stuff really easy to align when programming, and while I do like the idea of elastic tabstops and have tried it out before, in practice they don't work so well.
- yencabulator 3y agoFrankly, I've never desired for things to be aligned in source code. Are you, like, embedding tables of numbers in your code, or just explicitly aligning the equals signs in short = 42 and much_longer = 7?
- tczMUFlmoNk 3y agoA special case of (2) that is easy to do is to use tabs* for indentation and not do column alignment at all. To be clear, by "column alignment" I think we are both referring to patterns like this: myVars = { first: 123, second: 234, afterward: 345, also: 456, } //~~~~~~~~ <- alignment // or: def my_long_function(arg1, arg2, more_args, and_some_more) //~~~~~~~~~~~~~~~~~~ <- alignment This is, e.g., what Go uses for struct fields, and what some Python style guides use for hanging function definitions. Regardless of tabs/spaces preference, both of these are independently bad because they churn diffs unnecessarily: if you change `afterward` to `afterward2` then you need to change all the nearby lines, and likewise if you change `my_long_function` to `my_longer_function`. Some formatters, like Black, Prettier, and (mostly) Rustfmt, avoid this pattern entirely, and they are better for it. * You can do this and still use spaces if you prefer, too.
- junon 3y agoOr just configure your code formatter to do this and forget about ever getting it wrong again.
- brian-armstrong 3y agoThat doesn'f fix the ugly diff spam though
- junon 3y agoof course it does, why wouldn't it?
- brian-armstrong 3y agoWhat? How would it? Do you understand what is meant by that? The problem being referred to here is that a change on one line causes changes to unrelated lines. It makes it harder to pinpoint which line was changed intentionally in a diff and which ones were just caused by tab issues.
- arghwhat 3y agoAligning a character on one line with an arbitrary character on another line is purely a choice of style, not a requirement. It is perfectly doable to do only tabs, but many end up mixing in spaces. The curse of space-only files is in people that manage commit indentation errors, breaking auto-detection in some editors, which propagate to even more indentation errors... All it takes is an inattentive reviewer, or review-less merge.
- thecopy 3y ago>purely a choice of style Sure, but could i not say the same of using any indentation at all?
- arghwhat 3y agoWould you consider a file without any indentation as readable and practical as a file without single-space alignments? Not to mention that in languages like Python, indentation is syntax.
- deathanatos 3y agoReadability of the code is not mere style, and can directly translate into errors being more visible. Compare: a_variable = ( 'lorum ipsum dolor sit amet ' + 'my poor memory has left me quite upset ' + 'for i cannot remember what word comes next ' 'in this long descriptive text' + 'surely this is bound for the incinerator ' + 'but remember any haiku can end, refrigerator.' ) But now if I choose to align certain characters: a_variable = ( 'lorum ipsum dolor sit amet' + ' my poor memory has left me quite upset' * ' for i cannot remember what word comes next' ' in this long descriptive text' + 'surely this is bound for the incinerator ' + ' but remember any haiku can end, refrigerator.' ) … the errors in the first version are now plainly obvious. (Both the missed space, as well as the missed +.) (This is an example. Yes, there are languages for which you don't need the +. There are some for which you do, however. There are also some that resist having the + moved about: for example, in Javascript, the parens become required, or you'll trigger the horrid auto-semicolon "feature".)
- edave64 3y agoSimple solution: Auto formatters - If you have project wide automatic code formatting: Tabs - Otherwise: Spaces Nowadays, most of my projects use option 1.
- starspangled 3y ago> Unfortunately, only individual developers seem competent on their own to do #2, What do you mean? > You can never use only tabs. You can.
- GoblinSlayer 3y ago3. Use tabs for indentation
- mmis1000 3y ago> Use tabs for indentation and spaces for alignment The pains is, most website or editor never handled that well enough. You end up have mixed tab/space at unexpected position and never knew about it. Just banning the tab is probably not the most 'correct' option to fix it. But it is the most feasible one to get the job done. Because fixing all the tool, editors and websites is nearly impossible for an average man.