Comment On Extensive Date Parsing

If I had a dollar for every time I've seen someone doing custom date and time parsing, I'd have somewhere between eight and ten dollars. It's just not something you see much of these days. All major programming languages have built-in support for parsing dates, times, currency, etc., and programmers are pretty good about using them. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Extensive Date Parsing

2008-10-27 09:04 • by Eric L (unregistered)
the

@SuppressWarnings("deprecation")

Is totally priceless.

Re: Extensive Date Parsing

2008-10-27 09:04 • by jethr0 (unregistered)
TRWTF is the empty catch block in Ben's solution.

Re: Extensive Date Parsing

2008-10-27 09:04 • by ... (unregistered)
Gotta an error on TDWTF...
WTF?

XML Parsing Error: no element found
Location: http://thedailywtf.com/Comments/Extensive-Date-Parsing.aspx
Line Number 1, Column 1:
^

Re: Extensive Date Parsing

2008-10-27 09:06 • by snoofle
@SuppressComments("stupid comment")

Honestly, efficient code making good use of existing well tested standard libraries - what will they think of next?

Re: Extensive Date Parsing

2008-10-27 09:09 • by Enkurs (unregistered)
The <pre>'s and such are formatting and styles for automagic documentation software.

Re: Extensive Date Parsing

2008-10-27 09:12 • by PAG (unregistered)
I have an Electrical Engineer as a brother and, at his job, they make him program....

Oh the problems he shows me. He is in chrge of critical parts of sound playing in a flight simulator and let me tell you I wouldn't want to be in that simulator... He always come up with solutions so complex that he doesn't even care to look if something simple already exists...

You shoulad have seen the look on his face when I talked to him about DirectSound.....

Re: Extensive Date Parsing

2008-10-27 09:15 • by Trondster (unregistered)
224936 in reply to 224934
PAG:
I have an Electrical Engineer as a brother and, at his job, they make him program....
Oh the problems he shows me. He is in chrge of (..)

Mwhuahaha - an Electrical Engineer "in charge" of something. Thought you could get away with such an atrocious pun, did you? ;)

Re: Extensive Date Parsing

2008-10-27 09:18 • by anon (unregistered)
224938 in reply to 224934
PAG:
I have an Electrical Engineer as a brother and, at his job, they make him program....


I can see some logic in this reasoning. Computers run on electricity, so anyone who is an electrical engineer should understand how computers work. If you understand how computers work then you can program them.

Re: Extensive Date Parsing

2008-10-27 09:21 • by Mike (unregistered)
I love the other WTF in the code.. Using the miscellaneous "stop" boolean to detect if the inner for loop has been abandoned, just so that the outer loop can be broken out of! Instead of just using a labelled break.....

Re: Extensive Date Parsing

2008-10-27 09:21 • by ThomasP (unregistered)
DateFormat df = new SimpleDateFormat('A Format', Locale.ENGLISH);

At least the engineer's code compiles....

That was pseudocode, hence "A Format" -ed.

Re: Extensive Date Parsing

2008-10-27 09:22 • by Major Math (unregistered)
224941 in reply to 224938
anon:
Computers run on electricity, so anyone who is an electrical engineer should understand how computers work.

Almost... but computers run on electricity and math which is why we had to complete so many math courses before we could get jobs writing PHP.

Re: Extensive Date Parsing

2008-10-27 09:22 • by Steve (unregistered)
224942 in reply to 224938
anon:
PAG:
I have an Electrical Engineer as a brother and, at his job, they make him program....


I can see some logic in this reasoning. Computers run on electricity, so anyone who is an electrical engineer should understand how computers work. If you understand how computers work then you can program them.
Of course engineers program. Why else would FORTRAN still exist?

Re: Extensive Date Parsing

2008-10-27 09:23 • by pbean
DateTime parseDate(string dateString)

{
string[] dateParts = dateString.explode("/");
return new DateTime(dateParts[2], dateParts[0], dateParts[1]);
}


This one was obvious. I wonder what beauties all of you genious people can come up with. :-D

Re: Extensive Date Parsing

2008-10-27 09:25 • by Date This (unregistered)
I think there are some date formats missing in the original code... lots of them.

Which reminds me, we need some special kind of torture for people who represent dates such as 07/08/09.

Re: Extensive Date Parsing

2008-10-27 09:37 • by Why Too What? (unregistered)
224945 in reply to 224944
Date This:
I think there are some date formats missing in the original code... lots of them.

