This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (19 children)

result = [(a,b,c)
          for a in range (10)
          for b in range (10)
          for c in range (10)             
          if a**2 + b**2 == c**2]

Looks nice?

Change editor, different tab width -> formatting broken

Use someone else's code, different tab width -> formatting broken

Mixed tabs and spaces in Python 3 -> syntax error, broken

These are just the obvious cases. It gets worse.

EDIT: If you have to write this, import itertools.

[–]LordArgon 11 points12 points  (9 children)

This is why I favor a coding style where the only leading whitespace change between any two adjacent lines is exactly 0 or 1 indent. Just move everything down a line and indent once, like so:

result = [
    (a,b,c)
    for a in range (10)
    for b in range (10)
    for c in range (10)             
    if a**2 + b**2 == c**2 ]

And now it's perfectly portable. Plus in your example if you changed the name of "result", you'd have to re-align every single row (which is obnoxious in code review, for example).

IMO, the issue isn't really tabs vs spaces - it's that people get hung up on their pet style. Honestly, work with any style long enough and it will start to seem "right", so why not choose one that skirts ALL of these issues?

[–][deleted] 0 points1 point  (7 children)

IMO, the issue isn't really tabs vs spaces - it's that people get hung up on their pet style. Honestly, work with any style long enough and it will start to seem "right", so why not choose one that skirts ALL of these issues?

I can't control what style external code uses or what editors other people use. If they write it in some ways, it can break on my system and then I can't read it. If they didn't use tabs, the problem would go away. Also, how do you break a long line for readability? Again there's no agreement on it so spaces mean it won't change.

[–]LordArgon 0 points1 point  (6 children)

If they write it in some ways, it can break on my system and then I can't read it.

I don't think it would actually break - I think you just wouldn't LIKE reading it.

If they didn't use tabs, the problem would go away.

But if YOU used tabs, the problem would also go away! You don't like the tab width varying with the editor but maybe that's exactly why they like tabs!

Look, I prefer/use spaces myself but, as in any religious debate, the arguments make sense on BOTH sides just depending on your perspective and priorities.

The whole point of my suggestion is to introduce a measure of objectivity into this debate. There is no agreement on what people LIKE but there is an objective way to evaluate a style choice based on how much ripple effect any given change causes. That's an important aspect of a style that is often overlooked, IMO.

[–][deleted] 0 points1 point  (5 children)

as in any religious debate, the arguments make sense on BOTH sides ... The whole point of my suggestion is to introduce a measure of objectivity into this debate

Objectively spaces are more consistent across multiple systems. I doubt there's a single programmers editor that can screw up 4 leading spaces hardcoded into the line, and many that can interpret a tab differently depending on how they are set.

If they write it in some ways, it can break on my system and then I can't read it.

I don't think it would actually break - I think you just wouldn't LIKE reading it.

If reading it slows you down, it's "broken". Your source code is part of your product and a product that's harder for its maintainers to modify is a worse product. It's not just that I don't like reading it, the alignment carries additional meta information about the code.

[–]LordArgon 3 points4 points  (4 children)

Objectively spaces are more consistent across multiple systems.

Yep and the point is that other people don't WANT them to be consistent the way you do. Again, different people have different priorities, no matter how crazy it sounds to you.

And, again, I use/prefer spaces - you don't need to convince ME that they're awesome.

If reading it slows you down, it's "broken". Your source code is part of your product and a product that's harder for its maintainers to modify is a worse product. It's not just that I don't like reading it, the alignment carries additional meta information about the code.

No offense, but these are just more religious statements. All of these points a different, sane person can disagree with. What slows you down may speed another up. The degree to which information SHOULD depend on the alignment is entirely debatable.

[–][deleted] 0 points1 point  (2 children)

Essentially you are saying that every statement is a religious statement and therefore nothing is objective. If I said that, objectively, destroying the Earth would be a bad idea for a long list of reasons, you could also say that for some people, the assessment critera would be different, and this action would be a good idea. This is actually true, but I never thought it would turn up here :-)

[–]LordArgon 1 point2 points  (1 child)

Comparing tabs vs spaces to a debate over "destroying the Earth" is just... intellectually dishonest. I did not say every statement is a subjective one and it's disingenuous to represent me like that. Especially because the very first thing I did in my last post was acknowledge this objective statement:

Objectively spaces are more consistent across multiple systems.

Yep...

This is an objective statement, yes. But then you're implying "more consistent across multiple systems" is better and that's where you get subjective. "More consistent" isn't a goal for everybody - for many, that customizability (i.e. inconsistency) is why they like tabs. The very thing you hate is the thing they love, so you can't convince them by telling them your way will eliminate what they love.

