4 ms·
Tabs are better, simply because you can view them as you like. Go obviously does this, and Haxe too (with default formatting options, even tho its configurable)
by phplovesong 1y ago
Tabs are better, simply because you can view them as you like. Go obviously does this, and Haxe too (with default formatting options, even tho its configurable)
- gte525u 1y agoThis 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.
- jedberg 1y agoSpaces are better, simply because you don't have to worry if another developer is seeing the code different than you. See, I can do it too. This is why there is an ongoing discussion. Because there is no clear cut answer, just opinions. At least this article brings some data to the discussion.
- PaulDavisThe1st 1y ago> another developer is seeing the code different than you. but that's the whole damn point ... I like substantively indented code, you prefer minimally indented, we should both be happy (and we can be, by using tabs).
- jedberg 1y agoYou could certainly make that argument. You could also make the argument that all the developers on a project seeing the same view of the code enhances collaboration and team cohesion, especially if your team does pair programming. This is often why dev teams have more specific style guides that include things would be considered bike-shedding, like how many spaces an indent is.
- PaulDavisThe1st 1y agoIt seems that you don't understand what a tab character is ...
- jahewson 1y agoWait, no, if there is an 80 character line limit and you like 4 space tabs but I like 2 space tabs, we’re going to have a problem. My code will exceed the line length on your screen or be forced to wrap prematurely on my screen to suit your preferences.
- sokoloff 1y agoI'm not at all convinced that an 80 character line limit makes sense on modern equipment. On punch cards, teletypes, or VGA CRTs? Absolutely. On SVGA CRTs? Probably. On anything modern? No.
- vouaobrasil 1y agoI never bought this argument, because it seems the vast majority of people are fine with viewing tabs rendered as four spaces. And pretty much the default for spaces is four spaces. So I'm starting to think 99% of the world uses 4 spaces and it's the vocal minority that like 3 spaces or 5 spaces viewing for tabs. And in that case, the configurability is rather irrelevant.
- frizlab 1y agoUntil you are visually deficient. Then it matters a lot. Accessibility is not a joke.
- vouaobrasil 1y agoThat is a good point.
- IncreasePosts 1y agoIt seems problematic to have a single character in the entire universe for characters render as variable, user controlled width.
- pepa65 1y agoNo, that is its exact special purpose. And why have more than a single one??
- TheAceOfHearts 1y agoYou can view leading spaces however you like as well. Modern text editors can be configured to display any number of leading spaces as your preferred indentation width. It's not the 1970s anymore, modern text editors easily support something so trivial.