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

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      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

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      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

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

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

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

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

      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

    The best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    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

    CVE-2025-38226 – Linux Kernel V4L2 TPG Out-of-Bounds Write Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    This physical Clicks keyboard is the Pixel 9 upgrade I didn’t know I needed

    News & Updates

    CVE-2025-49157 – Trend Micro Apex One Damage Cleanup Engine Local Privilege Escalation Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-45842 – TOTOLINK NR1800X Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-1253 – RTI Connext Professional Classic Buffer Overflow

    May 8, 2025

    CVE ID : CVE-2025-1253

    Published : May 8, 2025, 9:15 a.m. | 2 hours, 52 minutes ago

    Description : Buffer Copy without Checking Size of Input (‘Classic Buffer Overflow’) vulnerability in RTI Connext Professional (Core Libraries) allows Overflow Variables and Tags.This issue affects Connext Professional: from 7.4.0 before 7.5.0, from 7.0.0 before 7.3.0.7, from 4.5 before 6.1.2.23.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Deconstructing the 35mm Website: A Look at the Process and Technical Details

    May 30, 2025

    I tried Samsung’s Project Moohan XR headset at I/O 2025 – and couldn’t help but smile

    May 21, 2025

    CVE-2025-3952 – Projectopia WordPress Project Management Unauthenticated Option Deletion

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

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