Andrew Klager wrote:
>
> Is this so bad?
>
> func ternary(cond bool, pos, neg interface{}) interface{} {
> if cond {
> return pos
> } else {
>         return neg
> }
> }
>
> color := ternary( temp < 80, "blue", "red" )
>

The issue with that proposal is both true and false expressions are always 
evaluated. In (most?) other languages the non-relevant expression in a 
ternary expression will not be evaluated.

Your proposal would also typically requires type assertion, e.g.  

color := ternary( temp < 80, "blue", "red" ).(string)

Of course if Go were to add a built-in ternary() function that offered 
short-circuit expression evaluation and did not require type assertions, 
then IMO yes, it would be a good alternative to C++'s style ternary.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to