Excellent idea!

Occasionally an error message needs to be created or elaborated, requiring 
a multi-line if statement body.

But the common situation is where the error is simply returned to the 
calling function using a single-statement if statement.

If these single-statement if statements could be:

if err != nil { return <any return arguments>, err }

the visual appearance of code would become far more compact and easier to 
read, and we wouldn't need any special new syntax.


On Sunday, 7 January 2018 03:09:41 UTC+11, 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1cdadf90-c7fa-4b30-b0dd-05416223fa61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to