- 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
My guess is that they noticed there was a FormatException when trying to use the form value as a decimal if the entered data wasn't decimal, then decided this must be the way to intercept that exception.
Admin
Not as "Silly" as it might appear... Context matters... Iaging a colection of converters 50 input formats, 50 outformats, potentially 2500 converters... Lookup, cast and pass. Now the implementation is overly complicated, but if from boiler plate probably not that bad.... and don't forget compilers optimize many things - only way to known what is running is to examine the actual machine level state [and remember attaching a debugger may itself disable optimizations]
Admin
This is a "pacifier": code which always "works", therefore takes the stress off
Admin
To be fair, this is probably just a simple brain-fart.. they put "decimal" in the header when they meant to put "string". Not great, but who hasn't ever made a mistake like that?
Admin
They probably put
decimal
in the declaration because they found they had a compiler error if they used astring
Admin
So basically he wrote Decimal.TryParse but wrong.
Admin
I'm going to guess that at one point in the past, it used to take the parameter as a string, and they were parsing it with
Decimal.Parse(inFormVersion)
. Then somebody decided to refactor it to pass the parameter as adecimal
without deleting the rest of the junk that then became useless.Admin
And yet, I bet the unit test passes.
There is a unit test, right?
Right?
Admin
Given the name of the method my best guess is that at some point the code in the try block used to be different. Then things changed but they left the exception handling "just in case".
Admin
Just interpreting a dotted version as a fraction.is already a WTF.
Admin
I'm enjoying reading some of the explanations of "why" this happens. It's been said of the American body politic (and probably in other countries as well) that the voters want the politicians to do something... even if it's wrong. Inaction -- even if it's the right thing to do -- is not acceptable. I've seen this from programmers far to often. Not sure what to do? Write something. Anything. Doesn't matter if it's right or wrong, or even if you know what you're doing.
Admin
This doesnt look like C# at all, first it doesnt follow method naming conventions and second .net developers would either use fluent validation or the validator class around since the .net beta ;-)
Admin
or it was a "string" parameter originally, and then got "fixed" later by someone only checking the function signature ...?