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

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.

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!

1

u/Slypenslyde Jul 22 '19

State of the art OO philosophies (as of about 2005?) don't even have this problem. Large-scale OO projects tend to deal with what used to be private methods via composition and DI today. So where I used to would have a CalculateWidgetTax() private method, now my class depends on IWidgetTaxCalculator. That is tested separately, and can be controlled in the context of whatever is using it.

I'm pretty sure if I sat down and wrote a lot of F# using only anti-patterns and smells, I could write an interesting article about how much FP costs. It'd be bad faith.

If I had to write an essay on this topic, my personal premise is history's greatest and most common programming disasters boil down to failures to manage complexity. The reason we make new languages is to try and handle that complexity better than the existing languages. But every approach is a tradeoff between different kinds of complexity and if we aren't careful we can use a perfect language to write a garbage pile.

Lots of atrocities were committed when OO was still very new. I don't think we really learned how to write good OO software until the mid 2000s. We learned good practices on top of the ashes of the bad practices. I think we also rediscovered a healthy amount of software engineering FP devs had known all along. But I find people still use examples of 1990s OO design as a condemnation of OO in the 2010s. That's like using Windows 95 to criticize Windows 10. I hate how often I find when someone writes, "This is what's wrong with {OO | FP | whatever}" what I'm actually reading is, "This is what was wrong with it when I changed jobs 10 years ago."

I don't have to write 1000 words to support, "Failure to properly maintain project complexity leads to unmaintainable code." And I don't care what language you give me, if I treat my project like a storage shed instead of a garden, pretty soon I'm going to have to move the lawnmower and the Christmas decorations to get at the grill and I'm going to ask why I created the mess.

1

u/RiPont Jul 22 '19

Very well said. In the end, we're dealing with complex issues, even if they can sometimes be stated simply. We try and manage that complexity, but as you said, there are tradeoffs.

Cargo-cult programming leads to using patterns badly and can overcomplicate things that shouldn't be quite as complicated. And then there is outright malice by contracting firms and charge-you-for-customization vendors that profit from complexity.

7

u/nullvoxpopuli Jul 11 '19

Uhm....

Oop and fp both have their pros and cons

7

u/The_One_X Jul 11 '19

I'm honestly not sure if this is a parody or not....

6

u/phillipcarter2 Jul 11 '19

“The need for a debugger almost disappears completely”

nope

17

u/[deleted] Jul 11 '19

I like FP but the whole, "OOP is completely wrong" is laughable. The overwhelming majority of software that actually does something is OOP.

6

u/pitkali Jul 11 '19

Much as I think the article is deeply flawed, your argument does not hold water. You say people have done useful things using OOP. Was it because they used OOP, or in spite of them using it? The only thing it shows is that it is possible to develop software using OOP, but nobody argues that in the first place.

7

u/JoelFolksy Jul 11 '19

Agreed, yet it was upvoted at least 16 times. "Usage implies fitness" is one of the psychological impulses underlying so many of the debates we have in this sub/industry. Unfortunately we rarely address it directly.

2

u/ken-amazing Jul 11 '19

I think that the majority of software that actually does something is procedural. OOP is a passenger at best. Have a look at this https://youtu.be/IRTfhkiAqPw

5

u/exhortatory Jul 11 '19 edited Jul 11 '19

Almost this entire article is cool kid "x bad y good" speak with like appeal to group mentality, there's very little meat here but a whole lot of straw.

See the first few sentences, which are ... farfetched. And the (first) "real-world example" section which contains no example but does lead to an image of a "promiscuous" woman.

Edit:

Objects (or nouns)

ok.

I expect some sort of reaction from the defenders of OOP. They will say that this article is full of inaccuracies. Some might even start calling names. They might even call me a “junior” developer 👶 with no real-world OOP experience. Some might say that my assumptions are erroneous, and examples are useless. Whatever.
They have the right to their opinion. However, their arguments in the defense of OOP are usually very weak. The funny thing is that most of them probably have never really programmed in a true functional language. How can someone draw comparisons between two things if you have never really tried both? Such comparisons are worthless at best.

^ the article is basically a bunch of paragraphs of that attitude repeated over and over, just like asserting stuff and assuming correctness with emotional fluff as the backup

4

u/[deleted] Jul 12 '19

Couldn't agree more. Almost every paragraph starts with the same thing. x bad y good and when everyone is hooked to get examples - " nah, let's skip to next paragraph where I ambiguously explain some stuff which says x bad y good, but i won't give any real life examples".

I come from OOP(C#) background, but when I read an article about comparing x,y I need something more than just -"I say so that is why" , I need examples, something to hold on to, not just because some dude said so.