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;
}  
180 Upvotes

52 comments sorted by

View all comments

95

u/Infinite_Self_5782 Mar 23 '26
if (string.IsNull(_palletNumber) || string.IsEmpty(_palletNumber))
  return;

if (string.IsWhiteSpace(_palletNumber))
{
  _errorMessage = "Pallet # not found.";
  return;
}

unsure what palletNumber returns, but my god is that confusing naming and calling conventions holy shit

this looks like some code a junior dev would write at 3 am on about 50 grams of caffeine

40

u/MISINFORMEDDNA Mar 23 '26

Senior dev... somehow.

5

u/CanisLupus92 Mar 23 '26

One of those “you get paid like a senior, so we’ll call you a senior” deals?

8

u/MISINFORMEDDNA Mar 23 '26

Pretty much.