Jump to content
  • Advertisement
Sign in to follow this  
Lode

strange indentation style

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

If you intended to correct an error in the post then please contact us.

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? 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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!