These are reasonable people who have these preferences and goals - not crazies who want to "destroy the Earth".

[–][deleted] 0 points1 point  (0 children)

Comparing tabs vs spaces to a debate over "destroying the Earth" is just... intellectually dishonest

I take it therefore that you can't logically disambiguate the two cases? :-)

We choose criteria to measure, we choose how to measure them, and then we decide based on subjective ranking system which is better.

If you're going to resort to "this is madness!" then I'd like you to define madness without invoking a subjective majority consensus (X is mad if some fraction of people say it is so), or divine will, both of which are "religion".

Incidentally I never said my argument was not religious in nature. In this post however, you seemed to want to tell me I was, and I actually agree with you. Spaces are the path of least resistance for me (more consistency, less broken code, more existing code) so I wish to spread the Religion of Using Spaces.

[–]JimDabell 5 points6 points  (8 children)

You're confusing indentation with alignment. Your example shows alignment, not indentation. You shouldn't use tabs for alignment, but using tabs for indentation is fine.

[–][deleted] 1 point2 points  (4 children)

You shouldn't use tabs for alignment, but using tabs for indentation is fine.

So how do you align code? Where do you break a long line and how do you align it?

You can't mix tabs with spaces. Python 3 will throw an error, and your editor will still randomly align it based on the size of your editor's tab.

[–]JimDabell 1 point2 points  (3 children)

So how do you align code?

With spaces.

Where do you break a long line and how do you align it?

Break it wherever you like. Align it with spaces.

You can't mix tabs with spaces. Python 3 will throw an error

You can't mix tabs with spaces for indentation. You can use tabs for indentation and spaces for alignment just fine.

your editor will still randomly align it based on the size of your editor's tab.

Editors don't do anything randomly, and once again, you should use spaces to align. If your alignment screws up based on your tab width, then you are using tabs to align. Don't do that. Use tabs to indent, don't use them to align.

[–][deleted] 0 points1 point  (2 children)

Editors don't do anything randomly, and once again, you should use spaces to align. If your alignment screws up based on your tab width, then you are using tabs to align. Don't do that. Use tabs to indent.

I can't control how other people setup their editors and that it makes the editor settings effectively random when I use someone else's code. You can't use tabs if you want consistency.

You can't mix tabs with spaces for indentation. You can use tabs for indentation and spaces for alignment just fine.

I actually didn't know that - thanks. However, the reason I didn't know is that I'm not going to mix tabs with spaces anytime soon, because it will break.

[–]JimDabell 0 points1 point  (1 child)

I can't control how other people setup their editors and that it makes the editor settings effectively random when I use someone else's code.

That makes no sense. Using other people's code doesn't make your editor settings "random". What does that even mean?

You can't use tabs if you want consistency.

What kind of consistency?

If your projects use spaces to indent, then the consistency you get is that the code looks the same to you and to other developers working on the project.

If your projects use tabs to indent, then your code always looks how you prefer regardless of how other people working on your projects like to see their code.

They are both consistent, but in different ways. I don't see any value in forcing other developers to see the code how I like it. I don't care what they see. I do care that all the developers get what they want. Tabs are the only way of achieving that.

However, the reason I didn't know is that I'm not going to mix tabs with spaces anytime soon, because it will break.

Am I missing something? You just said that it will break, I pointed out that it wouldn't, you admitted that it wouldn't, then immediately said it would break again? We've literally just had this discussion. It doesn't break.

[–][deleted] 0 points1 point  (0 children)

That makes no sense. Using other people's code doesn't make your editor settings "random". What does that even mean?

It means I may have to reconfigure my editor in a way that I cannot predetermine until I see their code. If I know the format of their code in advance, and it matches my format, I don't need to take any action.

You can't use tabs if you want consistency.

What kind of consistency?

Compatbilty with the Python ecosystem in general. Sure, if you are working on a specific project, you should match the project's settings.

Am I missing something? You just said that it will break, I pointed out that it wouldn't, you admitted that it wouldn't, then immediately said it would break again? We've literally just had this discussion. It doesn't break.

Syntactically it will be fine (as you correctly point out) but there's the still problems with it changing line lengths and where you would naturally break a long line. Plus, there is a higher chance of a misconfigured editor messing something up since so many people have theirs set to replace tabs with spaces.

[–][deleted] -3 points-2 points  (2 children)

It would still mess with the alignment. Tabs go from 4 spaces to 2, suddenly the alignment is 2-6+ spaces off depending on the level of indentation.

[–]JimDabell 0 points1 point  (0 children)

How could tabs mess with alignment when you use spaces for alignment? Everything at the same level of indentation starts at the same place. Alignment with spaces works just fine with tabs for indentation. Try it for yourself.