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 

    Hostinger
    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

    Hostinger

    Continue Reading

    A Coding Implementation of Extracting Structured Data Using LangSmith, Pydantic, LangChain, and Claude 3.7 Sonnet

    Machine Learning

    From OpenBSD to Linux: How Pledge can Enhance Linux Security

    Linux

    Google releases responsible AI report while removing its anti-weapons pledge

    News & Updates

    NASA and IBM Researchers Introduce INDUS: A Suite of Domain-Specific Large Language Models (LLMs) for Advanced Scientific Research

    Development

    Highlights

    Development

    Google Rolls Out May 2025 Android Security Bulletin, Fixes 46 Vulnerabilities Including CVE-2025-27363

    May 7, 2025

    Google has published its Android Security Bulletin for May 2025, delivering critical updates to the…

    Allen Institute for AI (AI2) Releases OLMo 32B: A Fully Open Model to Beat GPT 3.5 and GPT-4o mini on a Suite of Multi-Skill Benchmarks

    March 16, 2025

    SELMA: A Speech-Enabled Language Model for Virtual Assistant Interactions

    March 16, 2025

    Opera GX for Smart TV – Here’s How To Safely Install It

    June 20, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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