• (nodebb)

    What he should've done was serialize it as json, store it as a cloud blob, then retrieve it and deserialize it as decimal. One, the result would've been correct, and two, they can claim their software is in the cloud.

  • my name is missing (unregistered)

    In France this comment is 100 times more valuable.

  • (nodebb) in reply to Mr. TA

    Seems like you left out the wooden table.

  • dpm (unregistered)

    TRWTF of course is a numeric parser simply ignoring extraneous characters instead of throwing an exception. Bad data is bad data.

  • RLB (unregistered) in reply to dpm

    TRWTF of course is a numeric parser simply ignoring extraneous characters instead of throwing an exception. Bad data is bad data.

    Sure, but it's not the library's job to have such a radical reaction to what it calls "bad". Sometimes, you want to get a numeric prefix, not an entire numeric string. In that case, you need to be able to tell your parser: "Give me the number this string starts with, and tell me where it stops" rather than "Give me this number, and throw a hissy fit if you don't like everything in the string". (C's strtod() et al. can do this.)

  • RLB (unregistered)

    Oh, and Remy: Ming certainly does deserve being made an ass of! If he doesn't like it, he shouldn't have been so Merciless.

  • Prime Mover (unregistered)

    Thank goodness they didn't use this method on a certain John Cage number or they've be sitting there in silence for over 7 hours.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    If you have direct deposit set up with your payroll provider, the agreement you signed almost certainly has a clause in it that allows them to deduct money from your bank account if they overpaid you due to error.

  • Best Of 2021 (unregistered)

    Ok today's is a good one!

    Convert.ToDecimal has been in the Framework since the beginning, I think. So there's really no excuse for this one. And that's without even going into doing string formatting and parsing in different locales on adjacent lines.

  • (nodebb)

    The part that gets me is calling GetDoubleFromRandomMethod() at the beginning. If I wanted to know how much to pay somebody, I would be wanting to do a very deterministic database read, not something dependent on a Random number generation. Or is this just another example of deceptive function names?

  • (nodebb) in reply to Nutster

    I'm guessing that's not the real function name, it was just used here as a placeholder because that part is unimportant.

  • (nodebb) in reply to Mr. TA

    What he should've done was

    Toss an XML step in there too, so that it is "enterprise".

  • Carl Witthoft (google) in reply to Prime Mover
    Thank goodness they didn't use this method on a certain John Cage number or they've be sitting there in silence for over 7 hours.

    I'd pay good money, with or without the comma-shifting, for 7 hours of quiet. BTW, I have a video on YouTube of me performing 4'33" on cello.

  • dpm (unregistered) in reply to RLB

    Sometimes, you want to get a numeric prefix

    Then call something besides a method named "Parse" in which the only parameter is the string to be parsed. Default behavior should be to not accept bad data.

  • Best Of 2021 (unregistered) in reply to RLB

    Sometimes, you want to get a numeric prefix, not an entire numeric string

    This feels like it's the job of the calling code. I guess int.Parse and friends allow for nonsense after the number because atoi and friends always have done, but it's still bad design for me. "12bha" is not a valid integer and I'd expect an integer parsing method to throw an exception if given that, just like it does if given "bha12".

    And honestly, how useful actually is that? I've never had a genuine business problem of 'the beginning of this string is a number but I don't care about the rest of it. If you have some kind of munged string then you probably care about other parts and need some regex to extract the bits you want anyway, at which point you can use a \d+.

  • ZPedro (unregistered)

    I think the guilty party managed the trifecta of payment WTF*ckery: money amounts as floating-point combined with pointless casting combined with senseless exposure to locale-specific behavior. In only as many lines of code. I proclaim them the winner of WTF code golf.

  • Loren Pechtel (unregistered) in reply to dpm

    | TRWTF of course is a numeric parser simply ignoring extraneous characters instead of throwing an exception. Bad data is bad data.

    Truly bad data I agree, it should barf. However, a comma is quite common in human-formatted numbers, I have no problem with a numeric parser that zaps off the thousands-separator character without being careful about ensuring it's actually in the right position for a thousands separator. There's a limit to the amount of validation you want built into such routines because validation costs everyone time.

  • Hasseman (unregistered)

    You should know how much trouble dot and commas gives in all types of programs (Excel reading CSV files is one).

    Number separators group in different constellations in different countries (India uses lakh grouped as nn,nn,nnn), different separators as apostrophe, comma, dot, space. Depending on your settings in OS, App, Database etc. you can get surprising results when reading your CVS downloaded statements from your bank and open it in Excel.

  • Stu (unregistered) in reply to dpm

    It specifically ignores commas, not just any "invalid" character. Commas are (in '.'-decimal locales) simply added for clarity for human readers and there is no universal standard as to where they go. (e.g. the Indian convention is different to the US convention). It's completely correct to ignore commas, they're the "comments" of number formatting.

  • (nodebb)

    double origin = GetDoubleFromRandomMethod(); string str = origin.ToString().Replace(".",","); decimal result = decimal.Parse(str);

    So we have 1- Get a decimal value, 2- Convert.ToString().addWTFery, 3- parse result back into a number... to be used as the pay rate to calculate the amount of the check, which triggers the "people get a raise in non-French locales" problem...

    TRWTF is getting a number you need to do math, WTFing it with string "majick", and then recasting that to be used as the number to do the math when all along you should just be using the value of origin instead of the value of result. This, friends, probably is the Enterprisiest form of Enterprisey WTF, at its finest!

  • dpm (unregistered) in reply to Loren Pechtel

    There's a limit to the amount of validation you want built into such routines because validation costs everyone time.

    Yeah, no need to be precise when you're dealing with . . . money.

  • (nodebb)

    If only decimal had a constructor that took a double. If only…

  • RLB (unregistered) in reply to Best Of 2021

    This feels like it's the job of the calling code. I guess int.

    And how is the calling code going to do that without a function to partially parse a string? Do it by hand? That's a guaranteed way of ending up on TDWTF for reinventing the wheel.

    Parse and friends allow for nonsense after the number because atoi and friends always have done, but it's still bad design for me.

    That's why, these days, we use strtol() rather than atoi().

    And honestly, how useful actually is that? I've never had a genuine business problem of 'the beginning of this string is a number but I don't care about the rest of it.

    Neither have I - what I've had is "the beginning of the string is a number and the rest is a name - I need both". A function that throws an exception just because my users are sometimes sloppy typists, by contrast, has never been useful to me.

  • Best Of 2021 (unregistered) in reply to RLB

    what I've had is "the beginning of the string is a number and the rest is a name - I need both"

    But if you need both, this behaviour doesn't help you. You're going to need to do something like (pseudocode)

    Option A: let pos = str.IndexOf(' '); let number = int.Parse(str.Substring(0, pos)), name = str.Substring(pos + 1);

    Option B: let parts = str.evaluate(/(\d+)(.*)/) let number = int.Parse(parts[0]), name = parts[1]

    In neither case is it useful to be able to give '123abc' to int.Parse because you still need to be able to find 'abc'.

  • Ollie Jones (unregistered)

    The WTF here? WTF is that dotnet .ToString() stuff designed so its result is nondeterministic? HTF do we learn to reason about code like that? Why, oh, why, can't something like that get called .ToLocaleString()? As it is, we gotta read the popups in VS, carefully, carefully, or fall into this trap.

  • (author) in reply to Carl Witthoft

    You're lucky that YouTube's copyright protection bots didn't block it.

  • (nodebb) in reply to Best Of 2021

    And honestly, how useful actually is that? I've never had a genuine business problem of 'the beginning of this string is a number but I don't care about the rest of it. If you have some kind of munged string then you probably care about other parts and need some regex to extract the bits you want anyway, at which point you can use a \d+.

    I take it you never have to deal with measurements with units? Like Microsoft Word's:

    Left margin: 2 cm Right margin: 1"

    boxes?

    Hence the original comment:

    "Give me the number this string starts with, and tell me where it stops"

Leave a comment on “A Big Raise”

Log In or post as a guest

Replying to comment #524412:

« Return to Article