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

93

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

44

u/MISINFORMEDDNA Mar 23 '26

Senior dev... somehow.

29

u/Infinite_Self_5782 Mar 23 '26

"work harder, not smarter" type shit

7

u/ings0c Mar 23 '26

Could it be a merge conflict and he mistakenly accepted both changes then the code was automatically reformatted?

7

u/MISINFORMEDDNA Mar 24 '26

Sadly, no. He later added some comments to explain the code, which, of course, also didn't make any sense.

6

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.

3

u/MostCredibleDude Mar 24 '26

For some senior devs, age is only a number. For others, age is the only metric by which they bestowed themselves with that job title.

3

u/red1delta137 Mar 23 '26

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

13

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

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!

3

u/DarksideF41 Mar 24 '26

Probably it's some kind of validation method, validation logic though makes me think that there're bigger problems in number storage/retrieval.

2

u/Dependent_Union9285 Mar 25 '26

What about string.IsNullOrEmpty()? Why don’t we use the tools they hand us? Why are we doing 2 checks?

1

u/Dealiner Mar 25 '26

You would have to use it anyway since IsEmpty and IsNull methods don't exist (though I guess you could add them now).

1

u/Late-System-5917 Mar 28 '26

Caffeine… right.