At the moment func declarations leave it for the user, depending on whether 
the original was written on one line or not.

gofmt will change:

    func hi(){fmt.Println("Hi.")}
    func bye(){

    fmt.Println("Bye.")}


into:

    func hi() { fmt.Println("Hi.") }

    func bye() {

        fmt.Println("Bye.")

    }


So if statements could format the same way func declarations do.


On Monday, January 8, 2018 at 12:44:47 PM UTC+13, Jeff Goldberg wrote:
>
> Yes, but ...
>
> First the "yes" part.
>
> I find myself writing one line if statements, and then finding myself 
> annoyed at gofmt. When I write a one line if statement, there is a 
> presentational reason for it.
>
> But
>
> But such formatting would have to be an all or nothing thing if we wanted 
> consistency instead of developing a bunch of competing styles. There will 
> be case where there is only one statement within the conditional block 
> where doing it on one line isn't what we want. So we've got three choices 
> for the formatter.
>
> 1. Always put single statement if blocks on one line
> 2. Always do things as we do them now.
> 3. Leave it to the user.
>
> Number 3 leaves us with inconsistencies. And one of the reasons for gofmt 
> is to eliminate many style inconsistencies. So I think that (3) just is not 
> an option. That leaves us with a choice between (1) and (2). And with such 
> a choice, I think that 2 is the far better option, as the cases where (2) 
> is "wrong" are mildly irritating, while cases in which we do (1) where it 
> really isn't appropriate will be god-awful.
>
> So I'm happy to be mildly irritated when gofmt breaks up my single line 
> ifs when I consider the alternatives.
>
> Cheers,
>
> -j
>
> On Saturday, January 6, 2018 at 10:09:41 AM UTC-6, Tong Sun wrote:
>>
>> Hi, 
>>
>> *[This is just a thought, no flaming please if you don't agree]*
>>
>> Since `gofmt` supports one line func() definition, how about maintaining 
>> one line if statement as well if the user did so? 
>>
>> This way, many of the simple three line code can be simplified to one:
>>
>> I.e., from 
>>
>>  if !condition {
>>    return
>>  }
>>
>>
>> to just 
>>
>>  if !condition { return }
>>
>>
>> *provided* that the user uses the one line if format in the first place. 
>>
>> Thus, a *typical sample* code can be dramatically simplified, because so 
>> many three-line error checkings can now be, 
>>
>> if err != nil { panic("something wrong") }
>>
>> Thoughts? 
>>
>>
>>

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