how to format multiple conditions assignments in return statement [CLOSED] [Answered]

Greetings, I was wondering, how could I properly format this piece of code.
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
You can see I tried to format it somehow, but I don't think it looks good. :D
11 Replies
jcotton42
jcotton423y ago
the way you format that is by changing it to if/if else/else my eyes are crossing just trying to read that
Scottek utek
Scottek utekOP3y ago
I thought that cond assign is faster than if else in most cases
jcotton42
jcotton423y ago
no there's no perf difference not sure where you got that idea from
Scottek utek
Scottek utekOP3y ago
I saw it somewhere, but it was with strings, not ints that's why probably
jcotton42
jcotton423y ago
still doesn't make a difference
Scottek utek
Scottek utekOP3y ago
and it was in cpp
jcotton42
jcotton423y ago
just change to regular if statements wouldn't be different there either
jcotton42
jcotton423y ago
that's due to a quirk of how C++ handles declarations
std::string blah;
blah = condition ? if-true : if-false;
std::string blah;
blah = condition ? if-true : if-false;
and
std::string blah;
if(condition) {
blah = if-true;
} else {
blah = if-false;
}
std::string blah;
if(condition) {
blah = if-true;
} else {
blah = if-false;
}
would perform exactly the same also that nested ternary in the video is an unreadable abomination the guy in the video is trying to be really clever but in a bad way don't be "clever" like that, you'll hate yourself down the line
Scottek utek
Scottek utekOP3y ago
well he's not exactly one of my favourites okay thanks for help
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server