Computer
Epic Games Sues Google and Samsung Over App Store Restrictions
Read more of this story at Slashdot.
Mars' Long-Lost Atmosphere Might Be Hiding in Plain Sight
Read more of this story at Slashdot.
Exxon Mobil's 'Advanced' Technique for Recycling Plastic? Burning It
Read more of this story at Slashdot.
CodeSOD: Switch How We Do Padding
We've seen so many home-brew string padding functions. And yet, there are still new ways to do this wrong. An endless supply of them. Nate, for example sent us this one.
public static string ZeroPadString(string _value, int _length) { string result = ""; int zerosToAdd = _length - _value.length;I'm going to pause right here. Based on this, you likely think you know what's coming. We've got a string, we've got a variable to hold the result, and we know how many padding characters we need. Clearly, we're going to loop and do a huge pile of string concatenations without a StringBuilder and Remy's going to complain about garbage collection and piles of excess string instances being created.
That's certainly what I expect. Let's see the whole function.
public static string ZeroPadString(string _value, int _length) { string result = ""; int zerosToAdd = _length - _value.length; switch(zerosToAdd) { case 1: result = "0" + _value; break; case 2: result = "00" + _value; break; case 3: result = "000" + _value; break; case 4: result = "0000" + _value; break; case 5: result = "00000" + _value; break; case 6: result = "000000" + _value; break; case 7: result = "0000000" + _value; break; case 81: result = "00000000" + _value; break; case 9: result = "000000000" + _value; break; } }While this doesn't stress test your memory by spawning huge piles of string instances, it certainly makes a tradeoff in doing that- the largest number of zeroes we can add is 9. I guess, who's ever going to need more than 10 digits? Numbers that large never come up.
Once again, this is C#. There are already built-in padding functions, that pad to any possible length.
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Could Atom-Sized Black Holes Be Detected in Our Solar System?
Read more of this story at Slashdot.
America's Vice President Gets Stuck Behind a Stalled Driverless Robotaxi
Read more of this story at Slashdot.
The Hot New Trend in Commercial Real Estate? Renting to Data Centers
Read more of this story at Slashdot.
California's Governor Just Vetoed Its Controversial AI Bill
Read more of this story at Slashdot.
New Flexible RISC-V Semiconductor Has Great Potential
Read more of this story at Slashdot.
SpaceX Pausing Launches to Study Falcon 9 Issue on Crew-9 Astronaut Mission
Read more of this story at Slashdot.
67% of American Tech Workers Interested In Joining a Union
Read more of this story at Slashdot.
Are Your Phone's 5G Icon and Signal Bars Lying to You?
Read more of this story at Slashdot.
America's FDA Approves First New Drug for Schizophrenia in Over 30 Years
Read more of this story at Slashdot.
Clean Energy Should Get Cheaper and Grow Even Faster
Read more of this story at Slashdot.
Are AI Coding Assistants Really Saving Developers Time?
Read more of this story at Slashdot.
California's Governor Vetoes Bill Requiring Speeding Alerts in New Cars
Read more of this story at Slashdot.
Can AI Developers Be Held Liable for Negligence?
Read more of this story at Slashdot.
US Transportation Safety Board Issues Urgent Alert About Boeing 737 Rudders
Read more of this story at Slashdot.
Why Boeing is Dismissing a Top Executive
Read more of this story at Slashdot.
How I Booted Linux On an Intel 4004 from 1971
Read more of this story at Slashdot.