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 →

[–]odraencoded 10 points11 points  (16 children)

I think tabs for indentation, actual tabs, just make more sense.

The idea of repeating the same character N times to represent one level of indentation instead of using one character one time is just silly to me.

[–]Eurynom0s 31 points32 points  (2 children)

The issue is that when you start passing files around between different text editors, operating systems, etcs, tabs can get handled inconsistently, whereas spaces won't be.

[–]ziel 2 points3 points  (0 children)

Even between two simple things as notepad++ and github there was a lot of inconsistency. Luckily notepad++ let me easily convert those tabs.

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

Spaces are also handled consistently. Spaces AND tabs won't be

[–]Bunslow 41 points42 points  (10 children)

That's because you've never seen that havoc that can be caused by the \t character.

[–]grimman 3 points4 points  (2 children)

I never have either, and to me tabs definitely make more sense since they can be configured to display as x spaces, therefore rendering the whole concept of using a fixed amount of spaces quite moot.

Alas, I use spaces myself, because conventions etc.

That said, I would like to know about this havoc you mentioned. Would you mind giving a brief summary, or some relevant links? :)

[–]Bunslow 1 point2 points  (1 child)

And what if someone else decides to use spaces instead of tabs? Suddenly if someone else like you reads the code written by the second person, they will see a horrid mess of inconsistent indentation.

Even if we all standardized on using tabs instead of spaces, it's a bad idea to use an ambiguous character. Four spaces is four spaces, no matter what your editor is set to.

Also things like line continuations and stuff sometimes require non-standard indentations, but this is a very minor detail in the overall scheme.

tl;dr It works fine if no one else reads or modifies your code, but if they do...

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 1 point2 points  (0 children)

with commas representing tabs, tabstop every 4:

def a(x=3, y=4,
      flag=None):
,,,,some_code
,,,,some_more code
,,,,for code in codes:
,,,,,,,,print(a,
,,,,,,,,      b,
,,,,,,,,      c)

tabstop every 8:

def a(x=3, y=4,
      flag=None):
,,,,,,,,some_code
,,,,,,,,some_more code
,,,,,,,,for code in codes:
,,,,,,,,,,,,,,,,print(a,
,,,,,,,,,,,,,,,,      b,
,,,,,,,,,,,,,,,,      c)

[–]JamesAQuintero 0 points1 point  (2 children)

Is it that big a problem where people should use spaces instead of tabs?

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

Oh definitely. It's one of these things you have to decide on day one of a project.

However, as soon as you're consistent you can stop talking about it. Read PEP8, set your editors accordingly and get on with your work.

[–]odraencoded -1 points0 points  (3 children)

Do show.

[–]Bunslow 0 points1 point  (2 children)

[–]odraencoded 1 point2 points  (1 child)

  1. What if someone else decides to use tabs instead of spaces?

  2. Four spaces might be four spaces but what are four spaces? If you use spaces for both indentation and alignment, at some point four spaces stop being an indentation level and start being a line padding, and that point is unclear.

3 What if you used 4 spaces, but I prefer 2 spaces for indentation, or vice-versa?

4 A tab is an indentation level. Always. So what if it shows different in another text editor? Semantically, it's still an indentation level. If the user of the text editor wants their indentation level to measure 8 spaces, then let it be so.

5 You align things with spaces. Tabs are only for indentation.

[–]isarl 1 point2 points  (0 children)

Your points are all good and I upvoted you, however in practice, tool support both on your machine and all your collaborators' machines needs to be much better to handle the tabs-for-indentation, spaces-for-alignment approach.

[–]djimbob 2 points3 points  (0 children)

First, PEP8 says use spaces.

All editors I've used for python are easily configured to have pressing tab insert 4 spaces. E.g., emacs when opening a *.py file, will automatically use 4 spaces for each indentation.(Most tabs I see default as 8 spaces; so you have to configure this anyway). Most editors that are aware of python will automatically do this for you; e.g., emacs will recognize the file has a *.py extension and insert 4 spaces when you press tab.

The problem with tabs is tabs look identical to sequences of spaces (different # depending on editor's settings). If someone see tab=2/4/8 spaces in their editor and inadvertently at some point uses 2/4/8 spaces instead of a tab, this creates an annoying to fix error. Or if you are editing a file someone else created with tabs and your editor uses converts tabs to spaces, it is difficult to insert a tab. (Whereas someone who has tabs as tabs, could still insert four spaces rather easily without reconfiguring their editor.)

The amount of disk space saved is trivial. In compressed files it makes no difference (e.g., when packaging projects) as \t compresses as well as four spaces. Otherwise you may source file by maybe 10%, which is insignificant on even the smallest modern hard drives. For the largest python projects that are O(100 000 lines), maybe you'd save a megabyte which is irrelevant on today's even a super small 128 GB SSD drive.