5 ms·
It really doesn't matter how many spaces or tabs, what's important is that all code and scripts are written in the same style, which greatly reduces time requir
by amaks 13y ago
It really doesn't matter how many spaces or tabs, what's important is that all code and scripts are written in the same style, which greatly reduces time required to understand someone else's code. At Google, that's a norm.
- apr 13y agoIt actually does, 2 spaces indents are hard to read, period.
- gryz 13y agoyou're getting used to it within few months.. (currently we have tabs though)
- sdoering 13y agoIs there any scientific/empirical proof on this? I indent 4 spaces, no tabs, but I would like to see the real rationale there, not just the PEP-8 "rules".
- Shish2k 13y agoZero spaces makes indentation harder to spot than infinity spaces. Infinity spaces gives less space for code than zero. Conclusion: use as wide an indentation as possible while still keeping enough space for the code itself.
- praptak 13y agoThere is this: "Program indentation and comprehensibility (1983) by R J Miara, J A Musselman, J A Navarro, B Shneiderman" http://www.cs.umd.edu/~ben/papers/Miara1983Program.pdf http://www.cs.umd.edu/~ben/papers/Miara1983Program.pdf I'd classify it as an attempt rather than something decisive but whatever floats your boat.
- damncabbage 13y agop866: The level of indentation that seems to produce optimal results in comprehension is between 2 and 4 spaces; as the number of spaces increase, the comprehension level decreases. On the other hand, the sample program hard parts that were indented nine times (!) in places. It's an interesting read, but I'd not try to use it in a discussion. Personally, I don't care; just pick one (hopefully one that matches what most people are using with that language, eg. 2 spaces for Ruby), and get on with it.
- praptak 13y agoYup, they seem to have used an overly indent-happy indentation scheme. Two separate indents: he 'begin' after the 'for' and for the block body is superfluous. This raises the concern that their results are biased towards smaller indents.
- valisystem 13y agoNo. Indent space is just an opinion/preference/habit.
- oftenwrong 13y agoI prefer 2 space indents (tabs)
- fhd2 13y agoYup. After a decade of programming, the only thing I care about is consistency. Even the weirdest code style people can come up with is just fine in a clean, consistent code base. Mildly surprised to see people arguing for specific tab widths...
- mradmin 13y agoAgreed, consistency matters most. Regarding whether it matters whether tabs or spaces are used, I've come to realise that I cannot control the tab length when viewing code outside of my editor (obviously!). So, let's say we have a 80 char line length limit. If I set my tab size to be 2 spaces, the line length is obviously going to be different to someone who sets their tab size to be 4 spaces. Just having the option to control the size of tabs means tabs should never be used as it will result in inconsistencies across editing/viewing environments. Also, when viewing code online, generally you have a limited viewing area. If you're using tabs, the length of the lines are generally going to be very long, and it's very difficult to view the code. In conclusion, if you care about things like line lengths (you should), and if you care about keeping your code in a certain and consistent format, the only way to manage it is with spaces, imo.