# strange indentation style

This topic is 4156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Most gnu-style projects, which are usually written in C, have an indentation style that I don't really like. I really find it hard to read code with such an indentation style. But now I saw a library (libvorbis) with the weirdest indentation style I ever encountered. I'm wondering if this really is an existing indentation style, or if maybe it's just random? The thing that bothers me is that some lines of code are more to the left than the ending } after them, and that some braces are at seemingly random places. And at the top, the if is more to the left than the for in whose scope it is. Is there anything you can recognize in this style? Here's another image that shows some functions, that's what the above image was lacking to better see the structure...

##### Share on other sites
Looks to me like it is an issue with autoindentation and tabs versus spaces if anything.

##### Share on other sites
If I had to guess, I'd say that's the "some bastard mixing tabs and spaces" style. Specifically the "my tab is eight spaces, but I indent only two" school of indent-fu.

##### Share on other sites
Quote:
 Original post by SiCraneIf I had to guess, I'd say that's the "some bastard mixing tabs and spaces" style. Specifically the "my tab is eight spaces, but I indent only two" school of indent-fu.

Bingo!

If I search&replace all tabs into 8 spaces, it looks a lot better.

I wish tabs weren't used by people in code, any editor can show them in any different way, they screw up everyting.

##### Share on other sites
Quote:
 Original post by LodeI wish tabs weren't used by people in code, any editor can show them in any different way, they screw up everyting.

Which, oddly enough, is precisely the reason people who like tabs like tabs. (Well, not that they screw up everything, but that they can show them in any different way.)

##### Share on other sites
Quote:
Original post by Way Walker
Quote:
 Original post by LodeI wish tabs weren't used by people in code, any editor can show them in any different way, they screw up everyting.

Which, oddly enough, is precisely the reason people who like tabs like tabs. (Well, not that they screw up everything, but that they can show them in any different way.)

Ok but they shouldn't mix them with spaces then :)

##### Share on other sites
The best way to do it, IMHO, is use tabs to indent, and spaces to align things. In other words, tabs should only be the leading characters on each line, all other horizontal whitespace should be spaces.

Yes, it makes your files marginally larger, and it takes an extra second or two to use spaces, but in the end it means that the code looks nice using any size indentation, so everyone can use their preference.

I've made sure that all my code uses this style, and convert any of my code that I dig up from before I changed to this style. Its easy enough to test visually by changing the number of spaces that a tab uses and inspecting.

This style is especially nice when you use an editor that doesn't support custom tab sizes. Occasionally I open a code file in notepad or something to grab a small snippet of it, and its nice that the formatting doesn't go all wonky.

##### Share on other sites
Quote:
 Original post by ravyne2001The best way to do it, IMHO, is use tabs to indent, and spaces to align things. In other words, tabs should only be the leading characters on each line, all other horizontal whitespace should be spaces.

I'm with you on this one. Unfortunately, I've been unable to wrangle Visual Studio into going along with the scheme. If there are tabs followed by spaces on a line, it'll either convert the tabs to spaces or the spaces to tabs when you hit enter.

##### Share on other sites
Ah my eyes.

I agree with ravyne on this. Tabs and space to align when necessary.

##### Share on other sites
Quote:
Original post by Sneftel
Quote:
 Original post by ravyne2001The best way to do it, IMHO, is use tabs to indent, and spaces to align things. In other words, tabs should only be the leading characters on each line, all other horizontal whitespace should be spaces.

I'm with you on this one. Unfortunately, I've been unable to wrangle Visual Studio into going along with the scheme. If there are tabs followed by spaces on a line, it'll either convert the tabs to spaces or the spaces to tabs when you hit enter.

I'm sort of with you as well. Except that tabs should only be leading characters up to the current level of indentation. And I haven't been able to wrangle gVim into going along with that. There is no weird space/tab conversion going on, but when I hit enter and it decides that the next line should get "extra" indentation (because it continues the previous line), it will gladly use extra tabs to represent that indent.

It also chooses seemingly random amounts of indentation. I would like things to line up one space past the current open bracket (or aligned with the second token of the previous line, if not within any brackets):

if (foo(bar + (baz + quux) + (spam +                              ni))) { // <-- here! All spaces up to here.	return std::string("omgwtf") +	       hax; // <-- one tab at beginning and spaces after.}

Anyway, just wanted to point out that the screenshotted code is using Duff's device. BLECCH.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633721
• Total Posts
3013535
×