6 ms·
Not a fan of methods. Why should the first argument be so special? And how do you decide which struct should get method if you have a function that operates on
by cv5005 6mo ago
Not a fan of methods.
Why should the first argument be so special? And how do you decide which struct should get method if you have a function that operates on two different types?
- nh23423fefe 6mo agoAny parameter list is permutation invariant. the first argument is special because methods are members of classes and thus get private access in the body of the method. If the implementation of the method is improved with private access then make a design decision. You don't have to decide where to put the implementation if you dont want to, its just a type of inlining void foo(Type1 arg1, Type2 arg2) { // do something } class Type1 { void foo(Type2 arg) { foo(this, arg); } } class Type2 { void foo(Type1 arg) { foo(arg, this); } } vs class Type1 { void foo(Type2 arg) { // do something } } class Type2 { void foo(Type1 arg) { arg.foo(this); } }
- tmtvl 6mo agoThe first argument isn't special, though: (defmethod binary-search (object (collection Sequence) before?) ...) (defmethod binary-search (object (collection Vector) before?) ...) ...and so on. You could even specialize on everything but the first argument.