4 ms·
For me best described in, and also as a topic mentioned in the paper about the visitor pattern connection, "A Little Java, A Few Patterns". This book writes rea
by _glass 2y ago
For me best described in, and also as a topic mentioned in the paper about the visitor pattern connection, "A Little Java, A Few Patterns". This book writes really impractical Java, but in such a Scheme way, that you really can understand the deep connections between functional and object-oriented programming.
- liquid_bluing 2y agoOne 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 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.“
- bruce343434 2y agoI 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 2y agoWhenever 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 2y agoBut 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.
- deleted 2y ago[deleted]
- trealira 2y agoThis 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-essentially-same.html https://www.haskellforall.com/2021/01/the-visitor-pattern-is... [1]: https://news.ycombinator.com/item?id=26034790 https://news.ycombinator.com/item?id=26034790 [2]: https://news.ycombinator.com/item?id=26024600 https://news.ycombinator.com/item?id=26024600
- trealira 2y agoLooking 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.
- elbear 2y agoFunny coincidence. A few days ago I was reading a blog post also about the Visitor pattern in Java, but in the context of recursion schemes (category theory): http://logji.blogspot.com/2012/02/correcting-visitor-pattern.html http://logji.blogspot.com/2012/02/correcting-visitor-pattern...
- agumonkey 2y agoThat's what I get from studying FP and smalltalk. There are strong similar notions behind the paradigms. The dirt came from the industry.. they started to apply OO for large engineering projects and patterns became a fad.
- svieira 2y agoThe thing that really brought it home to me was the talk "Uniting Church and State: FP and OO Together" by Noel Welsh: https://www.youtube.com/watch?v=IO5MD62dQbI https://www.youtube.com/watch?v=IO5MD62dQbI