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
-
Grumpy28829y@craig939393 @craig939393 It's just as stupid as writing
if (x == 1)
return 1
else if (x == 2)
return 2
else if (x == 3)
return 3
... ad infinitum. -
Crost40749y@Grumpy sorry, but I want to understand if you are willing.
say you were coding in JavaScript and an element could be in 3 different positions on the page. what not use an if statement like above in that circumstance? -
Grumpy28829y@craig939393 Because it's completely senseless to transform a value into itself before returning it. It's like going to the bank and exchange a $100 bill for another identical $100 bill. What's the point?
So, the proper code in my initial post is
return (a==b)
and in my previous comment, it would be
return x -
Crost40749yso your point is don't save things to variables when you don't need to? do it directly in the if statement?
-
Grumpy28829y@craig939393 No. Look at my previous comment: There's no if statement at all. There's no need for one.
-
I'd say return (a==b) is to the point, but I get how the abomination could happen. Especially while still learning. It's unnecessary but more clear about what's going on for a newbie dev.
Related Rants
At first it seemed harsh, but then I learned that he committed code like
if (a == b)
return true;
else
return false;
undefined
abomination