4 ms·
Tabs for indentation, spaces for alignment. It is called "smart tabs" and good text editors already implement it.
by markrages 7y ago
Tabs for indentation, spaces for alignment. It is called "smart tabs" and good text editors already implement it.
- edflsafoiewq 7y agoIf you use spaces, you can check that files are okay by forbidding \t. If you use tabs, you can check that files are okay by forbidding /^\t* /. If you use tabs for indentation, spaces for alignment, ??????
- markrages 7y agoMy editor maintains it automatically, so it is never wrong. There is nothing to check. I'm sure there is a command-line pre-commit formatter I could use. But I have never tried to set it up, since I can reformat existing code with a couple of keystrokes in my editor.
- mrgriffin 7y agoForbid "\t* *\t"?
- deleted 7y ago[deleted]
- edflsafoiewq 7y agoOk, but if you get "\t[space][space][space][space]", how do you know this wasn't supposed to be "\t\t"? That is, how do you know trailing spaces are for alignment and not for indentation?
- jlokier 7y agoA code formatter knows, so your editor and other tools can also know. Most editors have code structure parsing of some kind built-in for tabbing already. E.g. pressing the <tab> key indents the current line to match the structure of surrounding code (or cycles between valid indents for something like Haskell or Python). So they know the difference between initial indentation (that people want to be able to configure visually) and alignment.