Computer
Bot Students Siphon Millions in Financial Aid from US Community Colleges
Read more of this story at Slashdot.
Meta Blocks Apple Intelligence in iOS Apps
Read more of this story at Slashdot.
How a Secretive Gambler Called 'The Joker' Took Down the Texas Lottery
Read more of this story at Slashdot.
India's IT Services Giants Hit With Steepest Growth Slowdown in Years
Read more of this story at Slashdot.
China Bans 'Smart' and 'Autonomous' Driving Terms From Vehicle Ads
Read more of this story at Slashdot.
How Nintendo's Legal Team Destroyed Atari Games Through Courtroom Strategy
Read more of this story at Slashdot.
LG TVs' Integrated Ads Get More Personal With Tech That Analyzes Viewer Emotions
Read more of this story at Slashdot.
CodeSOD: Static State
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.Astronomers Detect a Possible Signature of Life on a Distant Planet
Read more of this story at Slashdot.
'We Are Not Programmed to Die,' Says Nobel Laureate Venki Ramakrishnan
Read more of this story at Slashdot.
Microsoft Confirms Classic Outlook CPU Usage Spikes, Offers No Fix
Read more of this story at Slashdot.
Harvard's RoboBee Masters Landing, Paving Way For Agricultural Pollination
Read more of this story at Slashdot.
Researchers Grow Record-sized Lab Meat
Read more of this story at Slashdot.
Discord Begins Testing Facial Recognition Scans For Age Verification
Read more of this story at Slashdot.
Following Layoffs, Automattic Employees Discover Leak-Catching Watermarks
Read more of this story at Slashdot.
First Global Pandemic Treaty Agreed - Without the US
Read more of this story at Slashdot.
The Last RadioShack In Maryland Is Closing Its Doors
Read more of this story at Slashdot.
OpenAI In Talks To Buy Windsurf For About $3 Billion
Read more of this story at Slashdot.
Google Used AI To Suspend Over 39 Million Ad Accounts Suspected of Fraud
Read more of this story at Slashdot.
OpenAI Debuts Codex CLI, an Open Source Coding Tool For Terminals
Read more of this story at Slashdot.