A small suggestion for Go 2:
Allow implicit types and values in variable declaration blocks like there can be for constant declaration blocks. For example, this works:
const (
x int = 5
y
)
but this doesn't:
var (
x int = 5
y // syntax error: unexpected semicolon or newline
)
Allowing implied zero values would also be useful:
var (
x int
y
)
You can write this as
var (
x, y into
)
or even
var x, y int
I didn't know that const supported that syntax, but the last thing go needs
is more ways to declare variables.
On Sat, 8 Jul 2017, 09:57 Will Faught notifications@github.com wrote:
A small suggestion for Go 2:
Allow implicit types and values in variable declaration blocks like there
can be for constant declaration blocks. For example, this works:const (
x int = 5
y
)but this doesn't:
var (
x int = 5
y // syntax error: unexpected semicolon or newline
)Allowing implied zero values would also be useful:
var (
x int
y
)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/20951, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAcA3BwyMvZahnW033AaWCCzq7KARHiks5sLsXbgaJpZM4ORjfZ
.
@davecheney If you were to do that then you couldn't also document each one individually, e.g.
var (
// X...
X int
// Y...
Y
)
The two forms of declaration aren't equivalent, so I don't think redundancy is a concern here.
If your going to the effort of writing a comment, why not go through extra
mile and add the type as well?
On Sat, 8 Jul 2017, 10:29 Will Faught notifications@github.com wrote:
The two forms of declaration aren't equivalent, so I don't think
redundancy is a concern here.—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/20951#issuecomment-313821421, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAcA4j2qjGtJasytBCB_U-VAJacOgHAks5sLs1wgaJpZM4ORjfZ
.
You could similarly just write:
var x int
var y int
instead of:
var x, y int
so why not drop that superfluous syntax? In my opinion, this falls under the concerns of clarity and consistency of expression.
Example of exported use:
var (
// Dry...
Dry bool
// Quiet...
Quiet
// Verbose...
Verbose
// Sudo...
Sudo
// Home...
Home string
// User...
User
// Host...
Host
// ...
)
Example of unexported use:
var (
i int // i...
j // j...
k // k...
x float64 // x...
y // y...
z // z...
// ...
)
Along that same consistency line, it seems to me that it would actually simplify the language if the syntax were even more similar for both constant and variable blocks.
Please don't mistake brevity for readability; you're proposing a new form
which every go programmer would have to learn.
On Sat, Jul 8, 2017 at 11:02 AM, Will Faught notifications@github.com
wrote:
Along that same consistency line, it seems to me that it would actually
simplify the language if the syntax were even more similar for both
constant and variable blocks.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/20951#issuecomment-313823637, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAcA-JQK5n-mzMX4CIQoGudHcF4bqoEks5sLtVBgaJpZM4ORjfZ
.
I don't think I'm making that mistake; this is the first time you've mentioned that concern. Regarding readability, it seems to me that both constant and variable block declarations can have types, so if it makes sense to have "stamped" types for constants, I don't see why it doesn't make sense for variables too. Is there a reason you can think of to treat them differently in this respect? It seems like the only difference between the two syntaxes should be initialization.
I'd say the const declaration is the odd one out, which probably stems from
the way iota works.
On Sat, Jul 8, 2017 at 11:30 AM, Will Faught notifications@github.com
wrote:
I don't think I'm making that mistake; this is the first time you've
mentioned that concern. Regarding readability, it seems to me that both
constant and variable block declarations can have types, so if it makes
sense to have "stamped" types for constants, I don't see why it doesn't
make sense for variables too. Is there a reason you can think of to treat
them differently in this respect? It seems like the only difference between
the two syntaxes should be initialization.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/20951#issuecomment-313825307, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAcA_xy3M6noQfWcN1kk2zkuBYY-OUnks5sLtu4gaJpZM4ORjfZ
.
Good point, I can see that. I wonder whether it would be useful at all for var block decls to have type/expr "stamps" too, but that's a separate issue.
Can anyone help me out this is too smart for me
@allthewaylive247 What do you mean?
Most helpful comment
I'd say the const declaration is the odd one out, which probably stems from
the way iota works.
On Sat, Jul 8, 2017 at 11:30 AM, Will Faught notifications@github.com
wrote: