|
But again tabs aren't the same # of spaces on each editor. Sure it's fine when when you're just indenting lines but it gets messy if you have something like:
if(variableA == 0 && variableB == variable A && variableC == 50 && variableC == 2031) {
Something where you want to indent an amount that looks good, but isn't necessarily 'standard'.
Also it has problems where if someone uses spaces on one line for indentation (by mistake or whatever) then it's going to throw the whole formatting off. It can also be just a general pain in the ass, for example if I'm looking at a file through source control I may just open it in notepad++ or the source control's GUI editor where the tabs aren't configured to be a good # of spaces.
Meanwhile spaces are pretty much always handled correctly and always work out well.
|
On August 31 2011 04:43 Cambium wrote: Tabs don't work well because different people prefer different IDEs/editors and operating systems, so it's almost impossible to use tabs. Also, most diff tools don't work well with tabs from different OS.
Just because you use 4 spaces, it does not mean you have to press 'space' 4 times. Most IDEs offer you the option to use "soft tabs" which converts tabs to spaces automatically.
But then if you're deleting a "tab", you'd actually have to hold backspace for long enough to erase 4 spaces instead of one character, right? Still too annoying imo, and really, all that to solve a problem that you can solve just by talking to people (who are working with/on your code), or leaving some notes for people who come later on?
|
On August 31 2011 04:43 Cambium wrote: Tabs don't work well because different people prefer different IDEs/editors and operating systems, so it's almost impossible to use tabs. Also, most diff tools don't work well with tabs from different OS.
Just because you use 4 spaces, it does not mean you have to press 'space' 4 times. Most IDEs offer you the option to use "soft tabs" which converts tabs to spaces automatically.
what? different tabs from different OS's? are you serious? xD there is only one tab char (\x09 aka \t), just as there is only one space char (\x20). There's just three different kinds of line breaks. Unix uses LF or \n or \x0d, old macs used to use CR or \r or \x0a, and windows uses CRLF or \r\n or \x0a\x0d to do line breaks. but all tabs are equal. The only difference you can see in tabs is editor settings, which set the tab width to a multiple width of spaces, but it's still just the same kind of tabs.
|
On August 31 2011 04:54 Talin wrote:Show nested quote +On August 31 2011 04:43 Cambium wrote: Tabs don't work well because different people prefer different IDEs/editors and operating systems, so it's almost impossible to use tabs. Also, most diff tools don't work well with tabs from different OS.
Just because you use 4 spaces, it does not mean you have to press 'space' 4 times. Most IDEs offer you the option to use "soft tabs" which converts tabs to spaces automatically. But then if you're deleting a "tab", you'd actually have to hold backspace for long enough to erase 4 spaces instead of one character, right? Still too annoying imo, and really, all that to solve a problem that you can solve just by talking to people (who are working with/on your code), or leaving some notes for people who come later on?
instead of backspacing 4 spaces, on most IDEs you can just select the lines and shift+tab to move them "back" one indent-width (4 spaces)
|
I know people that use none. I wish I could punch code.
|
I use two, even though the standard for most editors seems to be 4, it's too much in my opinion to work with. First thing to change!
@MisterD, what micro management? Mouse control, ezpz, keyboard control? Use ctrl+shift+arrow key. To remove it, just do as you said yourself, shift+tab.
|
On August 31 2011 04:58 MisterD wrote:Show nested quote +On August 31 2011 04:43 Cambium wrote: Tabs don't work well because different people prefer different IDEs/editors and operating systems, so it's almost impossible to use tabs. Also, most diff tools don't work well with tabs from different OS.
Just because you use 4 spaces, it does not mean you have to press 'space' 4 times. Most IDEs offer you the option to use "soft tabs" which converts tabs to spaces automatically. what? different tabs from different OS's? are you serious? xD there is only one tab char (\x09 aka \t), just as there is only one space char (\x20). There's just three different kinds of line breaks. Unix uses LF or \n or \x0d, old macs used to use CR or \r or \x0a, and windows uses CRLF or \r\n or \x0a\x0d to do line breaks. but all tabs are equal. The only difference you can see in tabs is editor settings, which set the tab width to a multiple width of spaces, but it's still just the same kind of tabs. Ah you are right. I was thinking about new line, which almost always precedes the tabs.
|
Using tabs or spaces doesn't really matter as long as everybody's using the same thing. It makes diffs super annoying when you see a bunch of whitespace changes.
|
I use two since it's just enough to easily tell that it's indented. When I see 4-space indents, I feel like "whoaaaa calm down there!" Plus sometimes my terminal is only 80 characters wide and won't resize.
Another style convention I'm curious about is bracket usage, i.e.
int main(void) { return 0; }
vs
int main(void) { return 0; }
I personally prefer the first, although it probably doesn't add too much in terms of clarity.
EDIT: Er. Apparently the editor doesn't like leading spaces? The return statements above should be indented... <-- newb
|
I use two spaces indent and put the open bracket at the end of the same line rather than a new line.
But since I'm an EE you should probably look at all of my programming practices and do the opposite.
|
On August 31 2011 10:11 Melchior wrote: I use two since it's just enough to easily tell that it's indented. When I see 4-space indents, I feel like "whoaaaa calm down there!" Plus sometimes my terminal is only 80 characters wide and won't resize.
Another style convention I'm curious about is bracket usage, i.e.
int main(void) { return 0; }
vs
int main(void) { return 0; }
I personally prefer the first, although it probably doesn't add too much in terms of clarity.
EDIT: Er. Apparently the editor doesn't like leading spaces? The return statements above should be indented... <-- newb
If you quote my earlier post that has indentations like that, it'll show you the tags.
<code> fajskfjaskflg </code> will keep formatting proper. Obviously you use [] instead of <>
|
On August 31 2011 03:56 huameng wrote: 4 spaces is the standard I think. I highly recommend it.
yah, i'm pretty sure 4 is, because i always remember getting annoyed when everyone was tabbed and i would have to obsessive compulsively move everything back 1 space lmao.
|
I know we programmers love coding our own way and get annoyed by seeing other programmers coding style. But I had no idea the "proper amount of spaces" was a big deal. I don't know what you guys are using that doesn't convert tabs to spaces, but I have not run into issues with using Tab and Shift+Tab.
|
On August 31 2011 21:18 EscPlan9 wrote: I know we programmers love coding our own way and get annoyed by seeing other programmers coding style. But I had no idea the "proper amount of spaces" was a big deal. I don't know what you guys are using that doesn't convert tabs to spaces, but I have not run into issues with using Tab and Shift+Tab.
I think the question is more what is your softabbing setting rather than if you do it or just use non space converting tabs.
|
Depends on the language, but usually i use tabs and configure vim to use different tab sizes for different file types.
HTML: 2 PHP: 2/4/8 depending on the project i'm working on as my coworkers use wildly varying styles - from 2 spaces to some spaces, then tabs, then spaces, then start of the line or other crazy mixtures of tabs and spaces.
Perl: 4 C/C++/C#/Java: 8 Bash/Windows shell scripts: 2 SQL: Depends on the query, usually 4
Basically i go by whatever looks the most easy to read for the language and editor in question. I don't see a reason to use spaces instead of tabs as tabs allow everyone to use the indentation he likes. It only gets crazy if spaces and tabs are mixed, but thats a fault of the programmers, not of the tabs themselves.
Basically, if you use tabs, you avoid all arguments about which indentation to use... problem solved.
On August 31 2011 04:37 EtherealDeath wrote: Why did people ever use 8 back in the day anyways. Sounds horrible.
With small fonts, 4 character indent is too small and can easily be missed if you are not careful when reading the code, 8 gives a clearly noticeable indent and makes it easier to quickly read code. For bigger fonts, 4 is no problem, but with a fontsize 8 or 9 px it's just too small.
|
I don't really code anything serious nowadays (most I ever do at work is Excel VBA) but I've used 4 for most of the stuff.
|
4 but i usually do functional stuff these days so it doesnt really show up that much.
|
On August 31 2011 04:14 Torenhire wrote:if( spaces == 4 ) { spaces = perfect; } else { programmer sucks }
i still cant believe no one commented on how he's setting an int to perfect.
|
On September 01 2011 02:55 Enderbantoo wrote:Show nested quote +On August 31 2011 04:14 Torenhire wrote:if( spaces == 4 ) { spaces = perfect; } else { programmer sucks } i still cant believe no one commented on how he's setting an int to perfect.
Don't forget that he forgot the line terminator in the else (though some languages allow you to skip it). "perfect" might be a variable containing 4, ich which case that would be:
if (spaces == 4) { spaces = 4; } else { programmer sucks; // is it c++? why create a variable sucks of type programmer in a scope // where you don't do anything with. Constructor abuse? }
|
On August 31 2011 04:14 Torenhire wrote:if( spaces == 4 ) { spaces = perfect; } else { programmer sucks }
1>ClCompile: 1> main.c 1>.\main.c(15): error C2146: syntax error : missing ';' before identifier 'sucks' 1>.\main.c(16): error C2143: syntax error : missing ';' before '}' 1> 1>Build FAILED.
if(spaces == 2 && style == "like this") { code = "perfect"; } else { vomit(); }
|
|
|
|