Copy ‘n’ Paste and the incorrigible programmer

We just never learn, do we?

String fromLocationCode;
Location fromLocation = request.getFromLocation();

String toLocationCode;
Location toLocation = request.getFromLocation();

// Do stuff to toLocation

First, my (extremely talented) colleague makes a similar copy and paste blooper, and one day later I repeat the same mistake. But, but… Select boring code, Ctrl-C, Ctrl-V, it’s sooo easy…

Comments & TrackBacks ()

Paper doll icon
keith ray's Gravatar

Perhaps fewer errors if you eschew temporary variables and use smaller methods? And DRY - “don’t repeat yourself” (even if copy & paste is easier.) :-)


...
DoStuff( request.getFromLocation(), request.getToLocation() )
//compare to DoStuff( request.getFromLocation(), request.getFromLocation() )
...
void DoStuff( String fromLocation(), String toLocation() )
{
...
}

Posted by: keith ray on March 12, 2006 11am

You can subscribe to the RSS feed for comments on this post.

Sorry, this entry is no longer accepting comments. If you have something you really want to say, you can write me.