- 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
Oh! an unfinished sentence! I wish there were more
Admin
TRWTF is that readers have to finish the code in the original post, making it as WTFy as possible.
The code was eaten by our occasionally dysfunctional richtext editor, then the mistake was missed by our occasionally dysfunctional proofreading department. Fixed! -ed.
Admin
My guess is loops within loops within loops, probably using loop counters named ii, iii, iv, not_i, and paula_bean.
An interesting alternative would be to pretend that you're programming in a functional language, and to transform the original string by mapping it to a series of new strings, one character at a time.
Admin
I wonder what would happen if you entered some exotic characters like é, ü or å. But then, who needs applicants with French, German or -- God forbid -- Swedish names :)
Admin
Admin
"Yes, perhaps today is a good day to die. Release the Javascript!"
... although my favourite is still:
"My program has just dumped Stova Core!"
Admin
It still puzzles me that in this day and age of unicode é is seen as exotic a character as Jack Sparrow..
Admin
"In response to your interview question on how I feel I could contribute to the company I'd like to point out that I could start by updating, sorry, rewriting your online résumé form. I realize that this isn't saying much seeing as a 3 year old child with severe down syndrome could make a better form than this; it is however necessary to start with the basics if you'll have any hope of lifting yourself out of this pile of rancid manure you call code. If I may offer you some advice, I'd also propose to stop hiring high school kids to build forms. I understand that you can pay them in coke cans, but their "code" tends to suffer."
Admin
This comment goes something like this:
The real WTF is
Admin
Heey, the post wasn't like this!
Here is the code as I posted it.
function validate(field) { var A = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.:!?@#$%¨&*()_+=[]^
Çç{}
^<>\/|"; var B = " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.:_____________________________";var oldval = field.value; var newval = "";
for (var i=0; i<oldval.length; i++) { var char = A.indexOf(oldval.substr(i, 1)); newval = newval + B.substr(char, 1); } field.value = newval; }
o.O
Sorry for a WTF inside a WTF =P
Admin
Admin
whoever posted the code forgot to escape the <
it's not rocket science people...
Admin
I am too humble to call myself a "star programmer", but the code was quite obvious by what was displayed.
Two variables, one is the entire alphabet, the other is a matching alphabet in all UPPERCASE. Grab the user input (field.value), then you start with a 'for' loop. It was quite obvious what was going to happen.
Admin
Or maybe it is and THAT is why half of the code is missing? I think Gustavo is lying about how the code actually looked... the original OBVIOUSLY used a database to store xml data to determine which characters to change. It's just common sense!
Admin
This could've led to some brilliant support calls.
"Christopher Konstantopoulos says the site's running very slowly? But I just checked with Bob Jones and he says it's fine!"
Admin
Not to mention that if you use a pipe ('|'), it will probably fail as well, seeing that the result string (var B) is 1 character shorter then the input string (var A).
But this code might be valid. I'm not sure if Netscape 2.0 supported fancy functions like 'toUpperCase()'
Admin
Not that I'm saying that code is any good, but that method shouldn't be noticeably slow. It's 0(n) so it shouldn't deteriorate too much with larger strings. If you unroll the loop, you get this for "John" as a first name:
var char = A.indexOf(oldval.substr("J", 1)); newval = newval + B.substr(char, 1); char = A.indexOf(oldval.substr("O", 1)); newval = newval + B.substr(char, 1); char = A.indexOf(oldval.substr("H", 1)); newval = newval + B.substr(char, 1); char = A.indexOf(oldval.substr("N", 1)); newval = newval + B.substr(char, 1);
That should return in under a millisecond with todays computers... maybe I'm not appreciating how slow computers were when this was discovered.
Again, not advocating bad code, just surprised that this was even noticeable.
Admin
That's easy to say after he already posted the rest of the code ;)
Admin
BTW: The real WTF is the way that when I click Preview, I get a new Captcha with the same word but written differently, so I can get lots of examples to feed to my OCR. Oh, and does it use words randomly taken from Lorem Ipsum?
Admin
Admin
Also String.indexOf is O(n)...
Admin
No, it's actually O(n^2) because it actually searches for the character each time: A.indexOf(oldval.substr(i,1)). The 'correct' way would have been B=B+A.substr(i,1). I don't know why he didn't do that, it's more obvious IMO. If you want to change é, ă, etc. in simple English characters I think that this method is the simplest way (if you are careful about the complexity)
Admin
Nope. The backslash is escaped (with another backslash).
An additional WTF is that cedillas are included in the trap string but no other characters with accents or other funny non-english wiggly bits.
Admin
var myComment = "If there were only an easier way to make my comment all upper case I'd do it." this.comment.innerHTML = myComment.toUpperCase();
Admin
What's with all these ancient WTFs? Everything must be working perfectly now, I guess.
Admin
Hey, sounds like a clever way to weed out the Swedes from your job applicants without having to admit to discrimination. When they try to submit the resume, just reject it with "Invalid character in name".
(Need I explain that I'm of Norwegian descent?)
Admin
I agree - far too much of the content on this site is obvious - the stories are far too slow at getting to the point. For example, I remember reading the first Paula Bean story and thinking (halfway through), "oh she's probably not written more than a HelloWorld app that prints "Paula is Brilliant". Make it snappy people! And stop boring us with these obvious code snippets.
Admin
oldval.substr(1, 1) = "J" oldval.substr("J", 1) = unpredictable javascript behaviour
I agree with you that I would not expect it to be noticably slow on todays machines.
Admin
Please wait while we uppercase this comment...
Admin
God, I'm such a crushing bore sometimes. My Apologies...
Admin
Each string concat creates a new string object to add the previous two into. It does get tend to get slow.
You're better off pushing the letters to an array and joining that together afterwards.
Admin
Why insist on uppercasing everything in the first place?
Admin
Offtopic:
I really like these MUMPS programmer Google ads, considering this site's attitude towards MUMPS
Admin
Admin
Another vote for being puzzled at what's so dreadfully slow about this code? The stated times seem a bit slow for the first machine I ever worked with that I could time: TRS-80 Model 1. A CPU speed three orders of magnitude below current chips and it did a LOT less per cycle as well. Interpreted basic--shouldn't be any worse than javascript.
Admin
O(n) vs O(n^2)
I'm pretty sure it's 0(n). Look at the loop unrolling (fixed bug from last unrolling):
var char = A.indexOf(oldval.substr(1, 1)); newval = newval + B.substr(char, 1);
char = A.indexOf(oldval.substr(2, 1)); newval = newval + B.substr(char, 1);
char = A.indexOf(oldval.substr(3, 1)); newval = newval + B.substr(char, 1);
char = A.indexOf(oldval.substr(4, 1)); newval = newval + B.substr(char, 1);
The indexof is being done on a constant string, not the input string so is O(1). Substr is o(1). It seems to me that this algorithm is a perfect example of O(n). Can one of you O(n^2) advocates go into a little more detail please?
Thanks
F
Admin
Why
a) convert to upper case
and
b) convert to upper case on the client side?
Admin
We force all of our data to upper case for some unknown reason. I think it's because we used to have a paper form that people would handwrite their info on. Someone decided it's more accurate to OCR capital letters so we told them to write capital letters.
However, the important thing is that we do it server-side and don't bother users with it.
Admin
I WAS JUST GOING TO SAY. THAT IS THE REAL WTF, IN MY OPINION.
Admin
We've actually had a VistA programmer come by our LUG meetings - he's trying to adapt the code to private practice.
Yeech.
Although I'd probably rather use MUMPS than javascript...
Admin
Admin
So quityerwhining.
Also, you've mis-spelt "brillant." Is nothing sacred?
Admin
indexOf is O(n), so this is O(n^2).
Admin
Admin
One second?
Admin
I've seen this before....I think these are automatically generated validation routines that MS Frontpage puts in.
I saw something similar to this years ago when our "marketing" department (one young kid that discovered web development with frontpage) made some sort of customer contact information gathering page. My initial reaction was WTF too until I realized it was auto-generated by an MS tool....then it really didn't seem much like a WTF anymore since, you know, it was one of those common moronic things MS does from time to time.
But, hey, remember they only hire the best and the brightest! Every single applicant gets to answer questions about how to make dwarves wearing different colored hats cross a bridge in the most efficient way possible while smuggling tomatoes....
Admin
Just read this one. Technically, indexOf is O(m), m being the length of the character string, so it's really O(m*n). m is consistent in this case, but it would be naive to leave it out of the O notation, as it's the process that takes the longest.
also, I imagine the code looking more like this:
for(int i=0; i<field.value.length; i++){ for(int j=0; j<A.length; j++){ if(field.value[i] == A[j]){ newVal = newVal + B[j]; (heh...Bj) } } }
To cap it all, I don't know how "+" works with strings/characters in javascript. It could be doing this:
temp[] = new char[newVal.length + 1]; for(int i=0; i<newVal.length; i++) temp[i]=newVal[i]; temp[temp.length-1] = B[j]; newVal = temp;
this has obvious consequences.
Admin
The thing I really enjoyed about this WTF was th
Admin
JavaScript/ECMAScript IS a functional programming language, with support for first class functions and closures. Due to its C-like syntax and the fact that most people only use it to do a bit of DOM and maybe some asynchronous callbacks, most remain blissfully unaware what the LANGUAGE is capable of (most of the LIBRARIES on the other hand, are hideous trash).
Admin