On Saturday, 8 February 2020 18:38:19 UTC, addi t0t08 wrote:
>
>
> Also, without any additional changes to the language. Go already allows 
> separating statements with semicolons, so it would be even possible to do 
> the following.
>
>
>
> f, err := os.Open(file1) ; pass err
> defer f.Close()
>
> g, err := os.Open(file2) ; pass err
> defer g.Close()
>
> .....
>
>
>
gofmt will expand that onto multiple lines.

I just don't like the magic treatment of error values.  For example, 
remember that error is an interface.  What if a function returns multiple 
values, but more than one of them happens to implement the error 
interface?  Which one will "pass" set?

ISTM that what we have today is workable and unambiguous.  To make it 
tidier, one could propose something like Ruby's "if" statement modifier:

f, err := os.Open(file)
return nil, SomeError if err != nil

but that has its own problems <https://stackoverflow.com/a/55089794>.

Given that zero values are well defined, you could also add Python's 
ability to treat any type's non-zero value as "true":

f, err := os.Open(file)
return nil, SomeError if err

I'm sure I read a post explaining why the go language designers rejected 
that, but I can't find it right now; only some opinion 
<https://stackoverflow.com/questions/36854094/historical-reference-on-why-go-creators-choose-to-not-treat-nil-as-false>
 
on stackoverflow.

In any case: go is not ruby or python.  Every language has its own warts 
and wrinkles and special cases you need to learn - in go's case these 
include things like nil interface values versus nil pointers inside 
interface values.  But thankfully, go has a relatively low number of these.

>From that point of view, *not* introducing new syntax makes the language 
better - even if it means being a bit more verbose in what you write.

I also found discussion at https://github.com/golang/go/issues/32825

-- 
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/9772e24d-f22d-4472-8e84-522aff08d70c%40googlegroups.com.

Reply via email to