3 ms·
Why do so many style guides mandate spaces for indentation?
by valtron 13y ago
Why do so many style guides mandate spaces for indentation?
- jyap 13y agoIt is consistent across different editors. Deterministic layout view. Tabs are non deterministic as it depends on user settings.
- masklinn 13y agoPlus 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...
- chc 13y agoMainly 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.
- vvhn 13y agothe 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.
- valtron 13y agoAgreed. 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).
- gte910h 13y agoPython 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.
- dragonwriter 13y agoBecause 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.