2 ms·
enum situation { boring, clear, cleaver } selector(context) if context.proves(cond1) return cleaver if context.proves(cond2) return cle
by psychoslave 8y ago
enum situation { boring, clear, cleaver }
selector(context)
if context.proves(cond1)
return cleaver
if context.proves(cond2)
return clear
return boring
adjudicator(context)
switch( selector(context) )
cleaver: make_something_cleaver()
clear: make_something_clear()
default: make_something_stupid_simple()
Not completely the same situation, though, as there are no assignation here. For simple cases (`v = e0 ? e1 : e2`), ternary operator sure is fine, but for more complex cases, `some_var = selector(context)` tend to be a clearer path. That will also be better rendered in your API as the function fine documentation will have more chance to be extracted properly.