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

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      Handling JavaScript Event Listeners With Parameters

      July 21, 2025

      I finally gave NotebookLM my full attention – and it really is a total game changer

      July 22, 2025

      Google Chrome for iOS now lets you switch between personal and work accounts

      July 22, 2025

      How the Trump administration changed AI: A timeline

      July 22, 2025

      Download your photos before AT&T shuts down its cloud storage service permanently

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

      Laravel Live Denmark

      July 22, 2025
      Recent

      Laravel Live Denmark

      July 22, 2025

      The July 2025 Laravel Worldwide Meetup is Today

      July 22, 2025

      Livewire Security Vulnerability

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

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
      Recent

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025

      Halo and Half-Life combine in wild new mod, bringing two of my favorite games together in one — here’s how to play, and how it works

      July 22, 2025

      Surprise! The iconic Roblox ‘oof’ sound is back — the beloved meme makes “a comeback so good it hurts” after three years of licensing issues

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Static State

    CodeSOD: Static State

    April 17, 2025

    Today’s Anonymous submitter was reviewing some C++ code, and saw this perfectly reasonable looking pattern.

    class SomeClass
    {
    public:
    	void setField(int val);
    	int getField();
    }
    

    Now, we can talk about how overuse of getters and setters is itself an antipattern (especially if they’re trivial- you’ve just made a public variable with extra steps), but it’s not wrong and there are certainly good reasons to be cautious with encapsulation. That said, because this is C++, that getField should really be declared int getField() const– appropriate for any method which doesn’t cause a mutation to a class instance.

    Or should it? Let’s look at the implementation.

    void SomeClass::setField(int val)
    {
    	setGetField(true, val);
    }
    
    void SomeClass::getField()
    {
    	return setGetField(false);
    }
    

    Wait, what? Why are we passing a boolean to a method called setGet. Why is there a method called setGet? They didn’t go and make a method that both sets and gets, and decide which they’re doing based on a boolean flag, did they?

    int SomeClass::setGetField(bool set, int val)
    {
    	static int s_val = 0;
    	if (set)
    	{
    		s_val = val;
    	}
    	return s_val;
    }
    

    Oh, good, they didn’t just make a function that maybe sets or gets based on a boolean flag. They also made the state within that function a static field. And yes, function level statics are not scoped to an instance, so this is shared across all instances of the class. So it’s not encapsulated at all, and we’ve blundered back into Singletons again, somehow.

    Our anonymous submitter had two reactions. Upon seeing this the first time, they wondered: “WTF? This must be some kind of joke. I’m being pranked.”

    But then they saw the pattern again. And again. After seeing it fifty times, they wondered: “WTF? Who hired these developers? And can that hiring manager be fired? Out of a cannon? Into the sun?”

    [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.16: Ubuntu 25.04, Fedora 42, ParticleOS and a Lot More Linux Stuff
    Next Article Model Performance Begins with Data: Researchers from Ai2 Release DataDecide—A Benchmark Suite to Understand Pretraining Data Impact Across 30K LLM Checkpoints

    Related Posts

    News & Updates

    I finally gave NotebookLM my full attention – and it really is a total game changer

    July 22, 2025
    News & Updates

    Google Chrome for iOS now lets you switch between personal and work accounts

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

    You can now share an app/browser window with Copilot Vision to help you with different tasks

    Operating Systems

    CVE-2025-2771 – BEC Technologies Router Authentication Bypass Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    10 Best AI Code Review Tools and How They Work

    Development

    QuantSpec: Self-Speculative Decoding with Hierarchical Quantized KV Cache

    Machine Learning

    Highlights

    Apple Pay and security – what you need to know

    April 9, 2025

    Mobile payments look set to be one of the defining technologies of 2015, as the…

    Distribution Release: Proxmox 8.4 “Virtual Environment”

    April 9, 2025

    Windows 11 24H2 now fully ready, downloads even if you don’t want it

    May 4, 2025

    CVE-2025-29690 – OA System Cross-Site Scripting (XSS)

    May 14, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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