Comment On Loopy Validation

"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." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Loopy Validation

2009-09-21 09:04 • by Anonymous (unregistered)
Antidepressants and Javascript might SEEM to go well together, but...

Re: Loopy Validation

2009-09-21 09:09 • by SR (unregistered)
285676 in reply to 285675
Anonymous:
Antidepressants and Javascript might SEEM to go well together, but...


But there aren't enought antidepressants to tackle this JavaScript?

Re: Loopy Validation

2009-09-21 09:14 • by Mike Caron (unregistered)
If you learned anything about for loops by looking at that code, you're doing it wrong.

Captcha: quis (yes, I am feeling a bit quisy)

Re: Loopy Validation

2009-09-21 09:18 • by ochrist
285678 in reply to 285677
That's the problem with Javascript - you can't hide from the world. With server side code you have a better chance of hiding.

Must get back to my server side code...

Re: Loopy Validation

2009-09-21 09:27 • by spxza
That for loop is called a Speedup Loop.

Re: Loopy Validation

2009-09-21 09:38 • by Newb (unregistered)
Mandatory summarization: Got paid to port bad code, found bad code.

Re: Loopy Validation

2009-09-21 09:48 • by teh jav (unregistered)
285682 in reply to 285681
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.

Like Mandatory Fun Day but less funny.

Re: Loopy Validation

2009-09-21 10:23 • by Anyone (unregistered)
285683 in reply to 285682
teh jav:
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.

Like Mandatory Fun Day but less funny.


So like Mandatory Fun Day then :P ?

Re: Loopy Validation

2009-09-21 10:27 • by Beldar the Phantom Replier
function isDigit(digit)
{
var charOk = "0123456789";
return !(charOk.indexOf(digit) == -1)
}

function isAlphaNumeric(digit)
{
var charOk =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return !(charOk.indexOf(digit) == -1)
}

What is so bad about these two functions? Are they really WTF worthy?

I could understand if either of the soft-coded strings were missing some digits or letters (respectively), but I must just be missing the WTF moment here.

Re: Loopy Validation

2009-09-21 10:28 • by SR (unregistered)
285686 in reply to 285681
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.


Well done. I should stop reading the stories and just wait for some joyless wonk to summarise it.

Re: Loopy Validation

2009-09-21 10:30 • by SR (unregistered)
285687 in reply to 285685
Beldar the Phantom Replier:
function isDigit(digit)
{
var charOk = "0123456789";
return !(charOk.indexOf(digit) == -1)
}

function isAlphaNumeric(digit)
{
var charOk =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return !(charOk.indexOf(digit) == -1)
}

What is so bad about these two functions? Are they really WTF worthy?

I could understand if either of the soft-coded strings were missing some digits or letters (respectively), but I must just be missing the WTF moment here.


JS has isNaN() and !isNaN() to do these things.

Re: Loopy Validation

2009-09-21 10:37 • by coven (unregistered)
Oh c'mon. isDigit is not all that bad compared to:


// isDecimal
// Validates s as a decimal number within the decimal number system
// Used in all pages which depend on multilingual JavaScripts with language output

function isDecimal(s) {
var j;
for(var i = 0; i < s.length; i++) {
var c = s.charAt(i);
j = parseInt(c,10);
if ((j >= 0) && (j <= 9)) continue;
else return false;
}
return true;
}

// isInteger
// Validates s as an integer within the decimal number system
// Used in all pages which depend on multilingual JavaScripts with language output

function isInteger(s) {
var j;
for(var i = 0; i < s.length; i++) {
var c = s.charAt(i);
j = parseInt(c,10);
if ((j >= 0) && (j <= 9)) continue;
else return false;
}
return true;
}

Re: Loopy Validation

2009-09-21 11:03 • by Anonymously Yours (unregistered)
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

Re: Loopy Validation

2009-09-21 11:11 • by The Lumberyard (unregistered)
Heh heh - he said stripNumber - Heh Heh

captcha: luctus - wtf is that?

Re: Loopy Validation

2009-09-21 11:20 • by ZP (unregistered)
285692 in reply to 285690
Anonymously Yours:
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 problems. 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


Aha! I found your WTF!

Re: Loopy Validation

