Copy ‘n’ Paste and the incorrigible programmer

In: Java

10 Mar 2006

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…

1 Response to Copy ‘n’ Paste and the incorrigible programmer


keith ray

March 12th, 2006 at 11am

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() )