3 ms·
> Personally, where I try to avoid using ternary operator, is places where I don't care about returned value. As i asked below: Why though?
by Mithaldu 9y ago
> Personally, where I try to avoid using ternary operator, is places where I don't care about returned value.
As i asked below: Why though?
- TeMPOraL 9y agoNo solid reason, just a feeling. I feel that if-else block communicates intent more clearly when you're dealing with statements - because it can't return a value in languages we're discussing, it's specialized for that job. The same motivation makes ternary better when we care about a value.
- Mithaldu 9y agoTo be honest, with that explanation the decision you made has nothing to do with ternaries, and is entirely just the mirroring of the decision the if forced on you. Also, > in languages we're discussing Don't bury that lede. If you're restricting what you're saying to a specific language say that bold and as the very first thing, so people don't end up wasting their time parsing your post in a different context. Rude.
- TeMPOraL 9y ago> To be honest, with that explanation the decision you made has nothing to do with ternaries, and is entirely just the mirroring of the decision the if forced on you. I like to think of it as using the dedicated tool for a job it was designed for. In my mind, it's a good rule of thumb because it enhances readability (compare "the principle of least surprise"). > Don't bury that lede. If you're restricting what you're saying to a specific language say that bold and as the very first thing, so people don't end up wasting their time parsing your post in a different context. Rude. Why? Come on, at this point in the thread we'll still discussing C++ derivatives. I thought it was obvious. Also: if a lanuguage has an if/else as an expression and has a ternary operator, then IMO there's a problem with that language being cluttered with duplicate syntax for the same thing.