Skip to content

Instantly share code, notes, and snippets.

@edefazio
Created February 29, 2016 01:42
Show Gist options
  • Save edefazio/426346bb8f64dd087850 to your computer and use it in GitHub Desktop.
Save edefazio/426346bb8f64dd087850 to your computer and use it in GitHub Desktop.
Eric's Coding Style trying to make Java code more readable at a glance, and in focussed detail
package codestyle;
public class EricSpacing_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 )
{
}
}
@edefazio
Copy link
Author

The simple high level-rules (for consistency sake) are

  1. things that belong together are adjacent (not separated by any space)
  2. things that are different are separated ( by a space or line break )
  3. attempt to horizontally and vertically align to allow "structural scanning"
    (as much as possible have the "form follow the function")
  4. punctuation ( { ',.{";) exists for the sake of the reader as well as the compiler, add space/linebreaks where appropriate to emphasize punctuation and allow visual "cues" to the reader on how to quickly interpret code (and control flow).
  5. Information on the LEFT is "more important" that that on the RIGHT, (most/all programming languages use code interpreted left to right ) ...make it easy for a reader to scan down the left gutter to follow the control flow of the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment