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
-
working1279y@awol @bert what is it that you achieve by doing it? does it make your code order of magnitudes faster? how is one style significantly better than other?
-
working1279y@awol if your condition happens to return a null the verbose syntax actually returns the right value.
-
mb331249yIMO variables named "condition" should already be of Boolean type. If it's a nullable type then you shouldn't be testing it implicitly in an if anyway.
-
mb331249yvar authenticated = user?.loggedIn ?? false;
One line. Succinct. Readable.
My opinion: why write 5 lines when you can write one line (as long as clarity isn't lost)? -
bert2189y@working I like it when code is written in a verbose way to make it more readable, but in this case it is just unnecessarily. True is true because it is true, but only if true equals true considering it is true-ish. For js boolean expressions it can be necessary indeed, but that's because the language is crappy itself.
-
mb331249y^ agree. Verbosity for the sake of clarity == ok. Or should I have used ===? Damn it, JS!
-
mano2859yOr when you see someone write
if (condition) {
//whole lot of stuff
} else {
//exactly the same whole lot of stuff
//one extra line
} -
-Jay09yreadability is important but I would say something like this is easier to read without. also faster:
condition = false;
if(condition) {
return "foo"
}
return "falsy"
The main bonus is no else statement. -
james1149yIs it the bracket placement you're talking about? I don't personally have a preference but I know people seem to. What're the pros and cons of each?
Related Rants
When you see a someone write this
if(condition){
return true;
} else {
return false;
}
undefined
boolean