Page 1 of 1

Code Beautifier

Posted: 22 Oct 2005 23:06
by uzurpator
Does anyone know a good code beautifier? Because we are obviously are going to need a code standarizer...

Posted: 30 May 2006 01:40
by aarona
Code::Blocks comes with a plugin called "Source code formatter" (AStyle). This just changes the way it looks by auto-indenting, brace alignment etc.

It may not be to everyones liking however.

For example the following code

Code: Select all

class Something {
    int r(void) { return 10; }
    void c(int p) {}
};
gets tranformed into

Code: Select all

class Something
{
    int r(void)
    {
        return 10;
    }
    void c(int p)
    {}
}
;

Posted: 31 May 2006 15:32
by Steve
Well, the most obvious thing would be to make sure people to use Hard Tabs, not spaces. That way each person can view the code in whatever space indentation they prefer.

Posted: 04 Jun 2006 08:00
by aarona
Upon further research AStyle is actually a program which can convert to any style possible, be it hard tabs, fixed spaces, ANSI, gnu, unix, Kernighan and Ritchie, Java style or any custom variant.

I suggest checking out their web site http://astyle.sourceforge.net/. (Note this is actually an external program and plug-in to Code::Blocks)

Lets say people have different ideas of what looks good...

1. Someone loads the project from CVS
2. Applies their own AStyle to the code
3. Writes more code
4. Applies the universal AStyle (that the community decides upon) styling
5. Upload to CVS

This may solve any conflicts with, "lets do it my way" and will standardise the code format.

Posted: 15 Jun 2006 18:22
by Hellfire
aarona wrote:4. Applies the universal AStyle (that the community decides upon) styling
5. Upload to CVS
These two steps will only work well when applying steps 2 and 4 to a file will yield the same file again. But other than that, I don't see any objections.

Posted: 16 Jun 2006 13:37
by Steve
I do however predict many times where someone forgets to reapply the universal style. Is there anyway this can be done automatically when it's submitted to CVS?

Posted: 16 Jun 2006 18:15
by argonel
Steve wrote:I do however predict many times where someone forgets to reapply the universal style. Is there anyway this can be done automatically when it's submitted to CVS?
Yes, it could be done. But should it? It could cause merge conflicts in the working copy of the individual commiting the differently styled code. It could cause white space-only commits. If the tool doing the styling fails or outputs incorrect code, it could break the continuity of the repository.

It could be less dangerous to have a cron script check out the code, style it and check it back in - but still probably overkill.

I'm unsure of what problem you're trying to solve. Minor style errors are a fact of life.

Posted: 16 Jun 2006 21:17
by uzurpator
Geeeeez :)

A code is a code.

Code beautifier will parse a valid c++ code, whichever style, and outputs the desired style.

And yes - CVS should automagically to that.

Let's just apply before each release :-)

Posted: 15 Jun 2007 01:16
by neroden
Let's just apply the style standardizer before each release. :-)

OK, optimistic saying that there'll be a release, I know....