Java Formatter?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Java Formatter?

Veqryn
Administrator
This post was updated on .
Ok, so most IDEs, including Eclipse and Netbeans, have formatters.  

Click [shift] + [ctrl] + [F] and whatever document you are currently working on gets re-formatted so that the lines/whitespace/brackets/etc, line up or look the way you want them to.

I was about to reformat StrongAI.java when I thought I should ask you guys (mostly wisc and squid) if you have any particular format you prefer?

99% of the current TripleA code uses:
if (blah)
{
    stuff;
    more stuff;
}

rather than:
if (blah) {
    stuff;
    more stuff;
}

so, even though I kind of prefer the first brace being on the same line, I'll go with what SBG does for TripleA.

Other than that, What do you guys want?

Please take a look at this Eclipse format file, and tell me if you like it, or would change something in it.  (you can import it into Eclipse in the Pref/properties section of your workspace/projectspace)
Formatting2_for_TripleA.xml

When you get back to me, I'll post the new formatter.xml and you can feel free to use it or change it as you see fit.  Also, I will be formatting only the files I am personally working on, or files that are fugly.  So that pretty much just means StrongAI, SUtils, WeakAI, and maybe Matches, and that is about it.  If you created a file, I won't touch the formatting (so squid, if you like things a specific way, i won't touch those files you are making).  

Thanks,
Veqryn
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

squid_daddy
nar i'm easy, format anything any way you please as far as i'm concerned.
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Prussia
I think the standard java language have formatting set so that the opening braces and the closing braces have the same indentation, this way it's easier to track where all the braces are.
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Wisconsin
In reply to this post by Veqryn
The existing code format is actually the exact way I prefer it:

    * Indentation should be 4 spaces, no tabs
    * Instance variables should be prefixed with m_
    * Static, non final variables should be prefixed with s_
    * Interfaces should start with an I, such as IRemoteDiceServer
    * Curly braces are always on their own line

I'm sure everyone who's taken a look at the StrongAI code will silently thank you for this. :\
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Veqryn
Administrator
Ok, I formatted strong ai and sutils with this formatter: Formatting2_for_TripleA.xml
(i changed the formatter to basically ignore comments in blocks, as previously it was formatting code inside blocks to include * stars all the way down, which makes it unreadable as code)

unfortunately, svn commit seems to ignore white space changes, so only the changes to { went through.

Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Sean Bridges
Administrator
Veqryn wrote
unfortunately, svn commit seems to ignore white space changes, so only the changes to { went through.
Probably you're diff viewer is set to ignore whitespace, svn won't ignore whitespace when committing,

http://triplea.svn.sourceforge.net/viewvc/triplea/trunk/triplea/src/games/strategy/triplea/strongAI/StrongAI.java?r1=2891&r2=2890&pathrev=2891
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Wisconsin
In reply to this post by Veqryn
Veqryn, it appears that the auto-formatter added tabs in place of every four spaces...
------------------------------------------------------------------------------
The following coding standards are god given,

    * Indentation should be 4 spaces, no tabs
    * Instance variables should be prefixed with m_
    * Static, non final variables should be prefixed with s_
    * Interfaces should start with an I, such as IRemoteDiceServer
    * Curly braces are always on their own line
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Veqryn
Administrator
why spaces instead of tabs... i actually like tabs...
but, i'm happy to be convinced otherwise, and can change to using spaces...
but i am curious why?
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Wisconsin
Well, for one, tabs show up differently from place to place. In Netbeans, the tabs show up as 8 spaces, (At least for me) but they show up as 4 spaces in emails, the forums, and plain text editors.

There might be some other small differences, but that's the main one. (I was taking a look at the StrongAI code and I noticed everything 8-spaced)

Thanks Veqryn,
    Wisconsin
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

squid_daddy
hrm well my question is, what whitespace do individual editors generate?
i use eclipse, so is all the code i'm submitting that was auto-indented
have tabs or spaces?
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Veqryn
Administrator
In reply to this post by Wisconsin
you can customize in your IDE exactly how many spaces a TAB equals,... with the default for eclipse being 4 spaces.

i prefer tabs because they make everything line up nicely.....
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Wisconsin
Ah, you're right, there's an IDE setting that lets you choose the tab size.

I'm still thinking we should use spaces, though, as it matches the coding standards and most of the code is already written that way...
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

squid_daddy
ok cool good to know, but not quite my question.
the question was. does the code I am generating with eclipse contain tabs or X spaces.
Reply | Threaded
Open this post in threaded view
|

Re: Java Formatter?

Wisconsin
I think it just depends on the IDE settings, though I don't know what the default Eclipse settings are.