patterngoCritical
Optional Parameters in Go?
Viewed 0 times
optionalparametersstackoverflow
Problem
Can Go have optional parameters? Or can I just define two different functions with the same name and a different number of arguments?
Solution
Go does not have optional parameters nor does it support method overloading:
Method dispatch is simplified if it
doesn't need to do type matching as
well. Experience with other languages
told us that having a variety of
methods with the same name but
different signatures was occasionally
useful but that it could also be
confusing and fragile in practice.
Matching only by name and requiring
consistency in the types was a major
simplifying decision in Go's type
system.
Method dispatch is simplified if it
doesn't need to do type matching as
well. Experience with other languages
told us that having a variety of
methods with the same name but
different signatures was occasionally
useful but that it could also be
confusing and fragile in practice.
Matching only by name and requiring
consistency in the types was a major
simplifying decision in Go's type
system.
Context
Stack Overflow Q#2032149, score: 693
Revisions (0)
No revisions yet.