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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 21, 2025

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

      May 21, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 21, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 21, 2025

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025

      Windows 11 is getting AI Actions in File Explorer — here’s how to try them right now

      May 21, 2025

      Is The Alters on Game Pass?

      May 21, 2025

      I asked Copilot’s AI to predict the outcome of the Europa League final, and now I’m just sad

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

      Celebrating GAAD by Committing to Universal Design: Equitable Use

      May 21, 2025
      Recent

      Celebrating GAAD by Committing to Universal Design: Equitable Use

      May 21, 2025

      GAAD and Universal Design in Healthcare – A Deeper Look

      May 21, 2025

      GAAD and Universal Design in Pharmacy – A Deeper Look

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

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025
      Recent

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025

      Windows 11 is getting AI Actions in File Explorer — here’s how to try them right now

      May 21, 2025

      Is The Alters on Game Pass?

      May 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: A Set of Mistakes

    CodeSOD: A Set of Mistakes

    December 31, 2024

    One of the long-tenured developers, Douglas at Patrick‘s company left, which meant Patrick was called upon to pick up that share of the work. The code left behind by Douglas the departing developer was, well… code.

    For example, this block of Java:

    private String[] getDomainId(Collection<ParticularCaseEntity> particularCase) {
           
        // Get all domainId
        Collection<String> ids = new ArrayList<String>();
        for (ParticularCaseEntity case : particularCase) {
            ids.add(case.getDomainId());
        }
    
        Set<String> domainIdsWithoutRepeat = new HashSet<String>();
        domainIdsWithoutRepeat.addAll(ids);
    
        Collection<String> domainIds = new ArrayList<String>();
        for (String domainId : domainIdsWithoutRepeat) {
            domainIds.add(domainId);
        }
        return domainIds.toArray(new String[0]);       
    }
    

    The purpose of this code is to get a set of “domain IDs”- a set, specifically, because we want them without duplicates. And this code takes the long way around to do it.

    First, it returns a String[]– but logically, what it should return is a set. Maybe it’s meant to comply with an external interface, but it’s a private method- so I actually think this developer just didn’t understand collection types at all.

    And I have more evidence for that, which is the rest of this code.

    We iterate across our ParticularCaseEntitys, and add each one to an array list. Then we create a hash set, and add all of those to a hash set. Then we create another array list, and add each entry in the set to the array list. Then we convert that array list into an array so we can return it.

    At most, we really only needed the HashSet. But this gives us a nice tour of all the wrong data structures to use for this problem, which is helpful.

    Speaking of helpful, it didn’t take long for Patrick’s employer to realize that having Patrick doing his job, and also picking up the work that Douglas used to do was bad. So they opened a new position, at a higher pay grade, hoping to induce a more senior developer to step in. And wouldn’t you know, after 6 months, they found a perfect candidate, who had just finished a short six month stint at one of their competitors: Douglas!

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    news
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleDecember 2024: People on the Move
    Next Article Accessing Raw Model Data with Laravel’s attributesToArray Method

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 22, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-3111 – GitLab Kubernetes Denial of Service Vulnerability

    May 22, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Encountered Error Could not load type ‘OpenQA.Selenium.Internal.IWrapsElement’ from assembly ‘WebDriver

    Development

    Understanding the :root Selector and CSS Variables

    Web Development

    This AI-Powered Cybercrime Service Bundles Phishing Kits with Malicious Android Apps

    Development

    Hierarchical Graph Masked AutoEncoders (Hi-GMAE): A Novel Multi-Scale GMAE Framework Designed to Handle the Hierarchical Structures within Graph

    Development

    Highlights

    Development

    Typed Arr Getters Added in Laravel 12.11

    April 30, 2025

    The Laravel team released v12.11.0, which includes typed Arr getter methods, job payload additions, FakeJob…

    Chinese Hackers Deploy MarsSnake Backdoor in Multi-Year Attack on Saudi Organization

    May 20, 2025

    The Dual Impact of AI and Machine Learning: Revolutionizing Cybersecurity and Amplifying Cyber Threats

    July 11, 2024

    CVE-2025-46251 – VikRestaurants Table Reservations and Take-Away CSRF

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

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