from Hacker News

Object-Oriented Programming – The Trillion Dollar Disaster

by itistricky on 11/10/21, 7:44 AM with 7 comments

  • by nodejs_rulez_1 on 11/10/21, 9:39 AM

    I love typeful functional programming, but:

    > There’s no objective and open evidence that OOP is better than plain procedural programming.

    None such evidence for functional vs anything either.

    > Some might disagree with me, but the truth is that modern Java/C# OOP has never been properly designed.

    Really?

    > It never came out of a proper research institution (in contrast with Haskell/FP).

    Not designed 'by a committee' effectively? I guess there is a new definition for languages designed by "research institution": a language that nobody uses to ship things.

    > Erlang is OOP in its purest form.

    Erlang is a domain-specific language for backends. It's useless for front-end.

    > Contrast this to a similar refactor of non-OOP code in JavaScript:

    A language not made by a research institution, that had to have a bunch of higher-level languages created on top by non-'research institutions' to make it more usable (aka OOP)...

    > Refactoring OOP code is extremely risky. Complex dependency graphs and state scattered all over OOP codebase, make it impossible for the human brain to consider all of the potential issues.

    And you have picked JavaScript as a counter-example :)? Like, is there a single competent person on Earth who would pick refactoring a legacy JavaScript codebase over a legacy C# codebase? The types alone would be a game changer, not to mention ReSharper.

    > The development of functional languages is mostly community-driven.

    So, not by 'research institution's?

    > 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.

    O_O

    > However, their arguments in the defense of OOP are usually quite weak. It is ironic that most of them probably have never really programmed in a true functional language.

    Pre-deflecting personal attacks followed by a personal attack?

    ...etc. Too much to unpack there frankly. On a serious note, functional programming saved me a lot of stress in many situations. OOP done well is quite beautiful, and yes, closer to Alan Kay's original vision than modern Java.

  • by vbg on 11/10/21, 10:43 AM

    OO isn’t a disaster.

    What we have learned however is that it’s not the only way to do things.

    10 years ago the accepted wisdom was that the only way to program was object oriented.

    Thankfully there is hopefully a broader acceptance now that other ways of programming such as composed functions are also great ways to program.

    Program in whatever style you like, or whatever your team decides on. Be happy and don’t force your religion on others.

  • by ju_sh on 11/10/21, 11:31 AM

    Does anyone have any good references/examples of taking some OOP code and converting it to functional code? Even a trivial example of OOP inheritance such as Vehicle -> Car(Vehicle) -> SportsCar(Car) with a few methods & attributes (accelerate, brake, current_speed) etc..
  • by ahartmetz on 11/10/21, 11:03 AM

    > It never came out of a proper research institution (in contrast with Haskell/FP).

    Simula / University of Oslo and C++ / Bell Labs...

  • by tester34 on 11/10/21, 11:03 AM

    I have different take on OOP

    It's beautiful thing that managed to enable milions of people to express more or less complex reality inside computers.

    Sure it has it's quirks, something could be done better in $language, but that was decision/vision of $language design team how do they interprete object oriented programming.

    The bad thing is that it is incredibly hard.

    OOP and SOLID are kinda "basics of programming", yet those are incredibly difficult.

    You need to have a lot of hands-on experience with creating software, modeling systems in order to make it good (maintainable, sane, easy to understand, consistent, testable, yada yada)

    Simon Peyton Jones (Known for Glasgow Haskell Compiler) - Haskell is useless https://www.youtube.com/watch?v=iSmkqocn0oQ

    >Why is mutable state such a big problem? The human brain is the most powerful machine in the known universe. However, our brains are really bad at working with state since we can only hold about 5 items at a time in our working memory. It is much easier to reason about a piece of code if you only think about what the code does, not what variables it changes around the codebase.

    Isn't this part more about code "branches" instead of mutating state?

    >Yes, one can pass immutable objects to methods in Java/C#, but this is rarely done since most of the developers default to data mutation.

    Maybe because language designers didn't provide them right tool that'd enable their OOP vision to be more handy?

    It's seems like there work being done that want to make this better in C# world.

    >You, as a person, don’t have a “write” method either — you make the decision to write some text based on outside events or your internal thoughts

    Why you don't have "write" "skill"/"ability"/"method"?

    >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.

    "test small units of code in isolation"

    everything is about how you define "unit"

    "nearly impossible"

    I bet that even C# and Java provide "hacks" to OOP to test private methods.

    >public class InputValidatorFactory { public IInputValidator CreateInputValidator() => new InputValidator(); }

    You don't need factory, so in smaller version you added 6 lines of code (interface and impl) which allowed your code to be more flexible, I'd say that this is reasonable trade-off, but what if instead of interface, then you used function? like Func<T, bool> as argument, but maybe not to btnAddClick, cuz it's bad method anyway, but to some validate method.

    Func<string, bool> predicate = str => str.Length > 5;

    myFunction(predicate);

    So maybe OOP could be ""fixed"" by just introducting a few FP features? e.g C# - LINQ (not mutating state) and stuff like delegates, records, discriminated unions?

    >TransactionAwarePersistenceManagerFactoryProxy or RequestProcessorFactor

    >https://www.reddit.com/r/ProgrammerHumor/comments/418x95/the...

    >Further reading: FizzBuzzEnterpriseEdition

    Of course you can make OOP look dumb if you'll use example that were created with that purpose in mind.

    OOP itself doesn't force you to use things like TransactionAwarePersistenceManagerFactoryProxy that people meme about it being common within Java world, but I personally don't think I've witnessed stuff as hardcore as this in C# more than once, twice or thrice.