@prologic@twtxt.net Which one? I don’t mind the ternary operator at all. In fact, I often find myself missing it in Go. I don’t find the two alternatives particularly elegant:

foo := "eggs"
if bar {
    foo = "spam"
}

Or:

var foo string
if bar {
    foo = "spam"
} else {
    foo = "eggs"
}

To my eye, this just would look a lot nicer:

foo := bar ? "spam" : "eggs"

Or at least as the Pythons do it:

foo = "spam" if bar else "eggs"

The ternary operator especially shines with relatively short expressions.

⤋ Read More

@lyse@lyse.isobeef.org The one in question is more like the javascript version for unwrapping errors when accessing methods.

 const value = some?.deeply?.nested?.object?.value

but for handling errors returned by methods. So if you wanted to chain a bunch of function calls together and if any error return immediately. It would be something like this:

b:= SomeAPIWithErrorsInAllCalls()
b.DoThing1() ?
b.DoThing2() ?

// Though its not in the threads I assume one could do like this to chain.
b.Chain1()?.Chain2()?.End()?

I am however infavor of having a sort of ternary ? in go.

PS. @prologic@twtxt.net for some reason this is eating my response without throwing an error :( I assume it has something to do with the CSRF. Can i not have multiple tabs open with yarn?

⤋ Read More

@lyse@lyse.isobeef.org I have no problems with the ternary operator either. If it were added to Go I Wouldn’t mind. C has it right? I’d also by happy with if expressions, e.g: if foo ... else bah, but probably doesn’t fit the styoe of the Go grammer.

What I absolutely hate is this proposal. Making ? to magical™ things, making the code harder to read and reason about is bonkers.

⤋ Read More

@prologic@twtxt.net Yes, C has it. I even thought that C invented it, but it seems to stem from CPL.

The closest to get to if expressions at the moment is to use a lambda:

foo := func() {
    if bar {
        return "spam"
    }
    return "eggs"
}()

But that’s also not elegant at all.

⤋ Read More

Participate

Login or Register to join in on this yarn.