strange indentation style

Started by
32 comments, last by Cygon 16 years, 9 months ago
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? Image Hosted by ImageShack.us Here's another image that shows some functions, that's what the above image was lacking to better see the structure... Image Hosted by ImageShack.us
Advertisement
Looks to me like it is an issue with autoindentation and tabs versus spaces if anything.
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.
Quote:Original post by SiCrane
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.


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.
Quote:Original post by Lode
I 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.)
Quote:Original post by Way Walker
Quote:Original post by Lode
I 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 :)
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.

throw table_exception("(? ???)? ? ???");

Quote:Original post by ravyne2001
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.

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.
Ah my eyes.
Delete it please!

I agree with ravyne on this. Tabs and space to align when necessary.
Quote:Original post by Sneftel
Quote:Original post by ravyne2001
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.

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.

This topic is closed to new replies.

Advertisement