Which reminds me, we need some special kind of torture for people who represent dates such as 07/08/09.

I dunno, on my first job (at a COBOL shop) I saw a lot of 99/99/99 and that didn't seem to cause any problems. At the time.

Re: Extensive Date Parsing

2008-10-27 09:42 • by vt_mruhlin
Those pres in there are part of the comments, and I'm not sure why they're in there.


You've really never heard of javadocs?

Re: Extensive Date Parsing

2008-10-27 09:43 • by xalor (unregistered)
I'm looking at this and thinking the original engineer was probably told by management that it needs to work in any locale, as the company may have plans to open an overseas affiliate. Or perhaps the original engineer thought it would be responsible and professional to write something in such a manner that it didn't break when the locale changed.

But not so fast! Ben to the rescue! He's going to make your existing, working code simpler. That is, so six months from now he can get a call at 3:00 in the morning (that's 9:00 at the overseas affiliate) to asking why none of the dates are printing on the report.

Okay, so Ben took code which formerly would work with any locale, and made it work in only one. Normally, we'd call removing functionality and code robustness a bug. It's one thing to code simple, to the point functions, but quite another to break existing functionality because you believe the code is too complicated.

Re: Extensive Date Parsing

2008-10-27 09:49 • by rumpelstiltskin (unregistered)
224948 in reply to 224938
anon:
PAG:
I have an Electrical Engineer as a brother and, at his job, they make him program....


I can see some logic in this reasoning. Computers run on electricity, so anyone who is an electrical engineer should understand how computers work. If you understand how computers work then you can program them.


Back in the day, before someone decided that awarding college degrees in things like "women's studies" and "writing for-loops" made sense, EE was a typical path towards a programming career.

Re: Extensive Date Parsing

2008-10-27 09:53 • by I walked the dinosaur (unregistered)
The real WTF is using single quotes in java for a String and not "honestly" knowing what javadocs are. Seriously, what the hell kind of Java developer doesn't know if not extensively use javadocs?

Re: Extensive Date Parsing

2008-10-27 09:53 • by Cindy Dalfovo (unregistered)
What's with the programmers vs engineers?
I'm an engineer and I like to use parsers and to use the simple solution.
Then again, I'm just an engineer STUDENT, so maybe I still haven't learned how to do things the hard way...

Re: Extensive Date Parsing

2008-10-27 09:54 • by javacoder (unregistered)
224951 in reply to 224947
I agree. Ben introduced a major regression.

Re: Extensive Date Parsing

2008-10-27 09:56 • by Dirk Diggler (unregistered)
224952 in reply to 224947
Sure, I'll grant you that Ben made it work in only one locale, but, it's the only locale that matters!
USA USA USA USA

Re: Extensive Date Parsing

2008-10-27 10:02 • by Bot (unregistered)
The RWTF is obviously Ben's code. It doesn't even compile. Why is he using single quotes? What is 'A format'? Where is formats declared? Why is there even a for(String format:formats) loop when format isn't even used in it? Why does he swallow the exception?

Re: Extensive Date Parsing

2008-10-27 10:06 • by javacoder (unregistered)
224954 in reply to 224953
Maybe because Ben is a moron and he thinks he can do better without even checking his code compiles.

Re: Extensive Date Parsing

2008-10-27 10:09 • by Leonardo (unregistered)
Hey! As a Engineer I resent that "Tsk tsk, Ben. With your tendency to build simple solutions, you'll never make it as an engineer" comment!

Seriously, we ate usually tasked with complex tasks, so our solutions are equally complex. And we can have brain farts too, and this WTF is obviously one of them. An Engineer's best friend is laziness, if you're lazy you will never try to write a 50-line function, specially in a high-level language, without first to a simpler and easier solution.

Now, let me get back to work, this charged spinning flux capacitor isn't quite working yet.

Re: Extensive Date Parsing

2008-10-27 10:10 • by erich
224957 in reply to 224940
ThomasP:
DateFormat df = new SimpleDateFormat('A Format', Locale.ENGLISH);

At least the engineer's code compiles....



Yeah, Ben's solution more of a WTF than the original. I mean, yeah, it's nice and simple, so don't let the pesky fact that it doesn't work trouble you. Even if this is the work of the anonymizer, it never terminates the loop, so it basically only checks the last format in the array anyhow...

Re: Extensive Date Parsing

