<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[CS Thinking - Medium]]></title>
        <description><![CDATA[Coding is not just remembering syntax! More important are the deep and widely applicable ideas from Computer Science that can be taught using everyday examples. - Medium]]></description>
        <link>https://medium.com/cs-thinking?source=rss----a82878004055---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>CS Thinking - Medium</title>
            <link>https://medium.com/cs-thinking?source=rss----a82878004055---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:39:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/cs-thinking" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging the Tooth Fairy]]></title>
            <link>https://medium.com/cs-thinking/debugging-the-tooth-fairy-3f484ace7a7b?source=rss----a82878004055---4</link>
            <guid isPermaLink="false">https://medium.com/p/3f484ace7a7b</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[funge]]></dc:creator>
            <pubDate>Wed, 04 Mar 2015 22:18:31 GMT</pubDate>
            <atom:updated>2015-03-04T22:18:30.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FQvYXEKLgHEMvr8-CxNXRg.jpeg" /></figure><h4>CS Thinking</h4><p>Like most kids, my son used to believe in the tooth fairy. But, as he got older, he became suspicious that there was an error, or in computer programming terminology a “bug”, in his belief. Instead of simply asking if the tooth fairy was fabricated, he decided to try and debug his world view by conducting an experiment. The next time he lost a tooth, he secretly stowed it under his pillow without telling anyone. In the morning, when he discovered the tooth was still there and hadn’t magically been replaced with money, he felt his suspicions were confirmed.</p><p>The tooth fairy experiment is an example of constructing a <a href="http://en.wikipedia.org/wiki/Falsifiability">falsifiable hypothesis</a> and testing it. The hypothesis is that the tooth fairy is real and not just a hoax perpetrated by your parents. A reasonable consequence of this hypothesis is that even if you don’t tell your parents, the tooth fairy should still know there is a tooth under your pillow. If the tooth is still there in the morning, that is powerful evidence that the hypothesis, of the tooth fairy being real, is false!</p><p>The moment when the tooth fairy experiment concluded, and my son looked under his pillow to reveal the undisturbed tooth, is a wonderful illustration of a cornerstone of the <a href="http://en.wikipedia.org/wiki/Scientific_method">scientific method</a> in action. At that instant in time, my son’s world view re-aligned as one set of explanations about where money for teeth comes from was replaced by another. In hindsight, the alternative hypothesis, that the tooth fairy was your parents all along, is far more plausible and this is often the case with larger scientific discoveries. But that in no way lessens the “Eureka” moment at the point of discovery.</p><h4>Debugging</h4><p>What you might not realize is that programmers often get to experience that “Eureka” moment many times a day when they debug their code. Although, even among experienced programmers, debugging is sometimes thought of as a miserable and thankless task. But some of the best programmers approach debugging with scientific zeal as they try to figure out good falsifiable hypotheses that will uncover where their code is making incorrect assumptions.</p><p>Sometimes debugging is simply a matter of staring at your code and performing simulations in your head to test and refute hypotheses. More often it involves inspecting and asserting the values of intermediate variables to see if they violate expectations. Occasionally, it requires carefully crafting inputs and fixing timings to create elaborate experiments to reveal where the faulty assumptions lie.</p><p>Without contributions of teeth from siblings or friends, kids only get 20 chances to run experiments to debug the tooth fairy. In contrast, the experiments you can run on your code are endless. Running experiments on code is, in fact, so convenient that it can sometimes slow you down if careful deliberation is too often replaced by experimenting over a large set of permutations of your code.</p><p>Regardless of how you get there, the feeling as your world view suddenly shifts as you stare (initially incredulously) at the offending piece of code is, I assume, similar to how Galileo felt when his experiments suggested the Earth actually orbits the Sun instead of vice versa. Of course, these debugging discoveries are not as Earth-shattering as major scientific ones, but the important point is that the underlying satisfaction and feeling of discovery is similar. Depending on where you work, the feeling of fear about the consequences of publicizing your discovery might also be similar to <a href="http://en.wikipedia.org/wiki/Galileo_Galilei#Controversy_over_heliocentrism">Galileo’s</a> situation.</p><h4>Confirmation Bias</h4><p>A peculiar aspect of finding a bug is that the cause is often so obvious once you find it that it is staggering you didn’t see it earlier. The reason you were unable to see it easily is due, in large part, to <a href="http://en.wikipedia.org/wiki/Confirmation_bias">confirmation bias</a>. Confirmation bias is the tendency, especially among well-educated people, to ignore evidence that contradicts their beliefs. An analogous everyday equivalent is trying to find typos in something you wrote, it can be very hard to see them, but once you do they are blindingly obvious.</p><p>It’s incredibly hard to doubt what you believe. Programmers find it so hard to believe their code contains bugs that it is common to have a separate quality assurance (QA) group whose job it is to find bugs. In fact, programmers will often remain skeptical that a bug is real until a cast-iron reproducible (repro) case has been carefully documented. Of course, reproducibility of experiments is another cornerstone of the scientific method (one that has recently received renewed <a href="http://www.nature.com/nature/focus/reproducibility/">focus</a>) and so it is reasonable that programmers remain skeptical of anecdotal bug reports. However, even when a program has a clear bug in terms of its behavior, it’s still sometimes hard not to believe, no matter how unlikely, that the computer is not malfunctioning instead of seeing the mistake.</p><p>Nonetheless, debugging code is an activity in which you are inevitably and frequently brought face to face with your own confirmation bias. Frustratingly, fixing one bug can simply reveal another! So there is often a cascade of evidence that forces you to regularly confront your own fallibility. To be a successful programmer, it is key principles of the scientific method that you often learn to trust as a mechanism for uncovering your own erroneous beliefs.</p><p>While most of us don’t get to do science on a grand scale, programming provides (aside from the well publicized potential economic benefits) a powerful way to exercise the scientific-mindset muscle and possibly become more open-minded<strong>…</strong></p><h4><strong>Acknowledgements</strong></h4><p>Thanks to <a href="http://www.linkedin.com/in/jcham">James Cham</a><strong> </strong>for feedback on an earlier draft of this post and for his continuing encouragement to work on <a href="https://medium.com/cs-thinking/">CS Thinking</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f484ace7a7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cs-thinking/debugging-the-tooth-fairy-3f484ace7a7b">Debugging the Tooth Fairy</a> was originally published in <a href="https://medium.com/cs-thinking">CS Thinking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Put the Ketchup on the Table]]></title>
            <link>https://medium.com/cs-thinking/put-the-ketchup-on-the-table-183eb7a62720?source=rss----a82878004055---4</link>
            <guid isPermaLink="false">https://medium.com/p/183eb7a62720</guid>
            <dc:creator><![CDATA[funge]]></dc:creator>
            <pubDate>Mon, 16 Dec 2013 06:19:49 GMT</pubDate>
            <atom:updated>2015-10-04T00:28:40.891Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-pSe_SnldQvTPIvmfVQbVg.jpeg" /></figure><h4>CS Thinking</h4><p>My son has also noticed that it tends to be “fancy” restaurants that cut you off from easy access to condiments. Maple syrup, jam, you name it, they like to insert unnecessary interactions with the waiting stuff at every juncture. In CS terminology, their interface is bloated. They have introduced unnecessary dependencies that cause information, in this case which condiments you like to put on your food, to be exposed to the waiters who really don’t need to know or care.</p><p>The opposite of a bloated interface is a narrow interface. Narrow interfaces tend to reduce complexity by minimizing dependencies and information sharing between components. Obviously there is important information that needs to be shared, but hiding away details of how a component works reduces the possibility of unnecessary dependencies being introduced. With narrow, well-defined inputs and outputs between components, programs can be broken up into relatively self-contained and composable functions and modules. The opposite of this kind of design is sometimes referred to as “spaghetti code” or “<a href="http://en.wikipedia.org/wiki/Big_ball_of_mud">big balls of mud</a>.”</p><p><strong>Company Culture and Netflix</strong></p><p>Work can also be frustrating at times because of interfaces that are too broad. For example, I’m sure many of us have engaged in the work place theater of surfing the web, pretending to be productive, until it’s time to go home. Or felt like you had to sneak out early to go to the dentist. A narrower interface in this context would be to assess employees on their overall contribution and eliminate unnecessary dependencies, like having to track how many hours you’ve been in the office. The well known <a href="http://www.slideshare.net/reed2001/culture-1798664">Netflix culture<br>deck</a> is a good example of this kind of CS thinking being successfully applied in practice.</p><p>In contrast, micro-managers create big balls of mud because they introduce deep and unnecessary dependencies into areas where they don’t belong, in this case into the details of your job and even your personal life. Instead of providing a narrow interface with high-level goals and context, a micro-manager will obsess about low-level implementation details of how you do your job. Details that are usually best left for you to decide.</p><p><strong>Debugging and Steve Jobs</strong></p><p>Debugging is an important example in software development when you need to be prepared to dive into the details. The hard part can be finding out where the problem lies and you may need to delve into some very dark corners. Once the bug is identified, it can be a simple tweak to fix the problem, although that sometimes then reveals other bugs! Other times the conclusion you come away with is that the code is a mess and needs to be replaced, although you should be aware that this can be fraught with <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">difficulties</a>.</p><p>We can all probably identify “buggy” work colleagues. A manager or colleague may need to delve into the details in order to figure out the source of the problem. Often the person simply didn’t realize there was a problem and some appropriate feedback is all that is required. Just as in software, once uncovered the “bug” may have a simple fix.</p><p>The key point is that while detail-oriented, hands-on managing and micro-managing might share some superficial similarities, they are very different in intent and outcome. Hands-on management involves diving in to the details to debug a problem or make something better, micro-managing is an incessant obsession with details for no outward purpose other than a desire to control for the sake of control. People like to bring up Steve Jobs as an example of a wildly successful micro-manager. But from what I’ve read and heard, Steve Jobs was more of a debugger and narrow interface designer than a micro-manager. He constantly saw “bugs” in product designs and he was successful by paying attention to detail, root-causing those flaws, and inspiring people to design products with less bloated interfaces. To quote his close collaborator, Johnny Ive: “Simplicity is not the absence of clutter, that’s a consequence of simplicity.” Where “clutter” here is referring to precisely the same problem of bloated interfaces and “simplicity” is analogous to a well-designed narrow interface.</p><p>In terms of debugging the restaurant example, the reason you mostly see ketchup on the table in less expensive restaurants is probably more about reducing how much work a waiter has to do, and hence cost, than providing a better experience. Perhaps, there is then an even better design to narrow the interface with the waiters that doesn’t involve cluttering the table with more bottles. In particular, Japanese restaurants, of any calibre, tend to put a great deal of effort into designing how to present meals. For example, Bento boxes typically come with dipping sauce, wasabi, ginger and even utensils — everything you need to maintain a narrow interface with the waiters.</p><p><strong>Relationships</strong></p><p>It might seem like more of a stretch, but the same CS thinking principles can also potentially be applied to making personal relationships less frustrating. For example, my wife can become exasperated by the amount of money I waste on electronic gadgets and, to be fair, I often feel skeptical about some of her purchasing decisions. But she is also a <a href="http://awards.acm.org/award_winners/tu_9113567.cfm">computer scientist</a> and so the CS thinking solution we came up with to narrow the interface between us was to have three bank accounts. A shared one that we use to pay the bills and one each over which the other has no authority or visibility.</p><p>Of course, while the goal of some personal relationships might be to get as entangled with another person as possible, there might be value in avoiding introducing some unnecessary dependencies. So if your partner attempts to unnecessarily control implementation details of your life, you might suggest, being careful to be clear on what you are suggesting slimming down, making your interface less “bloated.”</p><p><strong>Acknowledgements</strong></p><p>Thanks to <a href="http://www.linkedin.com/pub/tong-acken/a/a35/a3"><strong>Tong Acken</strong></a> and <a href="http://www.linkedin.com/pub/kathleen-kovatch/0/116/1aa"><strong>Kathleen Kovatch</strong></a><strong> </strong>for feedback on early drafts of this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183eb7a62720" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cs-thinking/put-the-ketchup-on-the-table-183eb7a62720">Put the Ketchup on the Table</a> was originally published in <a href="https://medium.com/cs-thinking">CS Thinking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[High-priority Thread]]></title>
            <link>https://medium.com/cs-thinking/high-priority-thread-447b676f279c?source=rss----a82878004055---4</link>
            <guid isPermaLink="false">https://medium.com/p/447b676f279c</guid>
            <dc:creator><![CDATA[funge]]></dc:creator>
            <pubDate>Mon, 16 Dec 2013 06:14:45 GMT</pubDate>
            <atom:updated>2013-12-15T07:16:15.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*DM5ceYRgECw-t3zru3X0Og.jpeg" /></figure><h4>CS Thinking</h4><p>“Dad, you’re blocking my high-priority thread” my 7-year old son Arthur complains as I tell him to wash his hands before eating.</p><p>“No,” I explain patiently, “eating is a relatively low priority thread as you can last for several weeks without food. Drinking is a higher priority thread because you can only last for a few days without water.”</p><p>However, I do admit that I am blocking his eating thread. By which I mean that I am stopping him engaging in the task of eating until he has completed the task of washing his hands. Washing hands is a pre-condition to eating that I assume many parents place on their sometimes grubby children.</p><p>So why am I using the language of concurrent programming to talk about every day life to a young child? I can imagine that, when he’s older, my son’s answer might be that I like the sound of my own voice too much! The more charitable explanation, is that it’s my first simple example of how “Computer Science (CS) thinking” can be useful far outside the narrow context of talking about computer programs.</p><p><strong>Time Management</strong></p><p>It’s cliched and my 7-year old son might not yet realize it, but time is precious. Thinking in terms of threads and blocking, can help minimize the amount of time you waste. A few minutes here and there can quickly add up so that you have more time to devote to the things you really care about. So let’s look at another example.</p><p>Pretty much every time my son gets into the car with food I have to remind him to put on his seat belt first. Aside from a chance to express my exasperation over how many times I have to tell him the same thing, this is another good learning opportunity. So long as he is unbuckled, he is blocking the driving thread since we can’t go anywhere until he is securely fastened. But it’s also a great example of the advantages of parallel processing. So long as he unblocks the driving thread, by fastening his seat belt, then we can proceed in parallel. He can eat while I drive. The alternative, that seems to be his first impulse, is that we first wait until he finishes eating, then he buckles up, and then we drive. It’s the staggering inefficiency of this alternative that makes me so incredulous that he can’t figure out on his own to put his seat belt on first.</p><p><strong>Riches and Success</strong></p><p>Hopefully this blog will be useful and help you be more efficient and find more time in your busy lives to spend on the people and activities you love. You may, however, be thinking that none of this seems like a big deal. You might think that my son is a hungry growing boy and so I should perhaps just be more patient. Nevertheless, by understanding the underlying concepts you can apply the same ideas to problems beyond every day life. For example, if you remember the world before Starbucks, you may recall lining up in a long line at your local coffee shop waiting forever to buy a bottle of water. The hold up was because old-fashioned coffee shops ran with a single thread. You go to the person at the register, request a latte, and then they stop serving other customers while they go off and make it. The “latte making” task then blocks the “serving other customers” task and the result is a long line of frustrated customers. Or, in the language of concurrent programming, there is resource contention for the coffee shop employee’s attention.</p><p>Starbucks recognized the problem and realized that by having a separate person to make espresso drinks, they could run two threads in parallel. In Starbucks, when you order a latte the task is off-loaded to another thread. Someone else makes your drink while the person at the register quickly takes your money and moves on to serving the next customer. If all you want to do is buy a bottle of water, the wait in line at Starbucks is usually a lot less than in an old-fashioned coffee shop. Soon, they may even have <a href="http://www.huffingtonpost.com/2012/06/04/starbucks-buys-la-boulange-bakery_n_1568977.html"><strong>edible pastries!</strong></a></p><p><strong>Poor CS Thinking</strong></p><p>CS thinking can therefore be the path to riches and success. But even the most efficient companies can still make mistakes. FedEx is usually the epitome of efficiency and it has served them well in their rise to the top. However, I recently had the misfortune to use their <a href="http://www.fedex.com/us/office/"><strong>Office Print Online</strong></a><strong> </strong>service while I was waiting for a new printer to be delivered at work. Everything worked perfectly until it was time to go pickup my print out. I had even managed to pay online so all I had to do was go to the FedEx store to collect it. When I arrived, there was only one person in the line in front of me. A FedEx employee was helping him pick the right card stock for some art project or other he was working on. The process was taking forever, and all I wanted to do was pickup my print out before I had to go pickup my kids from school.</p><p>“You’re blocking my high-priority thread!” I wanted to scream at the employee, but of course he wouldn’t know what I was talking about. His instructions were obviously to treat whoever he was dealing with as the only person in the world. In the language of concurrent programming, the customer in front of me had a lock on the employee shared resource and I had to wait until he released his lock. Or alternatively, I could ask the gentleman in front of me if he could temporarily release his lock. Although I obviously didn’t phrase it in those terms, I did eventually ask if I could quickly interrupt to pickup my print out. He kindly obliged and after pointlessly waiting for over ten minutes I was on my way in only another thirty seconds! Needless to say, I will never use the printing service again since needlessly locking a critical shared resource for long periods of time while other threads (i.e. me quickly trying to pickup my print out) have to wait indefinitely is not good CS thinking!</p><p><strong>Big Picture</strong></p><p>A recurring theme throughout this series of blogs will be taking ideas and concepts from Computer Science and explaining them in every day life situations. Next time, I’ll describe how CS thinking can be applied to company culture and human relationships!</p><p><strong>Acknowledgements</strong></p><p>Thanks to <a href="http://www.linkedin.com/pub/kathleen-kovatch/0/116/1aa"><strong>Kathleen Kovatch</strong></a><strong> </strong>for feedback on early drafts of this post and to <a href="http://www.linkedin.com/in/jcham"><strong>James Cham</strong></a><strong> </strong>for originally suggesting that I turn the CS Thinking ideas into a blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=447b676f279c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cs-thinking/high-priority-thread-447b676f279c">High-priority Thread</a> was originally published in <a href="https://medium.com/cs-thinking">CS Thinking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>