- 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
All I'd have to do is turn off javascript and I can put 4@A5$)(W¤Õß+45n for my birthday!
...and watch it as the server throws an uncaught exception, because the morons thought server-side validation was unncessary, because the client can do it themselves!
All client side is good for is an extra layer of convenience (in terms of saved page hits, etc.) on top of server-side validation, where all the real action is.
Admin
where's the wtf? web services make /everything/ better. The author can also tell his boss that his code uses sophisticated SOAP AJAX web two point omg web technology to ensure the validity of dates.
Admin
I think we're being too harsh on this guy(girl.) This is an excellent example of reuse of well-tested code.
Admin
Alex, you misspelled "hellbent".
"...that lived in the house that Jack built."
Think of how much technical knowledge was used to avoid writing a date validation routine. As well, think of how little sense was being used. "Penny proud; pound foolish."
Sincerely,
Gene Wirchenko
Admin
thats actually quite clever..if it wasnt so dumb
Admin
quite true, there is no isDate() function, but...
<font style="font-weight: bold;" size="4">function isDate(testDate){
if(testDate.constructor == Date){
return true;
} else {
return false;
}
}</font>
doesn't seem to hard...
Admin
I think we're dealing with a Date represented as a String here - in which case it wouldn't have a Date constructor. Correct me if I'm wrong - I haven't "programmed" in JavaScript in a while.
Admin
There is no WTF here... this is how you do "enterprise" validation.
Admin
Lets not start the "enterprise" talk again. This is plain and simple. Google is god to programmers that don't have a clue where to begin.
Admin
What I find the worst about this function is it returns
< result >false< /result >
or
< result >true< /result >
rather than a Javascript boolean value.
What I find second worst is that if the web service is down all dates are invalid by default.
Admin
Also.... what if the web service date is in a different format than the one inputted by the user?
Admin
What a bad idea, everyone knows you just create a folder on the server that contains text files, each one named for a valid date for every year going backwards and forwards for 125 years and do a string compair.
Oh, and stopping when it finds a valid match is dangerous, let it check them all "just in case."
Admin
That could be construed as a feature.
Admin
Of course. That way when you are doing the time complexity analysis of your "date search," you don't have to worry about anything silly like best- or worst-case scenarios. You just have one "all case" scenario. That way, it runs in constant time. :)
Admin
How's this?
[I]function isDate(testDate) { return (new Date(testDate)!='NaN' || 'moose'); }
alert(isDate("04/01/2006")); // returns true.
alert(isDate("0X/01/2006")); // returns moose.
Admin
ummm, that would be nice if the text field automatically created a Date object for you... otherwise there's still no builtin isDate to validate a string. But who does that anyways? Just make them use a javascript calendar ;)
Admin
[cliche]The real WTF here[/cliche] is that he didn't do client-side VB in javascript to do date validation.
And to make sure it's a doubly-validated date, insert it into a table and see if the DB accepted it as a date (so long as you aren't running like SQLite that doesn't give a flying hoot about types) as well.
Admin
Granted, this code could use a little improvement, but its not really that bad of a WTF. What if this was in a web app that could be deployed in various places and the standard date format differs? i.e. - If they deployed it in the U.S. they might want U.S. format dates - mm/dd/yyyy, but if they deployed in Europe they may want dd/mm/yyyy. This allows the client to be format flexible without lots of extra JS. Of course, you would still need to do server side validation as well.
Aa
Admin
CAPTCHA: paycheck (and it's payday! w00t!)
This is not a WTF. It's stupid, but not a WTF.
If the web service is down, most likely the web server that also served the crappy Javascript code is also down. Now, the error will be hard to trace, but chances are with IIS monitoring you'll know that anyway.
For internationalization, this would be great... but would you indicate what culture the user is from strictly in the Javascript??? Does ASP.NET have a culture detector you can use so you Date.Parse() correctly based on your User-Agent header?
Admin
You would not, and culture is irrelevant since individual preference trumps that anyway. The international standard (ISO 8601?) is YMD format. The U.S. company that I work for happens to use YMD, and in the client billing system that I wrote and maintain, that format is set with one command: set date ansi, but if we wished to change it, it would be just that one command that would change. I save the date setting in a system information table, so that it can be changed by the operator if desired. There is no need to go to horrible lengths that are difficult to debug.
Sincerely,
Gene Wirchenko
Admin
What if you're working with different string formats... Different languages.. Different business logic (weekdays, or holydays, and so on).. Many of these cases are quite common on many "enterprise applications" that you guys make fun of.
You probably already have all this developed on your business layer, so why not expose this on the UI to give faster feedback about what's being entered? Would you prefer to code all that again in JS ??
Using WS for simply checking the isDate on the server is a big WTF.. but using webservices for validation on the client is not a completely stupid idea.
Admin
Wrong, and so is the punctuation. Once again the article is also a WTF.
Admin
Can you get it to return FileNotFound?
Admin
No no no no no! You have a folder on the server that contains text files, each one named for every invalid date! That way you can still use different date formats (mm/dd/yy, mm-dd-yy) without having to create more text files!
Admin
Hmmm, I think we're really stretching things a bit here...
This is pretty much standard operating procedure. The rest is just RPC.
Now if there was an 'eval( )' call in there somewhere, then we'd have something!
Admin
Actually, they were using a Token-Ring network.
Admin
I take it that you've never actually TRIED to return moose in a production environment. Even with the original store receipt, it's a cast-iron bitch.
Admin
Why would I pray for a tighter bomb pattern anyways?
Admin
I don't know where they are getting the date from in the first place, but if they used drop down menus it wouldn't matter the internationality because you say month, day, year!
April 13, 2006
Then you don't need validation.
Admin
Ask Yossarian.
Admin
Oh, I see the problem now. A valid date on the server may not be a valid date on the client.
Admin
Admin
You need the handy isNAMoose() function available to JavaScript 1.7 and later:
Admin
What if the culture is not on the Gregorian calendar? What if the client is Jewish, wouldn't you want that to be localized? Why even bother with validation at all? Data validation is silly and outdated!</sarcasm>
Admin
Moosey fate! Say moosey fate!
Admin
At least you can replace the code inside there and fix it in one place. It could have been far worse with the code pasted all over the place.
Admin
Oh, come on. Modifying the values of a drop-down is easy. Here's one of the harder ways to do it:
Admin
" All I'd have to do is turn off javascript and I can put 4@A5$)(W¤Õß+45n for my birthday!"
Client side validation is for YOUR benifit, not the web-devs. It means we don't have to send 10 transactions back and forth just to figure out that, yes, some people are as stupid as dilbert implies.
For instance, if this @#$(&( msg board did client side enabling of the post method, I wouldn't have to re-enter the worthless CAPTCHA everytime I forget to bang on the keyboard to create a name.
Admin
This is a fun page to read when bored at work...er, I mean when you have a free moment at home.
http://www.generationterrorists.com/quotes/catch-22.shtml
Admin
Can you pass multiple moose into this function? Mabye a linked list of meese that need validation sorted in decreasely antler size?
Admin
This WTF has inspired me; I have an idea how to use the network as the computer.
You create a www. .com with an http handler that handles all request.
Then you call it with /<CalendarType>/<Culture-Code>/<date parts>.ashx (eg /julian/en-us/dd.mm.yyyy.ashx ) and the page returns true or a 404 if the date is not found :P. Don't make any mistakes and set the headers to allow caching everywhere forever.
The you can just check your date by checking the that the url is valid.
I hereby give this to everyone, free as in beer, not free as in speech.
Admin
The only thing bad I see here was that the validation function isn't more general. Something like:
function validate(formObj) {}
Where the entire form is validated at once on the server-side.
The dilemna is that client-side validation is stupid, because you know the server is going to have to re-validate anyway, so why repeat the code in the client at all? You can't trust client-side validation. But it turns out it is nice to alert the client before a full round-trip on form submission of a potential problem so you don't have to re-draw the entire form with all their values in place and some retarded red "this field sucks" error.
Still, since you know the server has to validate, why not just keep all the validation code on the server and call it from the client for pre-validation? Do you enjoy writing twice the code? Javascript is fun ... but not that fun.
Admin
There's no WTF here. That's a perfectly reasonable hack for code that they probably wanted to throw together in a hurry. Sure it's inefficient and ought to be replaced eventually, but for a 1.0 it's fine.
Admin
I'm sure that we could do a Vector of moosen.
Admin
This is not a WTF. This is really not much different than Google Suggest - there's not even a database hit, and the function call acts as sufficient API that if performance ever became a problem, it could be re-implemented purely client-side without affecting other code.
The closest thing to a WTF is the whole "call to Ethernet to call to TCP to call to IP blah blah" jazz. Come on, haven't we gotten used to the idea that there's thing think called the "Internet" and that we can generally depend on it working?
Nowhere does this sample code reference ETHERNET... so it reads like the article summary in a fark.com article... funny but not particularly relevant.
Admin
Cool sig ... I never stopped and thought about the W.T.F. cause that is always how my week ends!!! I should really only work two days a week, that is the only time my work has my interest! [8-|]
Admin
Isn't that what you new-fangled types call a "composite application"? [:S]
Admin
The idea of releasing such junk as a 1.0 is ridiculous. What ever happened to doing it right the first time? Validating a date is not particularly difficult code to write. BTDT, wore out the T-shirt.
Sincerely,
Gene Wirchenko
Admin
You're kidding, right? Seriously, dude. That's funny...
I mean, I hope you're kidding. Right?
Admin
Unfortunately, this solution works for IE, but it does not work for browsers that properly implement the ECMAScript specification.