Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 12, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 12, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 12, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 12, 2025

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025

      Sam Altman doesn’t want his son to have an AI “bestie” — as Microsoft plans to turn Copilot into an AI friend and companion

      May 12, 2025

      ChatGPT downplays AI’s threat to humanity despite an apparent “99.999999% probability” of inevitable doom

      May 12, 2025

      Surface Pro 12-inch vs. iPad Air M3: Which should you choose?

      May 12, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      A customizable and accessible web component

      May 12, 2025
      Recent

      A customizable and accessible web component

      May 12, 2025

      How Agile Helps You Improve Your Agility

      May 12, 2025

      Laravel Seeder Generator

      May 12, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025
      Recent

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025

      Sam Altman doesn’t want his son to have an AI “bestie” — as Microsoft plans to turn Copilot into an AI friend and companion

      May 12, 2025

      ChatGPT downplays AI’s threat to humanity despite an apparent “99.999999% probability” of inevitable doom

      May 12, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Would a Function by Any Other Name Still be WTF?

    CodeSOD: Would a Function by Any Other Name Still be WTF?

    May 12, 2025

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

    [Advertisement]
    ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCVE-2025-4553 – PHPGurukul Apartment Visitors Management System SQL Injection
    Next Article Vine Linux is a Linux distribution with an integrated Japanese environment

    Related Posts

    News & Updates

    Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

    May 12, 2025
    News & Updates

    Sam Altman doesn’t want his son to have an AI “bestie” — as Microsoft plans to turn Copilot into an AI friend and companion

    May 12, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Private Federated Learning In Real World Application – A Case Study

    Machine Learning

    Revealing UX Design’s Impact: Unlocking its Power

    Development

    Qwen Researchers Introduce CodeElo: An AI Benchmark Designed to Evaluate LLMs’ Competition-Level Coding Skills Using Human-Comparable Elo Ratings

    Development

    10-Step Guide to Closing Your Books at the End of the Year

    Development

    Highlights

    Development

    Samsung and LG TVs are set to get Microsoft Copilot AI, but it’s going to just be a link to the website again

    January 6, 2025

    Microsoft Copilot is coming to your TV. Or at least, the web app is. Dual…

    This AI Paper Proposes Utilizing the AI-Based Agents Workflow (AgWf) Paradigm to Enhance the Effectiveness of Process Mining (PM) on LLMs

    August 21, 2024

    I went hands-on with every Google Pixel 9 model, and this is the one you should buy

    August 13, 2024
    Boson AI Introduces Higgs Audio Understanding and Higgs Audio Generation: An Advanced AI Solution with Real-Time Audio Reasoning and Expressive Speech Synthesis for Enterprise Applications

    Boson AI Introduces Higgs Audio Understanding and Higgs Audio Generation: An Advanced AI Solution with Real-Time Audio Reasoning and Expressive Speech Synthesis for Enterprise Applications

    April 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.