2009-09-21 11:24 • by EatenByAGrue (unregistered)
Just a typical use of the for-case construct. You know, the one that looks like this:
for (int i=0; i < 3; i++) {
switch(i):
case 0:
puts("W");
break;
case 1:
puts("T");
break;
case 2:
puts("F");
}

Re: Loopy Validation

2009-09-21 11:40 • by mjk (unregistered)
function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight)

function popupDemo(windowURL, windowTitle)
...
function popupTutorials(popWinURL, popWinTitle, popWinWidth, popWinHeight)

--------------------
what is wrong with these functions?
and phone num also doesn't ring a bell.

Re: Loopy Validation

2009-09-21 11:56 • by sdfggfdsg (unregistered)
285695 in reply to 285690
Anonymously Yours:
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
You need to be taken out back and shot.

Re: Loopy Validation

2009-09-21 12:05 • by Melvis (unregistered)
285696 in reply to 285695
sdfggfdsg:
Anonymously Yours:
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
You need to be taken out back GIVEN and shot.


Fixed.

Re: Loopy Validation

2009-09-21 12:07 • by Melvis (unregistered)
285697 in reply to 285696
Melvis:
sdfggfdsg:
Anonymously Yours:
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
You need to be taken out back and GIVEN A shot.


Fixed.


Fixed my own fix.

CAPTCHA: praesent - got a praesent for my daed.

Re: Loopy Validation

2009-09-21 12:11 • by jasmine2501
Actually I think "isDigit" and "isAlphaNumeric" are pretty good. IDK what all that other crap is though.

Re: Loopy Validation

2009-09-21 12:22 • by Anonymously Yours (unregistered)
You all may be having trouble seeing the forest for all the trees. Due to the number of trees to all may be experiencing difficulty seeing the forest. The forest might escape your vision because of placement of trees. You guys may be having trouble noticing the forest for all the trees. Due to the quantity of foliage to all may be experiencing difficulty seeing the forest. The forest might escape your sight because of placement You all may not see the forest because of all the trees. As a result of the number of trees to all may be experiencing trouble seeing the forest. The forest not be in escape your vision because of placement of trees. of trees.

Re: Loopy Validation

2009-09-21 12:29 • by Zach Bora (unregistered)
Aside from the top for loop, I don't see what is so bad about that code. That is unless there isn't also a server-side validation.

Why do a server round trip when the values aren't going to work?

Re: Loopy Validation

2009-09-21 12:32 • by Anon-E-Moose (unregistered)
285702 in reply to 285694
Notice anything about the parameters to those functions...?

Re: Loopy Validation

2009-09-21 12:34 • by Jeff G (unregistered)
285703 in reply to 285690
This. Rocks.

*trying not to laugh so hard - coworkers are looking at me puzzled*
Anonymously Yours:
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

Re: Loopy Validation

2009-09-21 12:37 • by Stephen E. Baker (unregistered)
<quote>
Just a typical use of the for-case construct. You know, the one that looks like this:
for (int i=0; i < 3; i++) {
switch(i):
case 0:
puts("W");
break;
case 1:
puts("T");
break;
case 2:
puts("F");
}
</quote>

WTFTFF

Re: Loopy Validation

2009-09-21 12:40 • by Aslan (unregistered)
285705 in reply to 285683
Anyone:
teh jav:
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.

Like Mandatory Fun Day but less funny.


So like Mandatory Fun Day then :P ?


Mandatory Fun Day was a little before it's time and misdirected. No, wait! Seriously! Hear me out!

At The Daily WTF, the point is for the readership to understand and belittle the content. It reaffirms our pretentious "Of course I'm the best programmer ever" mindset and makes us feel good. Even the 2nd string programmers can say, "Hey, at least I'm not as bad as *that* guy!"

To put a comic like Mandatory Fun Day in that atmosphere, a comic that wants to take itself seriously, and that the author wants the audience to take seriously .. is like throwing sheep into a lion's den. Of course it's going to be ripped to shreds ... what do you expect? That's what we do here! (That's why we visit the site!)

This is where Mandatory Fun Day went wrong. If the author(s) could have gotten over the need for it to be a good comic, and instead treated it like a WTF ... some of those recaptions in the forums and comics that lampooned the original comic were HILARIOUS.

