Feed aggregator
Google Chrome Smashes Speedometer 3 Record With Massive Performance Gains
Read more of this story at Slashdot.
Anthropic CEO Warns 'All Bets Are Off' in 10 Years, Opposes AI Regulation Moratorium
Read more of this story at Slashdot.
Amazon Prepares To Test Humanoid Robots for Delivering Packages
Read more of this story at Slashdot.
OpenAI Says Significant Number of Recent ChatGPT Misuses Likely Came From China
Read more of this story at Slashdot.
Andrew Ng Says Vibe Coding is a Bad Name For a Very Real and Exhausting Job
Read more of this story at Slashdot.
California's Carbon Market Reaches an Inflection Point
Read more of this story at Slashdot.
California Court Says Holding Phone For Maps While Driving is Illegal
Read more of this story at Slashdot.
Data Center Boom May End Up Being 'Irrational,' Investor Warns
Read more of this story at Slashdot.
Waymo Set To Double To 20 Million Rides As Self-Driving Reaches Tipping Point
Read more of this story at Slashdot.
New Spying Claims Emerge in Silicon Valley Corporate Espionage Scandal
Read more of this story at Slashdot.
Endangered Classic Mac Plastic Color Returns As 3D-Printer Filament
Read more of this story at Slashdot.
Missions To Mars With Starship Could Only Take Three Months
Read more of this story at Slashdot.
CodeSOD: Integral to a Database Read
One of the key points of confusion for people unfamiliar with Java is the distinction between true object types, like Integer, and "primitive" types, like int. This is made worse by the collection types, like ArrayList, which needs to hold a true object type, but can't hold a primitive. A generic ArrayList<Integer> is valid, but ArrayList<int> won't compile. Fortunately for everyone, Java automatically "boxes" types- at least since Java 5, way back in 2004- so integerList.add(5) and int n = integerList.get(0) will both work just fine.
Somebody should have told that to Alice's co-worker, who spends a lot of code to do some type gymnastics that they shouldn't have:
try { ps = conn.prepareStatement(SQL_GET_LOT_WORKUP_STATUSES); ps.setLong(1, _lotId); rs = ps.executeQuery(); while (rs.next()) { result.add(new Integer(rs.getInt(1))); } } finally { CloseUtil.close(ps,rs); } // instatiate a the array _workupStatuses = new int[result.size()]; // convert the integers to ints for (int h=0; h<result.size(); h++) { _workupStatuses[h] = ((Integer)result.get(h)).intValue(); }This runs a query against the database, and then iterates across the result to populate a List type with integers, and right away we're getting into confused territory. rs.getInt returns an int primitive, which they manually box with new Integer, and stuff into the List. And look, I wouldn't really call that a WTF, but it's what they do next that leaves me scratching my head.
They initialize a private member, _workupStatuses to a new array of ints. Then they copy every integer from the result collection into the array, first by casting the get return value to Integer, then by pulling off the intValue.
In the end, this whole dance happens because Java ResultSet types open cursors on the database side and thus don't have the capacity to tell you how many rows they returned. You need to iterate across each record until it runs out of results. That's why they populate an intermediate list. Then they can check the size and create an array, but that itself is a big why. I'm not going to say that using arrays in Java is an instant anti-pattern, but it's always something to be suspicious of, especially when you're holding result sets. It's probably a premature optimization: the key performance distance is on insertions where an ArrayList may need to resize and copy its internal backing store.
My suspicion, however, is that this code falls into the category of "C programmer forced to do Java". They're comfortable with an array of integers, which is covers 90% of the data types you use in C but a dynamic, complicated data structure is horrifying to them. So they use it when they absolutely have to, and then throw it away as quickly as they can to get back to what they're familiar with.
.comment { border: none; } [Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
Meta's Push Into Defense Tech Reflects Cultural Shift, CTO Says
Read more of this story at Slashdot.
Chinese Hacked US Telecom a Year Before Known Wireless Breaches
Read more of this story at Slashdot.
Apple's Attempt To Pause App Store Antitrust Order Fails
Read more of this story at Slashdot.
WHIP Muxer Merged To FFmpeg For Sub-Second Latency Streaming
Read more of this story at Slashdot.
American Science & Surplus Is Fighting For Its Life
Read more of this story at Slashdot.
Apple Gave Governments Data On Thousands of Push Notifications
Read more of this story at Slashdot.
DreamWorks Co-Founder Katzenberg Likens AI To CGI Revolution
Read more of this story at Slashdot.