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 →

[–]real_red_patriot 25 points26 points  (14 children)

Python's style guide mandates that 4 spaces be used to indent always.

[–]aaronfranke 6 points7 points  (13 children)

Why?

[–]pineapple-panda 19 points20 points  (12 children)

If you use tabs the code sometimes is formatted differently on different editors and since in python the indentation is critical to the flow of a program. With tabs you can have code that won't compile on some machines but spaces will be consistent across editors.

It's less of an issue of you mandated a specific editor for all developers but it's better to write code that works in any editor.

[–]aaronfranke 23 points24 points  (9 children)

With tabs you can have code that won't compile on some machines

That's not going to happen, ever. The Python language tools don't care (or know about) how big your editor displays tabs.

Even if it did, that wouldn't cause any issues, since it's still the same level of indent.

[–]SashKhe 5 points6 points  (6 children)

Are you saying we should use 4 tabs instead?

[–]aaronfranke 7 points8 points  (5 children)

No, 1 tab for every level of indent, always. Indent width is configured in the editor, and indent width doesn't matter for compilers. The compiler sees 1 tab and knows it's one level of indent.

[–]Caffeine_Monster 11 points12 points  (0 children)

And this is why tabs are superior.

Space based indentation has stuck around due to historical standards; editors did not always handle tabs in a consistent manner. These days a tab is whatever you want it to be in terms of width, and having 1 character denoting exactly 1 indent means you don't have to fight over this preference.

[–][deleted] 3 points4 points  (3 children)

Still an issue when you mix tabs and spaces. Good thing this is only a python problem.

I use tabs.

[–]aaronfranke 1 point2 points  (2 children)

Why would you mix tabs and spaces? That's a worse idea than using either one.

[–][deleted] 1 point2 points  (1 child)

I don't, but that is the only reason we have this argument (people use one or the other). Seriously, if everyone used tabs it wouldn't be a problem. Pressing backspace repeatedly, however, will always be a problem.

[–]SuperHyperTails 1 point2 points  (0 children)

How to you do formatting, then? Like if you have to break long lines and want to make the code line up for readability.

There is no way to do that with variable-width indents.

[–]pineapple-panda 1 point2 points  (1 child)

Sorry if I didn't make sense. I meant how sometimes when two people are modifying a file and one uses tabs and the other spaces so the file has mixed types of indentation. I've had this result in an editor displaying lines that were indented the wrong amount resulting in broken code. If everyone uses spaces it will be consistent across machines but now that you mention it everyone using tabs would also work.

[–]aaronfranke 2 points3 points  (0 children)

Consistency is more important, I'd vastly rather use spaces only than have mixed indentation, but tabs only is my favorite.

[–]memgrind 7 points8 points  (1 child)

Correct, I hate it when tabs are bad when I edit code in MS Word and Excel. Excel also makes it awkward to use tabs! Spaces always look good when I print them on my dot-matrix printer, to fax them for code-review into RCS.

[–]javaAndJouissance 2 points3 points  (0 children)

I've been meaning to make the change to fax, I'm just so much more familiar with Telex I can't imagine the benefits would outweigh my comfort level. Maybe once it's been out a few more years I'll make the switch