News for hackers. Stuff that matters.
Re:Programmer Competency Matrix (2016) by scriptkiddy on Monday March 27, 2017 @02:33AM (#13965596)
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.

Re:Programmer Competency Matrix (2016) by pka on Monday March 27, 2017 @04:34AM (#13966023)
But 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".
Re:Programmer Competency Matrix (2016) by scriptkiddy on Monday March 27, 2017 @11:54AM (#13968747)
Inheritance 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.
Re:Programmer Competency Matrix (2016) by no_wave on Monday March 27, 2017 @02:50PM (#13970548)
When is it preferable to composition?
Re:Programmer Competency Matrix (2016) by scriptkiddy on Monday March 27, 2017 @03:05PM (#13970686)
When modeling objects that need to encapsulate mutable data and pass messages between one another.
Re:Programmer Competency Matrix (2016) by pka on Monday March 27, 2017 @06:55PM (#13972571)
Inheritance is orthogonal to that. I.e. Erlang, an (impure) functional language without inheritance was literally built for that sort of thing.
Re:Programmer Competency Matrix (2016) by scriptkiddy on Tuesday March 28, 2017 @12:23PM (#13977967)
Oh, 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.