4 ms·
As I said above, I believe a mixture of paradigms tends to be the best approach for most software. I think OOP is a better way to build an ORM. That said, the
by scriptkiddy 10y ago
As I said above, I believe a mixture of paradigms tends to be the best approach for most software.
I think OOP is a better way to build an ORM. That said, the query constructors might benefit from a FP approach.
I think FP is a better way to build a mathematics library. That said, data structures might be better represented as objects.
It really depends on the specific application.
I also want to clarify that OOP does not necessarily require inheritance and such.
- pka 10y agoBut OOP without inheritance is what FP gives you anyway: data Address = Address { city :: String , street :: String } data Person = Person { name :: String , address :: Address } My general impression of recent-ish OOP developments is that people have started preferring composition over inheritance anyway, for good reasons. I guess I should've framed by question more like "the merits of inheritance over composition".
- scriptkiddy 10y agoInheritance is a useful tool when used sparingly. Ideally it should be used to encapsulate logic that is going to be re-used multiple times. I don't really think there are pros and cons as much as there are trade-offs between the 2 paradigms.
- no_wave 10y agoWhen is it preferable to composition?
- scriptkiddy 10y agoWhen modeling objects that need to encapsulate mutable data and pass messages between one another.
- pka 10y agoInheritance is orthogonal to that. I.e. Erlang, an (impure) functional language without inheritance was literally built for that sort of thing.
- scriptkiddy 10y agoOh, you were asking about inheritance, not objects. My bad. I'd say composition is almost always preferable. That said, single level inheritance can be useful if you need to have multiple different objects that require very similar business logic but contain vastly different data. A good example of this is Django's class based `View` class. I'm not talking about all the mixin views Django offers, just the simple generic `View` class. It handles routing to specific methods based on HTTP request METHOD. That eliminates the need to write the same ~100loc over and over. The alternative would be to use function based views. However, with function based views you end up basically recreating what the class does anyways after checking for each HTTP request method.