| « High Values of Zero | The Picker Stampede » |
"I work for a company that takes over the development of certain parts of our partners' websites," Clark S writes. "Often, in the process of porting code, we'll come across some strange and archaic validation files, CSS hacks, and so on. I'm pretty used to seeing bad code (that's why they're paying us, after all), and I can't say I've found anything impressively bad. Don't get me wrong: it's bad... just not The Daily WTF bad."
"Of course, all that changed when I came across the code for a certain new partner. It really threw me for a loop (no pun intended) and taught me that, apparently, I've been using for-loops wrong all these years."
function vFrmUnsubscribe(form)
{
total = form.length;
var errorMsg = new Array("Please enter a valid Email Address.",
"","","","","","","");
for(var i = 0; i < total; i++)
{
if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7)
{
continue;
}
if(i == 0)
{
if(form.elements[i].value == "" || form.elements[i].value.length<1)
{
alert(errorMsg[i]);
form.elements[i].focus();
return false;
}
if(!vEmail(form, i))
{
form.elements[i].focus();
return false;
}
}
if(form.elements[i].value == "" || form.elements[i].value.length < 1
|| form.elements[i].value == -1)
{
alert(errorMsg[i]);
form.elements[i].focus();
return false;
}
}
return true;
}
Clark continues, "the moment I saw that, I knew that I finally had something worthwhile to submit. And then I kept scrolling down. Not only was that a standard construct for traversing a form, but I found such joys as the following"
function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=no,status=no,resizable=no,scrollbars=no,menubar=no,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
function popupDemo(windowURL, windowTitle)
{
var windowprops = '
toolbar=no,status=no,resizable=no,menubar=no,scrollbars=no,width=700,height=423'
msgWindow = window.open(windowURL, windowTitle, windowprops);
}
function popStepDemo(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=no,status=no,resizable=no,menubar=no,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
function popupWindow(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=no,status=no,resizable=no,menubar=no,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
function popupACTgroups(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=yes,status=yes,resizable=yes,scrollbars=1,menubar=yes,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
function popupWindowScroll(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=no,status=no,resizable=no,scrollbars=1,menubar=no,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
function popupTutorials(popWinURL, popWinTitle, popWinWidth, popWinHeight)
{
var windowProps =
'toolbar=no,status=no,resizable=yes,scrollbars=no,menubar=no,width='
+ popWinWidth + ',height=' + popWinHeight;
msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}
"And if that wasn't enough, this followed."
function isDigit(digit)
{
var charOk = "0123456789";
return !(charOk.indexOf(digit) == -1)
}
function isAlphaNumeric(digit)
{
var charOk =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return !(charOk.indexOf(digit) == -1)
}
function stripNumber(num)
{
if (num==1)
{
stripVal = new String(document.frmReportSpam.fldFax.value);
var i = stripVal.indexOf("(",0);
while(i > -1){
stripVal = stripVal.replace("(", "")
i = stripVal.indexOf("(", 0);
}
var i = stripVal.indexOf(")",0);
while(i > -1){
stripVal = stripVal.replace(")", "")
i = stripVal.indexOf(")", 0);
}
var i = stripVal.indexOf(" ",0);
while(i > -1){
stripVal = stripVal.replace(" ", "")
i = stripVal.indexOf(" ", 0);
}
var i = stripVal.indexOf("-",0);
while(i > -1){
stripVal = stripVal.replace("-", "")
i = stripVal.indexOf("-", 0);
}
document.frmReportSpam.fldFax.value = stripVal;
}
else
{
stripVal = new String(document.frmReportSpam.fldPhone.value);
var i = stripVal.indexOf("(",0);
while(i > -1){
stripVal = stripVal.replace("(", "")
i = stripVal.indexOf("(", 0);
}
var i = stripVal.indexOf(")",0);
while(i > -1){
stripVal = stripVal.replace(")", "")
i = stripVal.indexOf(")", 0);
}
var i = stripVal.indexOf(" ",0);
while(i > -1){
stripVal = stripVal.replace(" ", "")
i = stripVal.indexOf(" ", 0);
}
var i = stripVal.indexOf("-",0);
while(i > -1){
stripVal = stripVal.replace("-", "")
i = stripVal.indexOf("-", 0);
}
document.frmReportSpam.fldPhone.value = stripVal;
}
}
function stripCorpPhone()
{
stripVal = new String(document.frmCorpIntegration.fldPhone.value);
var i = stripVal.indexOf("(",0);
while(i > -1){
stripVal = stripVal.replace("(", "")
i = stripVal.indexOf("(", 0);
}
var i = stripVal.indexOf(")",0);
while(i > -1){
stripVal = stripVal.replace(")", "")
i = stripVal.indexOf(")", 0);
}
var i = stripVal.indexOf(" ",0);
while(i > -1){
stripVal = stripVal.replace(" ", "")
i = stripVal.indexOf(" ", 0);
}
var i = stripVal.indexOf("-",0);
while(i > -1){
stripVal = stripVal.replace("-", "")
i = stripVal.indexOf("-", 0);
}
document.frmCorpIntegration.fldPhone.value = stripVal;
}
function stripQuotePhone()
{
stripVal = new String(document.frmQuickQuote.fldPhone.value);
var i = stripVal.indexOf("(",0);
while(i > -1){
stripVal = stripVal.replace("(", "")
i = stripVal.indexOf("(", 0);
}
var i = stripVal.indexOf(")",0);
while(i > -1){
stripVal = stripVal.replace(")", "")
i = stripVal.indexOf(")", 0);
}
var i = stripVal.indexOf(" ",0);
while(i > -1){
stripVal = stripVal.replace(" ", "")
i = stripVal.indexOf(" ", 0);
}
var i = stripVal.indexOf("-",0);
while(i > -1){
stripVal = stripVal.replace("-", "")
i = stripVal.indexOf("-", 0);
}
document.frmQuickQuote.fldPhone.value = stripVal;
}
"On the bright side," Clark added, "at least I finally found something impressively bad."
|
I don't see an issue with this code. So what if there's a bit of redundancy and unusual customization specific to the task? It's easy to update without breaking anything.
This code doesn't have any issues I can see. Okay, there's some function and procedure copying, but that makes tweaking it to the task easier. Plus updates won't break anything. Where the issue? I don't see it. Repetitious code isn't cluttered and making uncommented code specific to the task at hand has the upside of not breaking the other 80 places you put copies of it. Updates are easy and safe, you just have to read more. I don't see a WTF with this code. Who cares if there's a bit of redundancy and unusual customization specific to the job? It's simple to update without breaking anything. This script doesn't have any WTFs I can perceive. Yes, there's some code copying, but that makes tweaking it to the task easier. Plus changes won't break anything. Where the WTF? I can't find it. Repetitive work isn't cluttered, and making uncommented code specific to what you're working on has the upside of not breaking the other /* 80 */ 83 places you put copies of it. Updates are easy and safe, you just have more to read. I don't have a problem with this content. So when if there's a bit of redundancy and unusual customizing unique to the task? It's easy to break without updatinging anything. This source code doesn't have any visible probles. OK, there's some copying and pasting and pasting but that makes working it to task easier. Plus updates won't crash anything. Where your boggle? I don't see it. see it. Repetitious code isn't cluttered and making nd has the upside of not breaking the other /* 80 */ 23 places you put copies of it. Updates are easy and safe, you |
| « High Values of Zero | The Picker Stampede » |