2008-10-27 10:11 • by JD (unregistered)
Professionals treat all warnings as errors.
Amateurs ignore warnings.
Idiots suppress warnings.

Re: Extensive Date Parsing

2008-10-27 10:17 • by A Chartered Engineer (unregistered)
The real WTF is the lack of spaces around the '=' sign. Spot that and you know that something dangerous lies within.

Re: Extensive Date Parsing

2008-10-27 10:21 • by [twisti] (unregistered)
There is so much wrong with Ben's solution that I seriously wrote an American friend to ask if today is something like April 1st in America, because I couldn't believe someone who doesn't even know what javadoc is could be retarded enough to post such a buggy and broken "solution" to TDWTF.

At least someone finally proved Jeff Atwood right.

Re: Extensive Date Parsing

2008-10-27 10:31 • by McCrainky (unregistered)
224962 in reply to 224952
Dirk Diggler:
Sure, I'll grant you that Ben made it work in only one locale, but, it's the only locale that matters!
USA USA USA USA


If you make code run in other locales you are probably pal-ling around with terrorists, don'tcha know. You bet-cha!

Re: Extensive Date Parsing

2008-10-27 10:31 • by Daniel (unregistered)
The formats given wouldn't work outside English locale anyway.

Re: Extensive Date Parsing

2008-10-27 10:34 • by Chris (unregistered)
224964 in reply to 224929
jethr0:
TRWTF is the empty catch block in Ben's solution.


not only that, but a try and catch without a finally.

my boss goes completely nuts if he finds a try / catch without a finally.

the result: I have an entire army of empty finally blocks. (he doesn't like that either, but it's far less likely to send him into a condescending mini-lecture about good coding standards)

Re: Extensive Date Parsing

2008-10-27 10:36 • by Jythie (unregistered)
So basically we've got a programmer making code 'simpler' just for the sake of making it 'simpler' while making it more brittle and future-proof?

Strikes me as a 'wow! I finished my 4 week Java for Dummies course! I know more then one of those silly engineerings with years of intensive coursework!'

Reminds me of all those anti-ivory-tower-elite types that america seems so proud of.. people with less education thinking that they MUST know more then people with more education because education is worthless.

Re: Extensive Date Parsing

2008-10-27 10:42 • by Bobble (unregistered)
If your code will never be used outside of a given culture, what is the point of coding for it? QA isn't going to test against it and business is going to look at you like you are insane when you suggest that you need time in the project plan for ti-ET encodings for your internal app.

Re: Extensive Date Parsing

2008-10-27 10:42 • by 123456 (unregistered)
224967 in reply to 224946
vt_mruhlin:
Those pres in there are part of the comments, and I'm not sure why they're in there.


You've really never heard of javadocs?


Ok, but the "pre" tags are not necessary.

Re: Extensive Date Parsing

2008-10-27 10:46 • by Godot (unregistered)
224968 in reply to 224959
A Chartered Engineer:
The real WTF is the lack of spaces around the '=' sign. Spot that and you know that something dangerous lies within.
Wat?? Java is a real language, dude...

Re: Extensive Date Parsing

2008-10-27 10:50 • by Delve (unregistered)
224969 in reply to 224965
Jythie:
Reminds me of all those anti-ivory-tower-elite types that america seems so proud of.. people with less education thinking that they MUST know more then people with more education because education is worthless.


I love those types. It's a good thing we have so many in public office or, you know, we'd have made some environmental progress.

Re: Extensive Date Parsing

2008-10-27 10:51 • by SuperousOxide
So Ben took out the Locale loop, and introduced an obvious bug by looping through the formats but not actually using any of them. Maybe the locales weren't necessary, but it's not really a big WTF (the code to get out of the nested for loop is a little ugly, but I'll forgive that too)

Re: Extensive Date Parsing

2008-10-27 10:54 • by SuperousOxide
224971 in reply to 224929
jethr0:
TRWTF is the empty catch block in Ben's solution.


Well, that was in the original solution too. Ben's at least only catch and releases the ParseException

Re: Extensive Date Parsing

2008-10-27 10:58 • by JavaJaap (unregistered)
TRWTF is the current Java date and time implementation. But of coarse all our problems will be solved by JSR-310 :)

Re: Extensive Date Parsing

2008-10-27 11:00 • by MindChild (unregistered)
224973 in reply to 224939
I don't think this is necessarily a WTF at all. I think it is pretty apparent that this is likely a C++ programmer thrown into Java. If you have ever been in such a situation, you KNOW that you don't know all of the cool little language features... so you use what is good practice elsewhere. This is how you would break a loop in C/C++, without a goto. And it is clear what and why you are trying to do it.

