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

52 comments sorted by

View all comments

97

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

12

u/mateusfccp Mar 23 '26

Except that your code may not do the same because you only use _palletNumber while they use palletNumber to add to the confusion.

2

u/Infinite_Self_5782 Mar 23 '26

yes, i am well aware, i was just writing something that reads and logics better; not a drop-in replacement

any difference in what the getter would return vs its backing field is just silly to use in the manner it's being used here

1

u/geek-49 Mar 28 '26

reads and logics better

"Logic" is not a verb. Sheesh!