- 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
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.
Admin
In France this comment is 100 times more valuable.
Admin
Seems like you left out the wooden table.
Admin
TRWTF of course is a numeric parser simply ignoring extraneous characters instead of throwing an exception. Bad data is bad data.
Admin
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.)
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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?
Admin
I'm guessing that's not the real function name, it was just used here as a placeholder because that part is unimportant.
Admin
Toss an XML step in there too, so that it is "enterprise".
Admin
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.
Admin
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.
Admin
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+.
Admin
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.
Admin
| 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.
Admin
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.
Admin
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.
Admin
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!
Admin
Yeah, no need to be precise when you're dealing with . . . money.
Admin
If only
decimal
had a constructor that took adouble
. If only…Admin
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.
That's why, these days, we use strtol() rather than atoi().
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.
Admin
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'.
Admin
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.
Admin
You're lucky that YouTube's copyright protection bots didn't block it.
Admin
I take it you never have to deal with measurements with units? Like Microsoft Word's:
boxes?
Hence the original comment: