the Expression Problem and its solutions - [PROGRAMMING]
The Expression Problem is faced by all programmers who create anything other than simple programs. Represent abstractions with types, add procedures, methods or functions (choose your term) to manipulate those types, and some time later, one is invariably faced with the 2 problems: - adding new types/ classes - adding new operations/ functions This be the essence of the problem of programming abstractions. Eli Bendersky does a fine job of both laying out this "fundamental" problem of computing and the traditional approaches to solving this problem, namely: - OO programming with syntax for classes (syntactically co-located data with the operations on that data), whereby adding types is relatively straightforward (provided for syntactically); whilst adding operations requires changing function sets or "interfaces", which in general requires more than merely adding functions, impacting (undesirably) the type declarations (classes). - functional programming inverts this ease of modification aspect, since operations are the first order syntax, which thus leads the programmer to design his program with functions/ operations as primal, thus adding functions is the simple program extension mechanism just like adding data types or classes is the simple OO extension mechanism; whilst adding new data types in the functional language requires all existing functions to be (again, undesirably) modified to handle the new data type. The same "expression problem" thus manifests from either side of the programming language spectrum. Velly interdasting. Bendersky lays it out clearly, and with nice little matrix PNG images, then goes on with the (relatively, at least in C++) complex "visitor pattern" which is typically used to solve this problem in C++, using virtual multiple inheritance and dynamic type checking - not the simplicity we crave for our programming solution baskets. Enter the White Knight, Clojure, with syntax so powerful only Lisp dialects raise their heads in a collective superiority sneer. The secret? Clojure syntactically hides multiple dispatch behind reasonably elegant syntax - so the performance hit is there, but at least achieving the result is not a syntactic nightmare of virtual multiple inheritance + RTTI functionality or some ungodly template syntax. But it's actually only single dispatch? Yes, there be more lurking secrets - what Clojure calls "open methods": “Note a crucial difference between how methods are defined in C++/Java and in Clojure. In C++/Java, methods have to be part of a class and defined (or at least declared) in its body. You cannot add a method to a class without changing the class's source code. In Clojure, you can. In fact, since data types and multimethods are orthogonal entities, this is by design. Methods simply live outside types - they are first class citizens, rather than properties of types. We don't add methods to a type, we add new methods that act upon the type. This doesn't require modifying the type's code in any way (or even having access to its code).” Clojure "protocols" (from Java POV, "simple, usuall single-method Interfaces) also get a look in. Here's the source, Luke: The Expression Problem and its solutions https://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/ Bendersky even does a second round - recommended: More thoughts on the Expression Problem in Haskell https://eli.thegreenplace.net/2018/more-thoughts-on-the-expression-problem-i... So notwithstanding that Clojure runs on the JVM, note Java's first class syntactic citizens are classes (in comparison to Clojure's first class functions): java - What is a first class citizen function? - Stack Overflow https://stackoverflow.com/questions/5178068/what-is-a-first-class-citizen-fu... “So, objects are the first class citizens in java. Admittedly, java8 supports passing of methods (method behavior, to be precise) to other methods using functional interfaces and lambda expressions. But that does not mean that java has functions as first class citizens.” Note that Java 8 syntactically adds "first class functions" which are represented internally/ in the JVM, as classes (perhaps this is how Clojure runs on the JVM?): Java 8: Simple Example of First-class Functions http://4dev.tech/2015/08/java-8-simple-example-of-first-class-functions/ (Observing Java's predicates and other such Lisp wanna be syntax, it's rather fugly IMEHO.) The link to Bendersky was highlighted by Stephen Mann in his this week's mailing list mailout, where he also links to his recent blog on "good names" in programming: Good Code Depends on Good Names https://stephenmann.io/post/good-code-depends-on-good-names/ I can't find his email list archives, but here's his blog index: http://stephenmann.io/
On Wed, Oct 10, 2018 at 01:25:43PM +1100, Zenaan Harkness wrote:
Enter the White Knight, Clojure, with syntax so powerful only Lisp dialects raise their heads in a collective superiority sneer.
(Observing Java's predicates and other such Lisp wanna be syntax, it's rather fugly IMEHO.)
So. Lisp. God's one and only son's programming language. The alpha and the omega of conceptual reisms, the ultimate well for "mundane language of the du jour" enhancements and new features, the unassailable, maximally minimal, ultimately flexible in its sublime simplicity, the inherently superior and every other superlative a humble language such as English could even imagine... ... or ... well, actually yes, it's all these things and more, a mathematically pure mind expanding logical construct of meta syntax for the construction of logical constructs - so serenely ... DANGIT! List just does that to you … draws out superlatives. Well someone noticed this trait and ... attempts ... to call it out, before falling smack into the same problem. Woe be ye who enter here, into a twisty little maze of ye own creation from fundaments so bracketingly voluptuous and enticingly paleo, one wonders ... ah, one wonders ... oh firetruck it! Just read it already: How Lisp Became God's Own Programming Language Languages 14 Oct 2018 https://twobithistory.org/2018/10/14/lisp.html … Wouldn’t it be great if you could convince everyone that your new language had divine powers? But how would you even do that? How does a programming language come to be known as a font of hidden knowledge? How did Lisp get to be this way? Theory A: The Axiomatic Language John McCarthy, Lisp’s creator, did not originally intend for Lisp to be an elegant distillation of the principles of computation. But, after one or two fortunate insights and a series of refinements, that’s what Lisp became. Paul Graham—we will talk about him some more later—has written that, with Lisp, McCarthy “did for programming something like what Euclid did for geometry.”(2) People might see a deeper meaning in Lisp because McCarthy built Lisp out of parts so fundamental that it is hard to say whether he invented it or discovered it. … [ You didn't -really- think an article poking fun at Lisp's Godly status could get away from such superlatives? :D ] … In 1960, McCarthy published his famous paper on Lisp called “Recursive Functions of Symbolic Expressions and Their Computation by Machine.” By that time, the language had been pared down to such a degree that McCarthy realized he had the makings of “an elegant mathematical system” and not just another programming language.(13) He later wrote that the many simplifications that had been made to Lisp turned it “into a way of describing computable functions much neater than the Turing machines or the general recursive definitions used in recursive function theory.”(14) In his paper, he therefore presented Lisp both as a working programming language and as a formalism for studying the behavior of recursive functions. … That Lisp can be specified by such a small sequence of basic rules no doubt contributes to its mystique. Graham has called McCarthy’s paper an attempt to “axiomatize computation.”(15) … Theory B: Machine of the Future … The Symbolics 3600 cost $110,000 in 1983.16 So most people could only marvel at the power of Lisp machines and the wizardry of their Lisp-writing operators from afar. … Theory C: Learn to Program … In 1985, MIT professors Harold Abelson and Gerald Sussman, along with Sussman’s wife, Julie Sussman, published a textbook called Structure and Interpretation of Computer Programs. The textbook introduced readers to programming using the language Scheme, a dialect of Lisp. … SICP took Lisp and showed how it could be used to illustrate deep, almost philosophical concepts in the art of computer programming. Those concepts were general enough that any language could have been used, but SICP’s authors chose Lisp. As a result, Lisp’s reputation was augmented by the notoriety of this bizarre and brilliant book, which has intrigued generations of programmers (and also become a very strange meme). https://knowyourmeme.com/forums/meme-research/topics/47038-structure-and-int... Lisp had always been “McCarthy’s elegant formalism”; now it was also “that language that teaches you the hidden secrets of programming.” … and on it goes... PS: Found courtesy LWN Brief items: https://lwn.net/Articles/768154/
participants (1)
-
Zenaan Harkness