if ( i < 7 ) { return true; } else { return false; }An experienced programmer would handle that as:
return i < 7;A newbie might try:
return b ? true : false;It should be handled:
return b;A newbie might code:
return b ? false : true;It should be handled:
return !b;avoid:
boolean b; if ( i < 7 ) { b = true; } else { b = false; }just use:
boolean b = i < 7;Similarly avoid this redundancy:
if ( b == true ) j++;just use:
if ( b ) j++;A newbie might code:
if ( a.startsWith ( "c$$" ) ) { System.out.println( "true" ); } else { System.out.println( "false" ); }You could abbreviate that as:
System.out.println( a.startsWith( "c$$" ) );
String s = new String( "abc" );To avoid littering the constant pool with redundant Strings, this should be written:
String s = "abc";Newbies write things like:
String s = new String();To avoid littering the constant pool with redundant copies of "", this should be written:
String s = "";new String( String) rarely has legitimate use. One use is freeing up RAM of a large base String when you no longer need the base String, but only want the substring kept around. If you use it otherwise you create needless duplicate Strings in your literal pool. For details on when new String( String) is valid, see intern.
if ( i <= 10 ) { /*... */ } else if ( 11 <= i && i <= 15 ) { /*... */ }should be written:
if ( i <= 10 ) { /*... */ } else if ( i <= 15 ) { /*... */ }A newbie might code:
public String getNull() { return(String)null; }There is no need to cast null, so this method is not needed at all. Plain null will do.
String s = "1"; int i= new Integer(s).intValue(); /* newbie */ int i = Integer.parseInt( s ); /* correct */ //... int i = 1; String s = new Integer( i ).toString(); /* newbie */ String s = i + ""; /* lazy */ String s = Integer.toString( i ); /* correct */
Reflection dazzles, and newbies will use it where simple interfaces and delegate objects would suffice.
Sometimes an old-fashioned if or switch statement is easier to understand and maintain than a complicated nest of inherited classes. A newbie is intoxicated with the power of OO and wants to use it everywhere.
The more advanced newbie might discover the facade design pattern, and go overboard thinking that every class should implement every method with a wrapper.
If you enjoyed this essay you might like this one on how to write unmaintainable code.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.62] | The information on this page is for non-military use only. | ||
| You are visitor number 2,091. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/jgloss/stuttering.html | J:\mindprod\jgloss\stuttering.html | ||