Live data from Hacker News

Why I prefer no tabs in source code

adamspiers.org

11–20 of 37 posts

Re: Why I prefer no tabs in source code

#11
post #9

python... tabs == devil in python.

You're being modded down as that's not a complete sentence, but yes, since there's a standard (PEP 8) stating that spaces are preferable to tabs, and that indentation should be 4 characters, and all modules I've seen use that standard, tabs are indeed looked upon as being bad in Python.

Re: Why I prefer no tabs in source code

#12
"It's less portable, since different editors/pagers render a hard tab as varying numbers of spaces, and most editors can have this number altered on a per-user basis too. If you use spaces instead of tabs, you're never relying on a particular editor or pager to have tab width set correctly. Even if you're prepared to configure every editor/pager/platform combination you use, aren't you going to be making life difficult for others who want to read or modify your code?"

Nearly every editor I've used allows you to adjust tab size. In my mind, that means tabs allow every user to set the width that they prefer.

Re: Why I prefer no tabs in source code

#14
OT:

Do you not people see these two twin (troll?) threads posted by the same person? Within the same minute?

http://news.ycombinator.com/item?id=1058196 http://news.ycombinator.com/item?id=1058195

http://i.imgur.com/m1DyR.png

Someone went out of his way to find two trivial, but hot-button issues and submitted an argument for each. It's another "experiment".

Re: Why I prefer no tabs in source code

#15
post #11
post #9

python... tabs == devil in python.

You're being modded down as that's not a complete sentence, but yes, since there's a standard (PEP 8) stating that spaces are preferable to tabs, and that indentation should be 4 characters, and all modules I've seen use that standard, tabs are indeed looked upon as being bad in Python.

It's not just that. The REASON why tabs are so bad is because it makes very very subtle errors when they get mixed.

Additionally, tabs are 8 spaces to the python interpreter. If you're not using 8 space tab stop, you're setting up people who use your code for a world of hurt if they ever change anything in your files.

Re: Why I prefer no tabs in source code

#16
Sometimes I want to copy/paste SQL from the source code to a command-line interface like mysql or sqlplus. Tab characters are interpreted as tab keypresses, triggering auto-completion. To get around it I have to open a blank file in a text editor, paste the SQL, convert the tabs to spaces, then highlight/copy it again. It's a pain in the ass. I can't be the only one with this problem, but I never see it mentioned in tabs/spaces debates.

Re: Why I prefer no tabs in source code

#17
post #7

Oh yes. Tabs or spaces in source code. That's really what makes software great. Just have guidelines and stick to them. What sucks is inconsistency. Everybody's got an opinion about code layout. It doesn't matter. There's no good or bad layout. Readability is just another word for "looking like stuff I'm used to read".

What's interesting is that I never used to care how code was indented, never bothered me. However, I got a job using Python/Django, and almost all of the code in that community is in the PEP8 style (4 space indents, etc, http://www.python.org/dev/peps/pep-0008/).

Now whenever I read python code that is outside of PEP8 just a little bit, it makes me cringe, but I can still read other, non python code indented almost any way. Thought that was interesting.

Re: Why I prefer no tabs in source code

#18
post #7

Oh yes. Tabs or spaces in source code. That's really what makes software great. Just have guidelines and stick to them. What sucks is inconsistency. Everybody's got an opinion about code layout. It doesn't matter. There's no good or bad layout. Readability is just another word for "looking like stuff I'm used to read".

What's interesting is that I never used to care how code was indented, never bothered me. However, I got a job using Python/Django, and almost all of the code in that community is in the PEP8 style (4 space indents, etc, http://www.python.org/dev/peps/pep-0008/ ). Now whenever I read python code that is outside of PEP8 just a little bit, it makes me cringe, but I can still read other, non python code indented almost…

To be fair, this is partly because python is uniquely sensitive to whitespace issues. Other languages don't tend to care as much. C code that's mixed between 2, 4, and 8 space indentation might be untidy, but it's really not that big a deal to read it as long as the code isn't broken in other ways.

Re: Why I prefer no tabs in source code

#19
post #15
post #11

Earlier quoted context omitted.

You're being modded down as that's not a complete sentence, but yes, since there's a standard (PEP 8) stating that spaces are preferable to tabs, and that indentation should be 4 characters, and all modules I've seen use that standard, tabs are indeed looked upon as being bad in Python.

It's not just that. The REASON why tabs are so bad is because it makes very very subtle errors when they get mixed. Additionally, tabs are 8 spaces to the python interpreter. If you're not using 8 space tab stop, you're setting up people who use your code for a world of hurt if they ever change anything in your files.

tabs and spaces are different things to the Python interpreter. If you really want to, you can mix them in your code. But you cannot mix tabs and spaces on the same indent level.

Re: Why I prefer no tabs in source code

#20
If you use spaces instead of tabs, you're never relying on a particular editor or pager to have tab width set correctly.

Tabs aren't just used at the beginning of lines. There might be a left-aligned, multi-line comment to the right of a block of code(...)

I cannot fathom what point he thinks he's making with these. If you're using tabs in a way that depends on tab width, you're doing it wrong.

Tab indentation generally means that one tab character is one layer of indenting. That's it. It's about semantic structure, not layout.

If you want to make ASCII art, or align things like paragraph-style comments, or "indent" things that aren't part of a block of code like pieces of a lengthy conditional clause split over multiple lines, use spaces instead (and then the five people who use proportional fonts will complain that using spaces for alignment "isn't portable"). Of course, if you're using a language with an off-side rule for syntactic whitespace even a die-hard tabber ought to just use spaces.

Personally, I dislike that sort of non-semantic formatting business in source code (and I think off-side rules in syntax are a horrible idea), but that's a matter of taste. And obviously, consistency is vastly more important than the particulars of indenting style. But I get tired of people arguing against tabs on the basis of not knowing how to use them properly.

On the other hand, this unintentionally makes a different, very strong argument in favor of using spaces: people can't manage to use tabs properly, so don't let them. This is why we can't have nice things, folks!

Post reply on HN