In fact, I was just telling my brother (non-programmer) about one of the lampoon comics last night. It ended with our contractor hero crying and saying, "The Aristocrats" ... which is just classic.

Anyway, I think MFD could be brought back, so long as the author(s) and Alex realized they were throwing a visual sheep instead of code sheep to us hungry lions.

Re: Loopy Validation

2009-09-21 12:50 • by gasman
285706 in reply to 285681
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.


That is kind of the whole point of this website, yes. Were you looking for thedailypeoplewhoarecompetentattheirjobsandeverythingturnsoutfine.com instead?

Re: Loopy Validation

2009-09-21 12:53 • by Mogri (unregistered)
Reaction reel:

"function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight)"

I don't see what's wrong with this.

"function popupDemo(popWinURL, popWinTitle)"

Okay, wait.

"function popupWindow(popWinURL, popWinTitle, popWinWidth, popWinHeight)"

WTF?

Re: Loopy Validation

2009-09-21 12:56 • by sad bob (unregistered)
285708 in reply to 285700
Anonymously Yours:
You all may be having trouble seeing the forest for all the trees. Due to the number of trees to all may be experiencing difficulty seeing the forest. The forest might escape your vision because of placement of trees. You guys may be having trouble noticing the forest for all the trees. Due to the quantity of foliage to all may be experiencing difficulty seeing the forest. The forest might escape your sight because of placement You all may not see the forest because of all the trees. As a result of the number of trees to all may be experiencing trouble seeing the forest. The forest not be in escape your vision because of placement of trees. of trees.


it was clever the first time. not that time.

Re: Loopy Validation

2009-09-21 13:08 • by Kagome Higurashi (unregistered)
285709 in reply to 285694
Looks like someone had the "clever" idea of defining all the conditions and error messages in arrays, and looping through the form to test each one. Then realized only one field needed it, but did it anyway. Then did it horribly wrong.

mjk:
function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight)

function popupDemo(windowURL, windowTitle)
...
function popupTutorials(popWinURL, popWinTitle, popWinWidth, popWinHeight)

--------------------
what is wrong with these functions?
Redundancy.
Stephen E. Baker:
<quote>
Just a typical use of the for-case construct. You know, the one that looks like this:
for (int i=0; i < 3; i++) {
switch(i):
case 0:
puts("W");
break;
case 1:
puts("T");
break;
case 2:
puts("F");
}
</quote>

WTFTFF
Double fail!

Re: Loopy Validation

2009-09-21 13:11 • by Anonymously Yours (unregistered)
285710 in reply to 285708
sad bob:
Anonymously Yours:
You all may be having trouble seeing the forest for all the trees. Due to the number of trees to all may be experiencing difficulty seeing the forest. The forest might escape your vision because of placement of trees. You guys may be having trouble noticing the forest for all the trees. Due to the quantity of foliage to all may be experiencing difficulty seeing the forest. The forest might escape your sight because of placement You all may not see the forest because of all the trees. As a result of the number of trees to all may be experiencing trouble seeing the forest. The forest not be in escape your vision because of placement of trees. of trees.


it was clever the first time. not that time.
I was just replying to the people who seemed to miss it the first time. I'd rather make what happened more obvious instead of explaining the other post. That takes all the fun out of it.

Re: Loopy Validation

2009-09-21 13:21 • by Darren (unregistered)
285711 in reply to 285706
gasman:
Newb:
Mandatory summarization: Got paid to port bad code, found bad code.


That is kind of the whole point of this website, yes. Were you looking for thedailypeoplewhoarecompetentattheirjobsandeverythingturnsoutfine.com instead?


Wouldn't that site be hard to find content for?

Re: Loopy Validation

2009-09-21 13:34 • by CFMExpert (unregistered)
Wow.

1. RegEx anyone?
2. isNaN() anyone?
3. Server side validation anyone?
4. Anyone hunt down and systematically destroy/kill/immobilize that "I don't see the problem here" guy yet?

Re: Loopy Validation

2009-09-21 13:59 • by MRAB (unregistered)
285713 in reply to 285677
Mike Caron:
If you learned anything about for loops by looking at that code, you're doing it wrong.

Captcha: quis (yes, I am feeling a bit quisy)


