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
-
@electrineer It's a great feature, but has to be used with caution to avoid that.
It can be used however, to make conditions more expressive:
bool areTouching(... subject, ... touchable) {
// Are rectangles subject and touchable touching each other?
...
bool outOfY = subjectBottomY < touchableTopY || subjectTopY > touchableBottomY; bool outOfX = subjectRightX < touchableLeftX || subjectLeftX > touchableRightX;
if(!outOfY && !outOfX)
return true;
else
return false;
// or: return !outOfY && !outOfX;
}
Is a lot more easy to understand than to put everything into one giant condition. -
You can use it for loads of stuff. How about `return array.length > 0;` It's super cringy when people only use operators in if conditions like they haven't understood what an expression is
-
@12bitfloat you're right, even Google's c++ style guide tells to use that as the variable will be in narrower scope.
Related Rants
Probably a veery long time ago, but being able to use what you use in if(...){} for e.g. booleans like "bool(ean) isX = a == x;".
And than reusing that value in if again and so on.
Even if it sounds trivial, there was a time where it was not and "==" was only associated with "you use that in if/while only" rather than "a == b" returns a bool(ean)/int.
Same goes for other arithmetic operators and && / || ofc.
random
wk169