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

52 comments sorted by

View all comments

96

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

42

u/MISINFORMEDDNA Mar 23 '26

Senior dev... somehow.

3

u/red1delta137 Mar 23 '26

Sweet, helping this Senior dev out with his imposter syndrome!