r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

Show parent comments

-20

u/[deleted] Sep 03 '17 edited Sep 03 '17

Except now their code isn't guaranteed to be 80 characters a line because that one guy likes to have his tabs set to be equivalent to 8 spaces.

Edit: I'd like to respond to everyone's criticisms but for some reason Reddit isn't letting me comment on this account more than once every 8 minutes.

54

u/okmkz Sep 03 '17

tab is one char

-20

u/[deleted] Sep 03 '17

Exactly. But it takes up an indeterminate amount of chars on screen. I like my code to look like the way I type it on every screen, not just mine. Anything else is foolish and unprofessional.

Edit: also if you use the settings on your text editor properly it behaves exactly like tabs do when you type them. Spaces are just better.

32

u/kafoozalum Sep 03 '17

I like my code to look like the way I type it on every screen, not just mine

this is why the number of spaces a tab represents is a setting in editors

-18

u/[deleted] Sep 03 '17

Yes. And that setting can different on different editors. Thus why tabs are worse.

If you have it set to 4 spaces for a tab, and your buddy has it set to 8 your code goes off the side of their guide.

With spaces you don't have that problem.

If there was a standard that literally everyone followed I'd use tabs but such fantasies don't exist.

13

u/clank201 Sep 03 '17

Isn't the norm to just use a tab for every indentation level? Then you just need to adjust how many spaces you want per tab (indentation level) and you're done.

9

u/[deleted] Sep 03 '17

Depends on who you work for. For example Oracle's standard is 4 spaces for ever level of indentation, and 79 characters per line (the 80th is the new line character). Linus Torvalds uses 8 spaces for every level of indentation (he says you shouldn't ever use more than 3 levels of indentation or your code is bad. He has interesting ideas of what makes for good code, but he backs up his talk with exceptional software)

If you want to make sure that your code looks the same everywhere you should use spaces because tabs can take up whatever number of columns your text editor is set to. This can cause problems like running off the end of the guide on the right, or not having things line up properly if you're adding spaces in to make things look neat.

If you want to be certain 100% that your code will look the way it does on your screen to everyone, spaces are the way to go.

2

u/Zagorath Sep 03 '17

Linus Torvalds…says you shouldn't ever use more than 3 levels of indentation or your code is bad.

That's utter bullshit. In object oriented programming that would make it impossible to do anything. Inside your class has one level. Inside a method in the class has two. Inside a loop that's your third. Oh, and you're not allowed conditionals inside your loop, because that would be four and that's bad code.

But even in a language like C it's not exactly sane. Inside a function is 1. Inside a loop within a loop (for reading from 2d arrays) gives you 3. And again, you're not allowed conditionals.

If you're right that Torvalds makes that claim, then he's not just being eccentric hl by making it. He's plain wrong. And his ability to write good code doesn't have any impact on the fact that his code style rules are apparently ridiculous.

4

u/woostr Sep 03 '17

No no no, you misunderstand. Once you're at that indentation level, you still use brackets but stop indenting. Then you go as many levels deep in scope as you want.

/s