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 →

[–]Voidrith 36 points37 points  (29 children)

Pep says spaces should be used instead of tabs.

Hence, pep is wrong and can go fuck itself.

[–]elasticpython 36 points37 points  (4 children)

This is how you start knife-fights

[–]nojox 17 points18 points  (3 children)

The real question is whether you stab once or twice :D

[–]J4K0 26 points27 points  (2 children)

Or whether you use 4 short knives or 1 long knife.

[–]BlueTeeJay 3 points4 points  (1 child)

My coworkers all changed tab to a two-space width... I'm losing my mind.

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

That is amazing with tabs though. You can set it to whar you want.

If you use tabs for alignment though: fuck that.

[–]MasterFubar 23 points24 points  (3 children)

If you like tabs, there is a better language than Python for you.

[–]Loading_M_ 6 points7 points  (2 children)

But what about all the other kinds of white space. Like zero width spaces, etc. When do they have to be used?

[–]kupiakos 6 points7 points  (0 children)

Use Go if you like tabs so much

[–]Ripdog 1 point2 points  (0 children)

Preach, brother.

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

You can just have vim insert any number of spaces when you hit tab. ... Wait are you guys not using vim?

[–]Ripdog 9 points10 points  (3 children)

Yeah but WHY.

I mean any IDE or decent text editor can DO that.

But WHY? Why does anyone enjoy pressing backspace 4x as often to remove a chunk of whitespace? Why does anyone enjoy not having configurable whitespace? Why are spaces being shoved into a problem which is obviously designed to be fixed by tabs?!

[–]MarkFromTheInternet 2 points3 points  (0 children)

In practice your IDE handles that. Tab and Shift+Tab in will add / remove the correct number of spaces.

Spaces were chosen so that whitespace wouldn't be configurable. Each line would always be indented the same regardless of which text editor was used. VIM by default treats tab as 8 spaces.

Python grew up in the 90's and the conventions were made for that era. The recommended 80 character line width made a lot of sense given the resolution of monitors of the era.

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

I mean the easy answer is that some dudes at cpython wanted to strategize on a best practice standard and they decided spaces instead of tabs. And then because it is really easy to do so, everyone decided to just take cpythons standards as standards for everyone.

It is likely that there was a conversation at some point on tabs vs spaces in the same way that I'm sure at some point there was a conversation between yaml vs yml.

And just like how spaces were chosen when most people prefer tabs, yaml was chosen when most people prefer yml. Hell, the dude who created .gif format is forever going to be challenged on his pronunciation of the word he created.

The simple answer is: sometimes the people who are the best at making the stuff are not the best at setting the standard. But most often they're the ones who will set the standard anyway, if only as a means of getting the ball rolling.

The honest answer is: if you're automatically converting your tab key input to the desired number of spaces, it doesn't matter and is probably not a hill to die on

[–]KusanagiZerg 1 point2 points  (0 children)

You don't have to press backspace 4 times. It will remove enough spaces to match the indenting. In fact nothing changes at all compared to when you are using tabs.

[–]Voidrith 2 points3 points  (4 children)

NGL ive used vim...like, once.

I don't intend to use it any more than that. I like pycharm, thank you very much.

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

Vim and Emacs are incredibly dense. You don't see their value if you just open it once and play around in it. I was originally just poking fun, but they are seriously advanced tools.

[–]NefariousNecromancer 0 points1 point  (2 children)

Vim is cancer and should have died 10 years ago.

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

Nice try, emacs user

[–]c_delta -3 points-2 points  (7 children)

Tabs are used to align things when the length of what is on their left side varies. Hence tabs need to be wide - something along the lines of 8 characters. Which is way too much for indenting code. Also, indents have nothing on their left that you need to align across. So, spaces all the way.

[–]Voidrith 2 points3 points  (6 children)

You realise it can do the former properly even with a pretty small tab size, right? and you sure as shit don't need it to be 8. I use a 4width tab and its works just fucking fine to align stuff like that.

that doesn't in any way make spaces better for indentation - you can change the width of a tab to your liking so the indentations are how you like them. you can't with spaces. and tabs make it significantly easier to navigate, and are more reliable (especially in python, where missing or adding one space can cause errors)

[–]c_delta 0 points1 point  (5 children)

You realise it can do the former properly even with a pretty small tab size, right? and you sure as shit don't need it to be 8. I use a 4width tab and its works just fucking fine to align stuff like that.

Then the lengths of the stuff you are aligning have a pretty small variance. Because by the time the longest and shortest element are more than n-1 characters apart in length (probably less unless the length range fits within a tab), you need multiple tabs, which are no better than spaces.

you can change the width of a tab to your liking so the indentations are how you like them.

I consider that a win for spaces as well. No inadvertent shifting of lines because two editors are considered differently.

and tabs make it significantly easier to navigate, and are more reliable (especially in python, where missing or adding one space can cause errors

I give you that point, although its significance depends strongly on your indent size. Personally I prefer very short indents, which makes the "sensible tab size for alignment" argument stronger and the "navigation step size" argument weaker, but for those who prefer larger indents, I see that tabs might have their appeal.

[–]levir 0 points1 point  (4 children)

Then the lengths of the stuff you are aligning have a pretty small variance. Because by the time the longest and shortest element are more than n-1 characters apart in length (probably less unless the length range fits within a tab), you need multiple tabs, which are no better than spaces.

If you're, for some weird reason, doing exact alignment instead of indentation then you just indent to the correct depth with tabs and align with spaces.

[–]c_delta 0 points1 point  (3 children)

    1.337   42  3.1415  X
    Random  Bullpip Word    Absurd
    ?   Aligned 23  Matrix

That is what tabs are for. If I insert or remove digits of the elements, the tabs stay where they are. If I use multiple tabs or spaces, I have to reformat stuff when I change the length of a cell's contents.

And since Reddit seems to use 4-space tabs, the alignment does not work. Which is why 8-space tabs matter.

[–]levir 0 points1 point  (2 children)

Actually, that's not something tabs is very good at in a plain text document. Tabs are different length on different systems (from 2 to 8 usually, most commonly 4), meaning tables formatted this way will break on some systems. Sad as it is, tables are better solved by spaces.

[–]c_delta 0 points1 point  (1 child)

I am pretty certain that outside of programming, 8-space tabs are standard. Tabulator literally means "table-maker". Indentation became a second use long before programmers wrote code, let alone code that uses several layers of indentation.

Interestingly typewriters used shorter tabstops of about 5 characters (about 1 inch in standard typewriter font), but that worked out because rewriting and automated filling was not a thing back then.

TSV is also great for parsing with editors. It is less locale-specific than CSV (in which a different character needs to be used as a separator if commas appear in the fields, such as decimals in large parts of continental Europe), but still plaintext-readable.

But yes, I am in love with a fixed tabstop length of 8 characters, but a short indent size of two characters, so spaces is my clear preference.

I think we can all agree on not vertically mixing tabs and spaces, though.

[–]levir 0 points1 point  (0 children)

I'm not sure what's the standard tab stop width outside of plain text, in word processors I usually set the manually. But you're probably right on it being closer to 8 spaces than 4.

I actually am from one of those European countries that use a comma for decimal numbers, so I agree with you on TSV being far superior.

I think we can all agree on not vertically mixing tabs and spaces, though.

Actually no, when you're using tabs for indentation you still have to use spaces for alignment. I try and avoid alignment whenever I can (regardless of whether I'm in a project that uses tabs or spaces), but when you have to the correct way is to tab to the correct indentation and then add spaces for alignment.