With Common Lisp you get generic functions and design your classes around those.
[1] “OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.” - Alan Kay (http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay...)
[2] “The key in making great and growable systems is much more to design how its modules communicate rather than what their internal properties and behaviors should be.” - Alan Kay (https://wiki.c2.com/?AlanKayOnMessaging)
How about Class-Reified Abstract Programming? If the shoe fits...
Except: Smalltalk still lives (Squeak) and Erlang takes messaging to the extreme.
Sussman and Steele came up with a way to do lexical scoping in a LISP, thus closures in LISP were born. They then acknowledged that actors and closures are essentially the same concept (I'm assuming with mutation, i.e. Scheme's "set!" and friends because otherwise message passing to update independent actors would be meaningless).
And to put the cherry on the top, what do Java, Common Lisp, and Scheme all have in common? Guy L. Steele worked on the language specs of all of those. Which makes the dig against Java a bit hilarious, though understandable.
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
> [...] And by such examples one may be led into the functional style of programming, which is possible within Lisp/Scheme, though not required.
Do you have a good article explaining this ? To me actors is mainly a pattern for dealing with concurrency, and closures seem completely unrelated. But i assume i'm missing something...
If you'd like to explore this space look up the original papers by Carl Hewitt. He's also written some more recent papers on the subject. Also the "Lambda Papers" by Sussman and Steele are instructive. They deal with implementing various control structures and computational patterns with lambdas. Unfortunately there isn't a "Lambda the Ultimate Object" which could be written. I'm guessing they didn't go there because at the time OOP hadn't taken off and may have seemed obvious to the people who where involved in Lisp/OOP at the time.
In his essay "Objects Have not Failed" Guy Steele addresses the history that deckard1 mentions.
[1] "Viewing Control Structures as Patterns of Passing Messages" - Carl Hewitt
[2] "Actor Model of Computation: Scalable Robust Information Systems" - Carl Hewitt
[3] The Lambda Papers - https://research.scheme.org/lambda-papers/
[4] "Objects Have Not Failed" - Guy Steele, https://www.dreamsongs.com/ObjectsHaveNotFailedNarr.html
People like to ask "why should I use <insert language>?" I never really think about it too much - I don't pull out my weights and measures, and say "well, language X is 83.72% optimal for the problem, but language Y is 91.22% optimal, obviously using language X is a huge mistake!"
If something is obviously better for a problem, I'll pick that language. But if you have to dig too deeply into what language to use, the language probably doesn't actually matter that much.
I was "raised" on OOP, and I "got" it, but I've always preferred more standard procedural programming. I prefer Go over Java, and C over C++.
I like FP more than procedural programming. I prefer Elixir and Haskell over Go.
I like Lispy languages more than other languages. I prefer Clojure over Elixir and Haskell.
I thought racket was the holy grail due to the macro system but my real metamorphosis came after learning Haskell. I realize now that my previous preference for Clojure was because I was stuck in prototyping mode.
Once you truly understand your problem domain then types trump macros.
So while I owe a huge debt to Clojure/Racket for rescuing me from my java nightmare, and introducing me to other approaches like Erlang, it was Haskell/Purescript that matured me the most as a programmer.
It was so worth the (considerable) effort, because it has generalized the very nature of computation in a way that just never happened for me in all my years with lisp.
Halfway though I realized I was inventing a shittier Purescript.
Dsls are mostly masturbation. Custom syntax? Custom evaluation semantics? I always regret it after like cocaine.
The only thing macros are reasonable for is custom bindings.
Most people are not qualified to invent dsls. Myself included. And the people who are qualified don't need "language oriented programming" ala racket. They can spin up a lexer which is the least complicated part of the task anyway.
As for types, they have a HUGE power to weight ratio. All of my efficiency gains in Clojure due to macros were forfeited 10x over hunting down null pointer exceptions at runtime.
I still love Racket. And I still prototype in Clojure. But Haskell brings you closer to math. Closer to category theory.
Most programmers don't need new symbols and semantics. They need a deeper understanding of combinatorial logic.
Racket allows people with new ideas to prototype them efficiently by easily implementing a compiler that would've been an interpreter otherwise.
As I said, I like Racket. And I agree with you it's a nice environment for playing with new language ideas. But most of those ideas are bad and are just incidental complexity. And the 1 of 100 languages that are great ideas and needed by the world are better off spun out with their own parser and toolchain without being so tied to Dr Racket and Chez Scheme.
That seems mostly a fault of the JVM, no?
Clojure's nil punning and Java's Null Pointers are an unholy alliance here.
But a type system like Elm solves the problem before it ever gets to JavaScript for example.
A good type system like Haskell's gains you much more than it costs. Sure Json and Clojure are open and flexible, but this is not what you want when you understand your problem and can specify the types are Ohms -> Volts -> Amps etc, instead of just Number Number Number.
Specifying them after in spec or typed racket was just not the same and always rang similiar to unit tests after the fact.
Haskell types is like having a pair programmer sitting beside me. For systems that I have in production that have been ported from Clojure to Purescript the reduction in bugs, refactorability and overall confidence is something I didn't know I was missing until I did.
I understand Hickey's point in his Maybe Not talk, either you have the data or you don't. But at the end of the day, Clojurescript apps subject my users to blank screens and subtle "undefined is not a function" bugs, whereas the Purescript compiler forces ME to diligently deal with those unexpected possible scenarios before I ever ship.
In something like Java, sure. But Java is to static types as BASIC is to structured programming: the execution is so primitive that reasonable people can be misled into rejecting the concept if that's all they know.
Here's a completely painless encoding of JSON in Haskell:
`data Value = JObject (Map Text Value) | JArray (Vector Value) | JString Text | JNumber Double | JBool Bool | JNull`
Do you have any good examples of this? Code bases that can be read?
SQL queries are compiled into very efficient operations which would take a lot longer to get right imperatively. Not only that, but database engines are improving all the time, so the same code you wrote which declares your desired transformations tends to get faster over time and there is nothing to update or refactor. The transformations you write are sort of timeless because they are strongly decoupled from the implementation and hardware.
Lots of data transformation steps in imperative languages require the persistence of an intermediate calculation (e.g., np.ndarray). SQL database only do this when the query planner deems it absolutely necessary. It will show up in your query plan as a "materialize" step.
The EXPLAIN feature of SQL is the most useful performance debugging tool. It also alerts me to a potential logic flaw quickly when the proposed plan looks insane. I have personally replaced several analytical programs a very large bank used to monitor loan originations and performance.
I don't use any special SQL language features to this day. The most sophisticated it typically gets is involving lots of subqueries, joins, and window functions. The real skill is distilling the convoluted imperative mess into its essence. I got really good at this.
Half the work effort is usually spent on socializing the changes I have to make to their logic to get it working right in SQL when it changes the behavior of their existing application's logic. Often times I find the client's imperative code attempting to perform a logical operation such as a join but it is implemented incorrectly.
Their existing imperative code operations actually produced the wrong results (subtly) frequently or their imperative code depended on the order of the data returned from the database (undefined behavior). Yikes.
What they actually wanted was provably implemented incorrectly or relied on undefined behavior and their mistakes and the proper resolution in SQL could be easily verified with paper and pen on a sample set of loans if necessary to drive the point home.
Only true up to a certain extent. Counterexample: performance regressions due to changes in the query planner / its input statistics. Changes aren't always positive and logically equivalent plans can have very different perf characteristics.
Your point about equivalent plans can have very different perf characteristics is very true. I always try to review the query plan with EXPLAIN if my query takes more than a minute and rewrite the logic if necessary.
Although I heavily lean on psql with \COPY and stdin or stdout pipes to a compressor like zstd (psql can natively pipe CSV to and from any program reliably even in Windows) I found loading JSON records to be extremely frustrating this way.
Whatever you do NEVER use pipes in Powershell. They don't stream. They buffer in RAM fully into your computer crashes. Microsoft is insane.
Since you use NoSQL you can write a very short Python program that uses psycopg2 directly to load a list of dict as JSONB rows into a single Postgres table with one column (I call mine "record")
At that point you can basically use Postgres as a NoSQL database and structure the records if you want using a VIEW.
We're in the process of documenting their use of JSON for financial records keeping as a design defect.
That just sounds like very sloppy programming.
> Do you have any good examples of this? Code bases that can be read?
I don't know of any projects that do this, but I do this for many of my side projects.
It simply does not have formal definitions and examples. Almost everything in OOP books and content is defined like "imagine you have this situation and you want to do this thing..." and then it starts with ships, containers, ports, cranes or animals and lions.
The thing I like about fp is that there's surprisingly little things to know, and they all have formal definitions. The definitions are also quite simple and build on previous definitions. If you know what a data type and a `map` operation is, you can easily understand a functor. You add to it another ingredient and you have an applicative functor. Another one, and you get a monad.
You make small steps towards knowledge that are solid.
whenever I read a lisp / ml book, I sweat a bit and then I gain superpowers and insights, whenever I read mainstream OO books I just get a neverending stream of "please stop.. why ??"
and it's not only lisp to be frank but a mindset that lisp embodies a lot.. even using an hp48 felt better than basic+algebraic programming calcs .. (at the time I had no idea what was RPL)
Some ideas like using polymorhism to avoid branching conditionals was interesting though and I'm sure there's times it can be helpful.
Lisp and Scheme are great languages for object-oriented programming.
But that is all beside the point- OP specifically did not claim FP was always better, just that they found it more natural. That personal and subjective experience (which I share) is utterly orthogonal to the relative maturity of GUI libraries! The fact is, most GUI frameworks are OO, and the ones I learned were all OO. And I hated them! I am not a person who enjoys making GUIs, and that's in large part because I am not a person who enjoys OOP. When I learned my first functional language, it felt like a breath of fresh air. While I was a perfectly serviceable Java and Python programmer, Haskell just made sense immediately. That doesn't make Haskell a better language in absolute terms, but it was much better for me.
Now that I've worked with functional languages, I find I actually don't mind imperative languages at all. I don't really need 100% of the bells and whistles to write composition focused code that meshes with my brain, especially since just a hint of state here or there can free you up to do the rest of it statelessly. And now I find that as I build interfaces with LiveView or Vue that I actually do enjoy making GUIs- even if there is a little state here or there.
People, and this might come as a shock, are sometimes different from each other. And sometimes their talents don't match up perfectly with whatever task you feel is important in the moment. There's lots of programming which isn't as state-heavy as a GUI, just as there's lots of programming more state heavy than a data processing pipeline.
* React
* Elm
* Halogen
* Phoenix
* Phoenix LiveView
* Re-frame
* ReagentWhen the JS tuple/record proposal is finally implemented, I suspect they go even farther in that direction.
Of course, you could argue that closures are simply objects with one method (or that objects are a poor man's closures), but that's a rather pedantic line of discussion.
Take anything that has object semantics on the JavaScript VM out of React source code, and it will be reduced to almost nothing.
It is like writing React in Smalltalk and arguing that because the code uses code blocks it isn't OOP.
It mentions that functional programming removes the tripwire of state mutation as one of the "whys", but my experience slightly differs here.
I found, after years of struggling with the "why" of object-oriented programming and its early obsessions with design patterns, that functional programming simply resonated with me personally. To this day, I have a bit of inner cringe when reading (for example) Java code.
Early in my career, I thought my lack of "getting OOP" was due to some profound missing piece of understanding. But then Lisp (and Clojure) just made sense. Thinking functionally just works for me. It's not so much that I couldn't use OOP but just that each time I worked in deeper OOP projects, I felt some internal friction or vague uneasiness with the code.
I did find that functional programming made me significantly more comfortable with OOP languages. YMMV.