Feed aggregator
Coded Smorgasbord: Basically, a Smorgasbord
It's that time to take a look at a few short snippets.
Boolean values can hold true or false. But is that truly self documenting? I think we need clearer variable names for this. Certainly, the snippet Nonymous found thinks so:
boolean isTrue = false;Well, at least I'll know if it's true or not. I'm not sure what "it" is in this scenario, but I'm sure that's the least important part of all of this.
If you've worked in C#, you're aware that it offers both a string type, and a String type- they're the same thing. So Colin's co-worker isn't wrong for writing code this way, but they're also wrong for writing code this way.
writer.WriteLine(string.Empty); writer.WriteLine(String.Empty);Billie sends us this short bit of Java, which ensures that nulls are properly handled:
if (val == null) { return null; } return val;It's very important that, if val is null, we don't just return the contents of val, we should return null instead. Y'know, so no one is surprised by an unexpected null. Wait a second…
Finally, Jon finds this comment in the codebase. The code is elided, but I Jon has helpfully summarized it.
// Basically, … several thousand lines of dense code containing no further commentsHonestly, I'm not sure if that comment is a statement of surrender or just an ironic joke. Either way, I get it.
.comment { border: none; } [Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
Putin and Xi Caught Discussing Organ Transplants and Immortality
Read more of this story at Slashdot.
Switzerland Releases Open-Source AI Model Built For Privacy
Read more of this story at Slashdot.
Google's Latest Pixel Drop Brings the Material 3 Expressive UI To Older Devices
Read more of this story at Slashdot.
Garmin Beats Apple to Market with Satellite-Connected Smartwatch
Read more of this story at Slashdot.
AI Generated 'Boring History' Videos Are Flooding YouTube, Drowning Out Real History
Read more of this story at Slashdot.
Supermarket Giant Tesco Sues VMware, Warns Lack of Support Could Disrupt Food Supply
Read more of this story at Slashdot.
Instagram Is Coming To iPad, 15 Years Later
Read more of this story at Slashdot.
Cloudflare Stops New World's Largest DDoS Attack Over Labor Day Weekend
Read more of this story at Slashdot.
US Workers Are Becoming More Stressed About Finances, BofA Survey Shows
Read more of this story at Slashdot.
The New Dolby Vision 2 HDR Standard is Probably Going To Be Controversial
Read more of this story at Slashdot.
FreeBSD Project Isn't Ready To Let AI Commit Code Just Yet
Read more of this story at Slashdot.
Dumbing Down the SAT Bodes Poorly for Education
Read more of this story at Slashdot.
America is in a Serious Jobs Slump
Read more of this story at Slashdot.
Streameast, World's Largest Illegal Sports Streaming Platform, Shut Down in Sting
Read more of this story at Slashdot.
Google Critics Think the Search Remedies Ruling is a Total Whiff
Read more of this story at Slashdot.
Amazon Must Face US Nationwide Class Action Over Third-Party Sales
Read more of this story at Slashdot.
Common Pesticide Linked To Widespread Brain Abnormalities In Children
Read more of this story at Slashdot.
World's Biggest Iceberg Breaks Up After 40 Years
Read more of this story at Slashdot.
CodeSOD: Adding to the Argument
David G saw a pull request with a surprisingly long thread of comments on it. What was weirder was that the associated ticket was all about adding a single parameter to an existing method. What could be generating that much discussion?
How could adding an argument add to an argument?
registerFooWrapper: function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7, }); }); }This is the original version of the JavaScript function. The parameter names have been anonymized. That aside, this still isn't very good. Seven parameters is likely too many, and based on what I see in setting the context, there is an object type that holds them all, so maybe we should be passing the object around in the first place? Still, this isn't a WTF by any stretch, and since it's already deployed code, changing the interface significantly is a bad idea- maybe just adding a parameter is the right choice here. So what generated so much discussion?
This revision:
registerFooWrapper: function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, notArg8) { if (notArg8 === true) { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7, arg8: !notArg8, }); }); } else { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7 }); }); } }Okay, so if notArg8 is true, we pass false to the context. If it's any other value, we don't past arg8 at all. I do not understand what I'm looking at here. If the goal is to ensure that arg8 is either true or not set, there are clearer ways to express that idea. But also, the goal of the ticket was not to do that- it was simply to add another parameter, which means you could drop the condition entirely and just add the parameter. context was already receiving arg8 as undefined, so it could clearly handle an undefined value.
David made some comments on the pull request, but the original developer just ended up going radio silent on it. One of the juniors on David's team approved it, for some reason, but nobody ever actually hit merge. Instead, a different developer simply made a version that took arg8 as a parameter, passed it down to context, and called it a day. It worked, the tests passed, and everyone was happy.
Well, except the original developer, but again, who knows what they were trying to do?
[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.