Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
*sigh* That code annoyed me, I came over here to post... and forgot I was looking for an infinite loop somewhere in it and let the tests run for a couple minutes... :( maybe I should sleep... debug... sleep... :-/
-
Voxera115855yJust pray its left over from removing some other check.
But prepare for the worst.
At least its more or less harmless except in hi performance scenarios. -
C0D4681385yWhere did x come from?
Is it global?
Is it just left behind from a refactor that someone didn't finish?
Is this legit? -
Hazarth95035y@C0D4
@juneeighteen
It looks and reads like Java or .Net to me. which means the "x" is most probably a member variable in a class, maybe something like class Vector() or something that has x/y...
my assumption is that someone made the x/y Objects instead of primitives, so they are nullable, and wanted to assign a default value if its null, but instead screwed up and just returned "null" instead of "0" or something... -
Yes, it was Java, and it was new code not refactored legacy... just a horrible clueless getter for a member variable from someone who doesn't seem to understand how 'null' works. It was just supposed to not have an initial value and they didn't seem to think you could return null by returning the object....
-
@BluePanda so many of my colleagues forget how initial values work. I was tested on initial values of each data type in school. It’s important to memorize, and easy to test if you forget!
-
cprn17435y"they didn't seem to think you could return null by returning the object"
Actually, they knew the object can be null - they compared it to null in the if. Maybe it's just lack of coffee at 6am? Maybe the rest of it is better?
I'd just refactor as I read it. People hate me for it. I hate them for their code so we're even.
Seen in code:
public String getX(){
if (x != null){
return x;
}
else return null;
}
... I'm not gonna like looking at the rest of this, am I?
rant