← Back to context

Comment by cv5005

7 days 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?

Any 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);
        }
    }

The 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.