{"id":35678,"date":"2016-12-06T06:00:03","date_gmt":"2016-12-06T11:00:03","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=35678"},"modified":"2016-12-06T06:41:59","modified_gmt":"2016-12-06T11:41:59","slug":"object-oriented-debate-part-1-which-side-are-you-on","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=35678","title":{"rendered":"Object-Oriented Debate Part 1: Many Kinds of Coding"},"content":{"rendered":"<p>A while ago I came across this youtube video, which broadly denounces the programming paradigm known as &#8220;Object Oriented Programming&#8221;. (OOP)<\/p>\n<p><table class='nomargin' cellspacing='0' width='100%' cellpadding='0' align='center' border='0'><tr><td><iframe loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/www.youtube.com\/embed\/QM1iUe6IofM\" frameborder=\"0\" allowfullscreen class=\"embed\"><\/iframe><br\/><small><a href='http:\/\/www.youtube.com\/watch?v=QM1iUe6IofM'>Link (YouTube)<\/a><\/small><\/td><\/tr><\/table><\/p>\n<p>If you&#8217;re not a programmer, you might not get a lot out of it. Author Brian Will is deliberately talking to other coders and so the whole thing is fairly dense with jargon and theory. That&#8217;s fine. I&#8217;m going to translate bits of it for the purposes of our discussion here. In fact, this series is aimed at non-coders and casual coders who are curious what all the fuss is about and what people are talking about when they say &#8220;Object Oriented Programming&#8221;.<\/p>\n<p>Depending on who you ask, this video is either obvious, slightly controversial, or deeply heretical. The author certainly seems to believe they are about to say something likely to induce backlash. And indeed, with just over one-third of the people giving the video a thumbs down it does seem to be an unpopular opinion. After watching the introduction I was prepared for the screed of an iconoclastic madman. But by the end I didn&#8217;t find anything particularly objectionable. In fact, his final guidelines basically describe the coding style I&#8217;ve developed over years of working in both new and old coding paradigms.<\/p>\n<p>I might quibble over a few points, but I think Will is pushing back against a bit of orthodoxy that doesn&#8217;t get challenged nearly enough. This debate has popped up now and again over the years and it usually ends with a bunch of people talking past each other and arguing in circles. This is partly because it&#8217;s tough to challenge entrenched ideas, but mostly because programming is not one job, but dozens of different jobs.<\/p>\n<p><!--more--><\/p>\n<h3>One Paradigm to Rule Them All<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/ood_sauron.jpg' width=100% alt='Seriously? You&apos;re using the Whitesmiths bracket style? This is exactly why I&apos;m trying to cover the world in a second darkness.' title='Seriously? You&apos;re using the Whitesmiths bracket style? This is exactly why I&apos;m trying to cover the world in a second darkness.'\/><\/div><div class='mouseover-alt'>Seriously? You&apos;re using the Whitesmiths bracket style? This is exactly why I&apos;m trying to cover the world in a second darkness.<\/div><\/p>\n<p>People often make blanket statements like, &#8220;Code should be X&#8221; or &#8220;NEVER do Y because it&#8217;s too slow&#8221; or &#8220;Stop doing Z, because it&#8217;s insecure&#8221;. These statements will strike some people as preposterous others as completely obvious, depending on what domain they&#8217;re working in. One of the major problems with discussing programming is that far too often we talk about it as if it was a single discipline. Imagine if people who repaired stuff were all simply referred to as &#8220;mechanics&#8221; without ever bothering to specify if they work in automotive, aerospace, HVAC, electrical systems, security systems, robotics, or civil engineering. It would be chaos. <\/p>\n<p>People working on financial software have security and precision needs that would seem absurd to someone making a videogame. A videogame programmer has performance concerns that would seem unreasonable to someone working on data collection and analysis. Someone working in social media is probably really worried about distributed systems and scalability in a way that would seem alien to someone working on embedded systems<span class='snote' title='1'>Roughly, an embedded system is a fixed set of programs used to drive a device. The operating system of a camera, television remote, CD player, or weather satellite are all examples of embedded systems.<\/span>. <\/p>\n<p>Which is fine. The world of programming is getting bigger all the time. As computing power gets cheaper we keep finding new and inventive uses for it. And yes, there are different languages for different jobs in an attempt to address these differing needs. But often people discuss programming in this abstract theoretical sense that disregards all of these differences and assumes the problems they experience are universal to all programmers. <\/p>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/ood_pets.jpg' width=100% alt='Oh sure. FOUR dogs but not ONE scorpion? People are always leaving the scorpion owners out.' title='Oh sure. FOUR dogs but not ONE scorpion? People are always leaving the scorpion owners out.'\/><\/div><div class='mouseover-alt'>Oh sure. FOUR dogs but not ONE scorpion? People are always leaving the scorpion owners out.<\/div><\/p>\n<p>Look at any debate over coding theory and you&#8217;ll see a couple of engineers slugging it out without either of them ever specifying what they do for a living. If pet owners discussed their animals the way programmers discuss their craft, the debate would look like this:<\/p>\n<p>&#8220;I suggest grooming your animal with a typical hairbrush at least once a week.&#8221; (<b>Woman who owns a dog.<\/b>)<\/p>\n<p>&#8220;I am so sick of seeing the same useless suggestions given again and again. A hairbrush is designed FOR PEOPLE. Repeat after me: DO NOT USE HAIR-BRUSHES FOR GROOMING PETS. You&#8217;ll want to use something long that will enable you to reach the difficult high areas on the animal&#8217;s back. They sell long-handled brushes at the hardware store. Use one of those, and scrub the animal with warm soapy water before rinsing it off with a hose. Alternatively, sell your pet to someone who knows how to care for it properly!&#8221; (<b>Guy who owns an elephant<\/b>)<\/p>\n<p>&#8220;Nobody here is thinking about safety. Sure, go ahead and blast your pet with a hose and see how long it takes for them to bite you. SAFETY is the most important part of pet care, not cleanliness! All that scrubbing won&#8217;t do them any good if you end up dead in the process.&#8221; (<b>Guy who owns a cobra.<\/b>)<\/p>\n<p>&#8220;It&#8217;s always amusing to see just how many people overthink pet care. I suppose it&#8217;s easier to read articles online than to learn what your pet needs by getting to know them. Do you know that your pet is perfectly capable of grooming THEMSELVES? Amazing I know, but they managed just fine for millions of years before humans came along. Leave your pet alone and just enjoy the cuddles.&#8221; (<b>Lady who owns a cat.<\/b>)<\/p>\n<p>&#8220;Did you seriously suggest &#8220;cuddles&#8221;?!!?! Your pet is not a toy! Leave it in the tank where it belongs and enjoy looking at it. It will live longer that way. Idiot.&#8221; (<b>Dude who owns fish.<\/b>)<\/p>\n<h3>Kids These Days<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/ood_lecture.jpg' width=100% alt='Is this going to be on the test?' title='Is this going to be on the test?'\/><\/div><div class='mouseover-alt'>Is this going to be on the test?<\/div><\/p>\n<p>Contributing to the problem is the fact that the people who teach programming are for the most part not the people who actually do programming for a living. The people teaching kids to solve problems aren&#8217;t out in the real world solving real problems. Programming is typically taught by mathematicians and academics, not by seasoned veterans of the profession. We end up teaching kids to create new code for a world of abstract problems.<\/p>\n<p><strong>What you&#8217;re taught in school:<\/strong><br \/>\n&#8220;Write a program from scratch to find the first 1,000 primes larger than three digits and print them out using English words instead of numerals.&#8221;<\/p>\n<p><strong>What you&#8217;re asked to do once you get a job:<\/strong><br \/>\n&#8220;Our accounting reports are generated by 100,000 lines of spaghetti code. It was written in a mix of C and C++ by a long line of transient programmers over the course of three decades. Get in there and figure out why the even-year reports are always off by one day. Fix the problem as fast as possible, while changing as little as possible.&#8221;<\/p>\n<p>While I&#8217;ve never been to university myself, I&#8217;ve certainly talked to quite a few university-educated programmers. And I&#8217;ve never once heard of students being asked to work on an existing codebase. I&#8217;m not saying it <em>never<\/em> happens, but anecdotally it&#8217;s not common, even though that&#8217;s what you&#8217;ll be doing in the vast majority of jobs. <\/p>\n<p>This is not to say that academics are numbskulls or that we don&#8217;t have anything to learn from them. You could boot Professor Smugbones out of the university to go write &#8220;real&#8221; code for a few years. But during that time, he wouldn&#8217;t be teaching anybody. And it would take some time to distill all of that practical experience into some sort of curriculum. And by the time it was being taught in class, parts of it would be irrelevant because while half of this vocation is mired in the tar pits of 1975, the other half is experiencing radical and transformative change every couple of years.<\/p>\n<p>The book <a href=\"http:\/\/101.lv\/learn\/C++\/\">Teach Yourself C++ in 21 Days<\/a> is a pretty good example of this problem in action. It&#8217;s more interested in teaching you Object-Oriented Design than programming in C++. For example, it&#8217;s doesn&#8217;t really dig deep into dealing with header files, using external libraries, dealing with C-style strings, or memory management, even though those are complex topics that greatly impact your work and are required to make anything genuinely useful. Wrangling libraries, header files, and development environments will probably be a huge part of using C++ for most people. Instead the book spends about a third of the page space explaining how object-oriented programming is supposed to work.<\/p>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/ood_cat.jpg' width=100% alt='I&apos;m sick of car analogies, so this week we&apos;re doing animals.' title='I&apos;m sick of car analogies, so this week we&apos;re doing animals.'\/><\/div><div class='mouseover-alt'>I&apos;m sick of car analogies, so this week we&apos;re doing animals.<\/div><\/p>\n<p>The book uses funny <a href=\"http:\/\/101.lv\/learn\/C++\/htm\/ch06.htm\">example programs<\/a> like: <i>Hey look, you can make a base class called &#8220;mammal&#8221;. And from that we can derive the class &#8220;pet&#8221;. And then we can derive a class for cat&#8221;. And check it out, you can then do Cat.Meow () and Cat.Sleep ()! Cool, right?<\/i><\/p>\n<p>Maybe this is helpful to programming newbies, but when I read the book 15 years ago I spent the whole time scratching my head and wondering how any of this could be used to solve Real Problems. I&#8217;ve never seen (or heard of) a problem that allowed for a clean, intuitive structure as clear as Mammal&raquo;Pet&raquo;Cat. Objects in a program are very often only <b>sort of similar<\/b>. Two things will share a lot of superficial similarities but in practical terms they end up being totally different in behavior. They&#8217;re similar enough that Dogs and Cats do similar things &#8211; like Sleep () &#8211; but they do so in different ways, at different times, and in response to different situations. A lot of the same concepts appear again and again, but they don&#8217;t share any code and it leaves you wondering why we spent all of that page space on Pets and Mammals, trying to connect two dissimilar systems because of cosmetic similarities.<\/p>\n<p>(Note that I&#8217;m just as prone to domain bias as anyone else. Maybe there really is some discipline out there where things like Mammal&raquo;Pet&raquo;Cat is amazingly useful. But I haven&#8217;t seen it yet, and so a lot of the features of object-oriented programming come off like someone trying so hard to be clever that they forget they&#8217;re supposed to be solving problems, not building abstract frameworks for aesthetic reasons.)<\/p>\n<p>I&#8217;m not saying that Learn C++ in 21 Days is a bad book or that academics don&#8217;t have anything useful to add to computer science. The only reason the profession exists at all is because some professors invented it on the blackboard decades before guys like me showed up to pick through their discoveries and build our careers off of them.<\/p>\n<p>Academics tend to come up with a lot of ideas, both good and bad. Academia is where ideas are propagated.  It&#8217;s up to the software engineers to sort the good from the bad and figure out which ideas are worth propagating and which aren&#8217;t. That sort of exploration takes time. <\/p>\n<p>To put it another way: With each new graduating class there&#8217;s a steady flow of knowledge coming from the university to the private sector. But we need to make sure some information flows the other way. Videos like the one Brian Will made are part of that process of sorting the good from the bad and sending the information upstream for the next generation. <\/p>\n<p>Next time we&#8217;ll talk about what OOP is and why we need it. (Or don&#8217;t, depending on who you ask.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while ago I came across this youtube video, which broadly denounces the programming paradigm known as &#8220;Object Oriented Programming&#8221;. (OOP) Link (YouTube) If you&#8217;re not a programmer, you might not get a lot out of it. Author Brian Will is deliberately talking to other coders and so the whole thing is fairly dense with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-35678","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/35678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35678"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/35678\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}