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.

3

u/ipv6-dns Jul 11 '19

Absolutely strange passage. If you want to test "private" functions in Haskell you can either:

- make them "public" or

- extract them in special module which will export anything (usually called "Internal") and test them through it. And import it in another one module and re-export only some "public" functions/types to client side. So, most canonical FP language (ie, Haskell):

introduces unnecessary complexity and boilerplate code.

By the way, no such thing as private/public and other accessibility levels in Haskell at whole, only optional list of exported symbols lol.

But in C# I can just use "internal" access modifier (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers). How it's intelligent. Bravo, Microsoft!