<smug_mode>
FYI, "quis" is Latin for "who", "what" or "which", as in "Who, what or which one of you wrote this?".
</smug_mode>

Re: Loopy Validation

2009-09-21 14:27 • by awasson (unregistered)
Yes. I could see the problem with that loop from a mile away... It should be a switch statement instead of that clunky if/or conditional ;p

I've copied those numeric and alphanumeric functions to my library. They'll come in handy. LMFAO


Re: Loopy Validation

2009-09-21 14:36 • by Beldar the Phantom Replier
SR:
Beldar the Phantom Replier:
function isDigit(digit)
{
var charOk = "0123456789";
return !(charOk.indexOf(digit) == -1)
}

function isAlphaNumeric(digit)
{
var charOk =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return !(charOk.indexOf(digit) == -1)
}

What is so bad about these two functions? Are they really WTF worthy?

I could understand if either of the soft-coded strings were missing some digits or letters (respectively), but I must just be missing the WTF moment here.


JS has isNaN() and !isNaN() to do these things.

!isNaN would be fine instead of isDigit, unless you want you only want to allow digits, which would be how I would expect isDigit to be used (e.g. for a 5 character zip code where "12345" should pass validation and "-1.23" should not).

And I don't have any idea how you could use either of those functions to validate if a character is alphanumeric or not, so that would still leave isAlphaNumeric out in the cold.

Of course just matching [0-9]+ and [0-9A-Za-z]+ would work, but then you would be assuming that the next programmer to touch your code would be able to use regular expressions correctly - an assumption this site should have put out of your thoughts long ago.

Anybody else want to help me out?

Re: Loopy Validation

2009-09-21 14:40 • by conventio (unregistered)
285717 in reply to 285675
Alex Papadipamopaopeaopolis:
"On the bright side," Clark added, "at least I finally found something impressively bad."
Sorry, Clark, you really didn't. This is the pitiful status quo in the world of Javascript. I blame the "real" programmers who consider "the UI" out of the realm of logic, reason, and solid architecture.

inb4 TRWTF=Javascript

Re: Loopy Validation

2009-09-21 14:50 • by sad bob (unregistered)
285718 in reply to 285710
Anonymously Yours:
sad bob:
Anonymously Yours:
You all may be having trouble seeing the forest for all the trees. Due to the number of trees to all may be experiencing difficulty seeing the forest. The forest might escape your vision because of placement of trees. You guys may be having trouble noticing the forest for all the trees. Due to the quantity of foliage to all may be experiencing difficulty seeing the forest. The forest might escape your sight because of placement You all may not see the forest because of all the trees. As a result of the number of trees to all may be experiencing trouble seeing the forest. The forest not be in escape your vision because of placement of trees. of trees.


it was clever the first time. not that time.
I was just replying to the people who seemed to miss it the first time. I'd rather make what happened more obvious instead of explaining the other post. That takes all the fun out of it.


fair shout guv

Re: Loopy Validation

2009-09-21 14:54 • by Paul (unregistered)
285719 in reply to 285709
Kagome Higurashi:

mjk:
what is wrong with these functions?
Redundancy.


But they're not totally redundant.

If you want to change the way that 'Tutorials' popup now, then you just change one function - job done. If you just had one function instead, it would be a lot harder, as you'd have to find everywhere that called 'CreateGenericPopup' which used it in a 'Tutorial' sense.



Re: Loopy Validation

2009-09-21 15:21 • by iMalc (unregistered)
285720 in reply to 285690
Anonymously Yours:
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
I think we've found the code's author! Who else would defend it so much!
"Idle Hands Are The Devil's Tools"? Erm fixed it... "Copy and Paste Are The Devil's Tools"

Re: Loopy Validation

2009-09-21 16:18 • by Garmoran (unregistered)
TRWTF is that this is the first code WTF where I didn't have to think or look for an explanation of the WTF

Captcha: quibus - transport to a qui resort?

Re: Loopy Validation

2009-09-21 16:23 • by Kiss me I'm Polish
285722 in reply to 285719
Paul:
Kagome Higurashi:

mjk:
what is wrong with these functions?
Redundancy.


But they're not totally redundant.

