Experts reveal how to maintain a beautiful lawn this summer - and why you DON'T need to mow it all the time
Virat Kohli RETIRES from Test cricket as Indian legend ends glittering career in the longest form of the game 'with a heart full of gratitude'
BAFTA TV Awards 2025: Maura Higgins makes her red carpet return following Danny Jones kiss scandal in a backless gown as she joins glam Billie Piper, Tasha Ghouri and Ekin-Su Culculoglu on red carpet
Three men arrested and one man left with head injury at Essex village pub
Justin Bieber wishes wife Hailey a happy Mother's Day as she shares snaps of their son Jack Blues
A414 recap as huge crash shut major road near Danbury
Britain's richest plumber Charlie Mullins blasts new American owners of his former firm after they axed popular apprenticeship scheme
Danbury road 'blocked' and traffic building due to crash
Billie Piper ditches her pink gown for a black mini dress while Laura Whitmore slips into a red velvet look as stars let their hair down at the 2025 BAFTA TV Awards after party
Taylor Swift and Travis Kelce stun diners in Philadelphia as they break cover for first time in two months
The 100-year-old spa hotel that has become a luxury migrant hotel in rural village... with guards and some surprising deliveries
Amber Heard welcomes twins! Star, 39, announces arrival of daughter and son (and reveals their unusual names)
Council failed to report scale of special needs crisis for at least six months
Ever been worried a nuclear war would ground a flight and stop your holiday? Don't - experts are working to change policies from the 1950s
US Copyright Office found AI companies sometimes breach copyright. Next day its boss was fired
The head of the US Copyright Office has reportedly been fired, the day after agency concluded that builders of AI models use of copyrighted material went beyond existing doctrines of fair use.…
CodeSOD: Would a Function by Any Other Name Still be WTF?
"Don't use exception handling for normal flow control," is generally good advice. But Andy's lead had a PhD in computer science, and with that kind of education, wasn't about to let good advice or best practices tell them what to do. That's why, when they needed to validate inputs, they wrote code C# like this:
public static bool IsDecimal(string theValue) { try { Convert.ToDouble(theValue); return true; } catch { return false; } }They attempt to convert, and if they succeed, great, return true. If they fail, an exception gets caught, and they return false. What could be simpler?
Well, using the built in TryParse function would be simpler. Despite its name, actually avoids throwing an exception, even internally, because exceptions are expensive in .NET. And it is already implemented, so you don't have to do this.
Also, Decimal is a type in C#- a 16-byte floating point value. Now, I know they didn't actually mean Decimal, just "a value with 0 or more digits behind the decimal point", but pedantry is the root of clarity, and the naming convention makes this bad code unclear about its intent and purpose. Per the docs there are Single and Double values which can't be represented as Decimal and trigger an OverflowException. And conversely, Decimal loses precision if converted to Double. This means a value that would be represented as Decimal might not pass this function, and a value that can't be represented as Decimal might, and none of this actually matters but the name of the function is bad.