Cargo Cult Programming!
Tags: webdev, beginners, learning, career
Published: 2019-01-15 07:25:09

---
title: Cargo Cult Programming!
published: true
description: Cargo Cult Programming, A phrase I heard when watching a great talk from Simon Brown on Modular Monoliths at GOTO 2018. Read my take on what it means.
tags: webdev, beginners, learning, career
cover_image: https://thepracticaldev.s3.amazonaws.com/i/b0bgzn0z0046ei7adgvm.png
canonical_url: http://blog.designpuddle.com/web-development/coding-concepts-cargo-cult-programming/
series: Coding Concepts
---

<p>I was watching/listening to this great talk by <a href="https://twitter.com/simonbrown">Simon Brown</a> on <a href="https://www.youtube.com/watch?v=5OjqD-ow8GE&amp;list=PLEx5khR4g7PJELLTYwXZHcimWAwTUaWGA">Modular Monoliths from GOTO 2018.</a></p>
<p>In this he mentions a term called <strong>Cargo Cult Programming</strong> and it really struck a chord with me.</p>
<p>I've recently joined a new company with a new programming language, new tools, new processes and a new team. Actually, it's pretty much '<strong>new</strong>' everything.</p>
<p>This has caused me to do a lot of learning in recent months. Being relatively experienced, I like to look into the '<strong>whys'</strong> rather than the '<b>hows' </b>when learning new things. What I've realised is that this is <strong>not the most common approach</strong>.</p>
<p>When a user is tasked with adding to an existing codebase, extending the current solution, they will most probably check how this has been done previously, copying the approach for their solution. They may/will blindly follow this pattern as it's how it's been done before. Additional blocks get added on top of the tower, without questioning whether it's the right thing to do. If everybody does this, this will eventually happen.</p>
<p><img class="aligncenter" src="https://media1.tenor.com/images/719a7b6d54fe98b9933e4f4ab441c412/tenor.gif?itemid=4594310" alt="Related image" /></p>
<p>This is where the term '<strong>Cargo Cult Programming</strong>'  comes from.</p>
<p>Wikipedia explains it like this:</p>
<blockquote>
<p><b>Cargo cult programming</b> is a style of <a title="Computer programming" href="https://en.wikipedia.org/wiki/Computer_programming">computer programming</a> characterized by the ritual inclusion of code or program structures that serve no real purpose. Cargo cult programming is typically symptomatic of a programmer not understanding either a bug they were attempting to solve or the apparent solution (compare <a title="Shotgun debugging" href="https://en.wikipedia.org/wiki/Shotgun_debugging">shotgun debugging</a>, <a class="mw-redirect" title="Deep magic" href="https://en.wikipedia.org/wiki/Deep_magic">deep magic</a>).<sup id="cite_ref-1" class="reference"><a href="https://en.wikipedia.org/wiki/Cargo_cult_programming#cite_note-1">[1]</a></sup> The term <i>cargo cult programmer</i> may apply when an unskilled or novice computer programmer (or one inexperienced with the problem at hand) <a title="Copy and paste programming" href="https://en.wikipedia.org/wiki/Copy_and_paste_programming">copies some program code</a> from one place to another with little or no understanding of how it works or whether it is required in its new position.</p>
<p>Cargo cult programming can also refer to the practice of applying a <a title="Software design pattern" href="https://en.wikipedia.org/wiki/Software_design_pattern">design pattern</a> or coding style blindly without understanding the reasons behind that design principle. Examples are adding unnecessary comments to self-explanatory code, overzealous adherence to the conventions of a specific <a title="Programming paradigm" href="https://en.wikipedia.org/wiki/Programming_paradigm">programming paradigm</a>, or adding deletion code for objects that <a title="Garbage collection (computer science)" href="https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)">garbage collection</a> would have collected automatically.</p>
</blockquote>
<h2>A Common Problem?</h2>
<p>Imagine a scenario where you're working on a bug, finding the code that is causing the fault. You're not massively sure what's happening, so you;</p>
<ol>
<li>Google the error.</li>
<li>You find a StackOverflow question.</li>
<li>Search for the most upticked answer.</li>
<li>Copy and paste the solution into your code.</li>
<li>Try debugging to see if that's fixed your problem.</li>
</ol>
<p>It has, so you check it in and move on.</p>
<p><strong>Sound familiar?</strong></p>
<p>Why do we do that? Why do we blindly take this snippet and use it as-is, in our implementation?</p>
<p>The use case is probably not the same, so I'd be surprised if the solutions was. Simple examples aside, understanding the reasoning behind the solution is more important than the solution itself. There are many things you can't do with something you don't understand. You can't modify, improve or test it. You can't document it and you can't own it.</p>
<h2>Tech Trends, Buzzwords &amp; Microservices</h2>
<p>We all love what's new, and management especially seem to like following popular trends, keeping up with technological advancement.</p>
<p>Most teams will now follow an Agile approach. TDD and Automated Testing can be very useful in certain scenarios, Continuous Integration removes much of the overhead from the infrastructure team, Big Data and AI can vastly improve user satisfaction and Containerisation and most recently <strong>Microservices</strong> shift our old monolith architecture into smaller self contained services.</p>
<p>Each of these advancements is brilliant in its own right, and I don't condone any of them. My predicament is whether we need to adopt all of them into all our processes and code? We see blog posts from <strong>Netflix, Facebook, Twitter</strong> showing how their use has transformed how they work. If big companies deem them necessary, should we not too? This is where cargo cult programming rears its ugly head again.</p>
<p>We need to understand the problems with our current designs, why they happened, and how they can be jettisoned away in the future. Yes, these new processes may help us with our problems, but blindly following them in the faint hope that they do is not the way forward, nor does it make any logical sense.</p>
<p>I mention Microservices specifically as a lot of companies seem to be making the transition, citing such <strong>benefits</strong> as:</p>
<ul>
<li>Faster development time</li>
<li>High scalability</li>
<li>Easy to enhance</li>
<li>Ease of deployment</li>
<li>Autonomous teams with the freedom to choose technology</li>
</ul>
<p>With a list like that, what's there to think about? Let's all jump on the bandwagon!</p>
<p><img class="aligncenter" src="https://gifimage.net/wp-content/uploads/2017/09/bandwagon-gif-7.gif" alt="Image result for jump on the bandwagon gif" /></p>
<p>Wait a second... are there any <strong>drawbacks</strong> to this approach?</p>
<ul>
<li id="architectural-complexity">Architectural Complexity</li>
</ul>
<p>In monolithic architectures, the complexity and the number of dependencies reside inside the code base, while in microservices architectures complexity moves to the interactions of the individual services that implement a specific domain</p>
<ul>
<li><span style="font-size: 1.8rem;">Operational Complexity</span>
<ul>
<li>How to provision resources in a scalable and cost-efficient way</li>
<li>How to operate dozens or hundreds of microservice components effectively without multiplying efforts</li>
<li>How to deal with a lack of standards and heterogeneous environments that include different technologies and people with differing skill sets</li>
<li>How to deal with versioning</li>
<li>How to track and debug interactions across the whole system</li>
<li>How to keep track of hundreds of pipelines of code deployments and their interdependencies</li>
</ul>
</li>
</ul>
<p>These are lifted from Amazon's own "<a href="https://docs.aws.amazon.com/aws-technical-content/latest/microservices-on-aws/challenges-of-microservices.html">Challenge of Microservices</a>" whitepaper. Now I don't know about you, but the drawbacks look a lot scarier to me than the benefits. Once again, I'm not saying this is not the right approach to go down, but unless these benefits outweigh the drawbacks what are you gaining from following this approach?</p>
<h2>The 'Public' problem.</h2>
<p>It's simple really, Stop using the <strong>Public </strong>keyword, stop automatically creating <strong>Public </strong>classes. Why do we do it?</p>
<p>The problem with using the public keyword is you're missing out on the benefits related to encapsulation. Why do we use it so much? It's pretty much the default word we use when creating classes, all examples will use public classes, wizards and snippets will implement public classes. It's time to stop. How many people have a public Facebook account? Most things in this world are private, as should our classes be. Make them private by default, and then if you need them to be public, change them then. </p>
<h2>With great experience comes great apprehension.</h2>
<p>The longer you are in a field, the less naive you are to perceived improvements that a new tool or process will bring. Most of today's ideas come from decades old research into the field which are finally being embraced.  Once something has gained mass adoption, it's easier to feel comfortable with embracing it fully. That is, if it's the right thing to do.</p>
<blockquote>
<p><b style="font-size: 1.8rem;">"Good</b><span style="font-size: 1.8rem;"> judgment </span><b style="font-size: 1.8rem;">comes </b><span style="font-size: 1.8rem;">from </span><b style="font-size: 1.8rem;">experience</b><span style="font-size: 1.8rem;">, and </span><b style="font-size: 1.8rem;">experience comes</b><span style="font-size: 1.8rem;"> from bad judgment"</span></p>
<p>- Rita Mae Brown</p>
</blockquote>
<p>So feel free to keep on scouring the interwebs for solutions and tutorials to your problems; keep exploring new languages, frameworks and implementations. Just be aware of <strong>why </strong>they work, rather than simply <strong>how. </strong>We all learn from our own experiences and mistakes, so understanding the fundamentals will keep you from continuing down the same path in the future.</p>