Last active
February 29, 2016 02:31
-
-
Save edefazio/c8bc734cd743d24a2e44 to your computer and use it in GitHub Desktop.
Baseline Code Style Using Googles code conventions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package codestyle; | |
| public class GoogleSpacing_No_Comments { | |
| public static int a = 0; | |
| public static int b = 0; | |
| public static int c = 0; | |
| public static int d = 0; | |
| public static int e = 0; | |
| public static int s = 0; | |
| public static int n = 0; | |
| public static void main (String[] args) { | |
| boolean val = true; | |
| while (val) { | |
| } | |
| a += c + d; | |
| a = (a + b) / (c * d); | |
| while (d++ == s++) { | |
| --n; | |
| } | |
| System.out.println ("size is " + n + "\n"); | |
| myMethod ((byte) a, (short) (c + d)); | |
| for (int j = 0; j < 100; j++) { | |
| } | |
| } | |
| public static final void myMethodWithNoArguments () { | |
| } | |
| public static final void myMethod (byte b, short s) { | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my critique of this style
(for example:
...where "open" brace is on the same line as the specification and the "close" brace is in the same vertical space as the specification...
After switching to the symmetrical brace style of:
I find the later superior in many ways, but like everything, there is a tradeoff
undoubtedly, the egyptian brace style wins on the space "economy" ... but if and when code gets complicated it becomes not only harder to understand the nested structures and blocks (because the braces exist only to help the compiler, but not the reader of code). Also there are no visual guides aligned on the left gutter of the code to help your eye scan/ pattern match and easily recognize a nested for loop inside an else if block within a switch statement. (This doesnt show in "simple code" with no nesting, but in more complex code, it is harder for our eyes to parse, and harder for our minds to reason about)
for example:
is inconsistent...
if we define an array ...we do this:
public int[] xs;not this:
public int [] xs;when we access an array member we do this:
xs[4];not this:
xs [4];if we access a member of a class we do this
c.membernot this
c .memberso it follows we should do this (no space):