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-2024-13953 – Raritan ASPECT Device Logger Credential Exposure Vulnerability

    May 22, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    How to resolve the Null error displayed for shadowRoot element

    Development

    ‘We Refused to Pay,’ Evolve Bank Says as LockBit Leaks Data, Affirm Card Users Impacted

    Development

    Critical ‘BatBadBut’ Rust Vulnerability Exposes Windows Systems to Attacks

    Development

    I like SteelSeries’ tiniest high performance gaming keyboard, but it’s not the only great magnetic option

    News & Updates
    Hostinger

    Highlights

    Development

    UK, US and Canada Accuse Russia of Plot to Interfere With Elections in Moldova

    June 14, 2024

    The UK, US and Canada have accused Russia of an elaborate plot to interfere in…

    Perficient Awards $5,000 Global Grants to Breakthrough T1D and The Akshaya Patra Foundation

    March 28, 2025

    Microsoft details how to fix Windows 10/11 blue screen of death (BSOD) issue

    May 13, 2025

    Don’t Fall for the Fake Job! FBI Warns of Work-From-Home Scams Using Cryptocurrency

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

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