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 

    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

    Shock move by Microsoft: Hiring freeze in consulting to cut costs after significant recent layoffs

    News & Updates

    How to fetch data from PostgreSQL using PHP

    Development

    Copilot on Windows 11 is gaining the ability to see and interact with your apps — but only when you ask it to

    News & Updates

    What is Purchase Order Management? Steps, Best Practices and Benefits

    Artificial Intelligence

    Highlights

    Qubes OS – security-oriented operating system

    January 27, 2025

    Qubes OS is a free and open-source, security-oriented operating system for single-user desktop computing. It’s…

    The best CRM software of 2025: Expert tested

    March 19, 2025

    Meet Wisdom AI: An AI Startup that Bring Insights at your Fingertips with AI-Powered Analytics

    June 24, 2024

    The best CES 2025 products you can buy right now

    January 7, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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