Hacker News new | ask | show | jobs
by valtron 4704 days ago
Why do so many style guides mandate spaces for indentation?
5 comments

It is consistent across different editors.

Deterministic layout view. Tabs are non deterministic as it depends on user settings.

Plus not all tools can ignore whitespace changes (so indentation changes everywhere intermixed with actual code changes drown the code stuff), and if your codebase mixes whitespace-significant and whitespace-insignificant code...
Mainly it's that you don't want to mix both spaces and tabs — you want to use one or the other for a given file or else the indentation will be an incoherent mess from one machine to the next — and it's easier and more compatible to standardize on spaces than tabs.
Python really gets murderously difficult to debug in an organization with multiple types of indentation. Spaces are the least easy to screw up there, and has been why many guides I've seen have "spaces" instead of "tabs" as the default.
Because tab/space inconsistency causes problems, and because the space bar is easier to use in the flow of typing, so a style guide that mandates tabs will end up with lower compliance than one which mandates spaces.
the right way to use tabs (tabs for indentation, spaces for alignment) needs some amount of discipline to get right always. It's more flexible but very easy to make a mistake and mess it up.
Agreed. But doesn't it take discipline to follow a coding convention in general? I'd argue learning tabs-indent/spaces-align is easier than following most other semantic conventions (e.g. what constitutes a good name, how to organize code).