- 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
What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.
I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."
Admin
The situation is thus. You are a code monkey (JavaScript in this case), you are given a task - validate the input on this form. You sit in the dark being fed your tasks by you wise, all seeing project manager.
The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?
Admin
Omg i didn't even know that you could have multiline code inside an event handler? Thank god for tagsoup parsers :D
Admin
How true that is :( Because, we all know the project manager, despite having never really written software, knows all about how it's written and how to manage those silly programmers who always talk about "refactoring" and "testing" instead of producing code that Sales can sell to clients so the CEO can earn his millions.
Admin
how did the quotation mark(s) inside an attribute value ever work?
Admin
Why do so many programmers don't know bit operators?
Admin
Can someone explain why this is a WTF for people who don't have a clue about web development?
Admin
Admin
I have no idea what point you're trying to make. Are you trying to say that the project manager mandated that the coder not use functions or other basic hallmarks of good style?
Admin
I wonder if they check password with JavaScript on client side as well
Admin
I can't agree with the fact that the PM screwed up. I would rather say that the recruiting/HR department did. This is stuff you just have to question and not take for granted even if you are just a coder. And if you really are a monkey, at least you could do is ask yourself "is it really normal to have such a long string as an attribute value? All other attribues seem to be a lot shorter. Hmmmmmmm".
Admin
Perhaps it's the same reason that some don't know the difference between a bit operator and a logical operator.
Admin
There's a 66 line javascript function inside an HTML attribute. Attributes are never supposed to be more than a few words. The correct way to handle this would be to put the javascript somewhere else (like, in an actual function declaration) and call it from the handler, or even better, put an onload function somewhere that attaches the onclick handler at start so there isn't any javascript in the HTML at all.
Admin
if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) & validate(form.res_MM, "",form.res_YYYY) & validate(form.res_MM_end, "", form.res_YYYY_end))) {
will work just fine assuming those functions don't have side effects. :p
Admin
Admin
Those aren't bit operators.
Admin
Admin
What?
<click> Ouch!
Admin
There should also be a server side failback so users who have Javascript turned off still get the same functionality. Helps usability and security no end. Personally, I wouldn't bother with Javascript validation and just do it on the server
Admin
Unless you are coding in LISP, where you may end up with 7,8,9 levels of nested brackets to close, adding this kind of crap to code is just annoying.
} // end if
especially when the opening if statement is THREE lines above!
Admin
I dont know to me it looks like this is Five-fingered code that someone who didnt know better, like a marketer or graphic designer slapped into the page. The annoying comments are somethings that you keep your place as a new programmer, 2-3 weeks maybe, or when you get paid by the line.
Admin
Hmmm, why does the post have a vertical scrollbar (especially since only one line is hidden)? And, more importantly, why does it have a horizontal one? (1024x768)
Admin
I bet his name is Habib Abdul Habaldoasdkdsdkfdsusmuck.
Admin
It's a little known fact that Dante's Inferno is actually a metaphorical description of JavaScript:
"Dark, profound it was, and cloudy, so that though I fixed my sight on the bottom I did not discern anything there."
Admin
Admin
Second, readability is a nightmare. So, instead of putting all of the javascript code inside of an HTML attribute, it should have been stored in either its own javascript file or in the page header. This would leave a simple, very readable, function call as the button's onclick handler.
Admin
================= if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && validate(form.res_MM, "",form.res_YYYY) && validate(form.res_MM_end, "", form.res_YYYY_end)){
Why do so many programmers don't know bit operators?
Ummm... those are LOGICAL operators, buddy, not bitwise operators. Quite a difference.
Admin
I don't really see how "readability" is a nightmare, either. Firstly, it's Javascript. Javascript is not readable, IMO. Secondly, it would be equally unreadable if wrapped in a function call.
What I think we have here is a Perl programmer trying to carry the concept of anonymous subroutines across to Javascript. Not the world's brightest idea, granted, but more of a giggle than a WTF.
Admin
Although those aren't bit operators in your example, are they (afaik they're called logical operators)?
Admin
There are anonymous functions in Javascript.
Admin
Validating user input on the client side in addition to the server can improve server performance by reducing the number of calls to the server that contain invalid data, and the subsequent calls needed to resubmit the corrected data.
CAPTCHA: 'duis' - Don't drink and drive and you won't get any! [~])
Admin
At least its commented!
// end comment
Admin
Admin
Ouch, did we hit a new low when merely the use of functions is considered a "basic hallmark of good style"?
At least the guy was using functions for the validations...
Admin
Admin
Admin
My theory was that some sort of GUI generator tool did that, I've never, never seen anything vaguely resembling that before and it looks like someone just typed a whole script into an OnClick() prompt in a prompt somewhere
Admin
We hit that low a long time ago, Winston.
Admin
Wouldn't that have broken by the first " character?
Admin
I guess he used something like <input onclick="<?php include 'script.js' ?>" ...>
Admin
heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..
I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.
Admin
Admin
Method object.verb();
An oversimplification to be sure, but it gets to the heart of the distinction. And Javascript does support both approaches.
Admin
Casual racism never goes out of style, does it?
Admin
heh, thanks for the explanation, do appreciate it!
I THINK what is meant, and I'm probably off (have a tendency to be..) is that a method exists via instantiation of an object whereas the function is a static implementation? (IE: I use a static class such as the Math lib to use the static math FUNCTIONS) I never hear much about the difference between methods and functions in C#, but I figured this is what you were getting at maybe? :P Sorry, from a Delphi perspective (don't ask!) you have procedures which don't return anything vs functions, which have a return type -- I used this as the basis of all existing as methods.
Again, thanks for clarifying!
Admin
oh man, that's awesome that scrolling wrapper around the article that means the stupid thing is unreadable because every line extends off to the right of the div... clap
Admin
Code monkey think maybe manager wanna write god damn login page himself!
Code monkey not say it, out loud code monkey not crazy, just proud.
Admin
In that example, method is the name people give to member functions of a class when they want to sound like they know Object Oriented programing, but don't know it well enough to call them messages.
A method or message is a function that is designed to operate on or expose the internal state of an object.
It's entirely possible to have verb(object) functions that are actually methods - particularly in non natively object oriented languages, and it's also equally possible (but not necessarily good design) to have object.verb() functions that are just functions, and do nothing with the state of the object they're bound to.
Admin
Oooh.. this looks like something Brice Richard would do if he knew javascript!
And speaking of truncation, anyone else notice that the wtf text has a scrollbar? But it's long enough so that you can't see the bottom scrollbar. It's effectively truncated unless you're running a full screen browser at ~1600x1200 or better (at least in IE7)!
Admin
Yes, thank you, I know there are anonymous functions in Javascript. But why bother with all that "function(blah) { // Further blah, possibly involving the DOM } when you can just encase the whole lot in double quotes? Genius, I tell you, genius.
And admittedly the OP doesn't look like Perl's anonymous subroutines (leaving aside the stuff to do with closures). Yup, Perl is almost equally verbose: sub # No blah here!\n { # blah\n }.
However, the great thing about this particular idiom is that it effectively combines Perl's anonymous subroutines with Perl's "here-doc" technique to provide what any Java programmer worth their salt would recognise as a Singleton Pattern.
Brillant! Brillant!! Brillant!!!
Of course, it's still bloody stupid.
BTW, Is it just me, or does ECMAScript sound like a peculiarly horrible combination of tattoos and a rather unpleasant skin disease?