top | item 40773684

(no title)

liquid_bluing | 1 year ago

One of the most mind-bending papers on this topic is William Cook’s On Understanding Data Abstraction, Revisited https://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf “Object interfaces are essentially higher-order types, in the same sense that passing functions as values is higher-order. Any time an object is passed as a value, or returned as a value, the object-oriented program is passing functions as values and returning functions as values. The fact that the functions are collected into records and called methods is irrelevant. As a result, the typical object-oriented program makes far more use of higher-order values than many functional programs.“

discuss

order

trealira|1 year ago

This reminds me of this article: "The visitor pattern is essentially the same thing as Church Encoding" [0], although I think this comment [1] and this one [2] on HN explain it better. The article is written in Haskell, but it's basically saying that, because object-oriented programming languages lacked sum types, the visitor pattern makes the transform from

  (a | b | c) -> T
to

  (a -> T, b -> T, c -> T) -> T
where (a | b | c) is a sum type saying "it can be either a of type a, type b, or type c", and (a -> T, b-> T, c -> T) is a stand-in for a record of functions (i.e. the v-table of an instance of a visitor class).

[0]: https://www.haskellforall.com/2021/01/the-visitor-pattern-is...

[1]: https://news.ycombinator.com/item?id=26034790

[2]: https://news.ycombinator.com/item?id=26024600

trealira|1 year ago

Looking back but can't edit. The first line should say

  ((a | b | c) -> T) -> T
This is just a mistake I made paraphrasing link 1.

bruce343434|1 year ago

I think the best example of this is the strategy pattern. In that way, strategy classes are really just a wrapper around a function and its persistent, mutable internal data/state.

abecedarius|1 year ago

Whenever there's another interminable thread about, like, what is OO really and how thoroughly does it suck? I wish everyone knew this short paper as background.

Teaser: the first OO language was Church's lambda calculus.

voidhorse|1 year ago

But OO does suck, not because it is fundamentally different from the lambda calculus, but because it puts a kludgy set of handles that makes it easy to make bad decisions in front of a good, sound computational core. Of course, just like any advanced tool, an advanced practitioner can use traditional OO languages well, but the paradigm makes it just as easy for noobies to fall into pitfalls as does classical imperative programming, if not more so.

At the end of the day, all languages that are turing complete are the same language and the only differences lie in the kind of front end we provide. Unfortunately, we basically still have a single frontend, called C and every subsequent programming language has essentially just taken the C frontend and restricted or expanded it in small ways. We still ultimately work in terms of records, contiguous arrays and pointers. You can think of basically any more "advanced" construct in terms of pointers and it will make perfect sense nearly every time.