2 ms·
`derive` macros would not be possible to imitate with inheritance. `derive(PartialEq)`, for instance, examines all the fields of a struct definition and generat
by bccdee 3y ago
`derive` macros would not be possible to imitate with inheritance. `derive(PartialEq)`, for instance, examines all the fields of a struct definition and generates a function which compares them all. Using inheritance, you could inherit from a parent `PartialEquivalence` class, but if you added any new fields, you'd have to write your new implementation of the `==` operation by hand to accommodate them.
Macros have a much longer history in purely functional languages (in particular, lisps) than they do in procedural or OO languages. So you could argue that this problem is actually much easier to solve from a functional approach.