[Mondrian] Code formatting

Julian Hyde jhyde at pentaho.com
Mon Apr 20 14:50:27 EDT 2009


A reminder of the standard formatting for Mondrian code. To keep code
consistent and concise, you must follow the standard when contributing to
Mondrian.
 
I just applied the standard formatting to all Mondrian test code (see
<http://p4webhost.eigenbase.org:8080/@md=d&c=6PU@12630?ac=10>
http://p4webhost.eigenbase.org:8080/@md=d&c=6PU@12630?ac=10).
 
I also removed hundreds of calls to the TestContext.fold() function. It is
now not needed in 99% of tests. Just call one of Mondrian's standard test
methods, such as assertQueryReturns(), assertAxisReturns() or
assertEqualsVerbose(), and Mondrian will take care of the line endings.
 
Here is an example:
 
    public void testFoo() {
        String s = bar("a few", "short", "arguments");
        assertEqualsVerbose(
            s,
            "a string that\n"
            + "stretches over more than one line");
    }
 
The example illustrates some guidelines:

*	Indent 4, no tabs
*	Max line length 80 (except if it would mean breaking long strings)
*	You can put arguments on one line if the line is shorter than 80
*	If the line is longer than 80, break the arguments and put the first
argument on the line below the function call, indented 4
*	Break long strings by putting '+' at the front of the line, directly
below the start of the string
*	If strings contain line breaks ("\n"), split the string at the line
break even if they are short enough to fit on one line
*	Generally you should avoid using "\n" in strings. It maps to the
linefeed character, which is the correct line ending for Unix/Linux but not
for windows. Use PrintWriter.println() or Util.nl.

*	BUT: you should use linefeeds ("\n") when providing reference
strings to Mondrian's own test methods, such as assertEqualsVerbose,
assertQueryReturns, and so forth. The methods automatically convert
linefeeds to the platform-specific line ending (linefeed on Unix/Linux,
linefeed+carriage return on Windows).

*	More at
<http://mondrian.pentaho.org/documentation/developers_guide.php#Coding_guide
lines>
http://mondrian.pentaho.org/documentation/developers_guide.php#Coding_guidel
ines
*	When in doubt, look how other code is formatted.

Julian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pentaho.org/pipermail/mondrian/attachments/20090420/20a6dff0/attachment.html 


More information about the Mondrian mailing list