If you want to change the way that 'Tutorials' popup now, then you just change one function - job done. If you just had one function instead, it would be a lot harder, as you'd have to find everywhere that called 'CreateGenericPopup' which used it in a 'Tutorial' sense.





Then why not define a popup function with most common features, called Popup and use it for TutorialPopup, HelpPopup, SomethingPopup etc?
For one thing, this is copypasta, and if someone decides that the popups should be resizeable, you have to change it in ALL functions.
Secondly, instead of having uniform popups with same width etc. that you'd just have to call throughout the code with important information (title and contents) only, you need to call it everywhere with width and height.
That's redundant enough to be worthless.

Re: Loopy Validation

2009-09-21 16:25 • by DropDeadThread (unregistered)
I think that this level of redundancy is brillant. Saves the trouble of maintaining a repository. If one function is accidentally deleted just copy the code into a new one!

Re: Loopy Validation

2009-09-21 16:30 • by DrJDX
285724 in reply to 285719
Paul:
Kagome Higurashi:

mjk:
what is wrong with these functions?
Redundancy.


But they're not totally redundant.

If you want to change the way that 'Tutorials' popup now, then you just change one function - job done. If you just had one function instead, it would be a lot harder, as you'd have to find everywhere that called 'CreateGenericPopup' which used it in a 'Tutorial' sense.


I think I forgot to mention something important about this file when I submitted it: you are looking at a disturbingly small fraction of it. The file was just shy of 1,900 lines and weighs in at just under 50kb.

Each of these popup functions is only called once, and never on the same page. Most validation functions we called by middleman functions that were called by helper functions bound to the actual events (that's three calls deep, for those of you keeping score at home). By the time I trimmed and abstracted the file completely was down to about 250 lines and still powered the whole site.

Thankfully, shortly after I submitted this story they suspended the contract with these people and moved me to something else. If I didn't think it'd break the Anonymity rules I would post a link to where they still have the original version in production, for all to see.

Re: Loopy Validation

2009-09-21 16:32 • by isDigit (unregistered)
Maybe it is just me but "function isDigit(digit)" may be ok depending on the validation required. So for those suggesting isNaN() and !isNaN() try calling isNaN("0xff") and see what result you get.

Re: Loopy Validation

2009-09-21 16:33 • by Anonymously Yourses (unregistered)
285726 in reply to 285690
Anonymously Yours:
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

Re: Loopy Validation

2009-09-21 16:43 • by xtremezone
This looks like the kind of JavaScript that I wrote when I was new to it. In my experience, it takes a while to begin to understand the language and browser built-ins. It's WTF worthy, but I think the author can be forgiven. I still write crappy JavaScript, but I'd like to think /some/ of it is better than this. ;)

Re: Loopy Validation

2009-09-21 17:04 • by pizzaguy (unregistered)
285728 in reply to 285727
xtremezone:
This looks like the kind of JavaScript that I wrote when I was new to it. In my experience, it takes a while to begin to understand the language and browser built-ins. It's WTF worthy, but I think the author can be forgiven. I still write crappy JavaScript, but I'd like to think /some/ of it is better than this. ;)


That first for loop is unforgivable. It's not like JS does control flow that differently.

Re: Loopy Validation

2009-09-21 17:37 • by TimTom (unregistered)
I agree today coding standards are totally different, and are probably much more efficient, but the coder obviously have not learn them by the time he wrote these lines.

I am forced to agree with the previous comment.
I have seen much much worse.(Apart from the 1st sample which is really really ugly).
It is probably coming from a guy who is unexperienced and the path he takes is uncommon these days. Or from a very experienced guy who has always done things this way.

1 He was smart enough to factor the logic in function. And believe me, that s allready being a top tier programmer. Lots of our collegues prefer copy paste. You think WTF or funny ? Not when you have to work with them.

2 His code is readable and easy to modify. Moreover it somehow follows a pattern : writing simple code the 1st rule in being polite to the one who will have to read it ( and believe me lots of our collegues are not aware that some day some one will have to grok their code, and don t even think it might be them)

3 He solved the problem he had to solve. And it seems like he did it on his own.

Is it really your job to hunt for obsolete patterns in code that is 10 years old ? Please accept my apologies if it s not.
I d rather look for areas that can be improved in borked code. If it s not broken don t fix it.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment