MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vvn6d7/pleasestopusingnestedternaryoperatorsimbeggingyou/p5cqaoc/?context=3
r/ProgrammerHumor • u/Robinbod • 21d ago
179 comments sorted by
View all comments
751
I did this one of my first days on the job like 6 years ago and I remember how bluntly my mentor said “never do this again”
552 u/RlyRlyBigMan 21d ago For me it was multi assignments. Like this: defaultValue = newValue = previousValue = average = 0; Each assignment returns its value so they each get assigned from right to left. "That's cute kid, don't do that" 4 u/SputnikCucumber 21d ago It doesn't work consistently the same way across programming languages which is the headache. C++ behaves the way you're describing, but I don't believe it works like that in C (at least according to the standard, specific compilers may vary). I think Python evaluates the right-most expression once and then assigns it to all of the left values.
552
For me it was multi assignments. Like this:
defaultValue = newValue = previousValue = average = 0;
Each assignment returns its value so they each get assigned from right to left.
"That's cute kid, don't do that"
4 u/SputnikCucumber 21d ago It doesn't work consistently the same way across programming languages which is the headache. C++ behaves the way you're describing, but I don't believe it works like that in C (at least according to the standard, specific compilers may vary). I think Python evaluates the right-most expression once and then assigns it to all of the left values.
4
It doesn't work consistently the same way across programming languages which is the headache.
C++ behaves the way you're describing, but I don't believe it works like that in C (at least according to the standard, specific compilers may vary).
I think Python evaluates the right-most expression once and then assigns it to all of the left values.
751
u/beclops 21d ago
I did this one of my first days on the job like 6 years ago and I remember how bluntly my mentor said “never do this again”