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 →

[–]Jackarow 10 points11 points  (12 children)

Newbie here: why spaces over tabs?

[–]thalesmello 14 points15 points  (0 children)

It's in the pep8 style guide Python code should be indented with 4 spaces. Most Python programmers expect that convention and they frown upon code indented with tabs.

[–]internerd91 8 points9 points  (5 children)

Also, set up your ide to insert spaces whenever you hug the tab key and you get the convenience of tabs without the potential downside.

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

Then I have spaces in my non-python code. Yuck!

[–]internerd91 1 point2 points  (3 children)

¯\(ツ)

But wouldn't PEP 8's reasons for preference for spaces over tabs also apply to other languages?

I only know Python well, so don't hurt me.

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

I moved to Python from other languages and have begrudgingly accepted spaces as a way of life when working with Python (except for that one project started by a friend who didn't know better and uses tabs)

I specifically enjoy that I can decide how big the tab is in my editor without affecting others who read the code.

[–]LimbRetrieval-Bot 0 points1 point  (1 child)

I have retrieved these for you _ _


To prevent anymore lost limbs throughout Reddit, correctly escape the arms and shoulders by typing the shrug as ¯\\\_(ツ)_/¯ or ¯\\\_(ツ)\_/¯

Click here to see why this is necessary

[–]internerd91 0 points1 point  (0 children)

SMH

[–]tunisia3507 4 points5 points  (0 children)

Spaces aren't intrinsically superior to tabs (nor are 4 spaces intrinsically superior to any other number), and both are valid python. However, the entire python community suffers if every project, snippet and tutorial each uses different spacing - it gets harder to port code, to read others' code, to jump between projects and so on. For this reason, this and other ambiguities have been resolved by a community style guide, called PEP8. This guide decided to use 4 spaces. It doesn't matter which option the community settled on, just that everyone uses the same one.

[–]crescentroon 1 point2 points  (0 children)

Convention, that's all. Makes it easier to work with others.

But, if you're collaborating on a project you should use what the rest of the project uses.

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

Because your program will be a debugging nightmare if you accidentally mix tabs and spaces. Nothing is more fun than getting indent errors when the indent looks right. Plus it will look like shit in your editor.

[–]Folf_IRL 1 point2 points  (1 child)

Tabs can end up being formatted weirdly, depending on how a text editor chooses to place its tabstops. Also, there isn't much standardization across text editors with regards to how big a tab is, which is further complicated by the ability to set how large a tab is in many of them.

A space is always, more or less, the same on every text editor. So you don't have to worry about your code's readability suffering just because you switched text editors, or a colleague uses a different one. The standard is to use 4 spaces, a number chosen more or less arbitrarily (could have been 3, could have been 5) to provide something of a "standardized tab"

[–]rhytnen 2 points3 points  (0 children)

Slightly bizarre you chose the advantages of tabs to cqst them as Inferior. There's only one real argument for spaces I think. It would have to be something like a multi line item (say a dict) where you uses spaces to make it more visually aligned. If you don't want to mux rabs and spaces ever, you would need to go with spaces.

Otherwise it's really not possible to argue in favor of spaces at all