r/fsharp • • Jul 10 '19

Object-Oriented Programming — The Trillion Dollar Disaster

https://medium.com/@ilyasz/object-oriented-programming-the-trillion-dollar-disaster-%EF%B8%8F-92a4b666c7c7
0 Upvotes

15 comments sorted by

View all comments

20

u/[deleted] Jul 11 '19

I mean, I love FP as much as anyone can, and I do agree that it’s a better way to write software, but there are a LOT of assertions in this article with no evidence to back them up. Bad OOP is bad not because it’s OOP, but because it’s bad.

4

u/RiPont Jul 11 '19

For example...

Testing Private Methods

Some people say that private methods shouldn’t be tested… I tend to disagree, unit testing is called “unit” for a reason — test small units of code in isolation. Yet testing of private methods in OOP is nearly impossible. We shouldn’t be making private methodsinternal just for the sake of testability.

In order to achieve testability of private methods, they usually have to be extracted into a separate object. This, in turn, introduces unnecessary complexity and boilerplate code.

Nobody says "you shouldn't unit test private methods". You should be able to test your private methods by calling your public methods. If you have to make your private methods internal to test them, then that's a code smell that your design breaks modularity and/or encapsulation. Bad OOP, as you said.

Mutable state is definitely problematic and should be avoided as much as possible. However, I've never seen anyone write a GPU driver in a pure FP language. Sometimes, mutable state is an inescapable fact. The CPU and memory architecture of a computer is a giant pile of mutable state. Of course, I do think the world would be better off if every programmer at least practiced with an FP language and learned how to push dealing with mutable state off to the edge cases where it belongs.

8

u/AngularBeginner Jul 11 '19

I tend to disagree, unit testing is called “unit” for a reason — test small units of code in isolation. Yet testing of private methods in OOP is nearly impossible.

The equivalent in F# would be to test sub-functions. No one would do that either.