News for hackers. Stuff that matters.
Re:Ask HN: OOP in Functional Programming Language by PaulHoule on Wednesday January 19, 2022 @12:05PM (#29996396)
Back in the day (finishing up my PhD thesis in 1998) I would write C code with functions like

  some_method(Object* this, ...)
that was effectively "object based" even if there was no support for inheritance. Ultimately this style reifies data structures as objects and provides a systematic approach to many problems such as how you allocate memory. The one area where I feel it falls short is that there ought to be some way of switching from struct-of-arrays to arrays-of-struct representations.

This is not too different from how many real object-oriented systems are implemented.

There is a quite a bit of overlap between "using functional programming techniques to implement an object-oriented style" and "using object-oriented techniques to implement a functional programming style."

There's nothing more annoying in the lower teachings of programming that circulate than the "FUNCT10NS RULE, 0BJECTS DR001" sentiment you see so much of.

Re:Ask HN: OOP in Functional Programming Language by mollerhoj on Wednesday January 19, 2022 @12:25PM (#29996696)
AKA python style OOP ;-)
Re:Ask HN: OOP in Functional Programming Language by PaulHoule on Wednesday January 19, 2022 @12:41PM (#29997014)
Even in a language like Java which pushes objects pretty hard the mental model that "a method is just a function where the first parameter is this" is pretty useful, particularly if you are trying to break out of the OO box and write Java code that looks like LISP, ML, COBOL, FORTRAN, etc. (Super Fun IMHO, particularly in JDK 17!)

The tricky thing with this model is "how do you implement polymorphism?" The most sublime methods dispatch not just on this but also on the other methods but you do get extra complexity just as you would with multiple inheritance, or the C++/C# polymorphism models other than Java's "all-virtual" approach, etc.