3 ms·
Almost everyone I know who uses spaces or tabs does so because that's either the default on their IDE, or for their language. So this holier-than-thou argument
by scrollaway 9y ago
Almost everyone I know who uses spaces or tabs does so because that's either the default on their IDE, or for their language. So this holier-than-thou argument holds less water than the sun.
On the other hand, I find 2-space-indented code unreadable; in fact, 4-space wide indentation is the only size I find to be readable. I know plenty of people for whom that isn't the case. Using tabs lets the reader set the indentation level.
¯\_(ツ)_/¯
Edit: All the anti-tab arguments I'm reading below boil down to alignment. Don't align folks; there's good reasons not to align regardless of your indent style.
- nottorp 9y agoActually they all boil down to 'someone else, or another IDE that you haven't configured just right, will mess your tabs and make the code hard to read' :) They're fine for solo projects i guess, if you only ever use one editor. Edit: Also, in the long run the best thing you can do to your code is to make it easily readable. You will forget what you did. Not to mention your colleagues that have never seen it. So time spent aligning parameters to make code more readable is well spent, if you ask me.
- scrollaway 9y ago> So time spent aligning parameters to make code more readable is well spent, if you ask me. How is this[1] more readable than this[2]? [1] https://github.com/HearthSim/python-hslog/blob/5a6ad9a29a7d46672d563915ecfae74f3bfda94f/hslog/packets.py#L44-L53 https://github.com/HearthSim/python-hslog/blob/5a6ad9a29a7d4... [2] https://gist.github.com/jleclanche/ef40058731061e26d218e2a4c99099b0 https://gist.github.com/jleclanche/ef40058731061e26d218e2a4c... Let the lines get long enough and the latter is actually quite a bit harder to read; try to follow the variable all the way to its value and you might actually jump and be one line off. I deeply care about readability and code style, that's why I'm replying here :) And in all the codebases I have read and written, alignment has consistently been harmful to readability and maintenance.
- swift 9y agoWhen I hear "aligning parameters", I think more of the difference between this: someFunction(firstParam, secondParam, thirdParam, fourthParam); And this: someFunction(firstParam, secondParam, thirdParam, fourthParam); I've always found the second much easier to read, especially when there are multiple levels of nested expressions, and it's a style that has been encouraged on every project I've worked on. I agree that aligning '=' is actively harmful in the example you give, and that it's harmful in most situations where it's used. I've encountered very rare instances where it's helpful, though. Sometimes you have a sequence of values defined by expressions that follow a pattern: enum someEnum { FIRST = BASE + MASK & (1 << 0), SECOND_VALUE = BASE + MASK & (1 << 1), TH = BASE + MASK & (1 << 2) } Aligning the expressions can make it more clear what the pattern is and how it differs from value to value: enum someEnum { FIRST = BASE + MASK & (1 << 0), SECOND_VALUE = BASE + MASK & (1 << 1), TH = BASE + MASK & (1 << 2) } Often there are other ways to handle the issue, such as hiding the expression behind a macro or a function call; when that's more readable, that's the way to go. But in cases where writing the expression explicitly ends up being more readable, I find alignment to generally be a win in this case.
- ioquatix 9y agoI think you've just figured out why people who use spaces get paid more: they spend more time aligning the code nicely :D
- lmm 9y agoAny coding standard that relies on humans to do something right is going to fail. Tabs might work if there was a way to automatically enforce no alignment and no use of spaces. But I've never seen any organization actually do that.
- scrollaway 9y ago> But I've never seen any organization actually do that. You haven't looked very far! Most open source projects these days enforce code style through some forms of tooling. But saying that "Any coding standard that relies on humans to do something right is going to fail" is basically giving up and saying "do whatever". I mean, why even ask people to indent consistently if it's doomed to fail? It's a mixed indent party for everybody!
- lmm 9y ago> You haven't looked very far! Most open source projects these days enforce code style through some forms of tooling. Sure, but I've never seen a tool that was able to enforce that no-one was doing alignment. > But saying that "Any coding standard that relies on humans to do something right is going to fail" is basically giving up and saying "do whatever". Coding standards that you can implement in your enforcement tool are fine. But any rule you can't automate is not worth bothering with, IMO. > I mean, why even ask people to indent consistently if it's doomed to fail? It's a mixed indent party for everybody! Use a language that enforces indentation, or use a tool to autoindent. Trying to get people to indent consistently by hand is a waste of time.
- pseudalopex 9y agoclang-format, Uncrustify, YAPF, and RuboCop all have options to control alignment.
- lelandbatey 9y agoWith the spread of autoformatters which automatically format or reformat your code, I don't even know or care what kind of indentation I use anymore. In all the languages I use, it's out of my hands. Examples of autoformatters: YAPF for Python Gofmt for Go Rustfmt for Rust