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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 3, 2025

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

      June 3, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 3, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 3, 2025

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025

      These solid-state fans will revolutionize cooling in our PCs and laptops

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

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025
      Recent

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025

      A Comprehensive Guide to Azure Firewall

      June 3, 2025

      Test Job Failures Precisely with Laravel’s assertFailedWith Method

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

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025
      Recent

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Contains Bad Choices

    CodeSOD: Contains Bad Choices

    January 28, 2025

    Paul‘s co-worker needed to manage some data in a tree. To do that, they wrote this Java function:

    private static boolean existsFather(ArrayList<Integer> fatherFolder, Integer fatherId) {
            for (Integer father : fatherFolder) {
                    if (father.equals(fatherId))
                            return true;
            }
            return false;
    }
    

    I do not know what the integers in use represent here. I don’t think they’re actually representing “folders”, despite the variable names in the code. I certainly hope it’s not representing files and folders, because that implies they’re tossing around file handles in some C-brained approach (but badly, since it implies they’ve got an open handle for every object).

    The core WTF, in my opinion, is this- the code clearly implies some sort of tree structure, the tree contains integers, but they’re not using any of the Java structures for handling trees, and implementing this slipshod approach. And even then, this code could be made more generic, as the general process works with any sane Java type.

    Hostinger

    But there’s also the obvious WTF: the java.util.Collection interface, which an ArrayList implements, already handles all of this in its contains method. This entire function could be replaced with fatherFolder.contains(fatherId).

    Paul writes: “I guess the last developer didn’t know that every implementation of a java.util.Collection has a method called contains. At least they knew how to do a for-each.”.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Clear APT Cache and Free Up Disk Space
    Next Article How I am Moving Away From Google’s Ecosystem

    Related Posts

    News & Updates

    All the WWE 2K25 locker codes that are currently active

    June 3, 2025
    News & Updates

    PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

    June 3, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Predicting the (actually very exciting) future of next gen Xbox hardware

    Development

    How do you enter data from a jhtml Area element using selenium?

    Development

    Empower Financial Services Developers with the Document Model

    Databases

    libdatachannel is a WebRTC network library

    Linux

    Highlights

    Development

    Meta’s Llama Framework Flaw Exposes AI Systems to Remote Code Execution Risks

    January 26, 2025

    A high-severity security flaw has been disclosed in Meta’s Llama large language model (LLM) framework…

    Cohere Released Command A: A 111B Parameter AI Model with 256K Context Length, 23-Language Support, and 50% Cost Reduction for Enterprises

    March 16, 2025

    Learn College Calculus and Implement with Python

    April 29, 2025

    Tags – GNOME text tagger

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

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