- 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
Is this for real? You're killing me!!! By the way, isn't strings just yet another "beautiful" way of presenting byte arrays? Remove the unnecessary floats, strings and booleans!<o:p></o:p>
Admin
The comment probably should have been
Admin
Enough with the anonymyzing already. If it's really that bad, just run it through a formatter (change brace style) and rename the variables by pre-pending "paula" to each.
Admin
Maybe I am missing something here but doesn't this code also assume that it is base 100.
What if I want to do seconds to minutes? Or minuntes to hours?
Admin
Ok, so the code sucks.
And it doesn't take into account some obvious cases ($0.00 is mentioned above).
But this sounds like you are presuming that money is always done in floating point, when in fact, using fixed point decimal (ok, so this doesn't really do that either), and representing the numbers as integers, is generally much simpler. Depending on your integer math implementation (does it round?) you can avoid things like "$0.9999999999999999999" etc.
There seem to be plenty of reasons to dismiss this code as WTF without attacking the idea of integer money.
Admin
Well, it works - if either is equal to 0, the OR makes the output 1, so it's true. Now XOR, that would have been more interesting, and maybe even a new enterprise standard. (And a real WTF - "What do you mean, it causes errors if they're both equal to 0?")
Admin
In Java, try this:
and see how much change you get back from your two dollars.Admin
I think you mean doing money math in decimal instead of binary. Floating point has nothing to do with it.
There are a number of standards (SOX and otherwise) that explicitly specify what precision to carry for various operators.
Admin
It's a LION! GET IN THE CAR!
Admin
Wow... alot different than the code Alex had (still has even).... Also... Alex.... It'd be nice if you didn't edit your posts after you post them. It would work if you added to the post, re-pasteing the "fixed" code... Now, most of the posters look like idiots (especially me) because they were commenting on the original post...
Care to post the original in AS CLOSE AS POSSIBLE form?
Seriously, today's mis-hap has me thinking that the majority of comments people submit are actually comments on Alex's not-so-succesful conversion between languages.... Ouch.
Admin
What are you talking about? What number system do you suggest for working with money if not decimal?
The real WTF is that people don't know the difference between decimal and floating point.
Admin
Yeah, never user 10^n when you can use a for loop, Stringbuilder, and a type conversion.
--Rank
Admin
That's just the Perl naming convention to indicate a private method.
Admin
I have to agree on this one. Take for example this post which originally missed out the crucial last line, making (mainly me) looking stupid for saying it wasn't a massive WTF
Admin
You know, computers use binary. Wouldn't it be much better to get rid of all datatypes except for booleans?
Admin
yes,yes,yes,yes
Admin
well, I tried to compile it in visual studio .net, but it crashed with a "you are too dumb" exception.
I wonder how the CEF guys managed to compile it.
Captcha? wtf is captcha? and why is mine tps?
Admin
To those of you who are arguing storing floating point numbers as integers is a good thing if absolute precision is required, I'd like to say two things:
1. You are right
2. This is not the way to do it
To the designers of the CEF, I present: the System.Decimal type. It does what they want, and the best part is you can get a string representation using the normal ToString or String.Format methods that every .Net programmer should know.
EDIT: It would appear I was beaten to the punch. Or "ninja'd", as I believe the proper term is. :P
EDIT2: Although I get bonus-points for linking to the new MSDN2 site instead of the old .Net 1.1 MSDN docs. ;)
Admin
wtf is it doing in c# code then? or is this another anonymization?
Admin
The more I think about this, the more I stunned I am. Whoever came up with this crap should be fired and banned from development forever.
If I were told I needed to use this I would have one very short word in reply: no....
On another note: gotta love Community Server v2.0! Firebug reports 1811 errrors and counting! What, two errors per key click, what's wrong with that.....
Oooh now we're up to 2177 Errors.
now 2285, 2297, 2319
-me
Admin
Yeah, seriously Alex, this anonymyzing is getting bad. Change the variables to "string1", "string2", "int1", "int2", tweak the namespaces/classnames slightly and be done with it....
-me
Admin
THIS is a real WTF (... sandwich. It's made of 4chan, lion, wft code and getting into.)
Admin
I'm sorry, I don't speak jibberish
Admin
This puts me in mind of a magnificent application I had to support for many years, which took a real world approach to on-hand stock.
You see, there can't possibly be a negative number of things in stock, so the system wouldn't let you issue more than it had. This caused a problem of significant size if the data-entry person recording receipts hadn't yet placed items in stock when you were issuing them.
Worse than that, issues beyond what you had would be possible if they were in stock in another location...this meant that not only were you out of sync at your own location, but at other locations too.
Fortunately, the system had some quite good stock-taking options.
Admin
Admin
sure - to members, but methods?
Admin
Sure, no problem. But you guys got my back when I get sued for exposing proprietary trade secrets, copyright violation, libel, defamation, DMCA, causing someone to lose his job, etc., right? Then again, who could possibly recognize their own work if some one went so far as to change a word or two? Riiiiggghhhttt .....
Come one guys, if you're thinking "OMFGWTFBBQ!! He used a | instead of a ||" when you see the article, you need to go back and read it again. You missed the part where the CEF system uses only numbers and strings and requires a database call to convert integers to decimals.
Admin
rimshot!
He's here all week, folks! Tip your waitress!
Admin
wouldn't it be more enterprisey, if we had a table called called TBL_T_NUMBER that looked like this:
and so on. Then instead of calling the function
Admin
oh fuck. the forum software screwed the above post. lets do it again
wouldn't it be more enterprisey, if we had a table called called TBL_T_NUMBER that stored all possible combinations of numbers,decimal places and the result.
Then instead of calling the setdeicmalplace() function<font face="Lucida Console" size="2"></font>
, the user needs to create a xml file
The enterprise system will parse the xml file, get the correct value from the database and display it.
Its foolproof!
Admin
Why not? I use it so that I can quickly tell the difference between public and private methods. I picked it up in Objective-C where there are no private methods and it's used as a way of flagging "hey, don't touch!" for other programmers. It turns out that I find it makes the code a little bit more readable in other languages, too, so I started using it all the time.
Sure it's arbitrary and not really necessary, but then so is every other naming and formatting convention.
Admin
Umm... what about everyone added together at micro$oft? ;)
Admin
K, so you tell me exactly where in my post I mentioned dealing with currency...besides, wasn't I talking about using the decimal data type instead of integer in the first place? it'd be nice if people actually read the posts before replying.
Oh, BTW, if you wanted to do currency arithmetic as cents, could you not multiply the existing value by 100, then 'convert' it to integer by removing everything after the decimal then performing the mathematical operation? Although I'd keep it as decimal myself because most financial calculations these days use money values with 4 decimal places so that there's minimal loss due to rounding, therefor making interger calculations as cents useless (since it would then truncate any 0.5 cent values, causing monetary 'loss' or 'gain' in the system due to truncation errors). And as far as BigDecimal, i think you're thinking about one of the new SQL data types in 2005...cuz it doesn't exist in .NET 2, and I don't remember seeing it in 1.1 either.
Admin
It's not arbitrary in C++.
Having an underscore at the start of a name has a very specific meaning and should not be done in your own code.
Not sure if it's the same for C, probably isn't like that for C#.
Admin
How does one represent 1/12 or 1/365 in fixed point again? =p
'NUFF JIBBA JABBA, POOL'S CLOSED
<font size="1">I am a slave to the meme.</font>
Admin
Technically, it's only reserved in the global namespace, and class members should be fine (aside from VC6's horrible scoping); it's only when a uppercase letter follows the underscore when you risk hitting random macros. Just ensure that no intellisense window pops up when you type out your member name for the first time.
It's not like you're going to run up against severe problems that crash weirdly on random compilers unless you're "enthusiastically" cross-platform, like say, mozilla.
Admin
ok i give up, what happens if i do this
x = 100/30; ?
Admin
Wait a minute, that is a database call? So, for each time I want to print out information, I must pay a penalty of an I/O call? Then, with this database possibly being used by a lot of simultaneously running programs, I can see this system screaming to a crawl, given enough of a load, of course.
Admin
At all those who think integer for financial math is a good thing. No it is not.
In the finance sectore they use the BDC format for calculations. And believe it or not, but your x86 FPU actually supports BCD calculation.
Admin
eHarmony.com ?
The e is for enterprise, of course.
Admin
...Seeing as you asked...
Admin
<FONT size=5><: ( 3</FONT>
Admin
There is another WTF here.
They used a StringBuilder object.
The StringBuilder is great for large data, or data that is going to be appended to a lot. But it is going to impace performance when you start to have more than a few dozen.
This is in a class used for every integer/decimal data type. There is going to be quite a few here.
Their attempt increase speed is going to have the opposite effect.
Admin
Well because noone else pointed out, the code doesn't check field == null before using the Length property, so if someone would be so foolish, that they would pass a null reference to the method, the method itself would cause NullReferenceException, but naturally in this system it would be the callers fault..
Admin
Ok seeing shit like this is really starting to piss me OFF! You total idiots!!!! STOP WRITING SHIT. I'M FUCKING SERIOUS you bag lickers.
Captcha = tps
Admin
Wow.
Here's a site to catch other people's wtfs and right in the text they promote a wtf in itself.
You should never represent money with floating point! You will be out of a job real fast once your accounting department can't figure out why doesn't everything total at the end of the day.
Another value that should never be represented as a decimal is a unit of time. Always use an integer for time, or else you will run into floating point issues just as you did if you used it to represent money.
Admin
Admin
Let my give that a try
1 ct + 4 cts divided by two... Hey I still got a rounding problem, maybe the rounding problem is because the destination precison is 2 decimals and it's not an input problem...
Admin
Hm - that's called 'crossing the river to get some water'. Someone please invent a device that can stab lousy coders in the face, remotely...
Admin
Nice quote from Aliens, weird nobody else commented before?