3 ms·
> How do they suggest that? It might be a convention in some circles. I don't think it's a well-established one, though. For me, ternaries strongly suggest "e
by TeMPOraL 9y ago
> How do they suggest that?
It might be a convention in some circles. I don't think it's a well-established one, though.
For me, ternaries strongly suggest "expressions being run for its return value", but without any indication whether or not it's side effect-free. In practice, most of the time such expressions end up being side effect-free (getters, finders, etc.), but every now and then you do want to have a stateful expression (e.g. getting something from a map, and storing a default value there if the key is missing in the map). I believe such stateful expressions are fine to use with ternaries as well.
- emodendroket 9y agoOK, maybe I don't quite literally mean side effect-free. In that case I probably wouldn't think it's bad. What I would not expect in a ternary statement is code that, say, makes a network request, or writes to disk, or changes several different properties on the current object.