Coded Smorgasbord: Basically, a Smorgasbord

Date:

Share:

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 comments

Honestly, 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 Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

Source link

Subscribe to our magazine

━ more like this

‘People Who Go In That Locker Room Come Out…Different,’ Jets Custodian Warns Aaron Glenn

EAST RUTHERFORD, NJ—Speaking grimly as he mopped the floor beneath flickering fluorescent lights, longtime MetLife Stadium custodian Keith Browning reportedly approached first year New...

18 Chic Pieces From Boden’s Autumn Edit—All Editor Approved

Humaa is the Junior Branded Content Editor at Who What Wear UK, where she specialises in paid-for and affiliate content across beauty and fashion....

Analog(ue) #227: It’s Gonna Go How It’s Gonna Go

#227: It's Gonna Go How It's Gonna Go July 7th, 2024 · 80 minutes Casey's back from California, and soon he'll be joining Myke in London! This episode of Analog(ue) is...

The blueprint for AI in support didn’t exist. Until now.

Rolling out an AI Agent doesn’t just change how your team works – it changes who your team is. That’s something we learned firsthand. Before...

Extra 20% Off Bags & Shoes

If you’re already eyeing the early Labor Day sales popping up, there’s another big one to add to your list: Coach Outlet. The reader-favorite...