C
Join ServerC#
help
how to format multiple conditions assignments in return statement [CLOSED] [Answered]
PSpan Scott8/17/2022
Greetings, I was wondering, how could I properly format this piece of code.
You can see I tried to format it somehow, but I don't think it looks good. :D
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
Jjcotton428/17/2022
the way you format that is by changing it to if/if else/else
Jjcotton428/17/2022
my eyes are crossing just trying to read that
PSpan Scott8/17/2022
I thought that cond assign is faster than if else in most cases
Jjcotton428/17/2022
no
Jjcotton428/17/2022
there's no perf difference
Jjcotton428/17/2022
not sure where you got that idea from
PSpan Scott8/17/2022
I saw it somewhere, but it was with strings, not ints
PSpan Scott8/17/2022
that's why probably
Jjcotton428/17/2022
still doesn't make a difference
PSpan Scott8/17/2022
and it was in cpp
Jjcotton428/17/2022
just change to regular if statements
Jjcotton428/17/2022
wouldn't be different there either
PSpan Scott8/17/2022
Jjcotton428/17/2022
that's due to a quirk of how C++ handles declarations
Jjcotton428/17/2022
std::string blah;
blah = condition ? if-true : if-false;
and std::string blah;
if(condition) {
blah = if-true;
} else {
blah = if-false;
}
would perform exactly the sameJjcotton428/17/2022
also that nested ternary in the video is an unreadable abomination
Jjcotton428/17/2022
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
but in a bad way
don't be "clever" like that, you'll hate yourself down the line
PSpan Scott8/17/2022
well he's not exactly one of my favourites
PSpan Scott8/17/2022
okay thanks for help
AAccord8/17/2022
✅ This post has been marked as answered!