For me, choosing to write    

color = temp < 80 ? { "blue", "red") 

 vs 
func ternary(cond bool, pos, neg interface{}) interface{} {
if cond {
return pos
} else {
        return neg
}
}
color := ternary( temp < 80, "blue", "red")

is a no brainer


On Wednesday, April 24, 2019 at 5:25:09 PM UTC-4, 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")
>
>
>
> On Wed, Apr 24, 2019 at 4:14 PM Chris Broadfoot <
> ch...@chrisbroadfoot.id.au <javascript:>> wrote:
>
>>
>>
>> On Wed, Apr 24, 2019 at 4:22 AM Robert Engels <ren...@ix.netcom.com 
>> <javascript:>> wrote:
>>
>>> Though to the ops point, not sure why Go doesn’t have the ternary 
>>> operator - which is pretty ubiquitous. 
>>>
>>
>> https://golang.org/doc/faq#Does_Go_have_a_ternary_form
>>  
>>
>>>
>>> On Apr 23, 2019, at 9:56 PM, Robert Engels <ren...@ix.netcom.com 
>>> <javascript:>> wrote:
>>>
>>> Why? You have saved 5 characters for no practical gain. I think you 
>>> would enjoy Ada. 
>>>
>>> On Apr 23, 2019, at 8:05 PM, lgo...@gmail.com <javascript:> wrote:
>>>
>>> It sure would be nice if Go syntax allowed programmers to replace 
>>>
>>> if ( test) {
>>> ...do sonething
>>> } else {
>>> ..do something else
>>> }
>>>
>>> with 
>>>
>>> ? (test) {
>>> //...do something
>>> }
>>> {
>>> //..do something else
>>> }
>>>
>>> The ? operator can be anything the Go language team considers appropriate
>>>
>>> -- 
>>> 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 golan...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>>> 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 golan...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> 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 golan...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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