Re: Extensive Date Parsing

2008-10-27 11:01 • by JavaJaap (unregistered)
TRWTF is the current Java date and time implementation. But of coarse all our problems will be solved by JSR-310 :)

Re: Extensive Date Parsing

2008-10-27 11:03 • by dkf
224975 in reply to 224967
123456:
vt_mruhlin:
Those pres in there are part of the comments, and I'm not sure why they're in there.
You've really never heard of javadocs?
Ok, but the "pre" tags are not necessary.
Sometimes an engineer just has to add extra fail into the documentation. Why, I've never understood. Perhaps it's there to make the tech writer look good…

Re: Extensive Date Parsing

2008-10-27 11:04 • by JamesQMurphy
224976 in reply to 224958
JD:
Professionals treat all warnings as errors.
Amateurs ignore warnings.
Idiots suppress warnings.

Nice. That's going on my wall.

Re: Extensive Date Parsing

2008-10-27 11:07 • by Martin (unregistered)
A big wtf in the original code is that it tries all existing locales, instead of the current locale for the user.

This might cause big problems because there might might be multiple ways to map a string to a date, and just picking a random is NOT a good solution.

I have always thought that this
"Lets us read userinput, and se if we in some wierd way can handle the input as a date" is a big wtf. In that way the new code is better, because it either handle the date CORRECT or fail, which is much better then the old solution which in some cases could fail in wierd and unpredictable ways. (Example: It might only be able to handle days >12, try to debug that.)




Re: Extensive Date Parsing

2008-10-27 11:09 • by Cuthbert (unregistered)
224978 in reply to 224944
We did have a special kind of torture for those people. It was called "the Y2K fix".

Re: Extensive Date Parsing

2008-10-27 11:11 • by Paul (unregistered)
224979 in reply to 224948
rumpelstiltskin:
anon:
PAG:
I have an Electrical Engineer as a brother and, at his job, they make him program....


I can see some logic in this reasoning. Computers run on electricity, so anyone who is an electrical engineer should understand how computers work. If you understand how computers work then you can program them.


Back in the day, before someone decided that awarding college degrees in things like "women's studies" and "writing for-loops" made sense, EE was a typical path towards a programming career.


My dad ended up coding for a while after gaining a doctorate in EE in the 50's (before he figured that in those days, selling computers the size of a room earned you a hell of alot more money than designing them)

coming from a family of programers, the standard christmas lunch goes something like: You had it easy in your day, in my day we didn't have an IDE ... Back in my day we had to code in assembler.. and so on.

Clear winner ends up being the EE, 'back in my day, we had to code with a soldering iron and a bunch of valves'

Re: Extensive Date Parsing

2008-10-27 11:17 • by Nether
Oh god, the pain starts 10 lines in and it's still hurting.

I love the totally useless comments on the for loops, and the hyperlink to the SimpleDateFormat API. Because commenting what your code does is for chumps. Better assume that whoever's maintaining your code doesn't know basic language syntax and has no idea where the API documentation is!

This has to be one of the better submissions I've seen in a while. It's just total failure on every line. I had a coworker who used to write date/time management code like this. It wasn't quite this bad and its purpose was far more complicated than parsing a date, but it was such a messy conceptual trainwreck that it eventually required a total redesign and rewrite from scratch.

Re: Extensive Date Parsing

2008-10-27 11:31 • by ... (unregistered)
224983 in reply to 224964
Chris:
jethr0:
TRWTF is the empty catch block in Ben's solution.


not only that, but a try and catch without a finally.

my boss goes completely nuts if he finds a try / catch without a finally.

the result: I have an entire army of empty finally blocks. (he doesn't like that either, but it's far less likely to send him into a condescending mini-lecture about good coding standards)

There's nothing wrong about not using a finally block when you don't have open resources to close or similar stuff (and that's the case, there's nothing to be done in a finally block there). If your boss doesn't understand what finally is meant to, but loves preaching about it, he's stupid.

Re: Extensive Date Parsing

2008-10-27 11:34 • by operagost
224984 in reply to 224965
Jythie:

Reminds me of all those anti-ivory-tower-elite types that america seems so proud of.. people with less education thinking that they MUST know more then people with more education because education is worthless.

[citation needed]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment