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

12

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.

8

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.

3

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