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
-
Froot75547yIm on the fence with simple one line ifs.
Like:
if (asd === null) return;
Breaking those into multiple lines makes my design nerve twitch. It seems too long and drawn out. On the other hand your points make sense and I don't really have a good justification for having them on a single line so I always try to write:
if (x === null) {
return;
}
Tho here's the kicker. By same logic, you may want to add conditions. And when you do you should also split the conditional part. So then you should write it like so so you can easily add conditions later:
if (
x === null
) {
return;
}
But now it's really fucking drawn out.
I don't know... Currently I stick with what the OP suggests. Seems like the best of both worlds
Also, if you write:
if (x === null)
return;
then please fuck off! Go die in a hole. Burn!
No-one can read that shit and it provides 0 benefit. It even looks ugly 😄 -
Root826027yI disagree in cases of multiple single-line blocks, e.g.
if (!flag_one) blah;
if ( flag_two) blah;
The aligning absolutely makes it easier to read. -
Rohr7357yI seriously like the one-line-style from bash:
[ $a -eq $b ] && do_stuff || do_other_stuff
Makes code look so advanced 😂 -
cursee171597yI use auto format package with my sublime and it put {} even if I wrote a one line if statement.
I always use brackets for clarity even if there is only one statement inside them
if (boolean){
function ();
}
Cus it's so much easier to read, and if I need to add statements after the if I don't need to remember to add brackets. Plus the else may need brackets and an if with no brackets but an else with brackets looks awful.
rant