Is it possible to work similar way like the function overloading or optional parameter in C# using Golang? Or maybe an alternative way?
No it does not.
Why does Go not support overloading of methods and operators? Method dispatch is simplified if it doesn't need to do type matching as well.
No, operator overloading is not a feature of Go.
Rust allows for a limited form of operator overloading. There are certain operators that are able to be overloaded. To support a particular operator between types, there's a specific trait that you can implement, which then overloads the operator.
The idiomatic answer to optional parameters in Go is wrapper functions:
func do(a, b, c int) {
// ...
}
func doSimply(a, b) {
do(a, b, 42)
}
Function overloading was intentionally left out, because it makes code hard(er) to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With