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 comments

Honestly, I'm not sure if that comment is a statement of surrender or just an ironic joke. Either way, I get it.

[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!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *