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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

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

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 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

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

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

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: What a More And

    CodeSOD: What a More And

    November 27, 2024

    Today, we’re going to start with the comment before the method.

        /**
         * The topology type of primitives to render. (optional)<br>
         * Default: 4<br>
         * Valid values: [0, 1, 2, 3, 4, 5, 6]
         *
         * @param mode The mode to set
         * @throws IllegalArgumentException If the given value does not meet
         * the given constraints
         *
         */
    

    This comes from Krzysztof. As much as I dislike these JavaDoc style comments (they mostly repeat information I can get from the signature!), this one is promising. It tells me the range of values, and what happens when I exceed that range, what the default is, and it tells me that the value is optional.

    In short, from the comment alone I have a good picture of what the implementation looks like.

    With some caveats, mind you- because that’s a set of magic numbers in there. No constants, no enum, just magic numbers. That’s worrying.

    Let’s look at the implementation.

        public void setMode(Integer mode) {
            if (mode == null) {
                this.mode = mode;
                return ;
            }
            if (((((((mode!= 0)&&(mode!= 1))&&(mode!= 2))&&(mode!= 3))&&(mode!= 4))&&(mode!= 5))&&(mode!= 6)) {
                throw new IllegalArgumentException((("Invalid value for mode: "+ mode)+ ", valid: [0, 1, 2, 3, 4, 5, 6]"));
            }
            this.mode = mode;
        }
    

    This code isn’t terrible. But there are all sorts of small details which flummox me.

    Hostinger

    Now, again, I want to stress, had they used enums this method would be much simpler. But fine, maybe they had a good reason for not doing that. Let’s set that aside.

    The obvious ugly moment here is that if condition. Did they not understand that and is a commutative operation? Or did they come to Java from LISP and miss their parentheses?

    Then, of course, there’s the first if statement- the null check. Honestly, we could have just put that into the chain of the if condition below, and the behavior would have been the same, or they could have just used an Optional type, which is arguably the “right” option here. But now we’re drifting into the same space as enums- if only they’d used the core language features, this would be simpler.

    Let’s focus, instead, on one last odd choice: how they use whitespace. mode!= 0. This, more than anything, makes me think they are coming to Java from some other language. Something that uses glyphs in unusual ways, because why else would the operator only get one space on one side of it? Which also makes me think the null check was written by someone else- because they’re inconsistent with it there.

    So no, this code isn’t terrible, but it does make me wonder a little bit about how it came to be.

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAn Introduction to Docker and Containers for Beginners
    Next Article Save Big on Microsoft Project 2024 While Codes Last

    Related Posts

    Security

    Chrome Zero-Day Alert: CVE-2025-5419 Actively Exploited in the Wild

    June 2, 2025
    Security

    CISA Adds 5 Actively Exploited Vulnerabilities to KEV Catalog: ASUS Routers, Craft CMS, and ConnectWise Targeted

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Building a Retrieval-Augmented Generation (RAG) System with DeepSeek R1: A Step-by-Step Guide

    Machine Learning

    How to Zoom in and out of a Video in VLC Player

    Development

    Best Free and Open Source Alternatives to Apple Music

    Linux

    tCalc – simple calculator

    Linux

    Highlights

    DR-MPC: Deep Residual Model Predictive Control for Real-World Social Navigation

    March 16, 2025

    How can a robot safely navigate around people with complex motion patterns? Deep Reinforcement Learning…

    Supercharge Customer Journeys with Salesforce OmniStudio

    July 3, 2024

    Reimagining the Semantic Web: UCL’s Innovative Synthesis of AI and Web Science

    July 31, 2024

    Europol shuts down Ramnit botnet used to steal bank details

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

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