New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: spec: implicit types and values in variable declaration blocks #20951
Comments
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 ***@***.***> 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
<#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 ***@***.***> 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
<#20951 (comment)>, 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 ***@***.***> 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
<#20951 (comment)>, 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 ***@***.***> 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
<#20951 (comment)>, 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? |
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:
but this doesn't:
Allowing implied zero values would also be useful:
The text was updated successfully, but these errors were encountered: