Code Beautifier

Discussions related to programming Transport Empire.

Moderator: Transport Empire Moderators

Post Reply
User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2178
Joined: 10 Jan 2003 12:21
Location: Katowice, Poland

Code Beautifier

Post by uzurpator »

Does anyone know a good code beautifier? Because we are obviously are going to need a code standarizer...
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
User avatar
aarona
Traffic Manager
Traffic Manager
Posts: 221
Joined: 26 May 2006 15:54
Location: Perth, Australia
Contact:

Post 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)
    {}
}
;
User avatar
Steve
Tycoon
Tycoon
Posts: 2085
Joined: 10 Jan 2004 20:19
Location: London
Contact:

Post 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.
User avatar
aarona
Traffic Manager
Traffic Manager
Posts: 221
Joined: 26 May 2006 15:54
Location: Perth, Australia
Contact:

Post 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.
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post 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.
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
User avatar
Steve
Tycoon
Tycoon
Posts: 2085
Joined: 10 Jan 2004 20:19
Location: London
Contact:

Post 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?
argonel
Engineer
Engineer
Posts: 3
Joined: 27 Jan 2004 14:19

Post 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.
User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2178
Joined: 10 Jan 2003 12:21
Location: Katowice, Poland

Post 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.
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
neroden
Engineer
Engineer
Posts: 13
Joined: 29 May 2005 10:30

Let's just apply before each release :-)

Post by neroden »

Let's just apply the style standardizer before each release. :-)

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

Return to “Transport Empire Coding”

Who is online

Users browsing this forum: No registered users and 1 guest