Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Finally, I haven't read all 162 comments here - but OO is not "bad" nor "the holy graal". There are different ways of doing programming, and its as simple as that

What are we programmers supposed to do with all of our free-time unless argue about what is the holy grail versus which is not?! I feel so empty.

Jokes aside, I think this is the most important point really. There is no single language/paradigm that works best for everything, it all really depends on the context, environment, and so much more. It's easy to forget on the internet, that someones environment might be vastly different than yours, and think your solution will work for others because you miss their context.

OOP is hated all around the world, and still solves problems. Functional programming is loved all around the world, but is still not the right solution for everything.



Strangely a lot of the functional programming advocates are fine with closures, which are guilty of all the same issues -- private state, hidden state, combining data with functions. Closures are basically lightweight objects. Really the debate should be about whether you are dealing with pure objects or not, rather than whether you are binding code and data into a single variable that is passed around.

I once saw a python function that returned two other functions, a, b, such that depending on what was passed to a, the return value of b would change. Sounds terrible, right? Well, A was set_test_parameters(params) and B was get_test_results(test_run).

In OO parlance, they were two methods of the same test_ object but because they were returned as closures the underlying object was hidden as an internal variable in the function that returned a and b. In OO parlance that would be a factory. Wonder what Joe Armstrong would think about that -- it was both cringeworthy and also quite efficient, as the code that consumed A didn't need to know about B and vice versa. One could even think of A and B as two ends of a pipe, or as pointers to inputs and outputs of an unspecified function.

Being able to cleanly design a complex program so accurately that only immutable types are used is difficult. Then throw in large numbers of junior engineers working in tight time windows, subject to constantly changing requirements, and the odds of that codebase being pure a few years out is basically zero. In the end, we have to ship.


"Obligatory c2.com reference": https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

""" The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures."

Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.

On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened. """


> Strangely a lot of the functional programming advocates are fine with closures, which are guilty of all the same issues -- private state, hidden state, combining data with functions.

In functional programming closures (like other functions) only hold immutable data and cannot have side effects, so there is no private/hidden state involved. Code which can mutate state or produce side effects is procedural, not functional.


this is misguided to such an extent


As bizarre as the stated API sounds, it's actually a good choice for a lock-free triple buffer where set() and get() are called on separate threads and shouldn't block each other: https://lib.rs/crates/triple_buffer

I think it's also useful for SPSC channels.


Such an extent mere words can't even comprehend your reasoning.


"hated all around the world" sounds a bit harsh :) Sure, lots of people like "throwing hate" at it, but AFAICT it's mostly "bad use" that gets people riled up like insane deep inheritance or overly complicated frameworks. Also, it seems especially young guns feel cool by claiming FP is superior ;)

AFAIK OOP languages are still ruling the whole GUI space, which is reasonable since GUI was the main driving force behind it (see history of Smalltalk) and the domain is such an obvious candidate for composition of separate independent elements. What languages are primarily used for GUIs today? Java, C#, Swift, ObjC, C++, Dart, Kotlin ... and the list can probably be made much longer.

On the web ... well.


Not sure if OO really rules the GUI space. Afaik, at least Swift, Dart (Flutter) and Kotlin are trying to solve the mismatch between OO and Reactive Programming (where functional approaches very helpful)

Most of GUI development is pure data handling (render state and react to interactions) where a strong functional toolset is much appreciated (lambda, pattern matching) and some parts are well done with closures (where OO comes in)

Ultimately I would love to have a GUI development language that allows me to use one set of language features and constraints when I really just want to use functions on data immutable data, strong pattern matching and ADT for modelling) and another when I need strong closures, with message based dispatches and reactivity.

Basically, whatever React does, minus the constraints of requiring JS compatibility.


I'd say OO still does rule the GUI space. The various reactive programming GUI tools are still struggling to reach the levels of complexity of UIs that were already common place in the 90s. Functional GUIs have their own problems with giant balls of state that makes composition difficult. So we break it down into smaller bits and it starts to look like objects again.

IMO the functional GUI push has less to do with functional GUIs being superior and more about dealing with the piece of shit that is the DOM. Native environments that don't have to deal with the DOM don't get the same benefit and have new problems that are solved by more OO approaches.


It all depends if you consider basically all non web GUIs developed the last 40 years or if you limit yourself to reactive web UIs developed the last few years. Tongue in cheek :)

Sure, reactive frameworks in js that mainly operate on the DOM/HTML/CSS stack may be very little OO, but Swift/Dart/Kotlin are OOP languages and Flutter for example, while using a reactive model, is still 100% OOP with Widget classes in a composition and so on.


Well non-web GUIs have been basically stagnant for a good chunk of that 40 years :)

You're right that it's OO under the hood. The latest thing I've used is CLJFX which is a React-like wrapper around JavaFX. I don't feel the OO side has much effect on my experience using the library. It's still events, callbacks, state-updates. The class hierarchies are irrelevant to the library user the vast majority of the time.

I wouldn't be surprised if for the library writers it provides benefits with code reuse and type gymnastics. But for mere mortals that need to refactor and reorganize our messy ideas OO hierarchies seem scary after React-like development.


Not sure if you are sarcastic or not. But if you look at how you develop windows app (vb, winforms, wpf, uwp and now maui) or Mac/iOS (from mvc, mvvm, and now mvu) and not forgetting Delphi. I find it far from stagnant.

With React you just switch your complexity. I don't feel more productive with my functional components than with my class component. I even more scared to introduce a memory leak with my useEffect than I was before.

But I do feel more productive with svelte or Blazor. That make me realize that OO vs FP is the the real vector. Reactive programming with good design is.


Like you said reactive programming and OO are not exclusive.

And if you look how you do React now with useState, useEffect and all. It's exactly a reproduction of OO, but inside a function that don't behave like a function anymore. And goes HOC for the inheritance/mixins/composition you flush down the drain.


Well the DOM is basically an OO model. If you are going to have a retained mode UI it's basically going to look like an OO model.




In the end it is probably most important what you like to use rather than how it performs, which abstractions are best, etc.

If you can wake up every day and think "Today is a great day for some non-OO programming" and you get to it, adding value to you and hopefully others, who is someone else to look down on that?


> What are we programmers supposed to do with all of our free-time unless argue about what is the holy grail versus which is not?! I feel so empty.

Learn about monads for advanced pedantry points? (I joke.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: