set with different values
hey everyone, i am a total noob and i want to ask if there is a way for set having different values with different conditions? like
14 Replies
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
even if they did
it will throw stack overflow exception
its also violating "the rule of least surprise"
a setter not setting a value I give it is very surprising
Honestly ig, it is better to extract that logic to a method…I don’t think it should be the job of setters
it is, thats one of the main reasons properties exist
nah i just have a code that requieres setters
sorry if i spelt it wrong
this would be a potential result from the above
and make me throw your code in the nearest garbage bin
😔
if I set it to true, and thats not allowed, throw an exception
dont silently set it to false instead
setting Bool2 to false or true wont make a difference, because your setter never reads the value
Based on the code given, my interpretation was they wanted something more akin to
But they said the code requires setters so idk
yeah, which absolutely fucks with your expectations
if I set it to true, I expect it to be true, or throw an exception
I too somehow agree with that, silently modifying it internally will be a disaster sometimes
Yes, I would expect it to compute the value based on the input (value that I set), not based on some random value
a
. If I set Bool2 = true
and the state got changed due to some other random variable seems a bit off for me. I don't think thats an actual behaviour of setter.