4 ms·
> I thought that privileging the first argument of a function, which is all that separates a method from a function, was understood to be an ugly hack. I though
by Jtsummers 4y ago
> I thought that privileging the first argument of a function, which is all that separates a method from a function, was understood to be an ugly hack. I thought that this was acknowledged now, and only legacy languages are stuck with it. Julia, Rust and Go don't do this. So it's going out of fashion and becoming legacy. [emphasis added]
What?
Go has methods which "privilege" the first argument to functions:
https://go.dev/tour/methods/1 https://go.dev/tour/methods/1
func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
Though it moves the argument out of the argument list and between the func keyword and method name.
Rust also has a notion of methods:
https://doc.rust-lang.org/rust-by-example/fn/methods.html https://doc.rust-lang.org/rust-by-example/fn/methods.html
Were you thinking of other languages?
- mappu 4y agoIn Go you can assign this "method" to a func(v Vertex) float64 and it will run just fine: https://go.dev/play/p/NBS4Fc3r0w- https://go.dev/play/p/NBS4Fc3r0w- It really is just syntax sugar,