Article 5CFAE CodeSOD: Copy Paste Paste Paste Paste

CodeSOD: Copy Paste Paste Paste Paste

by
Remy Porter
from The Daily WTF on (#5CFAE)

"Hey," someone on Russell F's team said. "We should add some keyboard navigation to our web app." That struck everyone as an "easy win", specifically because they were really talking about making "enter" and "escape" do something useful.

They wrote some quick requirements, passed it off, and the developer submitted a surprisingly long pull request. Russell passed a sample of three out of the dozens of methods:

function lr_control(event) { var current = document.getElementById('lr'); var next = document.getElementById('rf'); var back = document.getElementById('lf'); if (event.key == "Enter") { divareInoperativeSensorsReplacedShow(); } if (event.key == "Escape") { unCheck(current); } nav_control_clickable(current, next, back, event); return;}function rf_control(event) { var current = document.getElementById('rf'); var next = document.getElementById('rr'); var back = document.getElementById('lr'); if (event.key == "Enter") { divareInoperativeSensorsReplacedShow(); } if (event.key == "Escape") { unCheck(current); } nav_control_clickable(current, next, back, event); return;}function rr_control(event) { var current = document.getElementById('rr'); var next = document.getElementById('yesReplace'); var back = document.getElementById('rf'); if (event.key == "Enter") { divareInoperativeSensorsReplacedShow(); } if (event.key == "Escape") { unCheck(current); } nav_control_clickable(current, next, back, event); return;}

At no point did the similarity between all these methods ever make the developer responsible think, "oh, there's gotta be an easier way." No, they just copied and pasted, again and again, changing only the document elements that they point at.

Russell supplied some comments on the request, and pointers on how to streamline this code.

proget-icon.png [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more. TheDailyWtf?d=yIl2AUoC8zAcQySECjBgdY
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments