Computer
Trump: Apple Building in China is 'Unsustainable,' Could Exempt Some Companies From Tariffs
Read more of this story at Slashdot.
Bank of England Says AI Software Could Create Market Crisis For Profit
Read more of this story at Slashdot.
CodeSOD: A Steady Ship
You know what definitely never changes? Shipping prices. Famously static, despite all economic conditions and the same across all shipping providers. It doesn't matter where you're shipping from, or to, you know exactly what the price will be to ship that package at all times.
Wait, what? You don't think that's true? It must be true, because Chris sent us this function, which calculates shipping prices, and it couldn't be wrong, could it?
public double getShippingCharge(String shippingType, bool saturday, double subTot) { double shCharge = 0.00; if(shippingType.Equals("Ground")) { if(subTot <= 29.99 && subTot > 0) { shCharge = 4.95; } else if(subTot <= 99.99 && subTot > 29.99) { shCharge = 7.95; } else if(subTot <= 299.99 && subTot > 99.99) { shCharge = 9.95; } else if(subTot > 299.99) { shCharge = subTot * .05; } } else if(shippingType.Equals("Two-Day")) { if(subTot <= 29.99 && subTot > 0) { shCharge = 14.95; } else if(subTot <= 99.99 && subTot > 29.99) { shCharge = 19.95; } else if(subTot <= 299.99 && subTot > 99.99) { shCharge = 29.95; } else if(subTot > 299.99) { shCharge = subTot * .10; } } else if(shippingType.Equals("Next Day")) { if(subTot <= 29.99 && subTot > 0) { shCharge = 24.95; } else if(subTot <= 99.99 && subTot > 29.99) { shCharge = 34.95; } else if(subTot <= 299.99 && subTot > 99.99) { shCharge = 44.95; } else if(subTot > 299.99) { shCharge = subTot * .15; } } else if(shippingType.Equals("Next Day a.m.")) { if(subTot <= 29.99 && subTot > 0) { shCharge = 29.95; } else if(subTot <= 99.99 && subTot > 29.99) { shCharge = 39.95; } else if(subTot <= 299.99 && subTot > 99.99) { shCharge = 49.95; } else if(subTot > 299.99) { shCharge = subTot * .20; } } return shCharge; }Next you're going to tell me that passing the shipping types around as stringly typed data instead of enums is a mistake, too!
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!Lawmakers Are Skeptical of Zuckerberg's Commitment To Free Speech
Read more of this story at Slashdot.
Microsoft Windows 95 Reboot Chime and Minecraft Soundtrack Inducted Into National Recording Registry
Read more of this story at Slashdot.
US Army Says It Could Acquire Targets Faster With 'Advanced AI'
Read more of this story at Slashdot.
Anthropic Launches Its Own $200 Monthly Plan
Read more of this story at Slashdot.
WordPress Launches AI Site Builder Amid Company Restructuring
Read more of this story at Slashdot.
Google DeepMind Has a Weapon in the AI Talent Wars: Aggressive Noncompete Rules
Read more of this story at Slashdot.
Google Maps is Launching Tools To Help Cities Analyze Infrastructure and Traffic
Read more of this story at Slashdot.
Scientists Recreate Brain Circuit in Lab For First Time
Read more of this story at Slashdot.
The AI Therapist Can See You Now
Read more of this story at Slashdot.
Samsung and Google Partner To Launch Ballie Home Robot with Built-in Projector
Read more of this story at Slashdot.
China Raises Tariffs on US Goods To 84% as Rift Escalates
Read more of this story at Slashdot.
Enterprises Are Shunning Vendors in Favor of DIY Approach To AI, UBS Says
Read more of this story at Slashdot.
CodeSOD: Single or Mingle
Singletons is arguably the easiest to understand design pattern, and thus, one of the most frequently implemented design patterns, even- especially- when it isn't necessary. Its simplicity is its weakness.
Bartłomiej inherited some code which implemented this pattern many, many times. None of them worked quite correctly, and all of them tried to create a singleton a different way.
For example, this one:
public class SystemMemorySettings { private static SystemMemorySettings _instance; public SystemMemorySettings() { if (_instance == null) { _instance = this; } } public static SystemMemorySettings GetInstance() { return _instance; } public void DoSomething() { ... // (this must only be done for singleton instance - not for working copy) if (this != _instance) { return; } ... } }The only thing they got correct was the static method which returns an instance, but everything else is wrong. They construct the instance in the constructor, meaning this isn't actually a singleton, since you can construct it multiple times. Each new construction replaces the shared instance with a new one.
The real "magic" here, however, is the DoSomething, which checks if the currently active instance is also the most recently constructed instance. If it isn't, this function just fails silently and does nothing.
A common critique of singletons is that they're simply "global variables with extra steps," but this doesn't even succeed at that- it's just a failure, top to bottom.
[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.Clean Energy Powered 40% of Global Electricity in 2024, Report Finds
Read more of this story at Slashdot.
Fake Job Seekers Are Flooding US Companies
Read more of this story at Slashdot.
Hackers Spied on 100 US Bank Regulators' Emails for Over a Year
Read more of this story at Slashdot.
UK Creating 'Murder Prediction' Tool To Identify People Most Likely To Kill
Read more of this story at Slashdot.