Code Beautifier

Discussions related to programming Transport Empire.

Moderator: Transport Empire Moderators

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

Code Beautifier

Post by uzurpator » 22 Oct 2005 23:06

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 » 30 May 2006 01:40

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 » 31 May 2006 15:32

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 » 04 Jun 2006 08:00

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 » 15 Jun 2006 18:22

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 » 16 Jun 2006 13:37

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 » 16 Jun 2006 18:15

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: 2134
Joined: 10 Jan 2003 12:21
Location: Wroclaw, Poland / Katowice, Poland

Post by uzurpator » 16 Jun 2006 21:17

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 » 15 Jun 2007 01:16

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