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
-
A classmate almost failed his test because of this. He forgot the else and with it, the code would have worked. :)
-
I NEVER use else, only modifying & guard ifs with early returns. I find it makes code easier to understand, and often prevents you from executing unnecessary code.
How? You first do your safety checks and return special values. If you still feel like you need else, maybe swap a bool using not. And finally, if you STILL need else, your method is probably too long and has too many responsibilities.
I only make exceptions for simple ternaries. -
7Raiden8757y@bittersweet I totally agree! If you need some fast branch prediction you can always use PGO ;)
-
Kimmax109877y@bittersweet this is how it should be done
Also TryXY() methods with out parameters for things that can fail, but aren't critical to fail
That moment.
undefined