• Eric L (unregistered)

    the

    @SuppressWarnings("deprecation")

    Is totally priceless.

  • jethr0 (unregistered)

    TRWTF is the empty catch block in Ben's solution.

  • ... (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: ^

  • (cs)

    @SuppressComments("stupid comment")

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

  • Enkurs (unregistered)

    The

    's and such are formatting and styles for automagic documentation software.

  • 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.....

  • Trondster (unregistered) in reply to PAG
    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? ;)
  • anon (unregistered) in reply to PAG
    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.

  • 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.....

  • ThomasP (unregistered)
    DateFormat df = new SimpleDateFormat('A Format', Locale.ENGLISH);
    At least the engineer's code compiles....

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

  • Major Math (unregistered) in reply to anon
    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.
  • Steve (unregistered) in reply to anon
    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?

  • (cs)
    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

  • 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.

  • Why Too What? (unregistered) in reply to Date This
    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.

  • (cs)
    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?

  • 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.

  • rumpelstiltskin (unregistered) in reply to anon
    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.

  • 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?

  • 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...

  • javacoder (unregistered) in reply to xalor

    I agree. Ben introduced a major regression.

  • Dirk Diggler (unregistered) in reply to xalor

    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

  • 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?

  • javacoder (unregistered) in reply to Bot

    Maybe because Ben is a moron and he thinks he can do better without even checking his code compiles.

  • 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.

  • (cs) in reply to ThomasP
    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...

  • JD (unregistered)

    Professionals treat all warnings as errors. Amateurs ignore warnings. Idiots suppress warnings.

  • 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.

  • [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.

  • McCrainky (unregistered) in reply to Dirk Diggler
    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!

  • Daniel (unregistered)

    The formats given wouldn't work outside English locale anyway.

  • Chris (unregistered) in reply to jethr0
    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)

  • 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.

  • 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.

  • 123456 (unregistered) in reply to vt_mruhlin
    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.

  • Godot (unregistered) in reply to A Chartered Engineer
    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...
  • Delve (unregistered) in reply to Jythie
    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.

  • (cs)

    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)

  • (cs) in reply to jethr0
    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

  • JavaJaap (unregistered)

    TRWTF is the current Java date and time implementation. But of coarse all our problems will be solved by JSR-310 :)

  • MindChild (unregistered) in reply to Mike

    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.

  • JavaJaap (unregistered)

    TRWTF is the current Java date and time implementation. But of coarse all our problems will be solved by JSR-310 :)

  • (cs) in reply to 123456
    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…
  • (cs) in reply to JD
    JD:
    Professionals treat all warnings as errors. Amateurs ignore warnings. Idiots suppress warnings.
    Nice. That's going on my wall.
  • 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.)

  • Cuthbert (unregistered) in reply to Date This

    We did have a special kind of torture for those people. It was called "the Y2K fix".

  • Paul (unregistered) in reply to rumpelstiltskin
    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'

  • (cs)

    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.

  • ... (unregistered) in reply to Chris
    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.

  • (cs) in reply to Jythie
    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]

Leave a comment on “Extensive Date Parsing”

Log In or post as a guest

Replying to comment #:

« Return to Article