Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Indentation (4 spaces vs 8 spaces)

This thread is locked; no one can reply to it. rss feed Print
Indentation (4 spaces vs 8 spaces)
ReyBrujo
Moderator
January 2001
avatar

In the end, there is always indent to indent if necessary.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Edgar Reynaldo
Member #8,592
May 2007
avatar

dimebagdan said:

But I've been forced to use the space more and more recently, because codeblocks didn't want to link up to allegro properly,

CodeBlocks links to Allegro just fine for me - start a new thread and I'll help you with it if you like.

bamccaig
Member #7,536
July 2006
avatar

ReyBrujo said:

In the end, there is always indent to indent if necessary.

I was disappointed to learn that GNU indent is apparently C only. I guess there are a few C++ formatters, but none seem to stand out. I had hoped to use it to automatically format code between some project agreed standard and my preferences, but would need support for C++ (and something that supported other languages, like C# would also be great).

Edgar Reynaldo
Member #8,592
May 2007
avatar

bamccaig said:

I had hoped to use it to automatically format code between some project agreed standard and my preferences, but would need support for C++ (and something that supported other languages, like C# would also be great).

SiegeLord mentioned using AStyle for formatting the other day - looks like it supports the uses you just mentioned.

CGamesPlay
Member #2,559
July 2002
avatar

I think Visual Studio does C++. If it does it as well as it does C#, you should be good.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

Edgar Reynaldo said:

SiegeLord mentioned using AStyle for formatting the other day - looks like it supports the uses you just mentioned.

Yeah, I had found that when I did a search. I was still in disappointment mode though from learning the GNU solution wouldn't satisfy my needs and haven't really given anything else a chance yet. :-/ Have you tried it yet?

CGamesPlay said:

I think Visual Studio does C++. If it does it as well as it does C#, you should be good.

There are a few things Visual Studio doesn't budge on, like for example my (possibly odd) habit of putting the colon for inheritance against the class/struct name, and then listing the various base classes (and, in C#, interfaces) that it inherits, each on it's own line, indented one level.

class MyClass:
    public YourClass,
    public HisClass
{
};

I can't get Visual Studio to do that automatically. It will either list them on the same line as the class name, or will drop the colon onto it's own line indented one level as well. :-/

I also got into the habit of using return syntactically like a function, in that I always follow it with parenthesis:
return(0);
Visual Studio insists on putting a space between the return and (0);, which I find annoying. Perhaps I should just get in the habit of not using parenthesis for statements like that. :P It would be nice though if whatever was formatting the code would allow specific rules, like if there is no outer parenthesis around the return value, put a space, but if there is, don't.

Also, though, I'm mostly interested in a UNIX solution because I don't like to develop in Visual Studio (I don't want to become dependent on a Windows-specific). And also, I expect UNIX probably has a more powerful and flexible solution. For example, something that could be scripted and automated.

Speaking of which, does anybody know if it's possible to tie something like a source formatter in with subversion? Preferably on the server-side so the repository's configuration was consistent, but also on the client-side so each client could configure the format for their own preferences.

For the server-side, I had the impression that hook scripts were able to affect the committed code in some way, but when I looked them up yesterday to confirm I was disappointed to see no suggestion and no data being passed that stood out as providing that kind of detail. I think there is a pre-commit or something that does get a transaction identifier, so in theory maybe it would be possible to affect the code at that time? :-/ It doesn't sound overly likely though.

** EDIT **

I took the time today to install AStyle and write up a configuration file for myself. I really like the configuration files that are full of comments and walk you through the configuration inline, so I basically created a template out of the online CLI options documentation. I figured it might be useful for some other people (even if you don't like my [untested] configuration, it should serve as a useful template to work with).

.astylerc

I tried to avoid the options that have disclaimers attached to them. :P I figured changing the suffix to something like .pre-astyle would be less likely to collide with a previously backed up version. Since AStyle doesn't seem to document what it would do in such a circumstance, I'm assuming that it must assume it created the .orig files and would subsequently overwrite them without thinking.

Note that while the command line arguments are supposed to override the configuration file, it doesn't look like all options have an off switch and I didn't see any syntax to undo an option from the command line, so I expect there are some options that the configuration file will insist upon. :( This is something that I believe should be fixed.

This should summarize the options I'm going with initially:

[bamccaig@rufus ~]$ cat ~/.astylerc | grep '^[^#]'
indent=tab
brackets=break
indent-namespaces
unpad=paren
suffix=.pre-astyle
preserve-date

** EDIT **

So far I am not impressed. >:( Not only did it [seemingly] modify the in-place file, but it also seems to have made changes to the "backup" file. >:( Not only that, but instead of removing padding from parenthesis, it's ADDING it! Fortunately, fixing the padding was apparently fixed with sed:

[bamccaig@rufus iq]$ sed -r 's/\( /\(/g' app.cpp | sed -r 's/ \(/\(/' > app.cpp 2>&1

As evidenced by meld1. I could be wrong about this (I certainly hope the mistake was mine)... I'm going to do some more testing (on backup files!) to see what the real result of AStyle is. :(

Unfortunately, I also forgot to put in the indent=tab option the first time so now my source file has spaces. I think I'll try to fix that with sed too (which I've been meaning to become more competent with anyway) until I have more faith in astyle... :-X

** EDIT **

Confirmed that AStyle is padding parenthesis... >:( Then WTF is unpad=paren for?!

1 I'm happy to find a nice and simple diff viewer. vimdiff is probably super powerful for experienced vim users, but right now I just find it difficult to use. I wonder if meld is cross-platform. sdiff also seems like a nice diff viewer, but it doesn't seem to support coloring and the like to make differences stand out (just a vertical bar by the looks of it)... Still should be a good complement to diff though.



Go to: