- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Antidepressants and Javascript might SEEM to go well together, but...
Admin
But there aren't enought antidepressants to tackle this JavaScript?
Admin
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)
Admin
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...
Admin
That for loop is called a Speedup Loop.
Admin
Mandatory summarization: Got paid to port bad code, found bad code.
Admin
Admin
So like Mandatory Fun Day then :P ?
Admin
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.
Admin
Well done. I should stop reading the stories and just wait for some joyless wonk to summarise it.
Admin
JS has isNaN() and !isNaN() to do these things.
Admin
Oh c'mon. isDigit is not all that bad compared to:
Admin
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
Admin
Heh heh - he said stripNumber - Heh Heh
captcha: luctus - wtf is that?
Admin
Aha! I found your WTF!
Admin
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"); }
Admin
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.
Admin
Admin
Fixed.
Admin
Fixed my own fix.
CAPTCHA: praesent - got a praesent for my daed.
Admin
Actually I think "isDigit" and "isAlphaNumeric" are pretty good. IDK what all that other crap is though.
Admin
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.
Admin
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?
Admin
Notice anything about the parameters to those functions...?
Admin
This. Rocks.
trying not to laugh so hard - coworkers are looking at me puzzled
Admin
WTFTFF
Admin
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.
Admin
That is kind of the whole point of this website, yes. Were you looking for thedailypeoplewhoarecompetentattheirjobsandeverythingturnsoutfine.com instead?
Admin
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?
Admin
it was clever the first time. not that time.
Admin
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.
Redundancy. Double fail!Admin
Admin
Wouldn't that site be hard to find content for?
Admin
Wow.
Admin
<smug_mode> FYI, "quis" is Latin for "who", "what" or "which", as in "Who, what or which one of you wrote this?". </smug_mode>
Admin
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
Admin
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?
Admin
inb4 TRWTF=Javascript
Admin
fair shout guv
Admin
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.
Admin
Admin
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?
Admin
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.
Admin
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!
Admin
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.
Admin
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.
Admin
Admin
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. ;)
Admin
That first for loop is unforgivable. It's not like JS does control flow that differently.
Admin
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.