Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread Robert Engels
I wouldn’t have don’t it that way. I would have made := mean all variables must be new. And = mean any new variable requires a decoration. So in this case, var x,err = means x is new and err is reused. The variable clauses are segregated by a , > On Apr 23, 2023, at 9:07 AM, Axel Wagner

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread 'Axel Wagner' via golang-nuts
On Sun, Apr 23, 2023 at 4:01 PM Robert Engels wrote: > Personally that syntax has always bothered me with readability. It > requires lots of previous knowledge in some cases. A syntax like > > x, var y int = blah > > Is more explicit that x is reused and y is declared. > That specific suggestion

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread Robert Engels
To clarify, the semantics of a go statement from a language perspective changes based on earlier statements. That is simply weird - and hurts readability. > On Apr 23, 2023, at 9:01 AM, Robert Engels wrote: > >  > Personally that syntax has always bothered me with readability. It requires >

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread Robert Engels
Personally that syntax has always bothered me with readability. It requires lots of previous knowledge in some cases. A syntax like x, var y int = blah Is more explicit that x is reused and y is declared. Go is all about being explicit until it isn’t. > On Apr 23, 2023, at 8:28 AM, 'Axel W

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread 'Axel Wagner' via golang-nuts
Just to nit-pick everyone: Short variable declarations are not there to omit type information. You can do that with a regular variable declaration: https://go.dev/play/p/6XePFCh-6G2 Short variable declarations exist to 1. be shorter and 2. allow you to avoid re-declaration errors when assigning mul

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread Jesper Louis Andersen
On Sun, Apr 23, 2023 at 12:31 AM jlfo...@berkeley.edu < jlforr...@berkeley.edu> wrote: > > Short definitions detract from one of Go’s primary goals - readability. I > started using Go in the first place because I wanted a strongly typed > language with explicit type declarations. > > Your claim of

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-23 Thread Shulhan
23 Apr 2023 05:31:25 jlfo...@berkeley.edu : > Short definitions detract from one of Go’s primary goals - readability. I > started using Go in the first place because I wanted a strongly typed > language with explicit type declarations.  > > As a result of all this, I’ve started to avoid short

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-22 Thread Bakul Shah
If you are not using an IDE, you can always use, for example, "go doc os.Open" to see what os.Open returns. For user packages, you can use for example "go doc github.com/benhoyt/goawk/parser.ParseProgram" from your directory that contains "go.mod" for your program. > On Apr 22, 2023, at 3:31 P

Re: [go-nuts] Short Variable Declarations Are Oversold

2023-04-22 Thread 'Dan Kortschak' via golang-nuts
On Sat, 2023-04-22 at 15:31 -0700, jlfo...@berkeley.edu wrote: > What type should I use to declare “file” in the parameter list for > myfunc()? As a new Go programmer I have to admit that I haven’t > memorized all the types used in the Go standard library. So, I have > to break off working on myfun

[go-nuts] Short Variable Declarations Are Oversold

2023-04-22 Thread jlfo...@berkeley.edu
As a beginning Go programmer, I was initially attracted to the short variable declaration syntax. It’s great for declaring variables of a simple type. What could be wrong with letting the Go compiler infer a variable type by looking at what’s being assigned to the variable, such as: func ma