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

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

      June 4, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 4, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 4, 2025

      Smashing Animations Part 4: Optimising SVGs

      June 4, 2025

      I test AI tools for a living. Here are 3 image generators I actually use and how

      June 4, 2025

      The world’s smallest 65W USB-C charger is my latest travel essential

      June 4, 2025

      This Spotlight alternative for Mac is my secret weapon for AI-powered search

      June 4, 2025

      Tech prophet Mary Meeker just dropped a massive report on AI trends – here’s your TL;DR

      June 4, 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

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025
      Recent

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025

      Simplify Negative Relation Queries with Laravel’s whereDoesntHaveRelation Methods

      June 4, 2025

      Cast Model Properties to a Uri Instance in 12.17

      June 4, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025
      Recent

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025

      Rilasciata /e/OS 3.0: Nuova Vita per Android Senza Google, Più Privacy e Controllo per l’Utente

      June 4, 2025

      Rilasciata Oracle Linux 9.6: Scopri le Novità e i Miglioramenti nella Sicurezza e nelle Prestazioni

      June 4, 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 test AI tools for a living. Here are 3 image generators I actually use and how

    June 4, 2025
    News & Updates

    The world’s smallest 65W USB-C charger is my latest travel essential

    June 4, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    The Dumbest Thing in Security This Week: Worst. Phishing. Test. EVER.

    Development

    Using CSS backdrop-filter for UI Effects

    News & Updates

    The Samsung Galaxy Watch 4 is on sale for just $99 right now

    Development

    Researchers from KAUST and Harvard Introduce MiniGPT4-Video: A Multimodal Large Language Model (LLM) Designed Specifically for Video Understanding

    Development

    Highlights

    The Ultimate Guide to Solo Beach Trips in USA

    June 16, 2024

    Post Content Source: Read More 

    Pixelpusher is a drone-based team combat game

    April 16, 2025

    The Allen Institute for AI (AI2) Releases Tülu 3 405B: Scaling Open-Weight Post-Training with Reinforcement Learning from Verifiable Rewards (RLVR) to Surpass DeepSeek V3 and GPT-4o in Key Benchmarks

    January 31, 2025

    CISA Warns of Critical Unauthenticated Access Vulnerability in Instantel Micromate Devices

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

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