• (cs)

    Frist!

    Hopefully there's some kind of cool UI to go with this code. Then it wouldn't be so WTF-y.

  • Anonymous (unregistered)

    That's pure genius. I'd love to see his "Count" function; I'm picturing a method that loops through single units, pushing each one along a virtual "bar" until the correct number of units has been "pushed". Then you just need to count the number of units on the right hand side of the virtual bar. After all, that's how an abacus does it and obviously we need to mimic mechanical devices in our code...?!

  • Jordan Bray (unregistered)

    You can .spin(1) and .spin() via a loop... :/

    P.S. I sincerely hope that '1' is an int.

  • Dom (unregistered)

    What's the fuss with that parseInt() replacement? The default implementation tries to guess the base - and ends up with treating numbers as octals occasionally.

  • MacHaggis (unregistered)

    "Confession" eh? You are just bragging, that is the most beautiful way to handle datetime I've ever seen in any language.

  • Rajendra Kumar (unregistered)

    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

  • (cs) in reply to Dom
    Dom:
    What's the fuss with that parseInt() replacement? The default implementation tries to guess the base - and ends up with treating numbers as octals occasionally.

    Nothing. I think we're all admitting that making a function that doesn't need a second parameter just to avoid issues with leading zeroes is a good thing.

  • Jordan Bray (unregistered) in reply to jonnyq
    jonnyq:
    Dom:
    What's the fuss with that parseInt() replacement? The default implementation tries to guess the base - and ends up with treating numbers as octals occasionally.

    Nothing. I think we're all admitting that making a function that doesn't need a second parameter just to avoid issues with leading zeroes is a good thing.

    Yea, I personally love making simple wrappers to pre-existing API's. It's particularly awesome in this case in that it gets rid of the bug of programmers not knowing what parameters to pass to a function.

  • Anonymous (unregistered)

    Oh Harry, you just had to try, didn't you?

    Sorry, obligatory post. Seriously though, this is a bit of "you just had to try" moment. Replicating a mechanical calendar wheel in code? Really?

  • Anonymous (unregistered) in reply to Rajendra Kumar
    Rajendra Kumar:
    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

    Rajendra, I just love your occasional but hilarious posts. I'd really like to see the app you're building with all the teh codes that you people pls send you. Can you pls send me teh codes when it's finished?!

  • (cs)

    This post has inspired me. I must now get to work on my next creation: A general math library based on emulation of a slide rule in code.

  • tragomaskhalos (unregistered)

    If I lean close enough to the PC's speaker, I can hear the tiny clicks of all those wheels spinning round - 'sbeautiful.

  • nB (unregistered) in reply to frits
    frits:
    This post has inspired me. I must now get to work on my next creation: A general math library based on emulation of a slide rule in code.
    Please do share, that sounds like hilarity. FWIW we have an intentional WTF in one of our libs. It's in there specifically to see if anyone ever actually looks at our code. So far, no one has commented/asked/posted it here. (it's along the lines of the above mentioned code, in that it works fine but is damn awkward.)
  • Ale (unregistered)

    A Date API that sucks. Well, every Date API known do man sucks. Please, prove me wrong.

  • TheSHEEEP (unregistered)

    You are wrong.

    letatio - No.. no, I won't say what I'm thinking right now...

  • TK (unregistered)

    I like it!

    Assuming that the library functions really were broken and needed to be rewritten, then this really isn't a bad solution. It's simple and works.

    In my CS101 class, on of our assignments was to rewrite the unix cal command. The algorithm we were told to use was exactly the same. Even on the computers of ~20 years ago this ran very fast.

    Sure you could do this more efficiently, but didn't somebody once say something about premature optimization?

  • (cs)

    OK, here's a confession: I've written date-handling code in javascript & vbscript relative to which the posted code would have been a marked improvement.

    Fortunately for the sanity of web developers everywhere, the company I wrote it for is out of business and my personal libraries have had these modules mysteriously deleted*, so I'm fairly sure that these scripts no longer exist anywhere.

    *This would have been much easier to do if the rm command had a -stupidcode switch. Come to think of it, somebody should write that ...

  • (cs) in reply to Rajendra Kumar
    Rajendra Kumar:
    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

    Since you'll have to replace the mechanical wheels you cannot fix this with code. It's clearly a hardware issue.

  • Anonymous (unregistered)

    When good programmers go Steampunk. Tomorrow on the next Oprah.

  • TW (unregistered) in reply to SCSimmons
    SCSimmons:
    OK, here's a confession: I've written date-handling code in javascript & vbscript relative to which the posted code would have been a marked improvement.

    Fortunately for the sanity of web developers everywhere, the company I wrote it for is out of business and my personal libraries have had these modules mysteriously deleted*, so I'm fairly sure that these scripts no longer exist anywhere.

    *This would have been much easier to do if the rm command had a -stupidcode switch. Come to think of it, somebody should write that ...

    I think someone beat you to it: rm -rf *

  • frits? (unregistered)

    Seriously? Who hasn't done something like this?

  • Hbuttle (unregistered) in reply to Anonymous
    Anonymous:
    When good programmers go Steampunk.

    I hereby grant to have enjoyed your fine comment. Thank you very much.

  • jpey (unregistered)

    hy

    ima copied thee codes from your good artickle for ym timedate applicachion. it doesnt not compile though do i need the libraries pls help?

  • jpey (unregistered)

    comon someone must know it ..

    any1????

  • Anonymous (unregistered) in reply to frits?
    frits?:
    Seriously? Who hasn't done something like this?
    Hey fake frits, you just had to try, didn't you?

    Oh God, I've become that which I despise...!

  • André (unregistered) in reply to nB
    nB:
    frits:
    This post has inspired me. I must now get to work on my next creation: A general math library based on emulation of a slide rule in code.
    Please do share, that sounds like hilarity. FWIW we have an intentional WTF in one of our libs. It's in there specifically to see if anyone ever actually looks at our code. So far, no one has commented/asked/posted it here. (it's along the lines of the above mentioned code, in that it works fine but is damn awkward.)

    In "A Discipline of Programming" Edward Dijsktra describes (at great length) Euclid's algorithm as mechanical device consisting of a board and a pebble. I guess you really must be a genious to conjure such Beaty into code!

  • (cs)
    Alex Papadimoulis:
    I thought I’d try something new: Confessions.
    Sounds like it'd be a good category for WTFs, but to be fair it's not exactly something new.
    TFA:
    Years ago, Harry Dewulf was the Javascript Guru.
    Ah, there's yer problem right there. Sometimes the downside of being the "guru" is that people who should question your work and keep your design decisions in check don't.
  • scott (unregistered)

    This seems like something that I would love to do as a proof-of-concept, but would never want to put into production code. I actually think it's kind of cool.

  • remi bourgarel (unregistered)

    JS is a big WTF and this is right to do some kind of a facade pattern

    parseInt for instance, I don't know how many stupid people you must have to get to this kind of mess :

    • Smart #1 hey we should do a function that parse a string and give you the int value
    • idiot #1 you're so right, but what if the guy want to parse a binary string ?
    • smart #1 no one do that
    • idiot #2 STFU you idiot ! we should add a parameter with the base
    • idiot #3 Yes , and if the user doesn't send this parameter we should guess on wich base
    • idiot #4 we will guess it like this : if it starts with a 0 it's octal no one starts an int with 0 if it's not octal, right ?
    • all the idiot around : Yes off course !
  • by (unregistered) in reply to Anonymous
    Anonymous:
    Rajendra Kumar:
    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

    Rajendra, I just love your occasional but hilarious posts. I'd really like to see the app you're building with all the teh codes that you people pls send you. Can you pls send me teh codes when it's finished?!

    Pssst... I think he's serious...

  • (cs) in reply to by
    by:
    Anonymous:
    Rajendra Kumar:
    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

    Rajendra, I just love your occasional but hilarious posts. I'd really like to see the app you're building with all the teh codes that you people pls send you. Can you pls send me teh codes when it's finished?!

    Pssst... I think he's serious...

    Me, too. ;)

  • Malcolm (unregistered)

    That sounds suspiciously like an enigma machine. This isn't used in some sort of super secure comms app is it?

  • ÃÆâ€â„ (unregistered)

    Alex forgot the part where the calendar ran out of wheels on December 23rd, 2012.

  • (cs) in reply to Ale
    Ale:
    A Date API that sucks. Well, every Date API known do man sucks. Please, prove me wrong.
    Well, every Date API that "does" a man, does indeed "suck."

    But other than that, C#'s is fine. I'm curious as to what you think sucks and what your required features are.

  • Stephen Cleary (unregistered)

    There's a lot that goes into a date/time library, when you really start thinking about all the possible situations.

    Jon Skeet is a Google employee who works in Java in his day job and is recognized as one of the top C# experts at night. He is porting Joda Time from Java to C#, and blogging about his experiences: http://noda-time.blogspot.com/

    Let me just say that I'm glad it's him doing it, and not me.

      -Steve
    

    P.S. Did you know that GPS time is (currently) 15 seconds off UTC time, and that the time difference will change undeterministically in the future? I just ran into this at my job - it turns out one of our GPS units was using GPS time (while reporting it as UTC time) and another GPS unit was using (correct) UTC time. Fortunately, we caught the discrepancy before it caused a lot of financial damage (and yes, it would have caused a lot of financial damage).

    The 15-second offset is due to leap seconds aggregating over the years. Date/time libraries universally ignore leap seconds, and still have surprisingly painful issues to deal with.

  • Mordred (unregistered)

    Someone has been reading Robert Jordan's the Wheel of Time series.

  • Anonymous (unregistered) in reply to frits
    frits:
    by:
    Anonymous:
    Rajendra Kumar:
    How to add functionality of other calendars to this wonderful code? I have requirements for Persian, Ethiopic, and Saka calenders. Also, I neeed the UI code for this, code you pls advise?!

    Thx pls URGENT!!!

    Rajendra, I just love your occasional but hilarious posts. I'd really like to see the app you're building with all the teh codes that you people pls send you. Can you pls send me teh codes when it's finished?!

    Pssst... I think he's serious...

    Me, too. ;)

    I know his date handling code is going to be awesome because he's been working on it since July!

    I think we may have a bonus redaction joke in here as well. Do you realise that if you select the text...

  • Alexis (unregistered) in reply to Sutherlands

    I'm pretty sure "sucking" isn't the only way to "do" a man, therefore your argument is invalid.

    Captcha: paratus - remedial class for people who can't get into APparatus

  • (cs) in reply to remi bourgarel
    remi bourgarel:
    JS is a big WTF and this is right to do some kind of a facade pattern

    parseInt for instance, I don't know how many stupid people you must have to get to this kind of mess :

    • Smart #1 hey we should do a function that parse a string and give you the int value
    • idiot #1 you're so right, but what if the guy want to parse a binary string ?
    • smart #1 no one do that
    • idiot #2 STFU you idiot ! we should add a parameter with the base
    • idiot #3 Yes , and if the user doesn't send this parameter we should guess on wich base
    • idiot #4 we will guess it like this : if it starts with a 0 it's octal no one starts an int with 0 if it's not octal, right ?
    • all the idiot around : Yes off course !

    It seems parseInt is to JavaScript as strtol is to C. In strtol, the "default" base of 0 means it will autodetect the base (be it octal, hexadecimal, or, in some cases, even decimal). I guess the reasoning behind making parseInt default to autodetecting base is that it mimics JavaScript's number parsing. Seeing as how C's most common application is writing C compilers, it logically follows that JavaScript's most common application is writing JavaScript compilers.

  • (cs) in reply to Dom
    Dom:
    What's the fuss with that parseInt() replacement? The default implementation tries to guess the base - and ends up with treating numbers as octals occasionally.

    I just guess when it says the wrapper was a tremendous sucess, the author isn't being ironic.

  • Anonymous (unregistered) in reply to remi bourgarel
    remi bourgarel:
    JS is a big WTF and this is right to do some kind of a facade pattern

    parseInt for instance, I don't know how many stupid people you must have to get to this kind of mess :

    • Smart #1 hey we should do a function that parse a string and give you the int value
    • idiot #1 you're so right, but what if the guy want to parse a binary string ?
    • smart #1 no one do that
    • idiot #2 STFU you idiot ! we should add a parameter with the base
    • idiot #3 Yes , and if the user doesn't send this parameter we should guess on wich base
    • idiot #4 we will guess it like this : if it starts with a 0 it's octal no one starts an int with 0 if it's not octal, right ?
    • all the idiot around : Yes off course !
    I know it's annoying if you don't understand the behaviour but the moral of this story is just RTFM. parseInt certainly isn't going to be your only problem if you're just guessing the behaviour of every method you call. JS has such a tiny little object model, is it really that much of a burden to read up on it?
  • (cs) in reply to Alexis
    Alexis:
    I'm pretty sure "sucking" isn't the only way to "do" a man, therefore your argument is invalid.

    Captcha: paratus - remedial class for people who can't get into APparatus

    I'm pretty sure that's not the argument he was making.

    He was talking specifically about Date APIs; perhaps "sucking" is all that they are capable of? I think that given our experience with Date APIs, many of us would find that suggestion plausible.

  • Alexis (unregistered) in reply to boog

    Except he went on to defend C#'s API...

  • (cs) in reply to Anonymous

    Octal is sooo much better than decimal or even hexidecimal, I always use leading zeros so that all my numbers can be expressed in Octal]

    ps: You can create an Octal printer out of a printing calculator. Back in the 1970's this was a common way to get hard copy memory dumps (and other outputs) out of micro-computers. Hex was not possible (no A-F on the printer bars, and decimal really did not make any sense for opcode and addresses.

    pps: Disclaimer: Once (after a marathon session of hand coding a computer via toggle switches) I balanced my check book in octal (none of the transactions nor the opening balance had an 8 or 9 in it)...I realize my mistake when I started bouncing tons of checks (about hald that monthly bills)....

  • Tim (unregistered) in reply to Jordan Bray
    Jordan Bray:
    You can .spin(1) and .spin() via a loop... :/

    P.S. I sincerely hope that '1' is an int.

    Hope no longer. There are no ints in JavaScript. The floating point available is able to represent reasonable ints up to 15 digits exactly though, so no worries.

  • Chelloveck (unregistered) in reply to jonnyq
    jonnyq:
    Dom:
    What's the fuss with that parseInt() replacement? The default implementation tries to guess the base - and ends up with treating numbers as octals occasionally.

    Nothing. I think we're all admitting that making a function that doesn't need a second parameter just to avoid issues with leading zeroes is a good thing.

    Bah. A real programming language wouldn't require a wasteful wrapper function. You could just write it as a preprocessor macro.

  • ÃÆâ€â„ (unregistered)

    I can't believe it took so long for someone to throw around "real programming language" with respect to JS.

  • (cs) in reply to Alexis
    Alexis:
    Except he went on to defend C#'s API...
    Saying that something is fine is hardly a defense, but point taken. However, if I may be serious for a moment, I'd like to point out that the following comment he made deserves more attention than it's getting:
    Sutherlands:
    I'm curious as to what you think sucks and what your required features are.
    In other words, how exactly does one go about measuring "sucky-ness" with respect to a given language's Date API (or any API for that matter)?
  • trwtf (unregistered) in reply to ÃÆâ€â„
    ÃÆâ€â„:
    I can't believe it took so long for someone to throw around "real programming language" with respect to JS.

    Begging your pardon, but I don't think there's any "respect" to JS here.

  • (cs) in reply to boog
    boog:
    Alexis:
    Except he went on to defend C#'s API...
    Saying that something is fine is hardly a defense, but point taken. However, if I may be serious for a moment, I'd like to point out that the following comment he made deserves more attention than it's getting:
    Sutherlands:
    I'm curious as to what you think sucks and what your required features are.
    In other words, how exactly does one go about measuring "sucky-ness" with respect to a given language's Date API (or any API for that matter)?

    An API method should require as close to one line of code with very few supplemental parameters as possible for routine tasks. One line of code with one parameter and one return value (when appropriate) is optimal. The further from this ideal the suckier the API is. In other words, don't make have to construct an API for your API.

Leave a comment on “Confessions: rachetingDateObject”

Log In or post as a guest

Replying to comment #:

« Return to Article