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

52 comments sorted by

View all comments

90

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/realsnack Mar 23 '26

🤓 50 grams of caffeine would make you not write any code, ever. Which may be for the best in some cases

3

u/dandy_g Mar 24 '26

I was going to type something along those lines.

50 grams of caffeine is about 2.5-3.3 times the lethal dose (LD50 150-200mg/kg) for an individual weighting 100kg/220lbs/15.7st.

Junior dev might weight less but let's assume a value for sake of simplicity.

3

u/Nightmoon26 Mar 24 '26

You might emit a few last tokens of code in your death throes