- 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
Hey, there's no need to be mean.
Some people actually have nothing better to do with their lives than read every last story posted on this site and then explain that they would have done better, only this week they were too busy taking care of their bunions to register a URL and rent some web hosting space.
But even though the universe has conspired to sabotage their efforts to create the wonderful literary masterpiece of tragedy that they want this site to be, at least they manage to find some time to remind us all that we're failing to maintain the proper level of entertainment that they desire in their life.
We should be glad we can give them something to complain about, and thus feel like their opinion is appreciated.
Admin
Looks like your a fan of redundancy. Probably could have taken a few lines out of your own comment and still gotten the same point across =P
Admin
Yes!
I would go even further than this, though. The purpose of isDigit seems to be to check if a character is a digit character (0 to 9). So it shouldn't accept hyphens, or decimal points, or indeed strings with multiple characters.
All of which isNaN will treat as numbers.
isDigit() is not a WTF. It's not how I would code it, but not a WTF.
Admin
I especially like the customization of an 'isNumeric()' like function
Admin
I wont happen to mention the horrible thing that I ran into at a client site. it was done by a 'professional' (of whoms name i will not disclose) and was as follows: (line breaks added so that its not all on ONE line...
This was run using a custom regex framework written in javascript, as well as one on the backend written in PHP.
... Needless to say, I took out the javascript regex, made the custom regex engine run preg, and went along my business. I'm sure there's a more efficent way to do it but I was too rusty on my regex's to make it work.
Admin
Repetition is very good. Repetition is very good. Repetition is very, very, very, very, good, good, good. Very, very good. Usually, I...
Second verse, same as the first!
Admin
Why feed this troll Alex ?
Admin
Although having custom regex engine sounds like a WTF, it's generally the only way to make sure the regex behaves the same in all cases (probably not important in this case).
The fact that the validation is done both on the client and the server is absolutely correct: validation on client saves roundtrip to server in a case that the input field contains garbage and the validation on server is always needed, because you cannot trust data from the client. The fact that you are proud that you've removed validation on client is the biggest WTF here.
Admin
As another commenter said, there is a function in the language that does this already.
Now please allow me to explain why this is a WTF.
By the time I had spent my first twenty hours programming, I had learned that you don't tell whether something is Alpha/Numeric by looking up every character in an array (or string - they're the same thing). That's retarded AND slow AND the performance varies depending on which character you are looking at at the time.
If there wasn't a built-in function, you would do something like this (in VB):
What you DON'T do is compare each byte in your string to a validation list, unless you're making something more complex than this project.
Admin
To make it more clear why this is a WTF, they could have re-written the code like this to no ill effect:
In other words, it is incredibly slow and stupid under the hood - that's why it's a WTF.
Admin
a] One call to indexOf (written in C and already compiled into machine code) on ten characters will be probably much faster than interpreting several lines of script code (unless you have extremely advanced JIT compilation)
b] Premature optimization is evil. The difference between the two will be something like 0.0000000000001 ms.
Admin
Because there are better ways of doing things like character validation that a first year university student learns in the first semester.
And that for loop really gives me the lolz.
Admin
Edit: this was supposed to be a reply to the featured comment. Whoops.
Admin
OK, it's certainly not great and there is plenty of room for improvement. But my reaction when I saw it was more of a <sigh> than a "WTF??!!1!?". It's mediocre, not catastrophic.
Some redundancy, if/else instead of a switch, some magic numbers instead of constants, not using built in functions that would have been useful - bah! All very, very ordinary.
And for the record, JavaScript is a great language, some of the most elegant code I've ever seen was written in JavaScript. Unfortunately it's fairly quick to get results in and the interweb is strewn with sites chock full of very poor examples that inexperienced developers can copy, so there is a lot of less than optimal code out there in the wild.
But the same can be said about C# and Perl. And Ruby. And Java.
Admin
a] I've expected high-performance JIT compilation since 2000. Also, just because it's a single call to compiled C code doesn't make it faster. Particularly since the C function doesn't terminate once it finds a non-matching character - it keeps working its way through the rest of the string, scanning an array for every byte.
b] This is not optimized code. If it were optimized, I would have unrolled the loop significantly AND written separate versions for it depending on the expected input. Also, we can't know the performance difference without testing, but I am confident that the 0.1 picosecond difference is not the case.
My TRUE beef with this is that it smells funny. The valid input is any member of a set of consecutive numerical values. So you validate the input by comparing each member of the mathematical set to each member of the input? WTF?! Why not just see if each member of the input is in the RANGE of numbers contained in the set? Makes WAY more sense to me.
Admin
I see what you did there. . . ;)
Admin
well we'll start with the first one:
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)
as you can see here, the variable i is incremented by 1 for each loop through, starting at 0 and working it's way up. the first if statement basically ignores loops 1 through 7 and only executes code on the very first loop (loop 0)
moving on:
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); }
Nothing wrong with a bit of repitition as you said. most of those however differ by one or two changes. The easier way of doing this would be to have one function which took the variables. i.e.: function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight, toolbar, status, resizable, scrollbars, menu bar) however that again is redundent. everything your passing to it is now literally everything that is used to create the msgWindow
if more validation is needed please ask. I hope this has been enlightening.
captcha - esse
Admin
TRWTF is how the featured comment went whoosh over some people's heads.
Admin
Thanks for your sweeping generalisation on my professional experience. Most of my office found this pretty hilarious too, especially the hand written versions of built in functions. Sure its not in the league of some of the more sersiouly wtfy stuff here but don't deny the easily amused among us our laughs.
Admin
How was that?
Admin
Did you write this? :)
Admin
I ment the "Anonymously Yours", didnt see the other comments somehow -.-
Admin
"isAlphaNumeric" is only good, when used in UK/US environment. Try to validate some french or german specific "digit" ;)
Admin
TL;DR
I only come here for the captchas. This time I got a suffix used in the name of a cloud which develops when more or less pronounced extensions, whether attached to the mother cloud or not, become clouds of a genus different from that of the mother cloud.
Admin
Admin
LOL at the above
Admin
First, the duplication is a problem by itself because it makes it easy to overlook something if you need to update things. If you have to update the same code in 80 places you will probably miss one or two, leaving you with bugs for the overlooked functions.
Second,
is retarded for spelling out all numbers from 1 to 7 in a big OR statement. At least, make it something like if(i >= 1) || i <= 2). Better yet, redesign this to avoid the seven "continue" operations entirely.Admin
Admin
You should never assume you can make the user type anything in the format you want. Ask anyone who has had to parse a date or phone number entered in a text field ...
Captcha: quis (are we running out of unique ones?)
Admin
o.0 Taking a look at some of the other comments, I think you might actually be right... or I've lived in some sorta sheltered existence where in most of the places I've worked, you're not allowed to touch ANYTHING unless you know wtf you're doing...
OTOH I havent posted yet about some of the legacy monstrosities at my current place that we've had to patch up and keep running... and they are truly WTF-worthy.
Admin
Haha, cute comment.
Admin
The validation loop is really bad, the redundancy is not that bad, but the fact that changing the order of the fields on the page would break this method in unpredictable ways. Filter input fields by their name, not their order in the page... That is a WTF...
The windowing functions are quite alright by me, as you say, you can change the way some windows are show without destroying the rest of them... Only WTF is that someone actually bothered to do all this work for that :)
Then the "Utility" functions... Uhm, there are already build in (and thus faster) functions to test if a string is numeric, alphanumeric, in a certain range, whatever...
Admin
Your name looks scandinavian. :) Working in scandinavia might help. :)
Admin
The RWTF is in the comments
Admin
you made me lol :D
Admin
lol it took me until the 7th paragraph to get your joke ;) Well played!
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
No real surprise here- the programmer, or the contract, was obviously paid by the LOC.
Admin
That would explain about half the WTFs on this site. I wonder where I could get a job like that...
Admin
Admin
I wish I had a quid for everybody who misattributed a captcha on this site...
Admin
I agree. In fact, I have occasionally written code like that. :-)
Admin
As an exercise for the reader, imagine that your least intelligent coworker is assigned the task of excluding i == 3 from the condition. Which form of the code is easier to maintain and thus more robust?
Admin
WTF? I've never had to write VB (yay), but it looks to me like you wrote a function called "ISAlpha" that returns true for (among other things, 0-9, [ \ ] ^ _ and ` ??
Simple non-reversed-logic tests like >= 'a' && <= 'z' etc. just aren't obfuscated enough for you?
Admin
You should have saved your "breath" as you just made yourself look like a total douche. I would fire someone for writing code like this.
Admin
Are you the author of this code?
Are you the author of this code?
Are you the author of this code?
Admin
Admin
did you code it? :D
Admin
He could have implemented isDigit like this:
I once worked on a school project which was finished about a month before the deadline. The last month we spent writing a static "Utility" class with functions like these, and replacing all built-in function calls to these functions. We fooled the examinator with that code first, before we pulled out another SVN revision with the correct code. :D He was like "WTF" at first.
Admin
Yeah, I was too lazy to write out the whole name of the function, which was "IsAlphaNumeric". And the function specifically excludes "" and such with the Case Else block.
The reason I used the ASCII code instead of the characters themselves is because I wasn't thinking of them as characters at the time, but as integers. So, it was obfuscated already in my head...