Feed aggregator
Global Tech-Sector Layoffs Surpass 244,000 In 2025
Read more of this story at Slashdot.
Wine 11.0 Released
Read more of this story at Slashdot.
JPEG-XL Image Support Returns To Latest Chrome/Chromium Code
Read more of this story at Slashdot.
Apple Bundles Creative Apps Into a Single Subscription
Read more of this story at Slashdot.
Taiwan Issues Arrest Warrant for OnePlus CEO for China Hires
Read more of this story at Slashdot.
EV Roadside Repairs Easier Than Petrol or Diesel, New Data Suggests
Read more of this story at Slashdot.
Apple: You (Still) Don't Understand the Vision Pro
Read more of this story at Slashdot.
Mercedes Temporarily Scraps Its Level 3 'Eyes-off' Driving Feature
Read more of this story at Slashdot.
Verizon To Stop Automatic Unlocking of Phones as FCC Ends 60-Day Unlock Rule
Read more of this story at Slashdot.
America's Biggest Power Grid Operator Has an AI Problem - Too Many Data Centers
Read more of this story at Slashdot.
Anthropic Invests $1.5 Million in the Python Software Foundation and Open Source Security
Read more of this story at Slashdot.
Scott Adams, Creator of the 'Dilbert' Comic Strip, Dies at 68
Read more of this story at Slashdot.
JPMorgan Warns 10% Credit Card Rate Cap Would Backfire on Consumers and Economy
Read more of this story at Slashdot.
Signal Creator Marlinspike Wants To Do For AI What He Did For Messaging
Read more of this story at Slashdot.
Meta Begins Job Cuts as It Shifts From Metaverse to AI Devices
Read more of this story at Slashdot.
Microsoft Pledges Full Power Costs, No Tax Breaks in Response To AI Data Center Backlash
Read more of this story at Slashdot.
Trump Says Microsoft To Make Changes To Curb Data Center Power Costs For Americans
Read more of this story at Slashdot.
Researchers Beam Power From a Moving Airplane
Read more of this story at Slashdot.
You Can Now Reserve a Hotel Room On the Moon For $250,000
Read more of this story at Slashdot.
CodeSOD: A Pirate's Confession
Today we have a true confession from Carl W. It has the benefit of being in R, which means that at a glance, I just assume "eh, looks fine to me." I guess I'm turning into Jimbo.
But let's dig into it. Carl's first snippet is this:
for(kk in 1:length(thematch)) { if(length(thematch)==0) break # actual code }"What WAS I thinking?" Carl asks.
You were thinking two things: you were thinking you wanted to iterate across a list, and you were thinking you didn't want to do anything if the list was empty. That these wires got crossed is natural- but sure, this isn't something that should end up in production code. The WTF is less the code itself, and more whatever allowed it to get released.
Carl's next snippet is described as "Yes, let's invert logicals as many times as possible."
slice <-rep(0,length(newxx)) slicelog<-as.logical(cuts[j]<=newyy & newyy<=cuts[j+1]) is.na(slice)<-!slicelogBecause R is weird, <- is one of the assignment operators (it also uses =, but for different purposes, and don't ask me to explain the difference), and because people like to have fun, it also has an -> operator (so the assignee is on the right side of the expression), and <<- and ->> versions which muck with scope in interesting ways.
In this example, the rep function replicates a value (0, in this case) length(newxx) times. So that gives us an array of zeros.
R supports broadcasting operations, so cuts[j] is an array and newyy is also an array (vector, if we're using R parlance), and by comparing two arrays we get an array of boolean values. Which we then pass to as.logical which converts an array into an array of boolean values.
Finally, in R, the NA value is their version of null. Thus is.na returns an array which is true if the original input held a null at that index, and false otherwise. Which is definitely going to be an array of falses, because slice holds an array of 0s. We just made it. Then we assign to the return value of that function. This is syntactically valid, but as you can imagine, it doesn't actually make sense- we just discard the result, at least based on me trying this in an R REPL.
Carl writes:
While the function containing these snippets was definitely a victim of "code it and design the requirements later," I can't believe that even Beginner Me wrote stuff that horrifying. But, it works perfectly so it ain't gonna get fixed.
Ah, that last sentence there, that is a dark truth. And it's important to note, it works perfectly: for now. But the world and runtime environment change. And someday, another developer will receive this code, and wonder, much like Carl, what the hell was going on when it was written.
In any case, Carl, consider yourself absolved. If it's stupid and it works, well, it's still stupid, but these WTFs are small and mostly self-contained.
Remember: code is a liability and starts accruing cruft and tech-debt the instant it's released. The functionality that code delivers is the asset, but that asset is inextricably tied to the code, which encodes assumptions about the world which, even if they were true to begin with, become increasingly false as the world changes.
Also, if you haven't figured out the headline, and because jokes are funnier when you explain them, this is clearly about a pirate's second favorite programming language, ARRRR. Why their second favorite? Because their first love will always be the C.
[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.