4 ms·
I thought Clojure was duck typed, so I thought it would not require extra boiler plate. Consider a max function that returns the largest of two entities by usi
by artsrc 17y ago
I thought Clojure was duck typed, so I thought it would not require extra boiler plate.
Consider a max function that returns the largest of two entities by using a "compare" function.
In Python/C++ Templates you must:
1. Have a compare method in your class
2. Call compare in max.
In Go you must:
1. Have a compare method for your type
2. Call compare in max.
3. Define a Go interface 'Comparable' with the compare function
4. Declare the args to max to be of type Comparable
In Java (OO Style) you must:
1. Have a compare method in your class
2. Call compare in max.
3. Define an interface Comparable to have a compare method
4. Declare max to take type Comparable
5. Declare that your class, with the comparable method implements Comparable.