- 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
Frist!
Hopefully there's some kind of cool UI to go with this code. Then it wouldn't be so WTF-y.
Admin
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...?!
Admin
You can .spin(1) and .spin() via a loop... :/
P.S. I sincerely hope that '1' is an int.
Admin
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.
Admin
"Confession" eh? You are just bragging, that is the most beautiful way to handle datetime I've ever seen in any language.
Admin
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!!!
Admin
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.
Admin
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.
Admin
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?
Admin
Admin
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.
Admin
If I lean close enough to the PC's speaker, I can hear the tiny clicks of all those wheels spinning round - 'sbeautiful.
Admin
Admin
A Date API that sucks. Well, every Date API known do man sucks. Please, prove me wrong.
Admin
You are wrong.
letatio - No.. no, I won't say what I'm thinking right now...
Admin
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?
Admin
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 ...
Admin
Admin
When good programmers go Steampunk. Tomorrow on the next Oprah.
Admin
I think someone beat you to it: rm -rf *
Admin
Seriously? Who hasn't done something like this?
Admin
I hereby grant to have enjoyed your fine comment. Thank you very much.
Admin
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?
Admin
comon someone must know it ..
any1????
Admin
Oh God, I've become that which I despise...!
Admin
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!
Admin
Admin
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.
Admin
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 :
Admin
Pssst... I think he's serious...
Admin
Me, too. ;)
Admin
That sounds suspiciously like an enigma machine. This isn't used in some sort of super secure comms app is it?
Admin
Alex forgot the part where the calendar ran out of wheels on December 23rd, 2012.
Admin
But other than that, C#'s is fine. I'm curious as to what you think sucks and what your required features are.
Admin
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.
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.
Admin
Someone has been reading Robert Jordan's the Wheel of Time series.
Admin
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...
Admin
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
Admin
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.
Admin
I just guess when it says the wrapper was a tremendous sucess, the author isn't being ironic.
Admin
Admin
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.
Admin
Except he went on to defend C#'s API...
Admin
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)....
Admin
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.
Admin
Bah. A real programming language wouldn't require a wasteful wrapper function. You could just write it as a preprocessor macro.
Admin
I can't believe it took so long for someone to throw around "real programming language" with respect to JS.
Admin
Admin
Begging your pardon, but I don't think there's any "respect" to JS here.
Admin
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.