- 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
Hey, he's using nearly only primitive types, must be hella efficient musn't it?
And let me guess, all these underscore-prefixed variables are... like... constants? or are they merely private instance variables?
Admin
[:|]
OMG... Convert has a ToDateTime method that takes a float... good grief
Admin
This is a joke, right? No one would actually convert it that many times? Right?
Admin
holy efficient............so like.....say 20 instances of the object call their GetDisplayValue function...............now we have 100 variables, weeeeeeeeeeeeeee!!!! That's what this thing must be......it's a variable-making machine!
Admin
What I can't figure out is why he's converting to decimal, then to double at all.
I can sort of understand the (whatever)-long-datetime If for some reason he wanted to truncate the time part of the datetime. But to get a locale-specific string representation of just the date requires only a single character in the format string. "d" or "D" depending on whether you want short or long format.
Admin
Wow...if THAT MANY problems can be crammed into that ammount of code, imagine what a gem the rest of the application must be...ok maybe we shouldn't.
Admin
Uh. This guy must know something mere mortals dont about the space time continum. For sure.
Or he might have been drunk/stoned while coding.
Admin
With that many crazy-ass turns in that short of a space, I'd say he's running from the cops.
Or developed a proprietary obfuscation scheme.
Admin
No... See, that's the method they expect us to use!
Admin
Hey um... where did the Preview button go?
Send out the search parties, it's missing!
Admin
Would it be a WTF if the rationale were readily discernable?
Admin
I think I figured out the reason. He's using the rube goldberg pattern for getting a string representation of a date!
Admin
Since it was completely buggy and more than likely wouldn't've been fixed, it was merely removed.
If you want some kind of preview, write in HTML and switch to design view .
Admin
The real question is: Why is a date being stored somewhere as a float? If the date was being stored properly, it would not have needed all those conversions in the first place.
Admin
Admin
Admin
<FONT face="Courier New" size=2>don't knock it 'til you've tried it. lest steve, king of miami be on the prowl:</FONT>
<FONT face="Courier New" size=2>http://www.moralminority.org/thread.phtml?tid=290</FONT>
Admin
this is c#. Nevermind the fact he could off by hours. the constructor for a datetime takes the number of 100-nanosecond intervals since 12:00 AM Jan 1, 0001, which he is retriving from a 32-bit floating point.
Admin
No way!
Gotta be made up.
Admin
Microsecond precision? Like PHP's microtime(), which returns a float UNIX timetamp with microseconds in the decimal. That's the only thing I can think of. Though this snippet doesn't exactly look like it came from a precision environment.
Admin
I see two possible explanations:
a) someone was making fun (most likely)
b) for some extremely strange reasons, they wanted to display date that can be safely converted back to any numerical type without further losing precision (because this function already lost anything that is to lose)
Admin
Any sane modern language has an arbitrary length integer type, or at least a 64bits one. C#'s "long" is an alias for System.Int64, a 64bits integer.
Since C#'s DateTime does a "tick count" since January 1st, 0001 and a tick is 100 nanoseconds, it can run up to year 58454 (and 3 months). I guess it's pretty much enough. And no, it's not a UNIX timestamp.
Admin
According to MSDN c# maxdate value is
MaxValue: The value of this constant is equivalent to 23:59:59.9999999, December 31, 9999, exactly one 100-nanosecond tick before 00:00:00, January 1, 10000.
Admin
Well, yeah, that's what's written in the documentation, but the datas you build your DateTime object from could allow them to run up to year 50000, that's all I meant.
Admin
Has to be fake, no one is that stupid... I hope.
Admin
Have you ever heard of the Y2K problem? This guy obviously has, and has taken the precautions (after all, in Java floats go up to ~2**127, whereas ints only go to 2**31).
Oh, wait...
Admin
Um, no. With a single thread of execution, there's only ever one call to the function at any one time.
Oh, and 20*4 is 80, not 100.
Name a single 'sane modern language' that has an arbitrary length integer type. Libraries for dealing with them don't count.
Admin
Python
Admin
If you're like me, when you see something like this you're going to start asking "what if the WTFers are wrong? what if this method is just poorly documented and is actually the best way of doing something special?" So I did some reading on MSDN and I can assure you, this is a legit WTF:
First, recall the C# aliases for .NET type names: float :: System.Single, decimal :: System.Decimal, long :: System.Int64
There is a miniscule possibility that the rounding done by conversion from Single to Int64 is meaningful, but I have another theory: this method was written by a programmer who had been given the specification and was pissed off that date-times were being stored in floats.
Admin
I don't recall giving you guys permission to print my copyright code for date converting...
Admin
java.lang.BigInteger
And don't tell me it is a library. It is a class and in java classes define TYPES.
Admin
There have been occasions where to replicate expected behavior from older systems (aka bugs with seniority), I've had to write date conversions like this.
I've always had the grace to write an "apology comment" for them in the routine, though, to try to prevent the inevitable emotional damage to future generations...
Admin
<FONT face="Courier New" size=2>you're the owner of this wtf?</FONT>
<FONT face="Courier New" size=2>i think copyright law doesn't apply here, since copyrights are supposed to protect intellectual and creative assets.</FONT>
<FONT face="Courier New" size=2>now, if you had written it as a joke...</FONT>
Admin
Admin
As far as I can establish, Python doesn't have built-in arbitrary length integer math, it just has libraries like every other language. Anyway, my point was that languages generally don't include an arbitrary length type as a native type.
In any case, using one for a datetime would be foolish.
Admin
No, classes are classes. The native types in Java are integer, boolean, etc. Just because it's part of the standard library doesn't mean it's a native type.
Admin
Why don't we start peeking at this forum's software code? Must have a dozen WTFs. Why look elsewhere..
Admin
Oops, you're right, Python does have built-in arbitary length integer math. Leaves me wondering why it also has libraries for the same purpose.
Anyway, it's still not 'any sane modern language'.
Admin
Not sane? Not modern? Not "any"?
Admin
You originally asked for an arbitrary length integer TYPE (without "native"), and a Java class most certainly is a type in Java terminology. And why should libraries that are part of the runtime distribution "not count"? This is a pointless debate based on uncertain definition of terms and arbitrary distinctions.
Admin
Dammit, I wanted to say it
Well, I'll add ruby to the list then, which behaves the same as Python: stores regular integers in the integer built-in type, and automatically switches to the built-in arbitrary int (long for Python and Bignum for Ruby) when it spills out of the base int's range
You, sir, can't establish shit.
From Python's Numeric Types page:
Ruby's bignum is built in and behaves the same way, Lisp has had arbitrary length for years, and I specified "arbitrary or at least 64bits long"
Oh, and Java types are still types even though they're not primitive types. From the Java tutorial itself, Java has two categories of data types, primitives (which you define as "native") and references which are still types. Integer, String or Bignum may not be primitive types, but they're still types (or do you consider that Java doesn't have any String type?)
Admin
If bigints are a native part of the language, you have literals and operators to work on them.
For example, the following ficitve Java snipplet would work:
Without that, it's less readable:
Of course, languages with operator overloading (C++, C#) would allow you to make the operators work as expected, but that's still not the same; literals would still be missing and of course bigints should be value types, not reference types, to be consistent with other numerical types. Other things still missing in C# would be the ability to use BigInts for switch statements, array indexing, casting etc.
Admin
Fine, I'll rephrase: Most languages don't have arbitrary length integer support built in. Most programs don't need it, and it's certainly not needed (or wise) for storage of a timestamp.
Java having a BigInt type is no different to any other language having a library for manipulating large integers. It happens to be in the standard library, but it's not part of the language. I asked for languages that had built in large integer types, not libraries.
Admin
woo hoo! Another language war thread! Only took about 20 odd posts this time and everybody has already forgotten about the WTF.
Admin
Lisp, Rexx, Haskell
http://en.wikipedia.org/wiki/Integer_%28computer_science%29
Admin
First post ;-)
While strings are not primitve types in Java, I still consider them native to the language; there are strings literals, string operators, the toString() method in the Object class; for that reasons, it's obvious that they are something special you could (unlike the BigInteger class) not build on your own within Java.
Admin
It is one of the many unfortunate flaws of Java that the J2SE API Specification and Java Language Specification are heavily bound in an ad hoc manner. One cannot talk about one without inadvertantly talking about the other, or at least, to do so makes little sense. The dependency pointed here is one of many. I know of one such language currently underway that takes advantage of the relative unbrokenness of the JVM Specification while completely rewriting the language and API specification "properly". In fact, I do this in my spare time however, while I'm at work, I implement the J2SE specification itself, which some might argue is competing against my employer, but that's another story.
--
Tony Morris
Admin
I find the effort and cleverness put into the blurb much more interesting than the code itself. The twisty maze of little casts, all alike isn't even bad in some inspired way that pushes the boundaries of badness.
Admin
You can thank microsoft excel for putting date and time into a float. That is the first place I saw it, about 16 years ago.
Admin
I don't think i could come up with any responses for that funtion until I get to know what the values for "_dateFormat", & "_dfpi" are...
Or do i?
Anyways, I demand for the values for those two unknown (possible properties[with bad naming convention] or a private member vars)!!!