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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

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

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

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

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

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

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

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

    News & Updates

    7 MagSafe accessories that I recommend every iPhone user should have

    June 1, 2025
    News & Updates

    I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    TIS-DPO: Token-level Importance Sampling for Direct Preference Optimization

    Machine Learning

    Integrate Grok AI in Laravel

    Development

    CVE-2025-45238 – Foxcms File Deletion Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Meta AI Introduces CoCoMix: A Pretraining Framework Integrating Token Prediction with Continuous Concepts

    Machine Learning

    Highlights

    Development

    Linguistics-aware In-context Learning with Data Augmentation (LaiDA): An AI Framework for Enhanced Metaphor Components Identification in NLP Tasks

    August 15, 2024

    Metaphor Components Identification (MCI) is an essential aspect of natural language processing (NLP) that involves…

    CVE-2025-43859: Request Smuggling Vulnerability in Python’s h11 HTTP Library

    April 27, 2025

    How a signed driver exposed users to kernel-level threats – Week in Security with Tony Anscombe

    July 26, 2024

    From Lost to Found: INformation-INtensive (IN2) Training Revolutionizes Long-Context Language Understanding

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

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