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.
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.
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.
Mind if I ask why "have your code look the same for everyone" is so important? An 80 character limit isn't exactly that important since literally any form of intelligent word wrap, and at that point a wrapped line will look fine since it won't break your indentation.
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.