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

      Tiny Screens, Big Impact: The Forgotten Art Of Developing Web Apps For Feature Phones

      July 16, 2025

      Kong AI Gateway 3.11 introduces new method for reducing token costs

      July 16, 2025

      Native vs hybrid vs cross-platform: Resolving the trilemma

      July 16, 2025

      JetBrains updates Junie, Gemini API adds embedding model, and more – Daily News Digest

      July 16, 2025

      My favorite Bose products are on sale plus an extra 25% discount – if you buy refurbished

      July 16, 2025

      Microsoft saved $500 million using AI — after slashing over 15,000 jobs in 2025

      July 16, 2025

      Obsidian’s Xbox RPG Avowed gets another update bringing bug fixes and these new abilities — and it’s now Steam Deck Verified

      July 16, 2025

      Half of Windows PCs are still yet to upgrade to Windows 11 — and are running out of time, says study

      July 16, 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

      The details of TC39’s last meeting

      July 16, 2025
      Recent

      The details of TC39’s last meeting

      July 16, 2025

      Vector Search Embeddings and RAG

      July 16, 2025

      Python Meets Power Automate: Trigger via URL

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

      Ubuntu 25.10 Fixes the Dock’s Inconsistent Radii

      July 16, 2025
      Recent

      Ubuntu 25.10 Fixes the Dock’s Inconsistent Radii

      July 16, 2025

      Microsoft saved $500 million using AI — after slashing over 15,000 jobs in 2025

      July 16, 2025

      Obsidian’s Xbox RPG Avowed gets another update bringing bug fixes and these new abilities — and it’s now Steam Deck Verified

      July 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Single or Mingle

    CodeSOD: Single or Mingle

    April 9, 2025
    CodeSOD: Single or Mingle

    Singletons is arguably the easiest to understand design pattern, and thus, one of the most frequently implemented design patterns, even- especially– when it isn’t necessary. Its simplicity is its weakness.

    Bartłomiej inherited some code which implemented this pattern many, many times. None of them worked quite correctly, and all of them tried to create a singleton a different way.

    For example, this one:

    public class SystemMemorySettings
    {
        private static SystemMemorySettings _instance;
    
        public SystemMemorySettings()
        {
            if (_instance == null)
            {
                _instance = this;
            }
        }
    
        public static SystemMemorySettings GetInstance()
        {
            return _instance;
        }
    
        public void DoSomething()
        {
        ...
            // (this must only be done for singleton instance - not for working copy)
            if (this != _instance)
            {
                return;
            }
        ...
        }
    }
    

    The only thing they got correct was the static method which returns an instance, but everything else is wrong. They construct the instance in the constructor, meaning this isn’t actually a singleton, since you can construct it multiple times. You just can’t use it.

    And you can’t use it because of the real “magic” here: DoSomething, which checks if the currently active instance is also the originally constructed instance. If it isn’t, this function just fails silently and does nothing.

    A common critique of singletons is that they’re simply “global variables with extra steps,” but this doesn’t even succeed at that- it’s just a failure, top to bottom.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Article14 Best Free and Open Source Electronic Design Automation Tools
    Next Article Personalizziamo un po’ GNOME – Versione 2025

    Related Posts

    News & Updates

    My favorite Bose products are on sale plus an extra 25% discount – if you buy refurbished

    July 16, 2025
    News & Updates

    Microsoft saved $500 million using AI — after slashing over 15,000 jobs in 2025

    July 16, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-31177 – Gnuplot Heap Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    K4DirStat – small utility program

    Linux

    CVE-2025-6823 – Code-projects Inventory Management System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-3079 – HP Officejet and LaserJet Printer Passback Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    How Retrieval-Augmented Generation (RAG) Is Transforming Enterprise AI Solutions🔍

    May 22, 2025

    Post Content Source: Read More 

    Grow is a declarative website generator

    June 5, 2025

    Over 269,000 Websites Infected with JSFireTruck JavaScript Malware in One Month

    June 13, 2025

    Building an AIOps chatbot with Amazon Q Business custom plugins

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

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