6 ms·
Swift Style: Are you a 4-denter?
- alttab 11y ago4 for Java, 2 for Ruby and javscript. Essentially, 4 for anything in an IDE, and 2 for VIM :)
- Mithaldu 11y agoAs i get older i opt for 4 spaces over 2 for a simple reason: My eyes are not getting better and reading 2 spaces is actually harder even though i'm only a little short-sighted.
- joeblau 11y agoI use 4 because that's how Xcode set it up. I used to use 2, but when you're working in a joint code-base without a linter (almost anything on GitHub) 4 spaces is the standard.
- shawkinaw 11y agoThe only language I sometimes use 2 spaces for is HTML, since you can get so damn deeply nested. But even then I usually use 4 because it's so much easier to see the structure.
- mooseburger 11y ago4 is more legible. Besides, that's what's recommended in the Python style guide, and Python is my sweet lover. https://www.python.org/dev/peps/pep-0008/#indentation https://www.python.org/dev/peps/pep-0008/#indentation
- julie1 11y ago8 in C if the lead says 8 because in C you want people to limit the cyclotymic complexity of their code. C is hard to read. 4 in C when I code for fun or the lead says 4. In fact 4 is a pretty decent visual aid and not to big for my use of 80 car/lines 25lines max per functions/method that I respect religiously and loosely) since 1998. I think being able to see the whole code without scrolling on a VT is kind of preparing yourself for the worst case (debuging in prod with vi/emacs or notepad) where attention is the key point under stress. Prepare yourself for the worst, the worst may happen. In python, well, I pray that the lead does not mix tabs and space. Because, what a beautiful idea to have made indistinguishable characters significant. That is one of my huge beef with python as well as the inability to control the scope of variables (hence preventing strictures). So I have strong opinions, but the lead wins when the lead is a benevolent dictator that proved to be right very often (like linus, theo, guido...). The one who lead the project to its success makes the rules and as long as the project is going a way I like, I follow the guidelines happily.
- d0lph 11y ago"Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program." --Linus Torvalds
- kazagistar 11y agoI prefer tabs for indentation and spaces for alignment, but sadly, everyone seems to hate this. Either way, I adapt to the norm/standard of the language/project in question, like a sensible developer.
- charlesism 11y agoIf everyone hates it, you've probably made the correct choice (for solo projects, at least). With spaces, you not only repeat yourself needlessly, but you also lose the semantic difference between indentation and token separation (which is why converting spaces to tabs always leaves you with a few incorrect sections, whereas tabs to spaces does not). But, again, it's tech, so the least sensible answer is usually the most popular. I wonder if it just makes some people feel manlier to write cryptic-looking camelCase with a crapload of redundant space characters.
- mixedCase 11y ago>If everyone hates it, you've probably made the correct choice That's why I'm a Visual Basic Rockstar Ninja.
- charlesism 11y agoDid you read my last sentence? The whole problem is that, despite consciously knowing better, programmers have a perverse urge, in the depths of their psyches, to make everything seem as difficult as possible. I can't think of any other reason why we still use camelCase, for example. I think most devs prefer spaces to tabs (yes, literally typing in redundant spaces, while also losing some semantic content) Maybe it's because you always get consistent spacing that way, but maybe - just maybe - it's because of a puritanical urge to make programming harder. Everyone in technology is aware of how important it is to keep things clear and simple, but deep in the soul, a lot of us just want to be Neo, typing bizarre hieroglyphs that only we ourselves are clever enough to decipher.
- charlesism 11y ago
- Rockslide 11y agoSo clearly, there are people who favor 2 and people who prefer 4. Solution: Indent with tabs, configure your editor, and everyone is happy. I don't get why people still promote the use of spaces.
- x1798DE 11y agoI generally use spaces (in Python) to make up the difference when aligning. If you switched the tab size a bunch of visually indented code would become a complete mess.
- Etzos 11y agoThe rule when using tabs is: indent with tabs, align with spaces. Tab everything out to the proper indentation level, and then if you want to align something then you use spaces on top of that indentation.
- CJefferson 11y agoThe problem is that when some line inevitable has space-based indent (which is basically impossible to see), then indentation goes crazy. Of course, the same thing can happen with spaces, but it generally easier to fix. You can have a "no tab anywhere" policy, and easily enforce it. You can't have a "no space anywhere", or even a "no spaces at the start of lines", for example: while(1) { if (a == b && b == c && d == e && f == g && h == i) { .... We need to tab-indent the 'if', but do tab+4 spaces the 'f == g'. That's very hard to automatically check and enforce
- Etzos 11y agoI personally turn invisible characters on so mistakes like that are a bit harder to make. Along that line of thinking, the code should probably be reviewed by at least one other person before being officially committed, so one would hope that would be the place to find and fix such errors. Personally I've always felt the benefit of letting everyone set their own indentation level far outweighs the off chance of someone misindenting code (and I've never seen it cause a problem so far, not that it means much).
- monocasa 11y agoTabs for indentation, spaces for alignment. Then everyone can setup their editor for whatever they prefer. Crazy, right?
- pklausler 11y ago3 spaces seemed to be the norm for block-structured languages (Pascal, PL/I, Cybil, PLUS, etc.) back in the "card image" days before tabs appeared in C source files. I think it worked because chains of END would line up in a nice diagonal. I got used to 2 spaces in C++ in a big shop overrun with Style Guide fundamentalists and really long API names, but it's just not enough to convey logical nesting at a distance. I've seen code, can't remember where, that used 4 space indentation for loops and 2 spaces for conditionals, so that indentation depth more accurately reflected runtime cost.
- breuleux 11y ago> They found that indentation level had a statistically significant effect on comprehension, and optimal indentation fell somewhere between 2 and 4 spaces. There's your answer. 3.
- tater_sent_me 11y agoWho cares. lint on check in.