// comment if(x < 10) { // comment1 if(x < 20) { // comment2 if(x < 30) { printf("hello, world\\n"); } } }
Comment on The Legends is among us
Jankatarch@lemmy.world 2 days agoThere are two types of programmers.
// comment1 if(condition1) { // comment2 if(condition2) { // comment3 if(condition3) { printf("hello, world\n"); } } }
and
// comment1 if(!condition!) { return; } // comment2 if(!condition2) { return; } // comment3 if(!condition3) { return; } printf("hello, world\n");
ICastFist@programming.dev 2 days ago
Jankatarch@lemmy.world 2 days ago
“Yeah x might be less than 10 but just in case check if it’s less than 30.”
underscores@lemmy.zip 2 days ago
This is the cursed case when you case the forbidden scroll of the ancients: switch (true) { }
undefined@lemmy.hogru.ch 2 days ago
I’m so the latter. The former drives me fucking crazy.
veganpizza69@lemmy.world 1 day ago
Add the
else
branches to the nested version and log the failed conditions (to make it more obvious).interdimensionalmeme@lemmy.ml 2 days ago
if(!condition) { return;}: If(!condition1) {return;}; if(!condition2) {return;};
rothaine@lemm.ee 2 days ago
if (condition && condition1 && condition2)
kernelle@0d.gs 1 day ago
The problem with this in the OP is the first ‘if’ checks if the object exists and the second gets a property of said object only if the original object exists.
I’m not saying the OP is good code, but chaining them like this would result in exceptions.
rothaine@lemm.ee 1 day ago
Not in a language with short circuiting.
kernelle@0d.gs 1 day ago
Could’ve sworn I’ve had this issue before! Maybe not with python
fushuan@lemmy.blahaj.zone 1 day ago
The language is python and it has short circuiting aka in an and condition, if the first block isn’t fulfilled the second one isn’t tested because it’s unnecessary.
Same with or and the reverse.