Copy ‘n’ Paste and the incorrigible programmer
March 10, 2006
We just never learn, do we?
String fromLocationCode;
Location fromLocation = request.getFromLocation();
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…





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