I just realize that go does not support function or method argument
default value?! Or I have missed some thing around?
Though, we can use closure for some purposes.But if there is a default
implamention it's will be much suitable.
Jason, just because there are ways to hack around it, and it's not
available in C, doesn't mean it shouldn't be considered for Go. Most
modern languages have a concept of default parameters, and they're
widely used in these languages.
In the Go library there are tons of situations where this feature
would be useful. I can think of two examples off the top of my head:
1. strings.Split requires a third parameter n, which is the most
number of substrings to return. The most common case is 0, so the
method could be written as:
func Split(s, sep string, n int = 0) []string
2. The template package has two methods: Parse and MustParse. Both
have the exact same signature, but one panics when there's an error,
so these methods could be reduced to one:
func Parse(s string, fmap FormatterMap, panicOnError bool=false) (t
*Template, err os.Error) .
In both cases, the interface is reduced to a more simple form.
- Mike
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Default_Arguments
Go is in many ways the language manifestation of Google's [C++] style
guide. While all points in there are arguable I find this one pretty
reasonable. So, I doubt this 'feature' will (should) be considered.
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Default_Argument_Values
There are clear pros and cons to this issue, but I'd rather look at
the tradeoffs and usability benefits than simply using a strawman and
comparing it to Google's C++ style guidelines.
- Mike
On Feb 8, 10:54 am, Peter Bourgon <peterbour...@gmail.com> wrote:
> Default parameters introduce a variability and unpredictability that
> Google has deemed Bad™:
>
> http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Defaul...
Huh. Learn something new every day.
> There are clear pros and cons to this issue, but I'd rather look at
> the tradeoffs and usability benefits than simply using a strawman and
> comparing it to Google's C++ style guidelines.
I don't know if it's a strawman, but point taken.