I find that one-concept-per-line, yielding more compact functions, is
easier to focus on, as it reduces vertical eye scanning and scrolling.

A single-line if stmnt and my switch example demonstrate
one-concept-per-line.

go fmt aspires to produce an odd sort of poetry, which I find inefficient.
It's especially bad in GitHub commits.

Providing a small menu of recommended project-wide formats, and allowing
maintainers to tailor one for their needs would be most helpful. As is, I
eschew it.

On Thu, Aug 16, 2018, 5:18 PM Christopher Nielsen <m4dh4t...@gmail.com>
wrote:

> How is a ternary more readable? I've found that they make code more
> complex and unreadable, in both C and the proposed go, and the one-liner
> you provide is equally or more unreadable than the more verbose if
> statement.
>
> On Thu, Aug 16, 2018, 16:55 Liam Breck <networkimp...@gmail.com> wrote:
>
>> 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. <m...@winterdrache.de> wrote:
>>
>>> On Wed, 15 Aug 2018 07:46:51 -0700 (PDT)
>>> Hoo Luu <qq510371...@gmail.com> 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 golang-nuts+unsubscr...@googlegroups.com.
>> 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