• chreng (unregistered)

    It's like my first date, nothing happened

  • bvs23bkv33 (unregistered)

    1970-01-01T00:00:00Z

  • Pavel (unregistered)

    Well, I'd think that there is room for one more category here at TDWTF and that could be called along the lines of Artisanal Calendars. There's simply been too much of this stuff already.

  • Zenith (unregistered)

    Remy...if you think that's bad, you're not going to believe the submission I've been holding onto.

  • just me (unregistered)

    true (1)

    do nothing, successfully.

  • ThaHax0r (unregistered)

    100% test coverage! I wouldn't consider that a WTF.

  • Foo AKA Fooo (unregistered)

    Protip: If your getFoo and setFoo functions are exactly identical, you're doing it wrong!

  • Gustav (unregistered) in reply to Foo AKA Fooo

    True, it should be renamed GetSetDate() in a future refactoring.

  • Zylon (unregistered)

    Remy, the term "clone" has a particular meaning in programming, that has nothing to do with how you've used it here. I know being a bad writer is kind of what you're famous for, but c'mon.

  • guest (unregistered)

    I guarantee that if you knew the story behind this code it would be even worse than you think it is.

    Without knowing the codebase, I strongly suspect that this code replaced something even stupider that was being done. And the poor developer who tracked the bug he was trying to squash down to the previous version of this DateUtil class wept softly in his chair as he realized how much of the codebase touched the stupid functions that whoever came before him had written. So he quietly refactored it into what we see here, checked it in so nothing calling it would break, and died a little bit more inside.

  • Nullivator (unregistered)

    No, asdf; is the line of code that makes it all make sense.

  • Your Name (unregistered) in reply to Zylon

    Remy, the term "clone" has a particular meaning in programming, that has nothing to do with how you've used it here.

    I would've used the same term. What are you talking about?

  • Paul Neumann (unregistered) in reply to Zylon

    Remy, the term "clone" has a particular meaning in programming, that has nothing to do with how you've used it here. I know being a bad writer is kind of what you're famous for, but c'mon.

    The spam bots have become nearly indistinguishable from y,our average idiot! Now, what are you selling?

  • Paul Neumann (unregistered) in reply to Zylon

    Remy, the term "clone" has a particular meaning in programming, that has nothing to do with how you've used it here. I know being a bad writer is kind of what you're famous for, but c'mon.

    The spam bots have become nearly indistinguishable from y,our average idiot! Now, what are you selling?

  • Appalled (unregistered)

    What kind of idiot names their variables "date".

    What kind of language allows variables to be named with a keyword "date", even if they're case sensitive and the Keyword is actually "Date".

  • radarbob (unregistered) in reply to Appalled

    Basic Visual Foxbase Basic Access

  • Anon (unregistered) in reply to Appalled

    TRWTF is case-sensitive languages.

  • _that_guy_ (unregistered) in reply to Anon

    ;fuoh nep

  • _that_guy_ (unregistered) in reply to _that_guy_

    :wat:

    → "Yeah no"

  • Dev (unregistered)

    I think this code is used to create defensive copies from Date objects, because java.util.Date is mutable in Java. A better solution would have been an immutable date object from Joda time or the new date library of Java 8.

  • Zylon (unregistered) in reply to Paul Neumann

    "Paul", judging by your grammar, punctuation, and triplicate attempt to post I'd say you're the idiot here, but nonetheless I'll answer your silly question. In object-oriented languages, cloning refers to creating a dereferenced duplicate of an object's data structures. It's frequently a non-trivial operation and thus subject to a great deal of discussion and debate.

    https://en.wikipedia.org/wiki/Cloning_(programming)

    In this article the Date object is in no way "cloned". It's just wrapped.

  • Ulysses (unregistered) in reply to Appalled

    Hey Appalled, have you left the site yet?

  • Simon (unregistered) in reply to Zylon

    Nope, you're the one who's wrong. There's no wrapping going on here, as should be immediately obvious from the code sample - it's taking one Date object, extracting the state in the form of a "millis since epoch" number, and creating a new Date with the same state. In short, a clone of the original object.

  • I'm not a robot (unregistered)

    asdf?

    another stupid date function?

  • Appalled (unregistered) in reply to Ulysses

    Nah. I'm addicted to viewing idiocy in action. I'll suffer through the ridiculous pod-casts and spamvertisements etc. in search of my daily fix.

  • Robert Hanson (unregistered)

    In java, I think that the date object is mutable -- note that I'm not a java developer, so I might be wrong. So this is an attempt to get a date object that is immutable, I presume.

  • Michael (unregistered) in reply to Zylon

    Zylon, my friend, you are displaying arrogance, rather than knowledge. From its beginnings, java provided a mechanism for cloning, which has since shown itself to be fundamentally broken, to the point that it is a code smell to use it. Best practice in Java is therefore to use copy-constructors instead of an actual clone mechanism, and this is what is done here. I would still refer to it as cloning, although the actual mechanism would be a copy constructor. In the case of java.util.Date, it has one important field, it's timestamp, and this is what is used to "clone" it, rather than the date object itself, which would be normal in a copy constructor.

    See e.g. http://www.artima.com/intv/bloch13.html for more about this.

  • Michael (unregistered) in reply to Appalled

    It's best to learn the very basics of a language before insulting other's code in said program.

    Date is not a keyword, it is a class name. In java, classes should always be capitalised and camel-cased, and variables camel-cased uncapitalised. So e.g. MyDate myDate = x.getMyDate(); would be absolutely normal. Often you would want to add some context to the variable name, but it doesn't always make sense.

  • Ulysses (unregistered) in reply to Appalled

    You mean spewing.

  • regsergsr (unregistered)

    Should've been wrapped in a PaulaBean.

  • Appalled (unregistered) in reply to Michael

    public static Date setDate(Date date) You freaking dolt. I was complaining about "date" not "Date". I don't care WTF languages it is. In this case "date" . It is quite obviously a local variable name for the item that was passed by the caller. Whether it's by value or reference or some other fancy Java bullshit doesn't matter. It is still the LOCAL VARIABLE name that the punk author use withing the scope of his piece of crap code. And that's my issue. How DARE someone call their variable "date". So I guess it's best to learn how to READ English before insulting someone else's comments.

  • Troll Spotter (unregistered) in reply to Appalled

    Obvious troll is obvious.

    Source: I printed off an official Elf Spotting Certificate from John Oliver's site and executed s/Elf/Troll/ with a sharpie.

  • opera mani (google)

Leave a comment on “Cloning Date”

Log In or post as a guest

Replying to comment #:

« Return to Article