- 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
Also, was that a paid message for the new Hangover movie?
Admin
TRWTF is the number of people here who really don't think this code is TDWTF worthy. Perhaps they could show me where the hardcoded WordCase is used in the code. Perhaps they could explain subtracting an int from a string ("num - dollars"). Perhaps they could explain "zero" or basing a decision off of "dollars_result = uno" rather than "dollars = 1" or why even do that since most checks (or cheques if you prefer) just have "<dollars> and <cents>/100 dollars." Any one of these would make me say "WTF??" if I came across them. The fact that so much is crammed into such a short function is a massive WTF.
Admin
I think the comments actually make it worse, especially the tone. You expect something more terrible and yes you can set way more terrible than this. That would be the same function that is over 100 lines long that doesn't do anything more than this function and that works even less or has more bugs.
This is more like a D than an F that you expect. Still wouldn't cut it in my book for someone coding to production.
A C would be if it worked for specific scenario.
An A would be something like storing the value as integer units and using a library to format the number as needed in and out. As for converting the number to text a library would also suffice, but I would forgive it if a library didn't exist for the technology used and a reasonably decent custom one was created. Particular one that has the minimum about of reasonable extensibility for additional locales and languages.
Addendum (2013-05-15 13:23):
I think the comments actually make it worse, especially the tone. You expect something more terrible and yes you can get much worse than this. That would be the same function that is over 100 lines long that doesn't do anything more than this function and that works even less or has more bugs. I have seen it. Many times. 90% of the time fixing bad code means pruning it.
This is more like a D than an F that you expect. Still wouldn't cut it in my book for someone coding to production.
A C would be if it worked for the specific scenario.
An A would be something like storing the value as integer units and using a library to format the number as needed in and out. The exact internal format isn't so important as that these is a single internal consistent format. Wrapping it as a struct {currency,amount} works well. As for converting the number to text a library would also suffice, but I would forgive it if a library didn't exist for the technology used and a reasonably decent custom one was created. Particular one that has the minimum reasonable amount of extensibility for additional locales and languages.
Addendum (2013-05-15 13:24): I hate this site's comment system. It does this on purpose as some kind of joke right?
Admin
I have used very little VB but I would assume there's an implicit cast to float on num for the - operator in: cents = CInt((num - dollars) * 100.0#)
It's not ideal and the conversion should be explicit, but if so it probably works fine, assuming num doesn't come unchecked from user input with things like white space, variable separators, etc. If you know a language well enough this kind of thing isn't such a huge WTF.
The # and the CInt are what look like a potential source of trouble. If the underlying implementation uses binary floating point rather than decimal I wouldn't rule out the possibility of getting a little less.
You can see this in javascript where Math.floor((0.1+0.22229) * 100000) loses a dollar. The WTF is I'm pretty sure VB, would support decimal types and maths along with several functions for currency handling in included libraries.
However, the sad fact is 90% or more of programmers are blissfully aware of this kind of thing. This is not a WTF because it is the standard.
Addendum (2013-05-15 15:40): "Perhaps they could show me where the hardcoded WordCase is used in the code"
Admin
Reading the article again, Adam doesn't know the Spanish for numbers past 29, as eViLegion said.
Therefor Adam only tested up to 29. The code may well function for larger amounts.TRWTF is Adam. The code isn't great, but as others have noted not the level of WTF we expect in a CodeSOD.
Admin
Googling Words_1_All yields http://www.vb-helper.com/howto_number_to_words.html
A couple of additional WTF: Could Adam have searched and found the code? Are there licensing conflicts? Was the code modified to properly case Mexican Spanish numeral verbiage? Could he get a Mexican Spanish domain expert to verify this?
And for the link: Why are all the functions private? Where is the entry point? Does this go in a module? A class?
Admin
Oh, and while we're discussing the consistent grammar and spelling rules of the American English language, where does the "i" in verbiage come from?
Admin
Given the variable names, it's my guess that this function is just copy-pasted from the existing English version. In that case, with the exception of the "zero/cero" comment all of Adam's complaints are with the original function, not the Spanish version. For something like this the logic of the original should be kept, even if it's clunky and sub-optimal. I wouldn't even try to refactor it into a nice generically localizable version. It just means more work un-refactoring when they finally get around to putting in a full-blown locale framework.
Adam is a dick.
Admin
TRWTF is that by being a pissy little bitch in his comments Adam has managed to out-WTF the guy who wrote the code.
Admin
Ah yes, the new 'frist' - being the first to call the story fake...
Admin
"English" (in England) is so-called because the Angles inhabited some minor piece of the place for some minor part of England's pre-history. And they didn't speak English.
Admin
Wouldn't that make TRWTF bad copypasta coding?
Admin
From the same place as the i in Carriage.
Admin
Carry => [s/y\b/i/ + $suffix] => Carriage
Verb => [??? + suffix] => Verb
Please fill in the ???.
Admin
Carry => [s/y\b/i/ + $suffix] => Carriage
Verb => [??? + suffix] => Verbiage
Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!
Admin
I would tend to agree, although I have found myself being similarly specific and thorough on mistakes when it comes to mission critical code. In my book it's not, you're either anal or your not. When it comes to financial code, it's right to be anal.
Admin
"Carry" is a verb. "Verb" is a noun. For equivalence you must use the verb form of "verb" which is, of course, "verby".
Verby => [s/y\b/i/ + suffix] => Verbiage
Q.E.D.
Admin
Multiply by 100, do string arithmetics if needed to get round any pesky floats for money with fractional errors and rounding errors, insert decimal point at appropriate place, and then convert the numbers to whatever it need be. Simple logic, straightforward, less error-prone, maintainable and less creepy bugs. Slightly more code, and possibly less elegant, perhaps, but such shortcomings outweigh the drawbacks when it comes to dealing with money, where you need to have 100% working code, 100% of the time.
Admin
something something money scale blah blah currency conversion:
http://stackoverflow.com/questions/224462/storing-money-in-a-decimal-column-what-precision-and-scale
Admin
I also read the same way.
Admin
Just write the check (sorry American spelling) as: "Mucho Dinero" and leave it at that.
As for "dollars", when I was in Mexico last, they used a dollar sign '$' as their currency prefix. It got a little weird when I saw sodas for "$10" and thought they were expensive, when they were not too bad in price (the conversion rate was 10 pesos = 1 dollar).
Of course this was before all this "euro" stuff with its silly symbol that looks like a 'C' with an equal sign '=' inside of it.
As for the euro, enjoy it while you can. With the rate Spain, Greece and Italy are spending Germany's money, it will go downhill. It is just a matter of time!
As for Spanish generally: "Se Habla Bullshit?"
Admin
I lost a week.
(credit: QI)
Admin
Admin
Admin
As for "color", there really isn't anything that makes the American spelling worse; the problem is removing a letter for no real reason. It's not spelling reform when you just change a bunch of arbitrary words while leaving everything else, regardless of how WTFy the spelling may be.
And that's one of the very few places in which English is less WTFy than most languages.Admin
Se usa pesos Mexicanos en Mexico aunque habla Espanol. Ud. no puedes leer Ingles, y no tiene la razon.
Admin
Admin
Admin
Not a VB coder, but what happens when cents has value of zero and it is used to build a string?
written_amount = cents + "/100"
does written amount become "0/100" or "/100" ?
Second thing Mexican Spanish is not the same as Puerto Rican Spanish is not the same as Madrid Spanish. There are slight vocabulary differences.
Admin
Zero becomes "0"
The correct idea would have been to use:
http://msdn.microsoft.com/en-us/library/18sthszb.aspx
Admin
LRPU (Lo reparé por Ud.)
Admin
Wtf?
" There were rumors flying around that it involved a drunken night in Cabo and a lost wager in a cock fight. And maybe a tiger in a bathroom. But none of this is germane to Adam’s story."
If it's not germane to the goddman story, don't put it in the goddamn story! How bad an editor/writer do you have to be to stop insulting your readers ?
Admin
Admin
Admin
Admin
Verby sounds more like an adverb, which would be a Moreause hybrid of verb and adjective.
Admin
Admin
VB has a Currency type, with 4 decimals places (like all MS stuff).
Crappy VB is hardly a WTF as there's so much of it; at least this code would sorta work.
Admin
About as bad as Douglas Adams, or maybe Herman Mellville?
Admin
TRWTF is that anyone is still using or indeed accepting cheques. What do they use them for, buying new buggy whips?
Admin
Your comment has no validity until the writer or the editor reaches anywhere near that level of skill. (I'm assuming never.)
Admin
Nobody was insulted as far as I can tell.
Admin
copy-pasted onto each occurrence of a copy-pasted routine.
Admin
Given the variety of accents used by English speakers, pronunciation of any given word is not a good way to determine its spelling. Nor should pronunciation be used to decide how it should be spelled.
The correct method for deciding how an English word should be spelled should be based on it etomology - ie the word's roots.
That's why "cheque" should be spelled with a 'que' and not a 'ck'.
I rest my case, Your Honor. Uh, I mean, Your Honour.
Admin
Because everyone likes the text that has been run by Google Translate with any bilingual person check. (En->Es->En)
Admin
Admin
So the boss's cousin's wife's brother's kid is the President? Or is she adopted?
Admin
Admin
just another douche
Admin
This code is fine. Why is it on this site?