5 ms·
> Finally, when another developer looks at the code, their IDE will render the tabs as whatever its set up for, 2 spaces, 4 spaces, etc. In other words, it adds
by jinglebells 9y ago
> Finally, when another developer looks at the code, their IDE will render the tabs as whatever its set up for, 2 spaces, 4 spaces, etc. In other words, it adds flexibility.
This is exactly why I use tabs and the reason which appears to never get cited in the holy wars.
People who use spaces want to line up their '=' signs, that's fine, but I don't believe it's my position to enforce the amount of whitespace another developer has to use in their editor. It's an accessibility thing, they might have their font size really large because of eyesight problems in which case 8 spaces is going to make reading the code a lot harder.
The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language.
- hollander 9y ago> People who use spaces want to line up their '=' signs How does that prevent the use of tabs? You can use tabs to indent, and spaces for your = signs.
- ElijahLynn 9y agoMixing tabs and spaces is a nightmare, unless it is your personal non-open project. If a project is open or shared with anyone you need a simple rule to follow. There shouldn't be another leaf in the decision tree for when to use tabs or spaces. We have enough decisions to make the way it is.
- IanCal 9y agoFirst, my golden rule is "do whatever the other devs using the repo do" but > People who use spaces want to line up their '=' signs, that's fine To me this feels like it's a good use of spaces as well as tabs. Tabs for indentation, to get your nesting right. Spaces to align things. That way setting your tabs to X spaces works just fine and everything remains nicely aligned. Though I'm not sure how common this is, so I just use spaces.
- jdmichal 9y agoGet your blasphemous mixing of spaces and tabs out of this holy war!
- pyre 9y ago> The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language. Not sure what you're talking about here. In Python, as long as the indentation is consistent you could (e.g.) use 2-space indentation to make a code block. It's considered bad practice, and most linters will complain about it since 4-space indentation is the "golden rule." If you're talking about the Python interpreter's interpretation of the tab character in indentation, that's different[1]. In any case, old code that has 8-space indentation using spaces rather than tabs is still good. The only issue would be old code that mixed tabs and spaces for indentation, which might not match up anymore to make correct code blocks. But, in general, it's just a bad idea to mix tabs and spaces for indentation. [1] To the uninitiated, the Python interpreter treats a tab as X number of spaces when parsing the source code. This means that technically you could mix a block's indentation between tabs and a corresponding number of spaces. For example, if X = 4, then this code block would work: def function(): <tab>something() something_else()
- waqf 9y agoThe right solution here would be to treat a tab as exactly pi spaces. This, while not forbidding the use of tabs, would guarantee that any inconsistent mixture of tabs and spaces would be considered misaligned.
- sicariusnoctis 9y agoI think pi*pi is even better. Twice the pi!
- tom_mellior 9y ago> exactly pi spaces That's an irrational choice.
- deleted 9y ago[deleted]
- tom_mellior 9y ago> This is exactly why I use tabs and the reason which appears to never get cited in the holy wars. I see this cited every time. Unfortunately, it's bogus in practice. Consider: print('some long thing', further, arguments) If this is an indented block, you'd have to indent the second line to the correct depth with tabs, then add exactly six spaces for alignment. You have to mix spaces and tabs, which is never good news. Additionally, if you try to actually type in the six spaces, editors might take, say, four of them and group them into a tab. (I have vague memories from a long time ago of Emacs doing this. I might be wrong.) If you get this wrong in program parts that are by definition invisible, it might look good for you and look really bad for others (i.e., the opposite of the stated goal). In code I see mixing spaces and tabs, the latter tends to be the case.
- gcb0 9y agoyou're going to be downvoted by the thou shalt not mix tabs and spaces crowd that fails to understand the reason of what they preach. sigh. also the fly by night devs who still don't see tabs on their text editors... I mean, ide.
- pseudalopex 9y agoYes, Emacs used to group spaces into tabs. I think most editors these days do the right thing. This problem goes away if you indent parameters instead of aligning them: print( 'some long thing', further, arguments) In this case it takes an extra line, but it's often shorter.[1] [1] https://github.com/pennersr/django-allauth/blob/a44134688f5be0a26f5e93b607f8c4e3f5b0782b/allauth/account/views.py#L685-L688 https://github.com/pennersr/django-allauth/blob/a44134688f5b...
- sqeaky 9y agoGross, You purt 3 parameters are on two lines. Either indent none of them and keep it on one line or indent all of them. What are you doing, trying to hide "arguments"?
- pseudalopex 9y ago
- zephyrfalcon 9y ago"""The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language.""" When exactly did it use 8 spaces? I have been using Python since 1996 and I don't recall this 8-spaces thing. Almost all code I've seen uses 4 spaces. In any case, it doesn't matter because, as another commenter pointed out, as long as your indentation is consistent, your code will work just fine, no matter how many spaces you use for indentation. Even if some code does use 8 spaces, it should work without problems. (Tabs as well, by the way... it's mixing tabs and spaces that is a problem.)
- Kevguy 9y agoI may be misremembering since it has been a long time since I've used it, but I thought at one point Python treated one tab as equivalent to eight spaces.
- SamBam 9y ago> This is exactly why I use tabs and the reason which appears to never get cited in the holy wars. It's probably been mentioned 20 times in this thread alone.
- dagenleg 9y ago> Python's rule used to be 8 spaces Interesting. Unfortunately I cannot find anything on the internet regarding that. Care to share a link proving that?
- _yosefk 9y ago"I don't believe it's my position to enforce the amount of whitespace another developer has to use in their editor." I suspect this might not be my most popular comment, but I honestly think that this is why tab users might actually make less than space users on average. On average, it's more productive to enforce things than leave everything configurable, thus different everywhere, thus harder to make sense of and debug. I knew brilliant people who don't want to "enforce" and decide and dim people who happily enforced and decided and it's always amazing how badly the former do career-wise relatively to their talent and effort, and how well the latter do relatively to theirs. (Of course there might be another explanation for the data and I don't claim that my just so story is in any way scientific; though I think it should pass as a scientific theory in the social sciences.)
- ccalf 9y agoIt's plausible and goes to show why the blog post choosing salary is itself a bad metric to begin with. It has skewed the entire discussion.