Skip to content
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: Go 2: unified return parameter format #30947

Closed
godcong opened this issue Mar 20, 2019 · 6 comments
Closed

proposal: Go 2: unified return parameter format #30947

godcong opened this issue Mar 20, 2019 · 6 comments
Labels
FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change
Milestone

Comments

@godcong
Copy link

godcong commented Mar 20, 2019

Problem
when we return a value,now is:

func A() string{}
func B() (string){}
func C() (string,string){}
func D() (s string){}
func E() (s1 string,s2 string){}

some need brackets, and some not

can Go 2 unified all return parameter format in the same?

all has no brackets

func A() string{}
func B() string,string{}
func C() s string{}
func D() s1 string,s2 string{}

or all has brackets

func A() (string){}
func B() (string, string){}
func C() (s string){}
func D() (s1 string, s2 string){}

i think it will make the code looks more cleaner.

@gopherbot gopherbot added this to the Proposal milestone Mar 20, 2019
@ianlancetaylor ianlancetaylor added LanguageChange v2 A language change or incompatible library change labels Mar 20, 2019
@ianlancetaylor
Copy link
Contributor

You also have to consider the case in which the result parameters have names.

@godcong
Copy link
Author

godcong commented Mar 20, 2019

@ianlancetaylor added result parameters have names.

@ianlancetaylor
Copy link
Contributor

Thanks.

I think it's a nice feature that the result parameter list looks like the argument parameter list.

The exception is that we permit a single unnamed result parameter to not use parentheses. I'm not seeing a good reason to extend that exception to the whole parameter list.

@DylanMeeus
Copy link

DylanMeeus commented Mar 20, 2019

I don't think Go should enforce that you always need to use parenthesis around the return arguments.
But there's also nothing to prevent you from using that style yourself. Your example:

func A() (string){}
func B() (string, string){}
func C() (s string){}
func D() (s1 string, s2 string){}

Is already Valid go code, even though you could optionally drop the parens for single-value (non-named) returns.

@deanveloper
Copy link

deanveloper commented Apr 3, 2019

Perhaps this would be better suited to go fmt rather than a language change. I'm personally a fan of consistency but I don't think that this change is worth breaking old programs.

@ianlancetaylor
Copy link
Contributor

The current syntax is familiar and simple. This proposal doesn't bring any significant advantage. It does not address any problem that people have writing Go.

@golang golang locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants