Live data from Hacker News

The Repeated Deaths of OOP (2015)

loup-vaillant.fr

71–80 of 220 posts

Re: The Repeated Deaths of OOP (2015)

#71
post #49

Earlier quoted context omitted.

> FP is a cult. It's a programming paradigm based on simple, well-understood mathematical framework. It's also the starting point for most research in programming language theory.

Explain why closures are allowed to mutate state in this “simple, well understood” framework.

Whether closures are or are not allowed to mutate state depends on the programming language (or the aim of the programmer, if the programming language doesn't force their way). Closures are a syntactical building block helping functional programming (building functions out of objects is just much more syntactical overhead), but whether a particular closure is a pure function or not is a separate concern. If the function is to be pure (hence satisfying the core of the "framework") then it would not be allowed to mutate state.

Re: The Repeated Deaths of OOP (2015)

#72
post #67

Earlier quoted context omitted.

FP means that every expression (= part that can be evaluated) is referential transparent. Nowadays the word "functional" is used different from the original meaning (which some now call "pure functional") > Some FP is lazy, some isn't. The definition of FP implies that laziness is irrelevant. A language can enforce a pure functional style without being lazy or not. > Some is immutable, some isn't That's wrong. And it…

> FP means that every expression (= part that can be evaluated) is referential transparent. Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent. It's why I distinguished between "core" and "meat" in my other response. Functional programming languages offer features that help making a larger part of the program referentially trans…

> Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent.

That's not correct though. Look at Haskell (or even stricter Idris). This is real world application code that can do whatever Java, C++, ... can do, but it is pure functional and hence doesn't contain any non referentially transparent parts. Just because an application is written in a pure functional style does not mean that it cannot e.g. write into a database when it is executed.

Of course many languages don't even allow to use a fully pure functional style. In that case, a more or less big functional "core" is the closest one can come to a pure FP style.

> I didn't go into immutability in my other response because you can use mutation inside pure functions, as long as the effect doesn't leave the function.

Sure you can do that and sometimes it is even the best practical solution. And the function might even be referential transparent - but your whole application is now not pure functional anymore, because a part of it is not referential transparent anymore.

Hence: if an application has to satisfy the criteria of being "pure functional" then every expression must be referential transparent and hence no mutation can be used.

Re: The Repeated Deaths of OOP (2015)

#73
post #53
post #28

Earlier quoted context omitted.

> Classes were never definitional for OO, so prototypes, as originated in Self and adopted in JS, are not a violation of it. If we put classes and prototypes in stark opposition, we can say yes, classes are not foundational. But what's the main distinction between classes and prototypes? One is defined statically and other dynamically. Static/dynamic distinction is a matter of optimization, it's not fundamental to th…

I like the use of the word "mold" here; I've not heard it applied to programming before. Manufactured objects are often very different from the prototype, but it's harder to differ substantially from the mold.

It's rather commonly used as a metaphor for classes (synonym: templates), I've seen that multiple times. More recently Urbit's Hoon language used the word for type-assertion functions [1], though I'm very sure that its choice is mostly due to its idiosyncratic naming convention where each class of words have the same number of letters.

[1] https://urbit.org/docs/hoon/hoon-school/molds/

Re: The Repeated Deaths of OOP (2015)

#74
post #70

Earlier quoted context omitted.

They are not allowed to. Why do you think they are?

From the Swift docs regarding closures (I would have used Haskell doc reference, but the Haskell docs are so esoteric and vague as to be nearly useless): “A closure can capture constants and variables from the surrounding context in which it’s defined. The closure can then refer to and modify the values of those constants and variables from within its body, even if the original scope that defined the constants and va…

Swift is not a language that enforces code to be pure functional though.

Re: The Repeated Deaths of OOP (2015)

#75
post #70

Earlier quoted context omitted.

They are not allowed to. Why do you think they are?

From the Swift docs regarding closures (I would have used Haskell doc reference, but the Haskell docs are so esoteric and vague as to be nearly useless): “A closure can capture constants and variables from the surrounding context in which it’s defined. The closure can then refer to and modify the values of those constants and variables from within its body, even if the original scope that defined the constants and va…

> From the Swift docs regarding closures

What makes you think Swift only supports functional programming?

> I would have used Haskell doc reference

And if you would have, you would have disproved your own point. In Haskell, closures cannot mutate state, because mutable state is not part of the language semantics. It's modeled explicitly via monads.

Re: The Repeated Deaths of OOP (2015)

#76

Earlier quoted context omitted.

It's true that functional programming also doesn't have a formal definition, but I wouldn't say it's "exactly the same" as with OOP. Functional programming is based on a simple well-understood mathematical model: lambda calculus. While there are different flavors of lambda calculus, they are related in obvious ways and one can reach formal conclusions them as a whole, e.g., the Church-Rosser theorem. In contrast, the…

To all the people downvoting me: if you really think OOP is as well understood as FP, learn some programming language theory. Tell me what the universally agreed foundation of OOP is. You won't be able to, but I can tell for FP it's lambda calculus.

I agree that functional programming has a more widely agreed-upon foundational set of definitions than OOP. However, it doesn't follow from that that "it's impossible to say anything meaningful about OOP".

Re: The Repeated Deaths of OOP (2015)

#77

It sounds a lot like he's trying to claim victory via semantic quibbling. We've learned a lot and incorporated a lot of ideas, machines, and concepts into the mainstream over the past few decades. But one thing that hasn't stayed the same is what set of things fits into what grab bag encompassed by a word someone came up with decades ago to describe the state of things at the time. Once you start arguing "OOP" vs xyz…

> Once you start arguing "OOP" vs xyz or "FP" vs xyz, you've missed the point. I think if we were intellectually honest in our arguments this would be fine—we could manage that OOP is poorly defined. Instead almost every debate about OOP takes this form: someone criticizes things which are exclusive to OOP (e.g., inheritance) or very common in OOP (kingdom of nouns, everything having references to everything else i.e…

> or they could give their definition of OO up front.

This is exactly what they must NOT do. If one is going to criticize, criticize the actual bad concepts, not the (poorly defined) paradigm. OOP and FP are effectively undefinable, and rightly so since they have outlived their usefulness as vehicles for introducing their respective "bunch of concepts".

Nobody's going to agree in the modern era what OOP or FP encompass, and anyone who attempts to define them will rightly be lambasted for it.

But we CAN agree on the definition and argue over the merits of concepts such as inheritance, immutability, lazy evaluations, closures, encapsulation, monads, etc. And the fact that languages are taking concepts from both "camps" shows how they were never actually opposed; merely components of different schools of thought that happened to contain some incompatible or opposing concepts.

Re: The Repeated Deaths of OOP (2015)

#78
post #39

Earlier quoted context omitted.

Isn't every existing programming language eventually based on (or at least traceable to) lambda calculus? OOP is just another way to organize code. Human language is unsuitable for " glass clear ", unambiguous definitions, just because of its inherent fuzziness (which is nota bene an essential property for efficient communication).

> Isn't every existing programming language eventually based on (or at least traceable to) lambda calculus? Not really. FP has an obvious connection to lambda calculus. Many OOP languages don't even have a straightforward notion of "function", which is what lambda calculus is all about.

> Not really

See e.g. Landin, P. J. (1965): A Correspondence between ALGOL 60 and Church's Lambda-notation.

Re: The Repeated Deaths of OOP (2015)

#79
post #67

Earlier quoted context omitted.

> FP means that every expression (= part that can be evaluated) is referential transparent. Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent. It's why I distinguished between "core" and "meat" in my other response. Functional programming languages offer features that help making a larger part of the program referentially trans…

> Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent. That's not correct though. Look at Haskell (or even stricter Idris). This is real world application code that can do whatever Java, C++, ... can do, but it is pure functional and hence doesn't contain any non referentially transparent parts. Just because an application is wri…

It's funny that you defend your view using Haskell, as I was replying with Haskell in mind.

If you use the state monad, you encode local side effects. Then you use runState in a function that has a non-monadic type--a pure function.

Feel free to argue that the state monad is only having pure expressions because it can be represented using only pure functions and partial evaluation. For all practical purposes it is used to write code that exerts (local) side effects into the state maintained by the state monad.

You can a function in say, OCaml, that fills an array via mutation using only function arguments to deduct the contents, and then returns that array. That function is pure (it exerts no side effects outside and is not exposed to side effects from the outside, its result value only depends on the function argument values). Yet how is that not using mutation, non-referentially transparent parts inside?

You can write the same function with a mutable vector in Haskell (Data.Vector.Mutable, using the ST monad). How is it not exactly the same code as the one in OCaml except for the types that guarantee the purity? Yes, it may be using pure expressions underneath to guide the type system to enable the proof of purity. But does that change what I said? Both to the programmer and (after optimization) to the machine the code is using mutation. You can model mutation using only pure functions. That may be useful in some ways, but you can also take a C program, represent every memory address as an entry in a tree of immutable nodes, the outside world as an abstract entity with versions, and recreate it with only pure expressions. That may be what is useful in some contexts for developing proofs or to implement type systems, but is this relevant for a programmer interested in writing more functional programs? Why not just say that using ST is using local mutation (that the type system can guarantee will not leak outside) and be done with it?

Re: The Repeated Deaths of OOP (2015)

#80

Earlier quoted context omitted.

Every OO proponent seems to have their own definition of OO. Another I’ve heard is “message passing”, although that one even has many different flavors since it isn’t well defined and some argue that methods constitute message passing and others envision something closer to an Actor model. This is all well and good as long as people are clear about what their definition is (although it is weird how many proponents ha…

For yet another definition, OO is about encapsulated polymorphic interfaces. Which raises a communication difficulty: encapsulated polymorphic interfaces are very useful in some of the cases (ADTs, modules), and a misfeature for the other cases (data modeling). I have yet to see a conversation, especially an internet conversation, where participants reach a rough consensus on the contextualized upsides / downsides of…

Do you have any references with detailed analysis of this issue? How much one should emphasize concrete data types vs. interfaces seems like a key consideration in language design.
Post reply on HN