<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/dont-teach-students-the-hard-way-first/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://varianceexplained.org/r/teach-hard-way/"> Variance Explained</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Imagine you were going to a party in an unfamiliar area, and asked the host for directions to their house. It takes you thirty minutes to get there, on a path that takes you on a long winding road with slow traffic. As the party ends, the host tells you “You can take the highway on your way back, it’ll take you only ten minutes. I just wanted to show you how much easier the highway is.”</p>
<p>Wouldn’t you be annoyed? And yet this kind of attitude is strangely common in programming education.</p>
<p>I was recently talking to a friend who works with R and whose opinions I greatly respect. He was teaching some sessions to people in his company who hadn’t used R before, where he largely followed my <a rel="nofollow" href="http://varianceexplained.org/r/teach-tidyverse/" target="_blank">philosophy on teaching the tidyverse to beginners</a>. I agreed with his approach, until he said something far too familiar to me:</p>
<blockquote>
<p>“I teach them dplyr’s <code>group_by</code>/<code>summarize</code> in the second lesson, but I teach them loops first just to show them how much easier dplyr is.”</p>
</blockquote>
<p>I talk to people about teaching a lot, and that phrase keeps popping up: <strong>“I teach them X just to show them how much easier Y is”</strong>. It’s a trap- a trap I’ve fallen into before when teaching, and one that I’d like to warn others against.</p>
<h3>Students don’t share your nostalgia</h3>
<p>First, why do some people make this choice? I think because when we teach a class, we accidentally bring in all of our own history and context.</p>
<p>For instance, I started programming with Basic and Perl in high school, then Java in college, then got really into Python, then got even more into R. Along the way I built up habits in each language that had to be painfully undone afterwards. I worked in an object-oriented style in Python, then switched to thinking in data frames and functional operations. I wrote too many loops when I started R, then I grew accustomed to the apply family of functions. Along the way there were thousands of little frustrations and little epiphanies, tragedies and triumphs in microcosm.</p>
<p>But when I’m teaching someone how to use R… <strong>they don’t care about any of that.</strong> They weren’t there! They didn’t make my mistakes, they don’t need to be talked out of them. Going back to the party host, perhaps the highway was built only last year, and maybe the host had to talk his friends, stuck in their habits, into taking the highway by explaining how much faster it is. But that doesn’t make any difference to the guest, who has never taken either route.</p>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr"><a rel="nofollow" href="https://twitter.com/ucfagls" target="_blank">@ucfagls</a> I think ppl teach base stuff preferentially because it’s what they still use or they’re reliving their own <a rel="nofollow" href="https://twitter.com/hashtag/rstats?src=hash" target="_blank">#rstats</a> “journey” <a rel="nofollow" href="https://twitter.com/drob" target="_blank">@drob</a></p>
<p>— Jenny Bryan (@JennyBryan) <a rel="nofollow" href="https://twitter.com/JennyBryan/status/556218754485321729" target="_blank">January 16, 2015</a></p></blockquote>
<p></p>
<p>It’s true that I learned a lot about programming in the path I described above. I learned how to debug, how to compare programming paradigms, and when to switch from one approach to another. I think some teachers hope that by walking students through this “journey”, we can impart some of that experience. But it doesn’t work: feeding students two possible solutions in a row is nothing like the experience of them comparing solutions for themselves, and doesn’t grant them any of the same skills. Besides which, students will face plenty of choices and challenges as they continue their programming career, without us having to invent artificial ones.</p>
<p>Students should absolutely learn multiple approaches (there’s usually advantages to each one). But <strong>not in this order</strong>, from hardest to easiest, and not because it happened to be the order we learned it ourselves.</p>
<h3>Bandwidth and trust</h3>
<p>There are two reasons I recommend against teaching a harder approach first. One is educational bandwidth, and one is trust.</p>
<p>One of the most common mistakes teachers make (especially inexperienced ones) is to think they can teach more material than they can.</p>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">.<a rel="nofollow" href="https://twitter.com/minebocek" target="_blank">@minebocek</a> talks philosophy of Data Carpentry.</p>
<p>Highlight: don't take on too much material. Rushing discourages student questions <a rel="nofollow" href="https://twitter.com/hashtag/UseR2017?src=hash" target="_blank">#UseR2017</a> <a rel="nofollow" href="https://t.co/txAcSd3ND3" target="_blank">pic.twitter.com/txAcSd3ND3</a></p>
<p>— David Robinson (@drob) <a rel="nofollow" href="https://twitter.com/drob/status/882933155119976449" target="_blank">July 6, 2017</a></p></blockquote>
<p></p>
<p>This comes down to what I sometimes call <strong>educational bandwidth</strong>: the total amount of information you can communicate to students is limited, especially since you need to spend time reinforcing and revisiting each concept. It’s not just about the amount of time you have in the lesson, either. Learning new ideas is hard work: think of the headache you can get at the end of a one-day workshop. This means you should make sure every idea you get across is valuable. If you teach them a method they’ll never have to use, you’re wasting time and energy.</p>
<p>The other reason is <strong>trust</strong>. Think of the imaginary host who gave poor directions before giving better ones. Wouldn’t it be unpleasant to be tricked like that? When a student goes through the hard work of learning a new method, telling them “just kidding, you didn’t need to learn that” is obnoxious, and hurts their trust in you as a teacher.</p>
<p>In some cases there’s a tradeoff between bandwidth and trust. For instance, <a rel="nofollow" href="http://varianceexplained.org/r/teach-tidyverse/" target="_blank">as I’ve described before</a>, I teach dplyr and the <code>%>%</code> operator before explaining what a function is, or even how to do a variable assignment. This conserves bandwidth (it gets students doing powerful things quickly) but it’s a minor violation of their trust (I’m hiding details of how R actually works). But there’s no tradeoff in teaching a hard method before an easier one.</p>
<h3>Exceptions</h3>
<p>Is there any situation where you might want to show students the hard way first? Yes: one exception is <strong>if the hard solution is something the student would have been tempted to do themselves</strong>.</p>
<p>One good example is in <a rel="nofollow" href="http://r4ds.had.co.nz/" target="_blank">R for Data Science</a>, by Hadley Wickham and Garrett Grolemund. <a rel="nofollow" href="http://r4ds.had.co.nz/functions.html#when-should-you-write-a-function" target="_blank">Chapter 19.2</a> describes “When should you write a function”, and gives an example of rescaling several columns by copying and pasting code:</p>
<div>
<pre><code><span>df</span><span>$</span><span>a</span><span> </span><span>&lt;-</span><span> </span><span>(</span><span>df</span><span>$</span><span>a</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>a</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span> </span><span>/</span><span> </span><span>(</span><span>max</span><span>(</span><span>df</span><span>$</span><span>a</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>a</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span>
</span><span>df</span><span>$</span><span>b</span><span> </span><span>&lt;-</span><span> </span><span>(</span><span>df</span><span>$</span><span>b</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>b</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span> </span><span>/</span><span> </span><span>(</span><span>max</span><span>(</span><span>df</span><span>$</span><span>b</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>a</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span>
</span><span>df</span><span>$</span><span>c</span><span> </span><span>&lt;-</span><span> </span><span>(</span><span>df</span><span>$</span><span>c</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>c</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span> </span><span>/</span><span> </span><span>(</span><span>max</span><span>(</span><span>df</span><span>$</span><span>c</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>c</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span>
</span><span>df</span><span>$</span><span>d</span><span> </span><span>&lt;-</span><span> </span><span>(</span><span>df</span><span>$</span><span>d</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>d</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span> </span><span>/</span><span> </span><span>(</span><span>max</span><span>(</span><span>df</span><span>$</span><span>d</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>df</span><span>$</span><span>d</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>))</span><span>
</span></code></pre>
</div>
<p>By showing them what this approach looks like (and even including an intentional typo in the second line, to show how copying and pasting code is prone to error), the book guides them towards the several steps involved in writing a function.</p>
<div>
<pre><code><span>rescale01</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>x</span><span>)</span><span> </span><span>{</span><span>
</span><span>rng</span><span> </span><span>&lt;-</span><span> </span><span>range</span><span>(</span><span>x</span><span>,</span><span> </span><span>na.rm</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span>
</span><span>(</span><span>x</span><span> </span><span>-</span><span> </span><span>rng</span><span>[</span><span>1</span><span>])</span><span> </span><span>/</span><span> </span><span>(</span><span>rng</span><span>[</span><span>2</span><span>]</span><span> </span><span>-</span><span> </span><span>rng</span><span>[</span><span>1</span><span>])</span><span>
</span><span>}</span><span>
</span></code></pre>
</div>
<p>This educational approach makes sense because copying and pasting code is a habit beginners would fall into naturally, <em>especially</em> if they’ve never programmed before. It doesn’t take up any educational bandwidth because students already know how to do it, and it’s upfront about it’s approach (when I teach this way, I usually use the words “you might be tempted to…”).</p>
<p>However, teaching a loop (or <code>split()</code>/<code>lapply()</code>, or <code>aggregate</code>, or <code>tapply</code>) isn’t something beginners would do accidentally, and it’s therefore not something you need to be talking.</p>
<p>In conclusion: <strong>teaching programming is hard, don’t make it harder.</strong> Next time you’re teaching a course, or workshop, or writing a tutorial, or just helping a colleague getting set up in R, try teaching them your preferred method first, instead of meandering through subpar solutions. I think you’ll find that it’s worth it.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://varianceexplained.org/r/teach-hard-way/"> Variance Explained</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/Np_hx7cFrbc" height="1"></a></div>