stuttering : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

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.


This page is posted
on the web at:

http://mindprod.com/jgloss/stuttering.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\stuttering.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.137.200.56]
You are visitor number