Computer
Representative Line: Tern Down a Date
Today's anonymous submitter has managed to find a way to do date formatting wrong that I don't think I've seen yet. That's always remarkable. Like most such bad code, it checks string lengths and then adds a leading zero, if needed. It's not surprising, but again, it's all in the details:
// convert date string to yyyy/MM/DD return dtmValue.Year + "-" + ((dtmValue.Month.ToString().Length == 1)? ("0" + dtmValue.Month.ToString()): dtmValue.Month.ToString()) + "-" + ((dtmValue.Day.ToString().Length == 1)? ("0" + dtmValue.Day.ToString()): dtmValue.Day.ToString());This is only one line, but it has it all, doesn't it. First, we've got good ol' Hungarian notation, which conveys no useful information here. We've got a comment which tells us the code outputs /es, but the code actually outputs -. We've got ternaries that are definitely not helping readability here, plus repeated calls to ToString() instead of maybe just storing the result in a variable.
And, for the record, dtmValue.ToString("yyyy-MM-dd") would have done the correct thing.
.comment { border: none; } [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.Software Maker SAP Becomes Europe's Largest Company
Read more of this story at Slashdot.
Meta Considers Charging For Ad-Free Facebook and Instagram In the UK
Read more of this story at Slashdot.
Samsung CEO Han Jong-hee Passes Away At 63
Read more of this story at Slashdot.
2 In 5 Tech Workers Quit Over Inflexible Workspace Policies
Read more of this story at Slashdot.
Software Engineer Runs Generative AI On 20-Year-Old PowerBook G4
Read more of this story at Slashdot.
Jack Ma-Backed Ant Touts AI Breakthrough Using Chinese Chips
Read more of this story at Slashdot.
Microsoft Announces Security AI Agents To Help Overwhelmed Humans
Read more of this story at Slashdot.
'China's Engineer Dividend Is Paying Off Big Time'
Read more of this story at Slashdot.
FaunaDB Shuts Down But Hints At Open Source Future
Read more of this story at Slashdot.
DNA of 15 Million People For Sale In 23andMe Bankruptcy
Read more of this story at Slashdot.
'What CERN Does Next Matters For Science and For International Cooperation'
Read more of this story at Slashdot.
How a Nephew's CD Burner Inspired Early Valve To Embrace DRM
Read more of this story at Slashdot.
Researchers Search For More Precise Ways To Measure Pain
Read more of this story at Slashdot.
Pentagon Axes HR System After 780% Budget Overrun
Read more of this story at Slashdot.
Google Says It Might Have Deleted Your Maps Timeline Data
Read more of this story at Slashdot.
China Unveils a Powerful Deep-sea Cable Cutter That Could Reset the World Order
Read more of this story at Slashdot.
China Bans Compulsory Facial Recognition and Its Use in Private Spaces Like Hotel Rooms
Read more of this story at Slashdot.
AI Will Impact GDP of Every Country By Double Digits, Says Mistral CEO
Read more of this story at Slashdot.
Linux Kernel 6.14 Officially Released
Read more of this story at Slashdot.