Feed aggregator
A Third of UK Firms Using 'Bossware' To Monitor Workers' Activity, Survey Reveals
Read more of this story at Slashdot.
Apple Ships iOS 26, iPadOS 26 and macOS Tahoe 26 With 'Liquid Glass' UI Overhaul
Read more of this story at Slashdot.
AI's Economic Boost Isn't Showing Up in US GDP, Goldman Says
Read more of this story at Slashdot.
Anthropic Finds Businesses Are Mainly Using AI To Automate Work
Read more of this story at Slashdot.
'USB-A Isn't Going Anywhere, So Stop Removing the Port'
Read more of this story at Slashdot.
Google Shifts Android Security Updates To Risk-Based Triage System
Read more of this story at Slashdot.
'If We Want Bigger Wind Turbines, We're Gonna Need Bigger Airplanes'
Read more of this story at Slashdot.
AI Triggers 70% Collapse in Fresh Graduate Hiring at India's IT Giants That Employ 5.4 Million
Read more of this story at Slashdot.
What Happens After the Death of Social Media?
Read more of this story at Slashdot.
CodeSOD: Functionally, a Date
Dates are messy things, full of complicated edge cases and surprising ways for our assumptions to fail. They lack the pure mathematical beauty of other data types, like integers. But that absence doesn't mean we can't apply the beautiful, concise, and simple tools of functional programming to handling dates.
I mean, you or I could. J Banana's co-worker seems to struggle a bit with it.
/** * compare two dates, rounding them to the day */ private static int compareDates( LocalDateTime date1, LocalDateTime date2 ) { List<BiFunction<LocalDateTime,LocalDateTime,Integer>> criterias = Arrays.asList( (d1,d2) -> d1.getYear() - d2.getYear(), (d1,d2) -> d1.getMonthValue() - d2.getMonthValue(), (d1,d2) -> d1.getDayOfMonth() - d2.getDayOfMonth() ); return criterias.stream() .map( f -> f.apply(date1, date2) ) .filter( r -> r != 0 ) .findFirst() .orElse( 0 ); }This Java code creates a list containing three Java functions. Each function will take two dates and returns an integer. It then streams that list, applying each function in turn to a pair of dates. It then filters through the list of resulting integers for the first non-zero value, and failing that, returns just zero.
Why three functions? Well, because we have to check the year, the month, and the day. Obviously. The goal here is to return a negative value if date1 preceeds date2, zero if they're equal, and positive if date1 is later. And on this metric… it does work. That it works is what makes me hate it, honestly. This not only shouldn't work, but it should make the compiler so angry that the computer gets up and walks away until you've thought about what you've done.
Our submitter replaced all of this with a simple:
return date1.toLocalDate().compareTo( date2.toLocalDate() ); .comment { border; none; } [Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.A New Nuclear Rocket Concept Could Slash Mars Travel Time in Half
Read more of this story at Slashdot.
UK's Data Watchdog Warns Students Are Breaching Their Schools' IT Systems
Read more of this story at Slashdot.
The World's EV Owners Discover Unheated Batteries Lose Distance in Freezing Weather
Read more of this story at Slashdot.
Tens of Thousands of US Emergency Workers Trained on How to Handle a Robotaxi
Read more of this story at Slashdot.
Apple Claims 'Most Significant Upgrade to Memory Safety' in OS History
Read more of this story at Slashdot.
Japan Sets Record: Nearly 100,000 People Aged Over 100
Read more of this story at Slashdot.
African Island Demanding Government Action Punished with Year-Long Internet Outage
Read more of this story at Slashdot.
America's FTC Opens New Probe into Amazon and Google Advertising Practices
Read more of this story at Slashdot.
Can Lab-Grown Coral Restore Reefs Damaged By Climate Change?
Read more of this story at Slashdot.
Microsoft Escapes EU Competition Probe by Unbundling Teams for Seven Years, Opening API
Read more of this story at Slashdot.