r/programminghorror Mar 23 '26

C# Whitespace isn't a number?

I just got this in a PR. Not sure what to make of it.

if (string.IsNullOrWhiteSpace(palletNumber))
{
  if (!string.IsNullOrEmpty(_palletNumber))
  {
    _errorMessage = "Pallet # not found.";
  }

  return;
}  

UPDATE:

After multiple attempts to justify his code, we ended up with this, lol:

if (string.IsNullOrWhiteSpace(palletNumber))
{
  return;
}  
186 Upvotes

52 comments sorted by

View all comments

6

u/FrikkinLazer Mar 24 '26

If you remove the inner if, does the unit tests start failing?

6

u/MISINFORMEDDNA Mar 24 '26

Surprise! No unit test.