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

      Error’d: Pickup Sticklers

      September 27, 2025

      From Prompt To Partner: Designing Your Custom AI Assistant

      September 27, 2025

      Microsoft unveils reimagined Marketplace for cloud solutions, AI apps, and more

      September 27, 2025

      Design Dialects: Breaking the Rules, Not the System

      September 27, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025

      Cailabs secures €57M to accelerate growth and industrial scale-up

      September 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

      Using phpinfo() to Debug Common and Not-so-Common PHP Errors and Warnings

      September 28, 2025
      Recent

      Using phpinfo() to Debug Common and Not-so-Common PHP Errors and Warnings

      September 28, 2025

      Mastering PHP File Uploads: A Guide to php.ini Settings and Code Examples

      September 28, 2025

      The first browser with JavaScript landed 30 years ago

      September 27, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured
      Recent
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: It’s Not Wrong to Say We’re Equal

    CodeSOD: It’s Not Wrong to Say We’re Equal

    July 1, 2025

    Aaron was debugging some C# code, and while this wasn’t the source of the bug, it annoyed him enough to send it to us.

    <span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-built_in">int</span> <span class="hljs-title">DoCompare</span>(<span class="hljs-params">Item item1, Item item2</span>)</span>
    {
    	<span class="hljs-keyword">try</span>
    	{
    		DateTime thisDate = ((DateField)item1.Fields[<span class="hljs-string">"Create Date"</span>]).DateTime;
    		DateTime thatDate = ((DateField)item2.Fields[<span class="hljs-string">"Create Date"</span>]).DateTime;
    
    		<span class="hljs-keyword">return</span> thatDate.CompareTo(thisDate);
    	}
    	<span class="hljs-keyword">catch</span> (Exception)
    	{
    		<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; <span class="hljs-comment">// Sorry, ran out of budget!</span>
    	}
    }
    

    Not to be the pedantic code reviewer, but the name of this function is terrible. Also, DoCompare clearly should be static, but this is just pedantry.

    Now, there’s a lot of implied WTFs hidden in the Item class. They’re tracking fields in a dictionary, or maybe a ResultSet, but I don’t think it’s a ResultSet because they’re converting it to a DateField object, which I believe to be a custom type. I don’t know what all is in that class, but the whole thing looks like a mess and I suspect that there are huge WTFs under that.

    But we’re not here to look at implied WTFs. We’re here to talk about that exception handler.

    It’s one of those “swallow every error” exception handlers, which is always a “good” start, and it’s the extra helpful kind, which returns a value that is likely incorrect and provides no indication that anything failed.

    Now, I suspect it’s impossible for anything to have failed- as stated, this seems to be some custom objects and I don’t think anything is actively talking to a database in this function (but I don’t know that!) so the exception handler likely never triggers.

    But hoo boy, does the comment tell us a lot about the codebase. “Sorry, ran out of budget!”. Bugs are inevitable, but this is arguably the worst way to end up with a bug in your code: because you simply ran out of money and decided to leave it broken. And ironically, I suspect the code would be less broken if you just let the exception propagate up- if nothing else, you’d know that something failed, instead of incorrectly thinking two dates were the same.

    [Advertisement]
    BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Article⚡ Weekly Recap: Airline Hacks, Citrix 0-Day, Outlook Malware, Banking Trojans and more
    Next Article Linux Sudo chroot Vulnerability Enables Hackers to Elevate Privileges to Root

    Related Posts

    News & Updates

    Building personal apps with open source and AI

    September 12, 2025
    News & Updates

    What Can We Actually Do With corner-shape?

    September 12, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Empowering students with disabilities: University Startups’ generative AI solution for personalized student pathways

    Machine Learning

    Building Smarter APIs with OpenAPI, AWS Bedrock & SageMaker Studio in Drupal 10

    Development

    5 Powerful MCP Servers To Transform Your Development Workflow

    Web Development

    Gemini just got two of ChatGPT’s best features – and they’re free

    News & Updates

    Highlights

    Machine Learning

    SYNCOGEN: A Machine Learning Framework for Synthesizable 3D Molecular Generation Through Joint Graph and Coordinate Modeling

    July 24, 2025

    Introduction: The Challenge of Synthesizable Molecule Generation In modern drug discovery, generative molecular design models have greatly…

    A new way to test how well AI systems classify text

    August 13, 2025

    Build an AI-powered document processing platform with open source NER model and LLM on Amazon SageMaker

    April 23, 2025

    INTERPOL Arrests 1,209 Cybercriminals Across 18 African Nations in Global Crackdown

    August 22, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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