Why I still teach Singleton even though modules make it…
    Neura MarketNeura Market/Stable Diffusion
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityStable DiffusionStable Diffusion
    DeepSeekDeepSeekCoPilotCoPilotMidjourneyMidjourney
    View All Directories
    OverviewPromptsBlogVideosGuidesCoursesCommunityModelsLoRAsComfyUI WorkflowsTrending
    Stable DiffusionBlogWhy I still teach Singleton even though modules make it redundant
    Back to Blog
    Why I still teach Singleton even though modules make it redundant
    webdev

    Why I still teach Singleton even though modules make it redundant

    Dmitry Sheiko June 12, 2026
    0 views

    Ask any developer what design pattern they know best and Singleton comes up first. Ask the same group...

    Ask any developer what design pattern they know best and Singleton comes up first. Ask the same group if they use it in production and half will say no. The module system already does the job.

    They're right. But I still include it in my patterns reference, and here's why.

    What Singleton actually solves

    The pattern ensures a class has only one instance and provides a global access point to it. Shared configuration loaded from env vars, a logger that buffers output, a connection pool you don't want duplicated. That kind of thing.

    The classical JavaScript version looks like this:

    class Config {
      static #instance = null;
      #data;
    
      constructor() {
        this.#data = {
          apiUrl: process.env.API_URL ?? "http://localhost:3000",
          timeout: Number(process.env.TIMEOUT ?? 5000),
        };
      }
    
      static getInstance() {
        if (!Config.#instance) {
          Config.#instance = new Config();
        }
        return Config.#instance;
      }
    
      get(key) {
        return this.#data[key];
      }
    }
    
    

    Boilerplate. Every time.

    The module alternative In JavaScript and Python, a module is already a singleton. The runtime caches it after the first import. So the same Config above becomes:

    // config.js
    export const config = {
      apiUrl: process.env.API_URL ?? "http://localhost:3000",
      timeout: Number(process.env.TIMEOUT ?? 5000),
    };
    
    // anywhere else
    import { config } from "./config.js";
    

    Same object, every import, no class, no getInstance(). Python works identically.

    So the pattern is "redundant" in the sense that you'd rarely write the classical version in a modern JS or Python codebase. You'd just export a module-level object.

    Why I still teach it

    Three reasons.

    You will read it in older code. Codebases written before ES modules were standard, Python 2-era code, Java and PHP services. If you've never seen the pattern explained properly, you'll waste time figuring out what the class is doing.

    It makes the intent explicit. A plain exported object and a Singleton both enforce one instance, but the Singleton makes that constraint visible and enforced at the type level. In teams, explicit beats implicit.

    Rust does not have the shortcut. OnceLock (stable since 1.70) or LazyLock (stable since 1.80) is the idiomatic way to get a static singleton in Rust. There is no module-level trick.

    use std::sync::LazyLock;
    
    static CONFIG: LazyLock<Config> = LazyLock::new(Config::from_env);
    

    That is the pattern, just dressed in modern syntax.

    The broader point

    This is what I tried to do with the whole reference. For each of the 23 GoF patterns, show the classical approach and then show what modern language features replaced or simplified it. Some patterns are still essential. Some you'd only write in a language without the shortcut. Some you'll only encounter as a reader, not a writer.

    The reference covers all 23 patterns plus the 5 SOLID principles, with examples in JavaScript, Python, and Rust. MIT licensed.

    https://github.com/dsheiko/design-patterns-for-web-developer

    Tags

    webdevjavascriptpythonrust

    Comments

    More Blog

    View all
    Context bankruptcy: The case for strategic forgetting for AI Agentsai

    Context bankruptcy: The case for strategic forgetting for AI Agents

    Most of us have seen a coding agent fail to complete a task we know it can do. We just don't...

    J
    James O'Reilly
    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestrationgooglecloud

    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestration

    When building Generative AI applications, developers often encounter a massive bottleneck: sequential...

    A
    Aryan Irani
    Is It Ethical to Post and Ask About Circuits on Dev.to?discuss

    Is It Ethical to Post and Ask About Circuits on Dev.to?

    I’ve been thinking about sharing some electronic circuit posts on Dev.to — small circuits, DIY...

    C
    codebunny20
    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limitsagents

    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limits

    What nobody tells you about exporting your multi-agent prototype to a local workspace. Every...

    L
    leslysandra
    Guarding the till while autonomous data agents do the diggingagenticarchitect

    Guarding the till while autonomous data agents do the digging

    Autonomous agents are genuinely good at answering messy business questions. Give one an LLM and a set...

    S
    Sireesha Pulipati
    Return on Attention: Why AI Code Reviews Are Wearing Us Outai

    Return on Attention: Why AI Code Reviews Are Wearing Us Out

    PR volume went up, ticket quality didn't, and the gap got filled with LLMs on both sides of the review: bots reviewing, bots replying, bots occasionally arguing with bots about priorities that only existed in a teammate's head. Our CEO named the actual problem, and it's bigger than code review.

    C
    christine

    Stay up to date

    Get the latest Stable Diffusion prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Stable Diffusion and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Stable Diffusion resource

    • Subscribe your team to blog or news (RSS + Email)make · Free · Uses make
    • Make a prefilled Airtable link for a new record in HubSpot CRM and shorten it by Rebrandlymake · Free · Uses make
    • Manage cancelled bookings from YouCanBook.me via KlickTippmake · Free · Uses make
    • Create draft payments for refund requests received by customersmake · Free · Uses make
    Browse all workflows