top | item 44686956

(no title)

gte525u | 7 months ago

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

discuss

order

Arelius|7 months ago

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"

camel-cdr|7 months ago

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

throwawayqqq11|7 months ago

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.

pepa65|7 months ago

It would be crazy that spaces would have "won" because of the silly idiosyncratic alignment that some people seem to like and then teach to others for many decades.

mananaysiempre|7 months ago

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|7 months ago

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.

phplovesong|7 months ago

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.

fsmv|7 months ago

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

AdamH12113|7 months ago

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|7 months ago

tabs for indentation, spaces for alignment

skylurk|7 months ago

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

phplovesong|7 months ago

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

fmbb|7 months ago

Only a goblin would align code.

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

gte525u|7 months ago

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