4 ms·
This works until someone tries to vertically align something like a table or a line that is wrapped.
by gte525u 1y ago
This works until someone tries to vertically align something like a table or a line that is wrapped.
- marssaxman 1y agotabs for indentation, spaces for alignment
- skylurk 1y agoMeanwhile, I'm trying to get away from languages where whitespace has semantics.
- PaulDavisThe1st 1y agoIt's not about semantics at all. whitespace has (virtually) no semantics in C or C++, but there are few programmers who would feel comfortable reading such code without the suggestive hinting that indentation provides.
- pepa65 1y agoVery few where you can delete or insert whitespace at will, (even if only in the middle of 'identifiers'). I am fine with a (single) space being an important part of syntax, just don't use more than 1 please.
- fmbb 1y agoOnly a goblin would align code. But if you must you can start with a new line and the right indent.
- gte525u 1y agoFrom my experience, it seems to be the people that learned PASCAL first for some reason.
- AdamH12113 1y agoI use tabs for indentation and spacing for alignment. Tables should be aligned with spaces. A wrapped line can be tabbed up to the start of the previous line and then spaced for alignment.
- Arelius 1y agoYes, this. Which the counter point is either, Don't align things, or use tabs for indentation, and spaces for alignment. And maybe you can enforce no alignment, but that's a hard fight to win. And as far as tabs for indentation and spaces for alignment, I've found no practical way to enforce this via tooling/linting. And a rule without enforcement becomes inconsistent, which is how we get files full of mixtures of spaces and tabs, which is how people get frustrated with tabs, and we decide to throw it all out. And inevitably, that's part of how spaces "won"
- throwawayqqq11 1y agoOr dont try to align lines with different indentation levels. Addind a comment with the right amount of tabs as a table header and align all fields with spaces after the tabs would do the trick.
- camel-cdr 1y agoDisallowing /[^\t]\t/ and /^ / is a good start.
- ytpete 1y agoThese regexes don't solve what I think is one of the major common problems/complaints though: using extra tabs past the logical indent point as a shortcut to avoid typing so many spaces for alignment purposes. To take this example from a sibling post: if (foo) { » frobnicate(bar, » ...........baz); } Many people will wind up doing this: if (foo) { » frobnicate(bar, » » » ...baz); } And then your alignment is all messed up if you have a different tabs setting. Checking for that requires something more like a linter with a detailed understanding of the syntax parse tree.
- g-b-r 1y agoAt some point you just have to flog people ;) Anyhow, if code reviewers always use tools that highlight the tabs during the reviews, there's a good chance to catch these things. Maybe you could also have the tab width set randomly at every review, to make these horrors stand out
- bigcojosh 1y agohttps://nick-gravgaard.com/elastic-tabstops/ https://nick-gravgaard.com/elastic-tabstops/
- Arelius 1y agoGreat, so now I need a special editor plugin, and a compatible editor just to be able to properly view code? No wonder why spaces "won"
- mananaysiempre 1y agoThat’s mostly editor braindamage (that has unfortunately leaked into some otherwise very good codebases, like LuaJIT). Indent things with tabs, align with spaces[1]: if (foo) { » frobnicate(bar, » ...........baz); } Both camps will hate you, but things will work just as they should. [1] https://www.emacswiki.org/emacs/SmartTabs https://www.emacswiki.org/emacs/SmartTabs
- jahewson 1y agoActually for me this shows why tabs don’t deliver on their promise. As soon as the user’s tab size is small enough that baz doesn’t need to wrap, the user gets suboptimal formatting. As someone who prefers tabs of 2 and often views code authored with tabs of 4 I encounter this often.
- g-b-r 1y agoYour team should settle on a maximum line length independent of which tab settings one has Of course that will always be a compromise, either people who use narrow tab widths or those who use wide ones will have a (slightly) suboptimal experience.
- phplovesong 1y agoFormatting by hand is probably only going to work for private hobby projects. In 99% of the other cases there needs to be a formatter that does the formatting.
- mananaysiempre 1y agoThat feels both largely irrelevant and false? False, because there are plenty of large projects that do have a house style but don’t use a formatter at code submission to enforce it—even if you reject the Linux kernel as an atypical example, basically every piece of commercial software from 20 years ago also fits, simoly because both formatters and presubmit checks weren’t nearly as common, and there were some chonkers there (like, I don’t know, Windows XP). Irrelevant, because it’s perfectly possible for a formatter to follow this convention (gofmt does, for example).
- fsmv 1y agoThis problem is solved by gofmt because it automatically aligns with spaces after the tab so humans don't mess up the whitespace
- phplovesong 1y agoWheb there i a formatter you should not care. You can rewrite the code if it bothers you.