![]() |
|
Indentation (4 spaces vs 8 spaces) |
OICW
Member #4,069
November 2003
![]() |
I prefer 2 spaces. Soft indentation at all costs, doesn't matter if the number of spaces should be higher, but tabs are evil. Because tab character is represented by various number of spaces across the editors. So I set tab in IDE to insert 2 or 4 spaces instead. And I know what I'm talking about, I opened .cs file generated in MSVC by two people in kwrite and what I got was a mess. Code wasn't aligned, because indentation was all messed up - sometimes spaces, sometimes tabs. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Audric
Member #907
January 2001
|
Tab characters are always ambiguous, some software show them as N hard spaces, some align on columns multiple of N. |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: Googlecode doesn't handle tab characters, the code loses all indentation when viewed in the site. Why don't I believe this? Oh, because it's completely untrue -- Ryan Patterson - <http://cgamesplay.com/> |
Audric
Member #907
January 2001
|
Well, on Firefox 2 the tabs disappear entirely. I don't blame the software or site, I just try to do my best with what I have (which is windows 98). |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: Glad to know it works on whichever browser you're using. Firefox 3, and tabs displayed fine in Firefox 2 -- Ryan Patterson - <http://cgamesplay.com/> |
Onewing
Member #6,152
August 2005
![]() |
Working by myself, whatever the default tab is. ------------ |
decepto
Member #7,102
April 2006
![]() |
Interesting reading for anyone interested in the coding style used in the linux kernel. http://www.linuxfromscratch.org/alfs/view/hacker/part2/hacker/coding-style.html My favorite quote from it: Quote: ...if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
-------------------------------------------------- |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Quote: ...if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
That's stupid. In many modern languages, there is a namespace, a class and then methods... That's 3 levels of indentation right there. No control structures for you!
|
bamccaig
Member #7,536
July 2006
![]() |
@Jonatan Hedborg: I'm pretty sure those are C specific style preferences. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
I'm not so sure. Quote: Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.
He seems pretty religious about it
|
Audric
Member #907
January 2001
|
To enforce a coding style you can convince people, or you can terrorize them into it OT: CGamesPlay, I was doubly mistaken about googlecode, the rendering is flawless on all FF versions, it's on ie6 (at work, I must have used it by accident) that it fails. Not on the page you tested (text/plainm no HTML), but on http://code.google.com/p/linkage/source/browse/trunk/src/EditColumnsDialog.cc which converts TAB characters from source into 8 spaces of <pre> HTML, and in http://code.google.com/p/linkage/source/detail?spec=svn545&r=512 which preserves TABs and spaces. In both pages, all indenting is lost, no matter if it's done in spaces or tabs. |
Steve++
Member #1,816
January 2002
|
While it's true that the display of tabs depends on the viewer, tabs should not be used on a line after any non-tab characters. So they should be used strictly for leading indents. When that rule is followed, the readability of code shouldn't be affected by the number of spaces that the tab character represents for the person viewing it. |
Johan Halmén
Member #1,550
September 2001
|
Quote: He seems pretty religious about it Well, there's something religious in the belief that there would be an optimal coding style, whether we're speaking about indents, is-a/has-a, global/local variables, mixing C with C++ or whatnot. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
ReyBrujo
Moderator
January 2001
![]() |
I hate tabs, they are awful, especially when people combine them with spaces (for example, if tab is set at 8 and they are indenting with 4, and need to do 12, they press a tab and four spaces!). So, I press the space bar four times and done. -- |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Quote: or example, if tab is set at 8 and they are indenting with 4, and need to do 12, they press a tab and four spaces What kind of idiot would do that? One tab = one level of indentation. If they have 8 that would be at 8, 16 and 24. Why would they need to do 12?
|
bamccaig
Member #7,536
July 2006
![]() |
We've already been over this... The optimal solution is to use tabs for indentation and spaces for alignment. teh_codez { [tab]teh_codez [tab]{ [tab][tab]teh_codez [tab][tab]teh_codez moar_codez moar_codez [tab][tab] moar_codez ^ identation ^ alignment [tab][tab]teh_codez [tab]} [tab]teh_codez } No matter what editor you view that code in, it should always appear cleanly indented. You can also indent with a single key press and remove indentation (even in simple editors) with a single key press. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
ReyBrujo
Moderator
January 2001
![]() |
Quote: What kind of idiot would do that? One tab = one level of indentation. If they have 8 that would be at 8, 16 and 24. Why would they need to do 12? Many. Especially if they want 4 spaces as tab, but they never configure tab to move 4 instead of 8, so they just do it manually mixing spaces and tabs. -- |
X-G
Member #856
December 2000
![]() |
3 spaces. -- |
Goalie Ca
Member #2,579
July 2002
![]() |
Softabs of 4 spaces in vim. Alignment comes out same in all editors. Vim's backspace doesn't break either. ------------- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Softabs of 42 spaces in vim. Alignment comes out same in all editors. Vim's backspace doesn't break either. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Indentation is for sissies. Real Programmers(TM) don't use line breaks, either. After all, unnecessary whitespace is wasteful. --- |
BAF
Member #2,981
December 2002
![]() |
That linux coding style is awful. And the doc is obviously written by an opinionated douchebag too. |
CGamesPlay
Member #2,559
July 2002
![]() |
It was written by Linus? -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
![]() |
I like to indent the outtards instead of the innards. Since indented things stand out more the important stuff (like function names) get the most attention. void output(ostream &out) { for(int i = 0; i < 24; i++) if(i%24) for(int j = 0; j < i; j++) out << i * j << endl; } It also just looks prettier. |
|
|