Ask HN: Relationship between OO and functional programming?
Already lots of good comments and ideas below. My first attempt here on this topic turned out too wordy -- and this attempt is also (I tried to explain things and where the ideas came from). A summary would be better (but Pascal was right). I&#x27;ll try to stash the references and background somewhere (perhaps below later in a comment).<p>I had several stages about &quot;objects&quot;. The first was the collision 50 years ago in my first weeks of (ARPA) grad school of my background in math, molecular biology, systems and programming, etc., with Sketchpad, Simula, and the proposed ARPAnet. This led to an observation that almost certainly wasn&#x27;t original -- it was almost a tautology -- that since you could divide up a computer into virtual computers intercommunicating ad infinitum you would (a) retain full power of expression, and (b) always be able to model anything that could be modeled, and (c) be able to scale cosmically beyond existing ways to divide up computers. I loved this. Time sharing &quot;processes&quot; were already manifestations of such virtual machines but they lacked pragmatic universality because of their overheads (so find ways to get rid of the overheads ...)<p>Though you could model anything -- including data structures -- that was (to me) not even close to the point (it got you back into the soup). The big deal was encapsulation and messaging to provide loose couplings that would work under extreme scaling (in manners reminiscent of Biology and Ecology).<p>A second stage was to mix in &quot;the Lisp world&quot; of Lisp itself, McCarthy&#x27;s ideas about robots and temporal logics, the AI work going on within ARPA (especially at MIT), and especially Carl Hewitt&#x27;s PLANNER language. One idea was that objects could be like servers and could be goal-oriented with PLANNER-type goals as the interface language.<p>A third stage were a series of Smalltalks at Parc that attempted to find a pragmatic balance between what was inevitably needed in the future and what could be done on the Alto at Parc (with 128K bytes of memory, half of which was used for the display!). This was done in partnership with Dan Ingalls and other talented folks in our group. The idealist in me gritted my teeth, but the practical results were good.<p>A fourth stage (at Parc) was to deeply revisit the temporal logic and &quot;world-line&quot; ideas (more on this below).<p>A fifth stage was to seriously think about scaling again, and to look at e.g. Gelernter&#x27;s Linda &quot;coordination language&quot; as an approach to do loose coupling via description matching in a general publish and describe manner. I still like this idea, and would like to see it advanced to the point where objects can actually &quot;negotiate meaning&quot; with each other.<p>McCarthy&#x27;s Temporal Logic: &quot;Real Functions in Time&quot;<p>There&#x27;s lots of context from the past that will help understanding the points of view presented here. I will refer to this and that in passing, and then try to provide a list of some of the references (I think of this as &quot;basic CS knowledge&quot; but much of it will likely be encountered for the first time here).<p>Most of my ways of thinking about all this ultimately trace their paths back to John McCarthy in the late 50s. John was an excellent mathematician and logician. He wanted to be able to do consistent reasoning himself -- and he wanted his programs and robots to be able to do the same. Robots were a key, because he wanted a robot to be in Philadelphia at one time and in New York at another. In an ordinary logic this is a problem. But John fixed it by adding an extra parameter to all &quot;facts&quot; that represented the &quot;time frame&quot; when a fact was true. This created a simple temporal logic, with a visualization of &quot;collections of facts&quot; as stacked &quot;layers&quot; of world-lines.<p>This can easily be generalized to world-lines of &quot;variables&quot;, &quot;data&quot;, &quot;objects&quot; etc. From the individual point of view &quot;values&quot; are replaced by &quot;histories&quot; of values, and from the system point of view the whole system is represented by its stable state at each time the system is between computations. Simula later used a weaker, but useful version of this.<p>I should also mention Christopher Strachey -- a great fan of Lisp and McCarthy -- who realized that many kinds of programming could be unified and also be made safer by always using &quot;old&quot; values (from the previous frame) to make new values, which are installed in a the new frame. He realized this by looking at how clean &quot;tail recursion&quot; was in Lisp, and then saw that it could be written much more understandably as a kind of loop involving what looked like assignment statements, but in which the right hand side took values from time t and the variables assigned into existed in time t+1 (and only one such assignment could be made). This unified functional programming and &quot;imperative like&quot; programming via simulating time as well as state.<p>And let me just mention the programming language Lucid, by Ashcroft and Wadge, which extended many of Strachey&#x27;s ideas ...<p>It&#x27;s also worth looking at &quot;atomic transactions&quot; on data bases as a very similar idea with &quot;coarse grain&quot;. Nothing ever gets smashed, instead things are organized so that new versions are created in a non-destructive way without race conditions. There is a history of versions.<p>The key notion here is that &quot;time is a good idea&quot; -- we want it, and we want to deal with it in safe and reasonable ways -- and most if not all of those ways can be purely functional transitions between sequences of stable world-line states.<p>The just computed stable state is very useful. It will never be changed again -- so it represents a &quot;version&quot; of the system simulation -- and it can be safely used as value sources for the functional transitions to the next stable state. It can also be used as sources for creating visualizations of the world at that instant. The history can be used for debugging, undos, roll-backs, etc.<p>In this model -- again partly from McCarthy, Strachey, Simula, etc., -- &quot;time doesn&#x27;t exist between stable states&quot;: the &quot;clock&quot; only advances when each new state is completed. The CPU itself doesn&#x27;t act as a clock as far as programs are concerned.<p>This gives rise to a very simple way to do deterministic relationships that has an intrinsic and clean model of time.<p>For a variety of reasons -- none of them very good -- this way of being safe lost out in the 60s in favor of allowing race conditions in imperative programming and then trying to protect against them using terrible semaphores, etc which can lead to lock ups.<p>I&#x27;ve mentioned a little about my sequence of thoughts about objects. At some point, anyone interested in messaging between objects who knew about Lisp, would have to be drawn to &quot;apply&quot; and to notice that a kind of object (a lambda &quot;thing&quot;, which could be a closure) was bound to parameters (which kind of looked like a message). This got deeper if one was aware of how Lisp 1.5 had been implemented with the possibility of late bound parameter evaluation -- FEXPRs rather than EXPRs -- the unevaluated expressions could be passed as parameters and evaled later. This allowed the ungainly &quot;special forms&quot; (like the conditional) to be dispensed with, they could be written as a kind of vanilla lazy function.<p>By using the temporal modeling mentioned above, one could loosen the &quot;gears&quot; of &quot;eval-apply&quot; and get functional relationships between temporal layers via safe messaging.<p>So, because I&#x27;ve always liked the &quot;simulation perspective&quot; on computing, I think of &quot;objects&quot; and &quot;functions&quot; as being complementary ideas and not at odds at all. (I have many other motivations on the side, including always wondering what a good language for children should be epistemologically ... but that&#x27;s another story.)