{"id":8275,"date":"2021-03-26T20:31:00","date_gmt":"2021-03-26T19:31:00","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=8275"},"modified":"2021-03-26T08:23:48","modified_gmt":"2021-03-26T07:23:48","slug":"its-what-they-told-you-about-oop-that-sucks","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2021\/03\/26\/its-what-they-told-you-about-oop-that-sucks\/","title":{"rendered":"It&#8217;s what they told you about OOP that sucks"},"content":{"rendered":"\n<p>These days it seems to be fashionable to say that &#8220;OO sucks&#8221;. Why OO Sucks by Joe Armstrong.<\/p>\n\n\n\n<p>We already read argumentations like this. That&#8217;s why the almighty <a href=\"https:\/\/gmazzap.me\/\">Giuseppe Mazzapica<\/a> titled one of his presentation<\/p>\n\n\n\n<p class=\"has-text-align-center has-large-font-size\"><a href=\"https:\/\/speakerdeck.com\/gmazzap\/what-they-told-you-about-oop-is-wrong\">What they told you about OOP is wrong<\/a><\/p>\n\n\n\n<p>This is also the case: dear Joe, your remarks are based on assumptions that often are not true.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Let&#8217;s see them:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>&#8220;Data structure and functions should not be bound together&#8221;. This assumes that functions have ominiscent knowledge of their input. I found the concept of Abstract Data Type really useful<\/li><li>&#8220;Everything has to be an object&#8221;. Well, in a computer everything is a sequence of bits. How we interpret them and what they represent is another matter. An object is what a sequence of bits represents and the (basic) operations we can do on them.<\/li><li>&#8220;In an OOPL data type definitions are spread out all over the place&#8221;. That&#8217;s usually because people make bad design and &#8220;too fat&#8221; modules.<\/li><li>&#8220;Objects have private state&#8221;. Also functional programming languages have private states. They just call turn it into an argument of the function. When you note that the typical OO notation joe.paint(a_box, yellow) turns into a_box = Painter_paint(joe, a_box, yellow) you are just a few steps away from a_box.add(my_pencil) which becames in a purely functional language such as Haskell <\/li><\/ol>\n\n\n\n<p>Data immutability is a nice concept, but tends to impact on performances. At least <a href=\"https:\/\/benchmarksgame-team.pages.debian.net\/benchmarksgame\/which-programs-are-fastest.html\">on Haskell it did<\/a>. <\/p>\n\n\n\n<p>Searching how Haskell handles state I discovered it has a really nice <a href=\"http:\/\/book.realworldhaskell.org\/read\/data-structures.html\">way to deal with units of measure<\/a>. I shall find a way to implement it in Eiffel.<\/p>\n\n\n\n<p>Summarizing, I would re-study <a href=\"https:\/\/en.wikipedia.org\/wiki\/SOLID_(object-oriented_design)\"><strong>SOLID<\/strong> <\/a> principles<\/p>\n\n\n\n<!--nextpage-->\n\n\n<blockquote>\n<article>\n<h1>Why OO Sucks by Joe Armstrong<\/h1>\n<p>(<em><strong>Note<\/strong>: This is a copy of the original that used to live at http:\/\/www.bluetail.com\/~joe\/vol1\/v1_oo.html<\/em>)<\/p>\n<p>When I was first introduced to the idea of OOP I was skeptical but didn\u2019t know why &#8211; it just felt \u201cwrong\u201d. After its introduction OOP became very popular (I will explain why later) and criticising OOP was rather like \u201cswearing in church\u201d. OOness became something that every respectable language just had to have.<\/p>\n<p>As Erlang became popular we were often asked \u201cIs Erlang OO\u201d &#8211; well, of course the true answer was \u201cNo of course not\u201d &#8211; but we didn\u2019t to say this out loud &#8211; so we invented a serious of ingenious ways of answering the question that were designed to give the impression that Erlang was (sort of) OO (If you waved your hands a lot) but not really (If you listened to what we actually said, and read the small print <em>carefully<\/em>).<\/p>\n<p>At this point I am reminded of the keynote speech of the then boss of IBM in France who addressed the audience at the 7th IEEE Logic programming conference in Paris. IBM prolog had added a lot of OO extensions, when asked why he replied:<\/p>\n<p>\u201c<em>Our customers wanted OO prolog so we made OO prolog<\/em>\u201d<\/p>\n<p>I remember thinking \u201chow simple, no qualms of conscience, no soul-searching, no asking &#8220;Is this the right thing to do\u201d \u2026<\/p>\n<h2>Why OO sucks<\/h2>\n<p>My principle objection to OOP goes back to the basic ideas involved, I will outline some of these ideas and my objections to them.<\/p>\n<h2>Objection 1 &#8211; Data structure and functions should not be bound together<\/h2>\n<p>Objects bind functions and data structures together in indivisible units. I think this is a fundamental error since functions and data structures belong in totally different worlds. Why is this?<\/p>\n<p>*Functions do things. They have inputs and outputs. The inputs and outputs are data structures, which get changed by the functions. In most languages functions are built from sequences of imperatives: \u201cDo this and then that \u2026\u201d to understand functions you have to understand the order in which things get done (In lazy FPLs and logical languages this restriction is relaxed).<\/p>\n<ul>\n<li>Data structures just are. They don\u2019t do anything. They are intrinsically declarative. \u201cUnderstanding\u201d a data structure is a lot easier than \u201cunderstanding\u201d a function.<\/li>\n<\/ul>\n<p>Functions are understood as black boxes that transform inputs to outputs. If I understand the input and the output then I have understood the function. <em>This does not mean to say that I could have written the function<\/em>.<\/p>\n<p>Functions are usually \u201cunderstood\u201d by observing that they are the things in a computational system whose job is to transfer data structures of type T1 into data structure of type T2.<\/p>\n<p><strong>Since functions and data structures are completely different types of animal it is fundamentally incorrect to lock them up in the same cage.<\/strong><\/p>\n<h2>Objection 2 &#8211; Everything has to be an object<\/h2>\n<p>Consider \u201ctime\u201d. In an OO language \u201ctime\u201d has to be an object. But in a non OO language a \u201ctime\u201d is a instance of a data type. For example, in Erlang there are lots of different varieties of time, these can be clearly and unambiguously specified using type declarations, as follows:<\/p>\n<pre><code class=\"\" data-line=\"\">-deftype day() = 1..31.\n-deftype month() = 1..12.\n-deftype year() = int().\n-deftype hour() = 1..24.\n-deftype minute() = 1..60.\n-deftype second() = 1..60.\n-deftype abstime() = {abstime, year(), month(), day(), hour(), min(), sec()}.\n-deftype hms() = {hms, hour(), min(), sec()}.\n...\n<\/code><\/pre>\n<p>Note that these definitions do not belong to any particular object. they are ubiquitous and data structures representing times can be manipulated by any function in the system.<\/p>\n<p>There are no associated methods.<\/p>\n<h2>Objection 3 &#8211; In an OOPL data type definitions are spread out all over the place<\/h2>\n<p>In an OOPL data type definitions belong to objects. So I can\u2019t find all the data type definition in one place. In Erlang or C I can define all my data types in a single include file or data dictionary. In an OOPL I can\u2019t &#8211; the data type definitions are spread out all over the place.<\/p>\n<p>Let me give an example of this. Suppose I want to define a ubiquitous data structure. <em>ubiquitous<\/em> data type is a data type that occurs \u201call over the place\u201d in a system.<\/p>\n<p>As lisp programmers have know for a long time it is better to have a smallish number of ubiquitous data types and a large number of small functions that work on them, than to have a large number of data types and a small number of functions that work on them.<\/p>\n<p>A ubiquitous data structure is something like a linked list, or an array or a hash table or a more advanced object like a time or date or filename.<\/p>\n<p>In an OOPL I have to choose some base object in which I will define the ubiquitous data structure, all other objects that want to use this data structure must inherit this object. Suppose now I want to create some \u201ctime\u201d object, where does this belong and in which object\u2026<\/p>\n<h2>Objection 4 &#8211; Objects have private state<\/h2>\n<p>State is the root of all evil. In particular functions with side effects should be avoided.<\/p>\n<p>While state in programming languages is undesirable, in the real world state abounds. I am highly interested in the state of my bank account, and when I deposit or withdraw money from my bank I expect the state of my bank account to be correctly updated.<\/p>\n<p>Given that state exists in the real world what facilities should programming language provide for dealing with state?<\/p>\n<ul>\n<li>OOPLs say \u201chide the state from the programmer\u201d. The states is hidden and visible only through access functions.<\/li>\n<li>Conventional programming languages (C, Pascal) say that the visibility of state variables is controlled by the scope rules of the language.<\/li>\n<li>Pure declarative languages say that there is no state.<\/li>\n<\/ul>\n<p>The global state of the system is carried into all functions and comes out from all functions. Mechanisms like monads (for FPLs) and DCGs (logic languages) are used to hide state from the programmer so they can program \u201cas if state didn\u2019t matter\u201d but have full access to the state of the system should this be necessary.<\/p>\n<p>The \u201chide the state from the programmer\u201d option chosen by OOPLs is the worse possible choice. Instead of revealing the state and trying to find ways to minimise the nuisance of state, they hide it away.<\/p>\n<h2>Why OO was popular?<\/h2>\n<ul>\n<li>Reason 1 &#8211; It was thought to be easy to learn.<\/li>\n<li>Reason 2 &#8211; It was thought to make code reuse easier.<\/li>\n<li>Reason 3 &#8211; It was hyped.<\/li>\n<li>Reason 4 &#8211; It created a new software industry.<\/li>\n<\/ul>\n<p>I see no evidence of 1 and 2. Reasons 3 and 4 seem to be the driving force behind the technology. If a language technology is so bad that it creates a new industry to solve problems of its own making then it must be a good idea for the guys who want to make money.<\/p>\n<p>This is is the real driving force behind OOPs.<\/p>\n<\/article>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">These days it seems to be fashionable to say that &#8220;OO sucks&#8221;. Why OO Sucks by Joe Armstrong. We already read argumentations like this. That&#8217;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, your remarks are based on&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2021\/03\/26\/its-what-they-told-you-about-oop-that-sucks\/\">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-8275","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-29t","jetpack-related-posts":[{"id":4877,"url":"https:\/\/monodes.com\/predaelli\/2018\/11\/06\/the-forgotten-history-of-oop\/","url_meta":{"origin":8275,"position":0},"title":"The Forgotten History of OOP","author":"Paolo Redaelli","date":"2018-11-06","format":false,"excerpt":"The Forgotten History of OOP \u2013 JavaScript Scene \u2013 Medium Eric Elliott Make some magic. #JavaScript Nov 1 The Forgotten History of\u00a0OOP Smoke Art Cubes to Smoke\u200a\u2014\u200aMattysFlicks\u200a\u2014\u200a(CC BY\u00a02.0) Note: This is part of the \u201cComposing Software\u201d series on learning functional programming and compositional software techniques in JavaScript ES6+ from the\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":6659,"url":"https:\/\/monodes.com\/predaelli\/2020\/02\/07\/why-most-code-sucks-better-programming-medium\/","url_meta":{"origin":8275,"position":1},"title":"Why Most Code Sucks &#8211; Better Programming &#8211; Medium","author":"Paolo Redaelli","date":"2020-02-07","format":"link","excerpt":"Why Most Code Sucks - Better Programming - Medium And what you can do to improve yours","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":11356,"url":"https:\/\/monodes.com\/predaelli\/2024\/02\/18\/criu\/","url_meta":{"origin":8275,"position":2},"title":"CRIU","author":"Paolo Redaelli","date":"2024-02-18","format":false,"excerpt":"CRIU Checkpoint\/Restore In Userspace, (pronounced kree-oo, IPA: \/kr\u026a\u028a\/, Russian: \u043a\u0440\u0438\u0443), is a Linux software. It can freeze a running container (or an individual application) and checkpoint its state to disk. The data saved can be used to restore the application and run it exactly as it was during the time\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":[]},{"id":14958,"url":"https:\/\/monodes.com\/predaelli\/2026\/02\/07\/qownnotes\/","url_meta":{"origin":8275,"position":3},"title":"QOwnNotes","author":"Paolo Redaelli","date":"2026-02-07","format":false,"excerpt":"QOwnNotes Open source markdown note-taking for Linux, macOS and Windows, that works together with Nextcloud Notes Has anyone made some comparisons with other markdown editors suck as Apostrophe?","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":11473,"url":"https:\/\/monodes.com\/predaelli\/2024\/03\/13\/multi-threading-is-always-the-wrong-design\/","url_meta":{"origin":8275,"position":4},"title":"Multi-threading is always the wrong design","author":"Paolo Redaelli","date":"2024-03-13","format":false,"excerpt":"\u201cWe\u2019ll just do that on a background thread\u201d Source: Multi-threading is always the wrong design Well, really? Multi-threading is always the wrong design \u201cWe\u2019ll just do that on a background thread\u201d uNetworking AB Say what you want about Node.js. It sucks, a lot. But it was made with one very\u2026","rel":"","context":"In &quot;Tricks&quot;","block_context":{"text":"Tricks","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/tricks\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2295,"url":"https:\/\/monodes.com\/predaelli\/2017\/03\/17\/tmate-%e2%80%a2-instant-terminal-sharing\/","url_meta":{"origin":8275,"position":5},"title":"tmate \u2022 Instant terminal sharing","author":"Paolo Redaelli","date":"2017-03-17","format":false,"excerpt":"Today I discovered tmate \u2022 Instant terminal sharing\u00a0 while issuing apt-cache search mate terminal. The Debian\/Ubuntu repository told me1 that tmate provides an instant pairing solution, allowing you to share a terminal with one or several teammates. Together with a voice call, it's almost like pairing in person. The terminal\u2026","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/monodes.com\/predaelli\/category\/software\/"},"img":{"alt_text":"video_macos_first_frame","src":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2017\/03\/video_macos_first_frame-1.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8275","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=8275"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8275\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=8275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=8275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=8275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}