• Jaloopa (unregistered)

    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.

  • TheCPUWizard (unregistered)

    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]

  • (nodebb)

    This is a "pacifier": code which always "works", therefore takes the stress off

  • Rich (unregistered)

    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?

  • (nodebb) in reply to Rich

    They probably put decimal in the declaration because they found they had a compiler error if they used a string

  • LZ79LRU (unregistered)

    So basically he wrote Decimal.TryParse but wrong.

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

    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 a decimal without deleting the rest of the junk that then became useless.

  • Richard Brantley (unregistered)

    And yet, I bet the unit test passes.

    There is a unit test, right?


  • (nodebb)

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

  • Duke of New York (unregistered)

    Just interpreting a dotted version as a fraction.is already a WTF.

  • Argle Bargle (unregistered)

    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.

  • MaxiTB (unregistered)

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

  • hartmut (unregistered) in reply to Rich

    they put "decimal" in the header when they meant to put "string"

    or it was a "string" parameter originally, and then got "fixed" later by someone only checking the function signature ...?

Leave a comment on “Simple Form Validation”

Log In or post as a guest

Replying to comment #:

« Return to Article