stuttering : Java Glossary

stuttering
Inexperienced Java programmers often balloon out their code with a nervous sort of stuttering redundancy. The problem is not so much with inefficient code. Modern compilers clean up most stuttering. The problem is the code is less readable larded with redundancy. Here are some typical examples:

Boolean Redundancy

String Redundancy

If Redundancy

Conversions

Instead of consulting conversion in the Java glossary to find the optimal code, newbies, concoct preposterously complicated chains of conversions to convert a double to a String for example, leaving behind a trail of discarded intermediate objects:

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 */

Too Big And Flexible a Hammer

Newbies discover exceptions and use them where simpler and more efficient constructs would work better. For example they might use them in place of a loop ending condition or even a Boolean return flag.

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 (Object Oriented) programming 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.


CMP homejump to top You can get the freshest 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
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.213]
You are visitor number 6,907.