
{"id":266,"date":"2013-05-23T21:04:46","date_gmt":"2013-05-23T20:04:46","guid":{"rendered":"http:\/\/serverdude.dk\/?p=266"},"modified":"2013-05-23T21:05:44","modified_gmt":"2013-05-23T20:05:44","slug":"oop-is-dead-and-alive","status":"publish","type":"post","link":"https:\/\/serverdude.dk\/?p=266","title":{"rendered":"OOP is dead and alive"},"content":{"rendered":"<h2>Discussing Programming topics with non-programmers<\/h2>\n<p>The other day I was in good company with a business owner, who is also a\u00c2\u00a0programmer, and a business controller, who isn&#8217;t a programmer. We were\u00c2\u00a0discussing the issues of one of my favorite topics: Software Quality.<\/p>\n<p>Naturally the software must do what it is intended to do, but the hidden\u00c2\u00a0issue, which to me is almost as important: Functionality must be placed in\u00c2\u00a0the right areas.<\/p>\n<p>The analogy became looking for $10 in a persons wallet.<\/p>\n<p>To the programmer getting this task, the basic work: Find person, find\u00c2\u00a0persons wallet, check if wallet contains $10. Has to be done regardless of\u00c2\u00a0where the functionality is applied. To the CPU the steps will be loaded in\u00c2\u00a0sequence anyway thus the &#8220;correct&#8221; position of the code is another matter.<\/p>\n<p>Now, in real life, if I ask someone if they have $10 in their wallet,\u00c2\u00a0they are able to check their own wallet and inform me. On the other hand,\u00c2\u00a0I could just take their wallet and check myself. Naturally this would be a\u00c2\u00a0violation of privacy &#8211; and I&#8217;d have to know where they keep their wallets.<\/p>\n<p>In the same sense, a controller could implement the functionality\u00c2\u00a0required leading to promiscuous objects being violated. Or the objects\u00c2\u00a0themselves could have the functionality implemented. The first leads to\u00c2\u00a0violation of Law of Demeter,\u00c2\u00a0tight coupling, and too much knowledge,\u00c2\u00a0which in turn leads to higher risk of introducing bugs, higher maintenance\u00c2\u00a0cost, intricate dependencies, and a big ball of mud.<\/p>\n<pre>Controller {\r\n\u00c2\u00a0 person.getWallet().hasAmount(amount)\r\n}<\/pre>\n<p>versus<\/p>\n<pre>Controller {\r\n\u00c2\u00a0 person.hasAmount(amount)\r\n}\r\nPerson {\r\n hasAmount(Integer amount){\r\n  return myWallet.hasAmount(amount)\r\n }\r\n}<\/pre>\n<p>The example is a bit far fetched, but it served the purpose of why it is\u00c2\u00a0important to have clean code in more than one sense.<\/p>\n<p>The first snippet the Controller will have to know of Person and Wallet.\u00c2\u00a0In the latter Controller needs to know of Person, and Person needs to know\u00c2\u00a0of Wallet. Even though there are the same amount of dependencies, the context\u00c2\u00a0for the Controller is much higher in the first snippet.<\/p>\n<h2>OOP is dead<\/h2>\n<p>A while ago Pinterest suggested I read <a title=\"OOP is Dead\" href=\"http:\/\/blogs.msdn.com\/b\/alfredth\/archive\/2011\/03\/22\/object-oriented-programming-is-dead.aspx\">Object\u00c2\u00a0Oriented Programming is Dead<\/a> which is a bit dated, nevertheless it\u00c2\u00a0is still relevant. I just think that there are more reasons why OOP is\u00c2\u00a0dead &#8211; and yet still alive.<\/p>\n<p>First off, we killed OOP by trying to fit a relational database as the\u00c2\u00a0persistence layer &#8211; this leads to\u00c2\u00a0data transfer objects, which are\u00c2\u00a0mostly grouped global variables or Java beans, which has nothing to do\u00c2\u00a0with encapsulation.<\/p>\n<p>Second, we killed OOP by placing logic in the wrong classes, classes in\u00c2\u00a0the wrong hierarchy, and generally forgetting what OOP is about.<\/p>\n<p>Third blow, we apparently insist on imperative styled programming for an\u00c2\u00a0OOP, which leads to the issues described above.<\/p>\n<p>Fourth stab, we seem to be grounded in the snapshot state of databases.\u00c2\u00a0That is, an object in a database has a single state, without any prior\u00c2\u00a0history. This is similar to register loading, and overwriting, and is\u00c2\u00a0prevalent in the Update keyword. You actually have to twist, turn, and\u00c2\u00a0contort the default behavior of an RDBMS to get a history\/audit trail for\u00c2\u00a0the values.<\/p>\n<p>The final death blow was delivered by Martin Odersky &#8211; who also kindly\u00c2\u00a0revived OOP in junction with FP &#8211; in his presentation <a title=\"Objects and functions, conflicts without a cause\" href=\"http:\/\/parleys.com\/play\/51704efce4b095cc56d8d4b5\/chapter0\/about\">Object\u00c2\u00a0and functions, conflict without a cause<\/a>. Well he has done so on\u00c2\u00a0other occasions touting the Scala horn.<\/p>\n<p>Rich Hickey &#8211; the Clojure guy &#8211; seems to at least backup the FP and OOP\u00c2\u00a0notion &#8211; primarily of stateless objects, and Datomic seems like a\u00c2\u00a0brilliant choice for a persistence layer.<\/p>\n<h2>OOP is alive<\/h2>\n<p>The Object Oriented notion is extremely important as it is what should\u00c2\u00a0drive SOA services. They should be defined by their interfaces and\u00c2\u00a0encapsulate data and implementations. As Steve Yegge\u00c2\u00a0<a href=\"https:\/\/plus.google.com\/112678702228711889851\/posts\/eVeouesvaVX\">mentioned<\/a> Amazon is quite good at, and Google not quite as good.<\/p>\n<p>I believe SOA is the right level of re-usability of software, and we will have to get much better at it as more and more mash-ups are wanted. That means we have to accept interoperability at a different level, keep disciplined and not query database tables which we know of, but really belongs to another service.<\/p>\n<p>We also have to embrace the functional style &#8211; I&#8217;m talking REST for web\u00c2\u00a0developers &#8211; in which objects are immutable\/stateless, and transformations\u00c2\u00a0can be predictably run whether in parallel or sequence, synchronous or\u00c2\u00a0asynchronous to the client.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discussing Programming topics with non-programmers The other day I was in good company with a business owner, who is also a\u00c2\u00a0programmer, and a business controller, who isn&#8217;t a programmer. We were\u00c2\u00a0discussing the issues of one of my favorite topics: Software Quality. Naturally the software must do what it is intended to do, but the hidden\u00c2\u00a0issue, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266"}],"version-history":[{"count":2,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":268,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions\/268"}],"wp:attachment":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}