3 ms·
Take Java as an example. In Java, there are no free functions. Every method belongs to an object or a class. So you couldn't write `f(a, b, c)` as `a.f(b, c)`,
by ar-nelson 6y ago
Take Java as an example. In Java, there are no free functions. Every method belongs to an object or a class.
So you couldn't write `f(a, b, c)` as `a.f(b, c)`, because `f` as a free function couldn't exist to begin with. Either it would already be `a.f`, or `f` would be a method of the current class or a static method imported via `import static`, in which case using the `a.f` syntax could deceive readers about what class `f` is a member of.
That's what I'm going for with this language, for uniformity and discoverability. If you want to add a new method that takes type `A` as its first argument, you should add it as an extension method on type `A`.
- vanderZwan 6y agoCould you elaborate on what "discoverability" means to you, because don't see any reason in this explanation why an IDE would not be able do autocomplete on `a.f(b, c)`, with automatic documentation on top, which is all that is needed for discoverability in my book. (also, to be clear, I'm not the one who downvoted you)