{"id":4877,"date":"2018-11-06T19:50:39","date_gmt":"2018-11-06T18:50:39","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=4877"},"modified":"2018-11-06T17:06:28","modified_gmt":"2018-11-06T16:06:28","slug":"the-forgotten-history-of-oop","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2018\/11\/06\/the-forgotten-history-of-oop\/","title":{"rendered":"The Forgotten History of OOP"},"content":{"rendered":"<h1><em><a href=\"https:\/\/medium.com\/javascript-scene\/the-forgotten-history-of-oop-88d71b9b2d9f\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1200\/1%2AuVpU7iruzXafhU2VLeH4lw.jpeg?w=910&#038;ssl=1\" alt=\"\"\/><\/a><a href=\"https:\/\/medium.com\/javascript-scene\/the-forgotten-history-of-oop-88d71b9b2d9f\">The Forgotten History of OOP \u2013 JavaScript Scene \u2013 Medium<\/a><\/em><\/h1>\n<p><!--more--><!--nextpage--><\/p>\n<blockquote><p><a class=\"ds-link ds-link--styleSubtle ui-captionStrong u-inlineBlock link link--darken link--darker\" dir=\"auto\" href=\"https:\/\/medium.com\/@_ericelliott?source=post_header_lockup\" data-action=\"show-user-card\" data-action-source=\"post_header_lockup\" data-action-value=\"c359511de780\" data-action-type=\"hover\" data-user-id=\"c359511de780\">Eric Elliott<\/a><\/p>\n<header class=\"container u-maxWidth740\">\n<div class=\"uiScale uiScale-ui--regular uiScale-caption--regular postMetaHeader u-paddingBottom10 row\">\n<div class=\"col u-size12of12 js-postMetaLockup\">\n<div class=\"uiScale uiScale-ui--regular uiScale-caption--regular postMetaLockup postMetaLockup--authorWithBio u-flexCenter js-postMetaLockup\">\n<div class=\"u-flex1 u-paddingLeft15 u-overflowHidden\">\n<div class=\"ui-caption ui-xs-clamp2 postMetaInline\">Make some magic. <a rel=\"tag\" class=\"hashtag u-tag u-category\" href=\"https:\/\/monodes.com\/predaelli\/tag\/javascript\/\">#JavaScript<\/a><\/div>\n<div class=\"ui-caption postMetaInline js-testPostMetaInlineSupplemental\"><time datetime=\"2018-11-01T00:00:06.433Z\">Nov 1<\/time><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/header>\n<div class=\"postArticle-content js-postField js-notesSource js-trackedPost\" data-post-id=\"88d71b9b2d9f\" data-source=\"post_page\" data-collection-id=\"c0aeac5284ad\" data-tracking-context=\"postPage\" data-scroll=\"native\">\n<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h1 id=\"cf12\" class=\"graf graf--h3 graf--leading graf--title\">The Forgotten History of&nbsp;OOP<\/h1>\n<\/div>\n<div class=\"section-inner sectionLayout--fullWidth\">\n<figure id=\"3c78\" class=\"graf graf--figure graf--layoutFillWidth graf-after--h3\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*uVpU7iruzXafhU2VLeH4lw.jpeg\" data-width=\"5151\" data-height=\"2346\" data-is-featured=\"true\" data-scroll=\"native\"><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/section>\n<\/div>\n<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--fullWidth\">\n<figure id=\"3c78\" class=\"graf graf--figure graf--layoutFillWidth graf-after--h3\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*uVpU7iruzXafhU2VLeH4lw.jpeg\" data-width=\"5151\" data-height=\"2346\" data-is-featured=\"true\" data-scroll=\"native\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/1%2AuVpU7iruzXafhU2VLeH4lw.jpeg?w=910&#038;ssl=1\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/2000\/1*uVpU7iruzXafhU2VLeH4lw.jpeg\"\/><\/div>\n<\/div><figcaption class=\"imageCaption\">Smoke Art Cubes to Smoke\u200a\u2014\u200aMattysFlicks\u200a\u2014\u200a(CC BY&nbsp;2.0)<\/figcaption><\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<blockquote id=\"62a6\" class=\"graf graf--blockquote graf-after--figure\"><p>Note: This is part of the \u201cComposing Software\u201d series on learning functional programming and compositional software techniques in JavaScript ES6+ from the ground up. Stay tuned. There\u2019s a lot more of this to come!<br \/>\n<a class=\"markup--anchor markup--blockquote-anchor\" href=\"https:\/\/medium.com\/javascript-scene\/abstraction-composition-cb2849d5bdd6\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/medium.com\/javascript-scene\/abstraction-composition-cb2849d5bdd6\">&lt; Previous<\/a> | <a class=\"markup--anchor markup--blockquote-anchor\" href=\"https:\/\/medium.com\/javascript-scene\/composing-software-an-introduction-27b72500d6ea\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/medium.com\/javascript-scene\/composing-software-an-introduction-27b72500d6ea\">&lt;&lt; Start over at Part 1<\/a><\/p><\/blockquote>\n<p id=\"8197\" class=\"graf graf--p graf-after--blockquote\">Most of the programming paradigms we use today were first explored mathematically in the 1930s with lambda calculus and the Turing machine, which are alternative formulations of universal computation (formalized systems which can perform general computation). The Church Turing Thesis showed that lambda calculus and Turing machines are functionally equivalent\u200a\u2014\u200athat anything that can be computed using a Turing machine can be computed using lambda calculus, and vice versa.<\/p>\n<blockquote id=\"aa57\" class=\"graf graf--blockquote graf-after--p\"><p>Note: There is a common misconception that Turing machines can compute anything computable. There are classes of problems (e.g., <a class=\"markup--anchor markup--blockquote-anchor\" href=\"https:\/\/en.wikipedia.org\/wiki\/Halting_problem\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/en.wikipedia.org\/wiki\/Halting_problem\">the halting problem<\/a>) that can be computable for some cases, but are not generally computable for all cases using Turing machines. When I use the word \u201ccomputable\u201d in this text, I mean \u201ccomputable by a Turing machine\u201d.<\/p><\/blockquote>\n<p id=\"25d7\" class=\"graf graf--p graf-after--blockquote\">Lambda calculus represents a top-down, function application approach to computation, while the ticker tape\/register machine formulation of the Turing machine represents a bottom-up, imperative (step-by-step) approach to computation.<\/p>\n<p id=\"cfed\" class=\"graf graf--p graf-after--p\">Low level languages like machine code and assembly appeared in the 1940s, and by the end of the 1950s, the first popular programming high-level languages implementing both functional and imperative approaches appeared. Lisp dialects are still in common use today, including Clojure, Scheme, AutoLISP, etc. FORTRAN and COBOL both appeared in the 1950s and are examples of imperative high-level languages still in use today, though C-family languages have replaced both COBOL and FORTRAN for most applications.<\/p>\n<p id=\"77a2\" class=\"graf graf--p graf-after--p\">Both imperative programming and functional programming have their roots in the formal mathematics of computation, and predate digital computers. Object Oriented Programming (OOP) came later, and has its roots in the structured programming revolution that arrived in the 1960s and 1970s.<\/p>\n<p id=\"c4f6\" class=\"graf graf--p graf-after--p\">The first objects I know of were used by Ivan Sutherland in his seminal Sketchpad application, created between 1961 and 1962 and published in his <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/dspace.mit.edu\/handle\/1721.1\/14979\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/dspace.mit.edu\/handle\/1721.1\/14979\">Sketchpad Thesis<\/a> in 1963. The objects represented graphical glyphs displayed on an oscilloscope screen (possibly the first use of a graphical computer monitor), and featured inheritance via dynamic delegates, which Ivan Sutherland called \u201cmasters\u201d in his thesis. Any object could become a \u201cmaster\u201d, and additional instances of the objects were called \u201coccurrences\u201d. This makes Sketchpad the first known programming language that implemented prototypal inheritance.<\/p>\n<p id=\"38c0\" class=\"graf graf--p graf-after--p\">The first programming language widely recognized as \u201cobject oriented\u201d was Simula, specified in 1965. Like Sketchpad, Simula featured objects, but also featured classes, class inheritance, subclasses, and virtual methods.<\/p>\n<blockquote id=\"1ada\" class=\"graf graf--blockquote graf-after--p\"><p>Note: A <strong class=\"markup--strong markup--blockquote-strong\">virtual method<\/strong> is a method defined on a class which is designed to be overridden by subclasses. Virtual methods allow a program to call methods that may not exist at the moment the code is compiled by employing dynamic dispatch to determine what concrete method to invoke at runtime. JavaScript features dynamic types and uses the delegation chain to determine which methods to invoke, so does not need to expose the concept of virtual methods to programmers. Put another way, all methods in JavaScript use runtime method dispatch, so methods in JavaScript don\u2019t need to be declared \u201cvirtual\u201d to support the feature.<\/p><\/blockquote>\n<h3 id=\"6222\" class=\"graf graf--h3 graf-after--blockquote\">What the Father of Object-Oriented Programming Wants You to Know About&nbsp;OOP<\/h3>\n<blockquote id=\"fe0b\" class=\"graf graf--pullquote graf--startsWithDoubleQuote graf-after--h3\"><p><em class=\"markup--em markup--pullquote-em\">\u201cI made up the term \u2018object-oriented\u2019, and I can tell you I didn\u2019t have C++ in mind.\u201d ~ Alan Kay, OOPSLA&nbsp;\u201897<\/em><\/p><\/blockquote>\n<p id=\"edba\" class=\"graf graf--p graf-after--pullquote\">Alan Kay coined the term \u201cObject Oriented Programming\u201d in reference to the Smalltalk programming language (1972), which was developed by Alan Kay, Dan Ingalls, and others at Xerox Park for a laptop project called \u201cDynabook\u201d. Smalltalk was more object-oriented than Simula\u200a\u2014\u200aeverything in Smalltalk is an object, including classes, integers, and blocks (closures). The original Smalltalk-72 did not feature subclassing. That was introduced in Smalltalk-76.<\/p>\n<p id=\"d58f\" class=\"graf graf--p graf-after--p\">While Smalltalk supported classes and eventually subclassing, Smalltalk was not about classes or subclassing things. It was a functional language inspired as much by Lisp as it was by Simula. Alan Kay considers classes as a code reuse mechanism to be a mistake, and the industry\u2019s focus on subclassing to be a distraction from the true benefits of object oriented programming.<\/p>\n<p id=\"a41f\" class=\"graf graf--p graf-after--p\">Because they share so many features in common, I like to say that JavaScript is Smalltalk\u2019s revenge on the world\u2019s misunderstanding of OOP. Both Smalltalk and JavaScript support:<\/p>\n<ul class=\"postList\">\n<li id=\"b132\" class=\"graf graf--li graf-after--p\">Objects<\/li>\n<li id=\"e8e4\" class=\"graf graf--li graf-after--li\">First-class functions and closures<\/li>\n<li id=\"bb4e\" class=\"graf graf--li graf-after--li\">Dynamic types<\/li>\n<li id=\"fbac\" class=\"graf graf--li graf-after--li\">Late binding (functions\/methods changeable at runtime)<\/li>\n<li id=\"fc38\" class=\"graf graf--li graf-after--li\">OOP without class inheritance<\/li>\n<\/ul>\n<blockquote id=\"3d18\" class=\"graf graf--blockquote graf--startsWithDoubleQuote graf-after--li\"><p>\u201cI\u2019m sorry that I long ago coined the term \u201cobjects\u201d for this topic because it gets many people to focus on the lesser idea. The big idea is messaging.\u201d<br \/>\n~ Alan Kay<\/p><\/blockquote>\n<p id=\"f1f4\" class=\"graf graf--p graf-after--blockquote\">In <a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/www.purl.org\/stefan_ram\/pub\/doc_kay_oop_en\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"http:\/\/www.purl.org\/stefan_ram\/pub\/doc_kay_oop_en\">a 2003 email exchange<\/a>, Alan Kay clarified what he meant when he called Smalltalk \u201cobject-oriented\u201d:<\/p>\n<blockquote id=\"40c5\" class=\"graf graf--blockquote graf--startsWithDoubleQuote graf-after--p\"><p><span class=\"markup--quote markup--blockquote-quote is-other\" data-creator-ids=\"anon\">\u201cOOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.\u201d<br \/>\n~ Alan Kay<\/span><\/p><\/blockquote>\n<p id=\"512b\" class=\"graf graf--p graf-after--blockquote\">In other words, according to Alan Kay, the essential ingredients of OOP are:<\/p>\n<ul class=\"postList\">\n<li id=\"b6c6\" class=\"graf graf--li graf-after--p\">Message passing<\/li>\n<li id=\"23fd\" class=\"graf graf--li graf-after--li\">Encapsulation<\/li>\n<li id=\"5ce9\" class=\"graf graf--li graf-after--li\">Dynamic binding<\/li>\n<\/ul>\n<p id=\"1a70\" class=\"graf graf--p graf-after--li\">Notably, inheritance and polymorphism were NOT considered essential ingredients of OOP by Alan Kay, the man who coined the term and brought OOP to the masses.<\/p>\n<h3 id=\"a0b6\" class=\"graf graf--h3 graf-after--p\">The Essence of&nbsp;OOP<\/h3>\n<p id=\"a9a5\" class=\"graf graf--p graf-after--h3\">The combination of message passing and encapsulation serve some important purposes:<\/p>\n<ul class=\"postList\">\n<li id=\"bebd\" class=\"graf graf--li graf-after--p\"><strong class=\"markup--strong markup--li-strong\">Avoiding shared mutable state<\/strong> by encapsulating state and isolating other objects from local state changes. The only way to affect another object\u2019s state is to ask (not command) that object to change it by sending a message. State changes are controlled at a local, cellular level rather than exposed to shared access.<\/li>\n<li id=\"7faa\" class=\"graf graf--li graf-after--li\"><strong class=\"markup--strong markup--li-strong\">Decoupling<\/strong> objects from each other\u200a\u2014\u200athe message sender is only loosely coupled to the message receiver, through the messaging API.<\/li>\n<li id=\"dccf\" class=\"graf graf--li graf-after--li\"><strong class=\"markup--strong markup--li-strong\">Adaptability and resilience to changes<\/strong> at runtime via late binding. Runtime adaptability provides many great benefits that Alan Kay considered essential to OOP.<\/li>\n<\/ul>\n<p id=\"60c6\" class=\"graf graf--p graf-after--li\">These ideas were inspired by biological cells and\/or individual computers on a network via Alan Kay\u2019s background in biology and influence from the design of ARPANet (an early version of the internet). Even that early on, Alan Kay imagined software running on a giant, distributed computer (the internet), where individual computers acted like biological cells, operating independently on their own isolated state, and communicating via message passing.<\/p>\n<blockquote id=\"274e\" class=\"graf graf--blockquote graf--startsWithDoubleQuote graf-after--p\"><p>\u201cI realized that the cell\/whole-computer metaphor would get rid of data[\u2026]\u201d<br \/>\n~ Alan Kay<\/p><\/blockquote>\n<p id=\"2a29\" class=\"graf graf--p graf-after--blockquote\">By \u201cget rid of data\u201d, Alan Kay was surely aware of shared mutable state problems and tight coupling caused by shared data\u200a\u2014\u200acommon themes today.<\/p>\n<p id=\"2af6\" class=\"graf graf--p graf-after--p\">But in the late 1960s, ARPAnet programmers were frustrated by the need to choose a data model representation for their programs in advance of building software. Developers wanted to get away from that because locking yourself into a data representation early could make it hard to change things later.<\/p>\n<p id=\"e416\" class=\"graf graf--p graf-after--p\">The problem was that different data representations required different code and different syntax to access in the programming languages of the day. The holy grail would be a universal way to access and manipulate data. If all data looked the same to the program, it would solve a lot of software evolution and maintenance problems for software developers.<\/p>\n<p id=\"bf25\" class=\"graf graf--p graf-after--p\">Alan Kay was trying to \u201cget rid of\u201d the idea that data and software were somehow separate things\u200a\u2014\u200athey\u2019re not treated differently in Lisp or Smalltalk. There is no separation between what you can do with data (values, variables, data structures, etc\u2026) and software constructs like functions. Functions are first-class citizens, and software is allowed to change at runtime. In other words, in Smalltalk, data does not get special, privileged treatment.<\/p>\n<p id=\"7c7a\" class=\"graf graf--p graf-after--p\">Alan Kay also saw objects as algebraic structures, which make certain mathematically provable guarantees about their behaviors:<\/p>\n<blockquote id=\"cb32\" class=\"graf graf--blockquote graf--startsWithDoubleQuote graf-after--p\"><p>\u201cMy math background made me realize that each object could have several algebras associated with it, and there could be families of these, and that these would be very very useful.\u201d<br \/>\n~ Alan Kay<\/p><\/blockquote>\n<p id=\"46e0\" class=\"graf graf--p graf-after--blockquote\">This has proven to be true, and forms the basis for objects such as promises and lenses, both inspired by category theory.<\/p>\n<p id=\"bd49\" class=\"graf graf--p graf-after--p\">The algebraic nature of Alan Kay\u2019s vision for objects would allow objects to afford formal verifications, deterministic behavior, and improved testability, because algebras are essentially operations which obey a few rules in the form of equations.<\/p>\n<p id=\"8244\" class=\"graf graf--p graf-after--p\">In programmer lingo, algebras are abstractions made up of functions (operations) accompanied by specific laws enforced by unit tests those functions must pass (axioms\/equations).<\/p>\n<p id=\"019f\" class=\"graf graf--p graf-after--p\">Those ideas were forgotten for decades in most C-family OO languages, including C++, Java, C#, etc., but they\u2019re beginning to find their way back into recent versions of most widely used OO languages.<\/p>\n<p id=\"56d3\" class=\"graf graf--p graf-after--p\">You might say the programming world is rediscovering the benefits of functional programming and reasoned thought in the context of OO languages.<\/p>\n<p id=\"c712\" class=\"graf graf--p graf-after--p\">Like JavaScript and Smalltalk before it, most modern OO languages are becoming more and more \u201cmulti-paradigm languages\u201d. There is no reason to choose between functional programming and OOP. When we look at the historical essence of each, they are not only compatible, but complementary ideas.<\/p>\n<p id=\"436a\" class=\"graf graf--p graf-after--p\">What is essential to OOP (according to Alan Kay)?<\/p>\n<ul class=\"postList\">\n<li id=\"9a19\" class=\"graf graf--li graf-after--p\">Encapsulation<\/li>\n<li id=\"959f\" class=\"graf graf--li graf-after--li\">Message passing<\/li>\n<li id=\"c4c7\" class=\"graf graf--li graf-after--li\">Dynamic binding (the ability for the program to evolve\/adapt at runtime)<\/li>\n<\/ul>\n<p id=\"8cc9\" class=\"graf graf--p graf-after--li\">What is non-essential?<\/p>\n<ul class=\"postList\">\n<li id=\"06d3\" class=\"graf graf--li graf-after--p\">Classes<\/li>\n<li id=\"84e7\" class=\"graf graf--li graf-after--li\">Class inheritance<\/li>\n<li id=\"3849\" class=\"graf graf--li graf-after--li\">Special treatment for objects\/functions\/data<\/li>\n<li id=\"d224\" class=\"graf graf--li graf-after--li\">The <code class=\"\" data-line=\"\">new<\/code> keyword<\/li>\n<li id=\"53cb\" class=\"graf graf--li graf-after--li\">Polymorphism<\/li>\n<li id=\"0fe5\" class=\"graf graf--li graf-after--li\">Static types<\/li>\n<li id=\"86db\" class=\"graf graf--li graf-after--li\">Recognizing a class as a \u201ctype\u201d<\/li>\n<\/ul>\n<p id=\"a3c9\" class=\"graf graf--p graf-after--li\">If your background is Java or C#, you may be thinking static types and Polymorphism are essential ingredients, but Alan Kay preferred dealing with generic behaviors in algebraic form. For example, from Haskell:<\/p>\n<pre id=\"b7de\" class=\"graf graf--pre graf-after--p\">fmap :: (a -&gt; b) -&gt; f a -&gt; f b<\/pre>\n<p id=\"337f\" class=\"graf graf--p graf-after--pre\">This is the functor map signature, which acts generically over unspecified types <code class=\"\" data-line=\"\">a<\/code> and <code class=\"\" data-line=\"\">b<\/code>, applying a function from <code class=\"\" data-line=\"\">a<\/code> to <code class=\"\" data-line=\"\">b<\/code> in the context of a functor of <code class=\"\" data-line=\"\">a<\/code> to produce a functor of <code class=\"\" data-line=\"\">b<\/code>. Functor is math jargon that essentially means \u201csupporting the map operation\u201d. If you&#8217;re familiar with <code class=\"\" data-line=\"\">[].map()<\/code> in JavaScript, you already know what that means.<\/p>\n<p id=\"8e19\" class=\"graf graf--p graf-after--p\">Here are two examples in JavaScript:<\/p>\n<pre id=\"ee47\" class=\"graf graf--pre graf-after--p\">\/\/ isEven = Number =&gt; Boolean\nconst isEven = n =&gt; n % 2 === 0;<\/pre>\n<pre id=\"386b\" class=\"graf graf--pre graf-after--pre\">const nums = [1, 2, 3, 4, 5, 6];<\/pre>\n<pre id=\"041c\" class=\"graf graf--pre graf-after--pre\">\/\/ map takes a function `a =&gt; b` and an array of `a`s (via `this`)\n\/\/ and returns an array of `b`s.\n\/\/ in this case, `a` is `Number` and `b` is `Boolean`\nconst results = nums.map(isEven);<\/pre>\n<pre id=\"ec01\" class=\"graf graf--pre graf-after--pre\">console.log(results);\n\/\/ [false, true, false, true, false, true]<\/pre>\n<p id=\"ea75\" class=\"graf graf--p graf-after--pre\">The&nbsp;<code class=\"\" data-line=\"\">.map()<\/code> method is generic in the sense that <code class=\"\" data-line=\"\">a<\/code> and <code class=\"\" data-line=\"\">b<\/code> can be any type, and&nbsp;<code class=\"\" data-line=\"\">.map()<\/code> handles it just fine because arrays are data structures that implement the algebraic <code class=\"\" data-line=\"\">functor<\/code> laws. The types don&#8217;t matter to&nbsp;<code class=\"\" data-line=\"\">.map()<\/code> because it doesn&#8217;t try to manipulate them directly, instead applying a function that expects and returns the correct types for the application.<\/p>\n<pre id=\"768e\" class=\"graf graf--pre graf-after--p\">\/\/ matches = a =&gt; Boolean\n\/\/ here, `a` can be any comparable type\nconst matches = control =&gt; input =&gt; input === control;<\/pre>\n<pre id=\"a406\" class=\"graf graf--pre graf-after--pre\">const strings = ['foo', 'bar', 'baz'];<\/pre>\n<pre id=\"09f9\" class=\"graf graf--pre graf-after--pre\">const results = strings.map(matches('bar'));<\/pre>\n<pre id=\"049f\" class=\"graf graf--pre graf-after--pre\">console.log(results);\n\/\/ [false, true, false]<\/pre>\n<p id=\"ba8e\" class=\"graf graf--p graf-after--pre\">This generic type relationship is difficult to express correctly and thoroughly in a language like TypeScript, but was pretty easy to express in Haskell\u2019s Hindley Milner types with support for higher kinded types (types of types).<\/p>\n<p id=\"1ac5\" class=\"graf graf--p graf-after--p\">Most type systems have been too restrictive to allow for free expression of dynamic and functional ideas, such as function composition, free object composition, runtime object extension, combinators, lenses, etc. In other words, static types frequently make it harder to write composable software.<\/p>\n<p id=\"e5a9\" class=\"graf graf--p graf-after--p\">If your type system is too restrictive (e.g., TypeScript, Java), you\u2019re forced to write more convoluted code to accomplish the same goals. That doesn\u2019t mean static types are a bad idea, or that all static type implementations are equally restrictive. I have encountered far fewer problems with Haskell\u2019s type system.<\/p>\n<p id=\"cff7\" class=\"graf graf--p graf-after--p\">If you\u2019re a fan of static types and you don\u2019t mind the restrictions, more power to you, but if you find some of the advice in this text difficult because it\u2019s hard to type composed functions and composite algebraic structures, blame the type system, not the ideas. People love the comfort of their SUVs, but nobody complains that they don\u2019t let you fly. For that, you need a vehicle with more degrees of freedom.<\/p>\n<p id=\"054a\" class=\"graf graf--p graf-after--p\">If restrictions make your code simpler, great! But if restrictions force you to write more complicated code, perhaps the restrictions are wrong.<\/p>\n<h3 id=\"339a\" class=\"graf graf--h3 graf-after--p\">What is an&nbsp;Object?<\/h3>\n<p id=\"e7b5\" class=\"graf graf--p graf-after--h3\">Objects have clearly taken on a lot of connotations over the years. What we call \u201cobjects\u201d in JavaScript are simply composite data types, with none of the implications from either class-based programming or Alan Kay\u2019s message-passing.<\/p>\n<p id=\"4135\" class=\"graf graf--p graf-after--p\">In JavaScript, those objects can and frequently do support encapsulation, message passing, behavior sharing via methods, even subclass polymorphism (albeit using a delegation chain rather than type-based dispatch).<\/p>\n<p id=\"7e74\" class=\"graf graf--p graf-after--p\">Alan Kay wanted to be rid of the distinction between the program and its data. JavaScript does that to some degree by putting methods on the same footing as data properties. You can assign any function to any property. You can build object behaviors dynamically, and change the meaning of an object at runtime.<\/p>\n<p id=\"a332\" class=\"graf graf--p graf-after--p\">An object is simply a composite data structure, and does not require anything more to be considered an object. But programming using objects does not make your code \u201cobject-oriented\u201d any more than programming with functions makes your code \u201cfunctional\u201d.<\/p>\n<h4 id=\"561b\" class=\"graf graf--h4 graf-after--p\">OOP is not Real OOP&nbsp;Anymore<\/h4>\n<p id=\"554f\" class=\"graf graf--p graf-after--h4\">Because \u201cobject\u201d in modern programming languages means much less than it did to Alan Kay, I\u2019m using \u201ccomponent\u201d instead of \u201cobject\u201d to describe the rules of <em class=\"markup--em markup--p-em\">real OOP. <\/em>Many <em class=\"markup--em markup--p-em\">objects<\/em> are owned and manipulated directly by other code in JavaScript, but <strong class=\"markup--strong markup--p-strong\">components<\/strong> should encapsulate and control their own state.<\/p>\n<p id=\"4a23\" class=\"graf graf--p graf-after--p\">Real OOP means:<\/p>\n<ul class=\"postList\">\n<li id=\"ae54\" class=\"graf graf--li graf-after--p\">Programming with <strong class=\"markup--strong markup--li-strong\">components <\/strong>(Alan Kay\u2019s \u201cobject\u201d)<\/li>\n<li id=\"450a\" class=\"graf graf--li graf-after--li\">Component state must be encapsulated<\/li>\n<li id=\"7af0\" class=\"graf graf--li graf-after--li\">Using message passing for inter-object communication<\/li>\n<li id=\"321e\" class=\"graf graf--li graf-after--li\">Components can be added\/changed\/replaced at runtime<\/li>\n<\/ul>\n<p id=\"d186\" class=\"graf graf--p graf-after--li\">Most component behaviors can be specified generically using algebraic data structures. Inheritance is not needed here. Components can reuse behaviors from shared functions and modular imports without sharing their data.<\/p>\n<p id=\"f5e7\" class=\"graf graf--p graf-after--p\">Manipulating <em class=\"markup--em markup--p-em\">objects<\/em> or using <em class=\"markup--em markup--p-em\">class inheritance<\/em> in JavaScript does not mean that you\u2019re \u201cdoing OOP\u201d. Using components in this way <em class=\"markup--em markup--p-em\">does. <\/em>But popular usage is how words get defined, so perhaps we should abandon OOP and call this \u201cMessage Oriented Programming (MOP)\u201d instead of \u201cObject Oriented Programming (OOP)\u201d?<\/p>\n<p id=\"b798\" class=\"graf graf--p graf-after--p\">Is it coincidence that mops are used to clean up messes?<\/p>\n<h3 id=\"ed05\" class=\"graf graf--h3 graf-after--p\">What Good MOP Looks&nbsp;Like<\/h3>\n<p id=\"2f7f\" class=\"graf graf--p graf-after--h3\">In most modern software, there is some UI responsible for managing user interactions, some code managing application state (user data), and code managing system or network I\/O.<\/p>\n<p id=\"b782\" class=\"graf graf--p graf-after--p\">Each of those systems may require long-lived processes, such as event listeners, state to keep track of things like the network connection, ui element status, and the application state itself.<\/p>\n<p id=\"98f8\" class=\"graf graf--p graf-after--p\">Good MOP means that instead of all of these systems reaching out and directly manipulating each other\u2019s state, the system communicates with other components via message dispatch. When the user clicks on a save button, a <code class=\"\" data-line=\"\">&quot;SAVE&quot;<\/code> message might get dispatched, which an application state component might interpret and relay to a state update handler (such as a pure reducer function). Perhaps after the state has been updated, the state component might dispatch a <code class=\"\" data-line=\"\">&quot;STATE_UPDATED&quot;<\/code> message to a UI component, which in turn will interpret the state, reconcile what parts of the UI need to be updated, and relay the updated state to the subcomponents that handle those parts of the UI.<\/p>\n<p id=\"95ef\" class=\"graf graf--p graf-after--p\">Meanwhile, the network connection component might be monitoring the user\u2019s connection to another machine on the network, listening for messages, and dispatching updated state representations to save data on a remote machine. It\u2019s internally keeping track of a network heartbeat timer, whether the connection is currently online or offline, and so on.<\/p>\n<p id=\"0cae\" class=\"graf graf--p graf-after--p\">These systems don\u2019t need to know about the details of the other parts of the system. Only about their individual, modular concerns. The system components are decomposable and recomposable. They implement standardized interfaces so that they are able to interoperate. As long as the interface is satisfied, you could substitute replacements which may do the same thing in different ways, or completely different things with the same messages. You may even do so at runtime, and everything would keep working properly.<\/p>\n<p id=\"42bd\" class=\"graf graf--p graf-after--p\">Components of the same software system may not even need to be located on the same machine. The system could be decentralized. The network storage might shard the data across a decentralized storage system like <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/en.wikipedia.org\/wiki\/InterPlanetary_File_System\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/en.wikipedia.org\/wiki\/InterPlanetary_File_System\">IPFS<\/a>, so that the user is not reliant on the health of any particular machine to ensure their data is safely backed up, and safe from hackers who might want to steal it.<\/p>\n<p id=\"4196\" class=\"graf graf--p graf-after--p\">OOP was partially inspired by ARPAnet, and one of the goals of ARPAnet was to build a decentralized network that could be resilient to attacks like atomic bombs.<\/p>\n<p id=\"5a3e\" class=\"graf graf--p graf-after--p\">A good MOP system might share those properties using components that are hot-swappable while the application is running. It could continue to work if the user is on a cell phone and they go offline because they entered a tunnel. It could continue to function if a hurricane knocks out the power to one of the data centers where servers are located.<\/p>\n<p id=\"93fc\" class=\"graf graf--p graf-after--p\">It\u2019s time for the software world to let go of the failed class inheritance experiment, and embrace the math and science principles that originally defined the spirit of OOP.<\/p>\n<p id=\"22ce\" class=\"graf graf--p graf-after--p\">It\u2019s time for us to start building more flexible, more resilient, better-composed software, with MOP and functional programming working in harmony.<\/p>\n<blockquote id=\"04c3\" class=\"graf graf--blockquote graf-after--p\"><p>Note: The MOP acronym is already used to describe \u201cmonitoring-oriented programming\u201d and its unlikely OOP is going to go away quietly.<\/p><\/blockquote>\n<blockquote id=\"89ca\" class=\"graf graf--blockquote graf-after--blockquote\"><p>Don\u2019t be upset if MOP doesn\u2019t catch on as programming lingo.<br \/>\nDo MOP up your OOPs.<\/p><\/blockquote>\n<h3 id=\"90b0\" class=\"graf graf--h3 graf-after--blockquote\">Learn More at EricElliottJS.com<\/h3>\n<p id=\"d76c\" class=\"graf graf--p graf-after--h3 graf--trailing\">Video lessons on functional programming are available for members of EricElliottJS.com. If you\u2019re not a member, <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/ericelliottjs.com\/\" target=\"_blank\" rel=\"nofollow noopener nofollow noopener nofollow noopener nofollow noopener nofollow noopener\" data-href=\"https:\/\/ericelliottjs.com\/\">sign up today<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body section--last\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\"\/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"5e7e\" class=\"graf graf--p graf--leading\"><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Eric Elliott<\/em><\/strong><em class=\"markup--em markup--p-em\"> is the author of <\/em><a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/pjabook.com\" target=\"_blank\" rel=\"nofollow noopener nofollow noopener noopener nofollow noopener nofollow noopener nofollow noopener nofollow noopener nofollow noopener nofollow noopener\" data-href=\"http:\/\/pjabook.com\"><em class=\"markup--em markup--p-em\">\u201cProgramming JavaScript Applications\u201d<\/em><\/a><em class=\"markup--em markup--p-em\"> (O\u2019Reilly), and cofounder of the software mentorship platform, <\/em><a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/devanywhere.io\/\" target=\"_blank\" rel=\"nofollow noopener nofollow noopener\" data-href=\"https:\/\/devanywhere.io\/\"><em class=\"markup--em markup--p-em\">DevAnywhere.io<\/em><\/a><em class=\"markup--em markup--p-em\">. He has contributed to software experiences for <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Adobe Systems<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Zumba Fitness<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">The Wall Street Journal<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">ESPN<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">BBC<\/em><\/strong><em class=\"markup--em markup--p-em\">, and top recording artists including <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Usher<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Frank Ocean<\/em><\/strong><em class=\"markup--em markup--p-em\">, <\/em><strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Metallica<\/em><\/strong><em class=\"markup--em markup--p-em\">, and many more.<\/em><\/p>\n<p id=\"98ef\" class=\"graf graf--p graf-after--p graf--trailing\"><em class=\"markup--em markup--p-em\">He works remote from anywhere with the most beautiful woman in the world.<\/em><\/p>\n<\/div>\n<\/div>\n<\/section>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">The Forgotten History of OOP \u2013 JavaScript Scene \u2013 Medium<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2018\/11\/06\/the-forgotten-history-of-oop\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72],"tags":[],"class_list":["post-4877","post","type-post","status-publish","format-standard","hentry","category-documentations"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-1gF","jetpack-related-posts":[{"id":1614,"url":"https:\/\/monodes.com\/predaelli\/2016\/06\/01\/javascript-factory-functions-vs-constructor-functions-vs-classes-javascript-scene-medium\/","url_meta":{"origin":4877,"position":0},"title":"JavaScript Factory Functions vs Constructor Functions vs Classes \u2014 JavaScript Scene \u2014 Medium","author":"Paolo Redaelli","date":"2016-06-01","format":"link","excerpt":"https:\/\/medium.com\/javascript-scene\/javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e#.13avjf4lk","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9317,"url":"https:\/\/monodes.com\/predaelli\/2022\/04\/28\/7-more-killer-one-liners-in-javascript-by-tapajyoti-bose-apr-2022-medium\/","url_meta":{"origin":4877,"position":1},"title":"7 More Killer One-Liners in JavaScript | by Tapajyoti Bose | Apr, 2022 | Medium","author":"Paolo Redaelli","date":"2022-04-28","format":false,"excerpt":"7 More Killer One-Liners in JavaScript | by Tapajyoti Bose | Apr, 2022 | Medium This is a continuation of the previous list of JavaScript one-liners. If you haven\u2019t checked out the article, you are highly encouraged to accomplish so. Let\u2019s crack on with the new list! 1. Sleep Function\u2026","rel":"","context":"In &quot;Javascript&quot;","block_context":{"text":"Javascript","link":"https:\/\/monodes.com\/predaelli\/category\/javascript\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14254,"url":"https:\/\/monodes.com\/predaelli\/2025\/11\/04\/abandonware-of-the-web-do-you-know-that-there-is-an-html-tables-api\/","url_meta":{"origin":4877,"position":2},"title":"Abandonware of the web: do you know that there is an HTML tables API?","author":"Paolo Redaelli","date":"2025-11-04","format":false,"excerpt":"Abandonware of the web: do you know that there is an HTML tables API? When people turn data into HTML tables using JavaScript, they either use the DOM methods (createElement() and the likes), but most of the time just append a huge string and use innerHTML, which always is a\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8275,"url":"https:\/\/monodes.com\/predaelli\/2021\/03\/26\/its-what-they-told-you-about-oop-that-sucks\/","url_meta":{"origin":4877,"position":3},"title":"It&#8217;s what they told you about OOP that sucks","author":"Paolo Redaelli","date":"2021-03-26","format":false,"excerpt":"These days it seems to be fashionable to say that \"OO sucks\". Why OO Sucks by Joe Armstrong. We already read argumentations like this. That's why the almighty Giuseppe Mazzapica titled one of his presentation What they told you about OOP is wrong This is also the case: dear Joe,\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5130,"url":"https:\/\/monodes.com\/predaelli\/2019\/01\/15\/intuitive-asynchronous-javascript-edwin-yung-medium\/","url_meta":{"origin":4877,"position":4},"title":"Intuitive Asynchronous Javascript \u2013 Edwin Yung \u2013 Medium","author":"Paolo Redaelli","date":"2019-01-15","format":false,"excerpt":"Escape callback hell! Source: Intuitive Asynchronous Javascript \u2013 Edwin Yung \u2013 Medium \u00a0 Asynchronous Javascript Explained Simply and Intuitively Edwin Yung Dec 29, 2017 Escape callback hell with this\u00a0article! Asynchronous Javascript is difficult to wrangle. The following is my quick attempt to elucidate their inner workings. Before we get started,\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9041,"url":"https:\/\/monodes.com\/predaelli\/2022\/01\/04\/is-the-macos-gui-development-scene-really-this-bad\/","url_meta":{"origin":4877,"position":5},"title":"Is the macOS GUI development scene really this bad?","author":"Paolo Redaelli","date":"2022-01-04","format":false,"excerpt":"Paul WalkerFollow on last summer asked Is the macOS GUI development scene really this bad? That's a question I'm interested in because while I've been using exclusively Linux since 1997 I strive to write portable programs. Most people are still \"shackled\" into proprietary operative systems. He enlist Swift, JavaScript, C#,\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/4877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=4877"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/4877\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=4877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=4877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=4877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}