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.
You also have to consider the case in which the result parameters have names.
@ianlancetaylor added result parameters have names.
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.
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.
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.
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.
Most helpful comment
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:
Is already Valid go code, even though you could optionally drop the parens for single-value (non-named) returns.