• (cs)

    Also, was that a paid message for the new Hangover movie?

  • Terrified (unregistered)

    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.

  • (cs) in reply to neminem
    neminem:
    Yeah, I'm with people saying this doesn't really look all that terrible, and that while yes, it does have some bugs in it that should have been fixed, the real wtf is Adam's attitude.

    Who hasn't accidentally left in a few hardcoded values in things that were supposed to be localized?

    That said, the other wtf is specifically localizing for Spanish, rather than doing a general refactor for generic localization, which would probably not have been too much more work and would have left them with the ability to expand to other markets, too. (Just not rtl-using markets. That's a whole nother story, work-wise. RTL is a pain.)

    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):

    neminem:
    Yeah, I'm with people saying this doesn't really look all that terrible, and that while yes, it does have some bugs in it that should have been fixed, the real wtf is Adam's attitude.

    Who hasn't accidentally left in a few hardcoded values in things that were supposed to be localized?

    That said, the other wtf is specifically localizing for Spanish, rather than doing a general refactor for generic localization, which would probably not have been too much more work and would have left them with the ability to expand to other markets, too. (Just not rtl-using markets. That's a whole nother story, work-wise. RTL is a pain.)

    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?

  • (cs) in reply to Terrified
    Terrified:
    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.

    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"

    ' Check to see if anyone has hacked the program to change the 
    ' hard coded case value
    
      If WordCase = "U" Then
         SpanishMoney = SpanishMoney.ToUpper
      End If
    
  • HowItWorks (unregistered) in reply to Paul Neumann
    Paul Neumann:
    eViLegion:
    The limit of 29 was because that is the highest number the dude could count to in Spanish. Presumably he couldn't remember the word for 30.
    It would be awesome if we could see the code which was actually in error. I spent the entire article trying to figure out how 29 was a limiting factor in any of the cited code.
    Likewise, I was looking for something in the code that failed above 29 pesos, which I do not see.

    Reading the article again, Adam doesn't know the Spanish for numbers past 29, as eViLegion said.

    Adam:
    Well it appeared to be working up to 29 pesos..
    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.

  • Paul Neumann (unregistered)

    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?

  • Paul Neumann (unregistered) in reply to Paul Neumann

    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?

  • Chelloveck (unregistered)

    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.

  • Ronald (unregistered) in reply to AAA
    AAA:
    What's the WTF here? It's not great code, but it's not terrible. I'd hate to work with Adam. Judging by his comments, he's very passive-aggressive. Code review pro-tip: say what's wrong with the code ("convoluted control flow", "bug when converting", etc), make constructive suggestions ("Can be expressed better as [whatever]"), and leave out the rest.

    TRWTF is that by being a pissy little bitch in his comments Adam has managed to out-WTF the guy who wrote the code.

  • Anonymous Paranoiac (unregistered) in reply to Zylon
    Zylon:
    But none of this is germane to Adam’s story.

    Or, in fact, happened at all.

    Ah yes, the new 'frist' - being the first to call the story fake...

  • JimTheJam (unregistered) in reply to ip-guru
    ip-guru:
    They are our words not yours (the Language is ENGLISH) If you don't like the way our language is structured get your own :-)
    We do have our own! The Language is American (USA). You are confused because in the American Language "English" when applied to language means "American".

    "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.

  • (cs) in reply to Chelloveck
    Chelloveck:
    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.

    Wouldn't that make TRWTF bad copypasta coding?

  • ThatSlyQuarian (unregistered) in reply to Paul Neumann

    From the same place as the i in Carriage.

  • Paul Neumann (unregistered) in reply to ThatSlyQuarian
    ThatSlyQuarian:
    From the same place as the i in Carriage.
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verb

    Please fill in the ???.

  • Paul Neumann (unregistered) in reply to Paul Neumann
    ThatSlyQuarian:
    From the same place as the i in Carriage.
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verbiage

    Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!

  • (cs) in reply to Chelloveck
    Chelloveck:
    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.

    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.

  • Chelloveck (unregistered) in reply to Paul Neumann
    Paul Neumann:
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verbiage

    Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!

    "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.

  • chris (unregistered)

    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.

  • (cs)

    something something money scale blah blah currency conversion:

    http://stackoverflow.com/questions/224462/storing-money-in-a-decimal-column-what-precision-and-scale

  • (cs) in reply to bored_again
    bored_again:
    I thought it said SpanishMonkey at first.

    I also read the same way.

  • (cs)

    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?"

  • Anders (unregistered) in reply to TheEgg
    TheEgg:
    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.
    I once wanted to know why Germans are so fastiduous, so I googled "German anal".

    I lost a week.

    (credit: QI)

  • Zack (unregistered) in reply to ThatSlyQuarian
    ThatSlyQuarian:
    But At least we don't give our words genders. (im looking at you French)
    Many languages have gender, including nearly all the Romance languages, and several Semetic and other Indo-European ones. English used to have genders, too.
  • (cs) in reply to Andy
    Andy:
    Everything else is a matter of style, we might agree with Adam on most of the points, but there's no need to frame everything so negatively, Adam comes out sounding like a git with a superiority complex, by making the original coder look bad, he forces him onto the defense
    There's a point where this style simply indicates that the author doesn't have a slightest clue about what he/she is doing. The author is merely following some cargo cult without understanding what it all means. Good code must tell that you are competent with the tools available to you. If you consistently do things in the most contrived, back-asswards way, it means you're clueless, and when faced with any assignment more complex than this one, you'll fail miserably.
  • Your Name (unregistered) in reply to ThatSlyQuarian
    ThatSlyQuarian:
    Phoenettically ghoti is an acceptable alternate spelling of fish. This is why English is one of the harder languages to learn. But At least we don't give our words genders. (im looking at you French)
    No it's not. There is no word in English in which GH is pronounced as /f/ without being proceeded by OU, and there is no word where TI is pronounced like /ʃ/ without being followed by a vowel. The O from "women" actually is really weird, of course.

    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.

    Zack:
    ThatSlyQuarian:
    But At least we don't give our words genders. (im looking at you French)
    Many languages have gender, including nearly all the Romance languages, and several Semetic and other Indo-European ones. English used to have genders, too.
    And that's one of the very few places in which English is less WTFy than most languages.
  • Tasty (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    ' Nice conversion from a string to an integer to a decimal. No reason
    ' to go straight to decimal. Yes, the purpose is to get just the
    ' dollar portion, but really?
      dollars = CInt(num)
    Dollars? In Mexican money? Surely "peso portion" would be better. And the function name is bad for another reason: it doesn't do anything with Spanish money (Spain uses the euro, and even before that it used the peseta, not the peso).

    The fundamental WTF here is that the unnamed (and only marginally identified) "coder" was left to hack something together, and so he did. The resulting code fails the desirability criterion on multiple grounds, while being nowhere desperately bad, but the WTF is in the management process by which the code was created, not in the code itself.

    Se usa pesos Mexicanos en Mexico aunque habla Espanol. Ud. no puedes leer Ingles, y no tiene la razon.

  • Terrified (unregistered) in reply to TheEgg
    TheEgg:
    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#)
    No. num is a string (a WTF in its own right) and does not implicitly convert to any numeric type in VB.
    TheEgg:
    Addendum (2013-05-15 15:40): "Perhaps they could show me where the hardcoded WordCase is used in the code"
    ' Check to see if anyone has hacked the program to change the 
    ' hard coded case value
    
      If WordCase = "U" Then
         SpanishMoney = SpanishMoney.ToUpper
      End If
    
    That's not "using" it. He never checks what case his strings ought to be.
  • Paul Neumann (unregistered) in reply to Terrified
    Terrified:
    TheEgg:
    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#)
    No. num is a string (a WTF in its own right) and does not implicitly convert to any numeric type in VB.
    TheEgg:
    Addendum (2013-05-15 15:40): "Perhaps they could show me where the hardcoded WordCase is used in the code"
    ' Check to see if anyone has hacked the program to change the 
    ' hard coded case value
    
      If WordCase = "U" Then
         SpanishMoney = SpanishMoney.ToUpper
      End If
    
    That's not "using" it. He never checks what case his strings ought to be.
    Umm, yes it is using it. It may not be using it in any reasonable sense, but it is dereferenced and therefore it is being used. He he.
  • Rob (unregistered)

    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.

  • (cs) in reply to Rob
    Rob:
    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.

    Zero becomes "0"

    The correct idea would have been to use:

    CDec(num).ToString("C2", CultureInfo.CreateSpecificCulture("es-MX"))

    http://msdn.microsoft.com/en-us/library/18sthszb.aspx

  • (cs) in reply to Tasty
    Tasty:
    Se usa pesos Mexicanos en Mexico aunque habla Espanol. Ud. no puedes leer Ingles, y no tiene la razon.
    No. "Se usa pesos mexicanos en México aunque se habla español. Ud. no puede leer inglés, y no tiene razón."

    LRPU (Lo reparé por Ud.)

  • Nobody (unregistered)

    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 ?

  • Norman Diamond (unregistered) in reply to herby
    herby:
    As for "dollars", when I was in Mexico last, they used a dollar sign '$' as their currency prefix.
    They do not. They use the pesos sign, formed from an overlap of P and s. The Spanish-Mexican pronunciation of dollar was only slightly corrupted from the German thaler. When thirteen British colonies revolted, they issued paper money promising to repay in Spanish-Mexican dollars (which of course they reneged on). They copied the pesos symbol along with it. Mexico continued using their pesos symbol.
  • Norman Diamond (unregistered) in reply to Rob
    Rob:
    Mexican Spanish is not the same as Puerto Rican Spanish is not the same as Madrid Spanish. There are slight vocabulary differences.
    Just like American English is not the same as English English. This topic has been tabled every day recently.
  • Bill C. (unregistered) in reply to Thanatos Complex
    Thanatos Complex:
    To be fair, the pronunciation of the word "women" makes no fucking sense.
    Who needs women's pronunciation or sense?
  • Islander (unregistered) in reply to Chelloveck
    Chelloveck:
    Paul Neumann:
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verbiage

    Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!

    "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.

    Verby sounds more like an adverb, which would be a Moreause hybrid of verb and adjective.

  • Norman Diamond (unregistered) in reply to Islander
    Islander:
    Chelloveck:
    Paul Neumann:
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verbiage

    Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!

    "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.

    Verby sounds more like an adverb, which would be a Moreause hybrid of verb and adjective.
    I verbify verbily that verby reverberates very much like an adjective.

  • Jay (unregistered) in reply to TheEgg
    TheEgg:
    The WTF is I'm pretty sure VB, would support decimal types and maths along with several functions for currency handling in included libraries

    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.

  • Isikyus (unregistered) in reply to Nobody

    About as bad as Douglas Adams, or maybe Herman Mellville?

  • Gordonjcp (unregistered)

    TRWTF is that anyone is still using or indeed accepting cheques. What do they use them for, buying new buggy whips?

  • Randy Snicker (unregistered) in reply to Isikyus

    Your comment has no validity until the writer or the editor reaches anywhere near that level of skill. (I'm assuming never.)

  • wernsey (unregistered) in reply to Nobody
    Nobody:
    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 ?

    Nobody was insulted as far as I can tell.

  • chris (unregistered) in reply to Remy Porter
    Remy Porter:
    My code review comments always start with, "Have you thought about...". Start from the assumption of competence, no matter how much evidence you have to the contrary.

    And we all know TRWTF is writing code review comments directly into the code.

    My favourite review comment that I've seen is probably: // WHAT ON EARTH IS THIS TRYING TO DO????

    copy-pasted onto each occurrence of a copy-pasted routine.

  • Spudley (unregistered) in reply to Thanatos Complex
    Thanatos Complex:
    Herr Otto Flick:
    When ... Webster wrote his dictionary, he arbitrarily changed the spelling of lots of words, in order to make his English less English. By dropping the u from colour, making it's pronunciation less clear, he was saving America from being in thrall to Europe.

    He also changed "women" to "wimmin", and "medicine" as "medicin".

    No, I don't get it either.

    To be fair, the pronunciation of the word "women" makes no fucking sense.

    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.

  • David (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    And apparently he hadn't heard of Goggle Translate.

    Because everyone likes the text that has been run by Google Translate with any bilingual person check. (En->Es->En)

  • Joe (unregistered) in reply to Norman Diamond
    Norman Diamond:
    Islander:
    Chelloveck:
    Paul Neumann:
    Too Shay :)

    Carry => [s/y\b/i/ + $suffix] => Carriage

    Verb => [??? + suffix] => Verbiage

    Please fill in the ???. FTFM: Try and be snarky and Murphy will snark me!

    "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.

    Verby sounds more like an adverb, which would be a Moreause hybrid of verb and adjective.
    I verbify verbily that verby reverberates very much like an adjective.
    Looks more like an adverb to me.

  • (cs) in reply to kpcrash
    kpcrash:
    ObiWayneKenobi:
    Article probably left out the part where Adam was told that the code is good enough, just put it in production, because the boss's cousin's wife's brother's kid says he's a great developer and doesn't need his code reviewed.

    Because it turns out that the boss's cousin's wife's brother's kid is the President's daughter.

    So the boss's cousin's wife's brother's kid is the President? Or is she adopted?

  • (cs) in reply to FragFrog
    FragFrog:
    Erm, I may be missing something here (as I never wrote much VB, luckily), but apart from shoddy naming conventions and somewhat roundabout way of doing things, is this really WTF code?

    I mean, having a translation method that cannot parse 'zero', and doing it in the calling method, that's a bit silly. The redundant check on uppercase, well, that looks like it used to be a parameter but got rewritten, not really that much of a WTF either. The triple conversion from string value to cents, at least I see the logic behind it. All in all, the method looks to me like it does exactly what it needs to, without bugs, and without fun things like 100-item switch cases or using floats for money representation.

    I guess what I am trying to say, is that this looks shoddy, but hardly WTF level shoddy, at least to someone not familiar with VB; am I missing something?

    To me, TRWTF is that they didn't take the opportunity to generalize the localization, with English and Spanish their first two implementations. Then if they sold any in England they could add British localization with their misspelling of check as "cheque".

  • ForFoxSake (unregistered)

    just another douche

  • how long have you been ten (unregistered)

    This code is fine. Why is it on this site?

Leave a comment on “Habla Currency”

Log In or post as a guest

Replying to comment #:

« Return to Article