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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

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

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 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

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

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

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Maximally Zero

    CodeSOD: Maximally Zero

    August 22, 2024

    Today’s anonymous submitter found some Java code which finds the largest value in a quartet of floats. Now, the code is quite old, so it actually predates varargs in Java. That doesn’t excuse any of what you’re about to see.

    public float CalculateMaximumValue(float a, float b, float c, float d) {
    int i = 0;
    float[] arr = new float[] { 0, 0, 0, 0 };
    float gtval = 0;

    for (i = 0; i < 4; i++) {
    arr[i] = 0;
    }
    arr[0] = a;
    arr[1] = b;
    arr[2] = c;
    arr[3] = d;
    gtval = arr[0];
    for (i = 0; i < 4; i++) {
    if (arr[i] > gtval) {
    gtval = arr[i];
    }

    }

    return gtval;

    }

    The best thing I can say about this is that they didn’t use some tortured expansion of every possible comparison:

    if (a > b && a > c && a > d) return a;
    if (b > a && b > c && b > d) return b;
    …

    Honestly, that would be awful, but I’d prefer it. This just makes my eyes sting when I look at it.

    But let’s trace through it, because each step is dumb.

    We start by creating an empty array, where every value is initialized to zero. This isn’t necessary, as that’s what Java does by default. But then, we loop across the array to set things to zero one more time, just to be sure.

    Once we’re convinced every value is definitely zero, we replace those zeroes with the real values. Then we can loop across the array and find the largest value with straightforward comparisons.

    This code is, in some ways, the worst kind of code. It’s bad, but not so bad as it’s ever going to cause real, serious problems. No one is going to see any bugs or inefficiencies coming from this method. It’s just an ugly mess that’s going to sit there in that codebase until the entire thing gets junked, someday. It’s just an irritant that never rises to the level of frustration which drives action.

    [Advertisement]
    Continuously monitor your servers for configuration changes, and report when there’s configuration drift. Get started with Otter today!

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleWhy Pixel phone’s enhanced Astrophotography mode is perfect for snapping the night sky
    Next Article Quick, Easy BOI Filing for Just $89

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-47893 – VMware GPU Firmware Memory Disclosure

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    SlideModel Review: Professional PowerPoint Templates for Serious Presenters

    Development

    Top 8 Automation Testing Trends Shaping 2025

    Development

    If you’re not working on quantum-safe encryption now, it’s already too late

    News & Updates

    Meet the ‘LangChain Financial Agent’: An AI Fintech Project Built on Langchain and FastAPI

    Development

    Highlights

    Machine Learning

    Amazon Bedrock launches Session Management APIs for generative AI applications (Preview)

    March 25, 2025

    Amazon Bedrock announces the preview launch of Session Management APIs, a new capability that enables…

    Passes is a GUI tool to manage your digital passes

    April 25, 2025

    CVE-2025-4172 – VerticalResponse WordPress Newsletter Widget Stored Cross-Site Scripting Vulnerability

    May 3, 2025

    OtterCookie v4 Adds VM Detection and Chrome, MetaMask Credential Theft Capabilities

    May 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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