> > > This is meant as a followup to an earlier thread[1] on the subject and > the > > related ticket[2]. > > > > [1]: http://thread.gmane.org/gmane.comp.lang.rust.devel/2622/ > > [2]: https://github.com/mozilla/rust/issues/6974 > > > > The idea in those earlier discussions is that methods could also be > called > > using function syntax, supplying `self` as the first argument, so instead > > of `self_arg.method(arg)`, you could write `method(self_arg, arg)`. I'm > > wondering if this could be taken a couple steps further to simplify the > > whole story regarding functions, methods, traits, and impls. The idea is > > that the distiction between functions and methods would be erased almost > > completely, and methods (now being just functions) would be imported > > explicitly. > > > > It would involve the following pieces: > > > > - If the first argument of a top-level `fn` is named `self`, it can be > > called using method syntax. So if you have `fn foo(self: &MyType, n: int) > > { .. }` at the top level, you can write `object_of_my_type.foo(123)`. You > > can also still call it using function syntax: `foo(object_of_my_type, > 123)`. > > > > I see no reason for the restriction of "self". Why not simply say that any > function can be called with "first_arg.func(...)" style ? >
D has that rule (which they call UFCS), and I find it confusing sometimes. When a function is declared with function syntax and it makes sense or "feels right" that it "should" be a function, my mind is not expecting to see method syntax and I may have trouble figuring out later what an apparent method call refers to, even if I've seen the function declaration. Mind you it is worse in D than Rust, because in D, function declarations can be hidden inside what they call "eponymous templates", which has stumped me in the past. In any case, wouldn't it help narrow down searches if you could search for "fn foo(self" instead of only "fn foo"? (again though, Rust is not as bad for searching as the C-family languages that have no "fn" keyword.) In C# it's nice that I can find all the so-called extension methods by searching for "(this ".
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev