Remix.run Logo
phplovesong a day 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 a day ago | parent | next [-]

This works until someone tries to vertically align something like a table or a line that is wrapped.

Arelius a day ago | parent | next [-]

Yes, 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 a day ago | parent | next [-]

Or 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 a day ago | parent | prev [-]

Disallowing /[^\t]\t/ and /^ / is a good start.

ytpete a day ago | parent [-]

These 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.

mananaysiempre 20 hours ago | parent | next [-]

There are degrees of “detailed”.

For example, I considered writing a small Awk program to check C code in response to another poster’s complaint about lack of tooling, but then quickly came to the conclusion that, with C’s insistence that (say) /??/<newline>* is a valid comment starter, getting this exactly correct probably does need an actual lexer that would go character by character. That sounded like it wouldn’t fit in an HN comment, so I stopped there.

(That said, that’s as far as you’d need to go in the majority of cases. A dishonorable mention is warranted for languages that use the same character as an operator and a paired delimiter simultaneously, that is C++, Java, C#, TypeScript, and Rust with their abuse of the less-than and greater-than symbols, because that would in fact require a parser. In C++ especially, you’ll need full semantic analysis with template expansion, name resolution, and consteval evaluation. Because C++.)

Yet you probably don’t actually need to be that accurate, do you? The majority of syntax highlighters aren’t, and they are still useful. You can usually afford to say that code that perverse deserves to lose, and in return I expect you should be able to gain a fair amount of language independence, which could be worth the tradeoff.

So instead of checking if things are aligned with what they should be, you would just check they are aligned with something, like a left word boundary preceded by a delimiter, and so on. I can already see unpleasant corner cases after thinking about it for a few minutes, but it doesn’t look hellish yet, it looks something like you could experiment with over a weekend to see if it was viable.

g-b-r a day ago | parent | prev [-]

At 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

mananaysiempre a day ago | parent | prev | next [-]

That’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

jahewson a day ago | parent | next [-]

Actually 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 a day ago | parent [-]

Your 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 15 hours ago | parent | prev [-]

Formatting 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 10 hours ago | parent [-]

That 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 a day ago | parent | prev | next [-]

This problem is solved by gofmt because it automatically aligns with spaces after the tab so humans don't mess up the whitespace

bigcojosh a day ago | parent | prev | next [-]

https://nick-gravgaard.com/elastic-tabstops/

Arelius a day ago | parent [-]

Great, 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"

phplovesong 15 hours ago | parent | prev | next [-]

Wheb there i a formatter you should not care. You can rewrite the code if it bothers you.

AdamH12113 a day ago | parent | prev | next [-]

I 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.

marssaxman a day ago | parent | prev | next [-]

tabs for indentation, spaces for alignment

skylurk a day ago | parent [-]

Meanwhile, I'm trying to get away from languages where whitespace has semantics.

PaulDavisThe1st a day ago | parent [-]

It'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.

fmbb a day ago | parent | prev [-]

Only a goblin would align code.

But if you must you can start with a new line and the right indent.

gte525u a day ago | parent [-]

From my experience, it seems to be the people that learned PASCAL first for some reason.

vouaobrasil a day ago | parent | prev | next [-]

I 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 a day ago | parent [-]

Until you are visually deficient. Then it matters a lot.

Accessibility is not a joke.

vouaobrasil a day ago | parent [-]

That is a good point.

TheAceOfHearts a day ago | parent | prev | next [-]

You 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.

IncreasePosts a day ago | parent | prev | next [-]

It seems problematic to have a single character in the entire universe for characters render as variable, user controlled width.

jedberg a day ago | parent | prev [-]

Spaces 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.

phplovesong 15 hours ago | parent | next [-]

This if a fallacy. With tabs i can view on indent as 2,4 or even 8 spaces. With spaces i force some preset on the dev, not always a bad thing, bit less flexible.

PaulDavisThe1st a day ago | parent | prev [-]

> 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 a day ago | parent [-]

You 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.

phplovesong 15 hours ago | parent | next [-]

Everyone is diffrent, some people might be visually impared, and having a bigger indent helps them out. The opposite also applies.

rkomorn a day ago | parent | prev | next [-]

So are we also going to have team themes, team syntax highlighting colors, team fonts, team dark/light mode, team screen resolution, etc?

Why not bikeshed the bikeshedding?

Lvl999Noob 7 hours ago | parent [-]

FWIW, team screen resolution is pretty much already there when the company provides the laptops (+ screens).

rkomorn 4 hours ago | parent [-]

People run different UI zoom levels with modern laptops and (especially 4K) screens.

PaulDavisThe1st a day ago | parent | prev [-]

It seems that you don't understand what a tab character is ...

jahewson a day ago | parent [-]

Wait, 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 a day ago | parent [-]

I'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.

jahewson 17 hours ago | parent [-]

Personally I use a 100 character limit. Anything more and the ability to have two editor windows side by side gets impeded upon. The point is, there is a limit.

sokoloff 12 hours ago | parent [-]

Eh. If 1 line of code in 500 has a trailing bit of punctuation scrolled off the side for 1 in 8 coders who have chosen to have both narrow windows and wide tabs, that hardly seems like a deal-breaker, but if it is, enforce common settings/standards.

(I'm fully converted to Team Spaces, but I also don't get too wrapped up in treating what seem to be soft limits as hard limits.)