Feed aggregator
Wisk Aero, NASA Sign 5-Year Partnership To Advance Sustainable Autonomous Flights
Read more of this story at Slashdot.
New Bacteria Have Been Discovered on a Chinese Space Station
Read more of this story at Slashdot.
CodeSOD: A Trying Block
Mark sends us a very simple Java function which has the job of parsing an integer from a string. Now, you might say, "But Java has a built in for that, Integer.parseInt," and have I got good news for you: they actually used it. It's just everything else they did wrong.
private int makeInteger(String s) { int i=0; try { Integer.parseInt(s); } catch (NumberFormatException e) { i=0; return i; } i=Integer.parseInt(s); return i; }This function is really the story of variable i, the most useless variable ever. It's doing its best, but there's just nothing for it to do here.
We start by setting i to zero. Then we attempt to parse the integer, and do nothing with the result. If it fails, we set i to zero again, just for fun, and then return i. Why not just return 0? Because then what would poor i get to do?
Assuming we didn't throw an exception, we parse the input again, storing its result in i, and then return i. Again, we treat i like a child who wants to help paint the living room: we give it a dry brush and a section of wall we're not planning to paint and let it go to town. Nothing it does matters, but it feels like a participant.
Now, Mark went ahead and refactored this function basically right away, into a more terse and clear version:
private int makeInteger(String s) { try { return Integer.parseInt(s); } catch (NumberFormatException e) { return 0; } }He went about his development work, and then a few days later came across makeInteger reverted back to its original version. For a moment, he wanted to be mad at someone for reverting his change, but no- this was in an entirely different class. With that information, Mark went and did a search for makeInteger in the code, only to find 39 copies of this function, with minor variations.
There are an unknown number of copies of the function where the name is slightly different than makeInteger, but a search for Integer.parseInt implies that there may be many more.
[Advertisement] Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.Denver Detectives Crack Deadly Arson Case Using Teens' Google Search Histories
Read more of this story at Slashdot.
Brembo's New Brakes Cut Particulate Emissions By 90 Percent
Read more of this story at Slashdot.
Phone Companies Failed To Warn Senators About Surveillance, Wyden Says
Read more of this story at Slashdot.
SEC Sues Crypto Startup Unicoin and Its Executives For Fraud
Read more of this story at Slashdot.
Quebec To Impose French-Language Quotas On Streaming Giants
Read more of this story at Slashdot.
The Information: Microsoft Engineers Forced To Dig Their Own AI Graves
Read more of this story at Slashdot.
Most AI Chatbots Easily Tricked Into Giving Dangerous Responses, Study Finds
Read more of this story at Slashdot.
Apollo For Reddit Dev Christian Selig To Join Digg As an Advisor
Read more of this story at Slashdot.
Android XR Glasses Get I/O 2025 Demo
Read more of this story at Slashdot.
Microsoft Says 394,000 Windows Computers Infected By Lumma Malware Globally
Read more of this story at Slashdot.
AI Set To Consume Electricity Equivalent To 22% of US Homes By 2028, New Analysis Says
Read more of this story at Slashdot.
Why Does the US Always Run a Trade Deficit?
Read more of this story at Slashdot.
OpenAI Acquires Jony Ive's Startup in $6.5 Billion Deal To Create AI Devices
Read more of this story at Slashdot.
Windows 11 To Get Apple-Style App Continuity
Read more of this story at Slashdot.
Meta Targets More 'Underperformers' in Mid-Year Reviews
Read more of this story at Slashdot.
Google's Brin: 'I Made a Lot of Mistakes With Google Glass'
Read more of this story at Slashdot.
Amazon Gives Refunds for Years-Old Returns
Read more of this story at Slashdot.