Placement of parameters for methods makes generic methods awkward #1512
Replies: 2 comments
-
It depends on what you want that method to be a member of. If it's a member of
(I also added If you want |
Beta Was this translation helpful? Give feedback.
-
I do not think this is a problem. Instead of trying to distinguish between the two, they could be considered as the same concept, which is allowed to be called both ways. So would be strictly equivalent to
(this is what python does, as far as I know. method syntax is just syntactic sugar) This makes the language overall simpler, as there is now one fewer concepts. Methods are just functions. |
Beta Was this translation helpful? Give feedback.
-
So when you have an instance method, what differentiates it from a static method is that it accepts as an implicit parameter in the [] block a value of type Self:
However, Self is already a keyword for (as far as I can tell) "the type of this object", so why are methods not just defined as functions having the first parameter be Self, possibly const qualified, possibly pointer qualified?
In particular, the current design makes it very confusing to me where I would add a generic parameter. For example, lets assume I wanted to get the
Distance
to any object that implementsPointlike
defined as:How would I write that method with the current syntax?
Beta Was this translation helpful? Give feedback.
All reactions