- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Lucky Penny
- Mike's Job Search Job
- Teamwork
- Cuts Like a Knife
- Charge Me
- Que Sera, Sera
- Hot Dog
- Sentinel Headline
-
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
Not great code, but not too damaging to have an exception unless it is invoked millions of times in a loop.
public static bool IsFrist(string theValue) { try { Convert.ToOrdinal(theValue); return true; } catch { return false; } }
Admin
Too bad double.TryParse() is around for 25 years since .net BETA.
Feels to me like yet another RTFM situation, most likely from someone coming from Java since this person doesn't even know the basic value types of .net - something most C# devs learn like on the first day - and therefore used such a weird name for that useless method.
Admin
What's Convert.ToOrdinal() ?
That method never existed on the Convert class of .net.
And the correct answer is as stated in the article: https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse?view=net-9.0
Admin
"...pedantry is the root of clarity"
A large portion of my career has just been vindicated! :)
Admin
Telling that simple verification functions like this should be built into .net without all the intellectual drama devs inject into their code. We've got 170IQ devs who write code like function()=>Foo.New(a => ^Bar(1).First().Flarg(a.Color) (goes on for another 256 characters) ...then Dev:"Look at this...I turn the label Blue!". Me: "Why not just turn the label blue? Wouldn't that be simple?" Dev: "Pffft...simple is relative....look at this code!!!"
Admin
I got the joke even if MaxiTB didn't.
Admin
So did I, but,
ToOrdinal()
will also return true for secnod and thrid.Addendum 2025-05-12 10:18: and
FileNotFound
for brillant.Addendum 2025-05-12 10:19:
s/ToOrdinal/isFrist/
ToOrdinal()
won't throw an exception for the other cases is what I meant to say.Admin
Enlighten me :-)
Admin
I'd think IsFrist would be dead give away...
Admin
You guys don't understand, this is simply exceptional programming.
/s
Admin
They all say that until you have to debug why a function call is timing and locking up a web server out only to discover someone wrote code similar to this inside a double nested loop that does in fact get called millions of times AND has millions of lines to loop through.
Admin
The name might be wrong, but have some sympathy, since naming things, invalidating cache and off-by-one errors are the two hardest problems to solve in programming
Admin
To be fair (or pedantic, your pick,) C# should share some of the blame for this WTF, as decimal is a bad name for a numeric type, unless it can store any decimal value - which it cannot.
Admin
By that logic integer is a bad name because it can't store any integer value and male connector is a bad name because it could be a trans-gender female connector ;-).
Lament natural language terms have never anything to do with technical definitions of terms; it can't because natural languages are by definition as vague as possible to allow for less social friction during conversations.
Admin
when i am speaking to someone who will understand what i mean, i actually prefer using "top" and "bottom" for connectors instead of "male" and "female" for this exact reason