Indeed, the problem is largely go fmt, I already raised this, but no one
picked up on it:
I use this one-liner:
v := a; if t { v = b }
This is not compatible with go fmt, but that tool's effects are
undocumented (see issue 18790 <https://github.com/golang/go/issues/18790> which
was declined), and it has no switches to disable/enable features. A
syntax-aware sed is a good idea, but sadly go fmt destroys useful
constructs. Other examples:
err := fn()
if err != nil { return err }
switch v {
case 1: pkg.one()
case 2: pkg.two()
case 3: pkg.thrice()
}
On Thu, Aug 16, 2018, 3:30 PM Matthias B. <[email protected]> wrote:
> On Wed, 15 Aug 2018 07:46:51 -0700 (PDT)
> Hoo Luu <[email protected]> wrote:
>
> > 在 2018年8月15日星期三 UTC+8上午12:43:37,Mark Volkmann写道:
> >
> > > var color = temperature > 100 ? “red” : “blue”
> >
> >
> > Although this feature will not be accepted, we could just talk about
> > it. I prefer 'if-expression' to ternary.
> >
> > var color = if temperature > 100 { "red" } else { "blue" }
> >
> > vs. current if statement syntax:
> >
> > var color
> > if temperature > 100 {
> > color = "red"
> > } else {
> > color = "blue"
> > }
> >
>
> I get the impression that the real issue here is that gofmt will break
>
> if temperature > 100 { color = "red" } else { color = "blue" }
>
> over multiple lines and that what the people asking for a ternary
> operator really want is a one-liner. So ask yourselves, if gofmt were
> to format your ternary operator (or the above suggested if-expression)
> identical to the if statement, i.e. across the same number of lines,
> would you still want it?
>
> var color =
> if temperature > 100 {
> "red"
> } else {
> "blue"
> }
>
>
> var color =
> temperature > 100 ?
> "red"
> :
> "blue"
>
>
> If you would NOT use these, your real issue is with gofmt, not the Go
> language.
>
>
> MSB
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.