<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/advent-of-code-most-popular-languages/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://masalmon.eu/2018/12/15/adventofcode/"> Posts on Maëlle's R blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>You might have heard of the <a rel="nofollow" href="https://adventofcode.com/" target="_blank">Advent of Code</a>,<br>
a 25-day challenge involving a programming puzzle a day, to be solved<br>
with the language of your choice. I’ve noted the popularity of this<br>
activity in my Twitter timeline but also in my GitHub timeline where<br>
I’ve seen the creation of a few <code>advent-of-code</code> or so repositories.</p>
<blockquote class="twitter-tweet" data-dnt="true">
<p lang="en" dir="ltr">AoC is largely an exercise in figuring how to write your favourite language as if were C or C++ <img alt="😁" src="https://s.w.org/images/core/emoji/2.4/72x72/1f601.png" class="wp-smiley">, which can be fun … in moderation</p>
<p>— Jenny Bryan (@JennyBryan) <a rel="nofollow" href="https://twitter.com/JennyBryan/status/1072724282705203201?ref_src=twsrc%5Etfw" target="_blank">December 12, 2018</a></p></blockquote>
<p></p>
<p>If I were to participate one year, I’d probably use R. Jenny Bryan’s<br>
tweet above inspired me to try and gauge the popularity of languages<br>
used in the Advent of Code. To do that, in this post, I shall use the<br>
search endpoint of GitHub V3 API to identify Advent of Code 2018 repos.</p>

<h1>Searching repositories on GitHub</h1>
<h2>Study design <img alt="😉" src="https://s.w.org/images/core/emoji/2.4/72x72/1f609.png" class="wp-smiley"></h2>
<p>GitHub’s V3 API offers a <a rel="nofollow" href="https://developer.github.com/v3/search/#search-repositories" target="_blank">search<br>
endpoint</a>,<br>
that however gives you less results than doing the <a rel="nofollow" href="https://github.com/search?q=adventofcode+2018" target="_blank">same search via the<br>
web interface</a>, even when<br>
using pagination right (or at least, when believing I use pagination<br>
right!). I’m however willing to use that sub-sample as basis for my<br>
study of language popularity. It’s actually a sub-sub-sample, since I’m<br>
only looking at Advent of code projects published on GitHub.</p>
<p>In order to circumvent the sub-sub-sampling a bit, I’ll do the search in<br>
two steps:</p>
<ul>
<li>
<p>Searching for Advent of code 2018 in general among repos, and<br>
extracting the language of the repos.</p>
</li>
<li>
<p>Searching for Advent of code 2018 <em>for each of these languages<br>
separately</em> and extracting the total count of hits.</p>
</li>
</ul>
<p>Note that I am not filtering the repos by activity, so some of them<br>
could very well have been created for a few days only. If they are empty<br>
though, they do not get assigned a language.</p>
<p>Regarding the language of repos, GitHub assigns a language to each<br>
repository. This information can be wrong, which is e.g. mentioned in<br>
<a rel="nofollow" href="https://ropensci.github.io/dev_guide/grooming.html#github-linguist" target="_blank">rOpenSci’s development<br>
guide</a>.<br>
Furthermore, my using this piece of information means I’m disregarding<br>
the fact that <a rel="nofollow" href="https://www.benkraft.org/2017/12/26/advent-of-code/" target="_blank">some people actually use a mix of technologies to solve<br>
the puzzles</a>.</p>
<h2>Actual queries</h2>
<p>I first defined a function to search the API whilst respecting the rate<br>
limiting. I even erred on the side of caution and queried very slowly.</p>
<pre><code>.search &lt;- function(page){
  gh::gh(&quot;GET /search/repositories&quot;,
         q = &quot;adventofcode 2018&quot;,
         page = page,
         fork = FALSE)
}

search &lt;- ratelimitr::limit_rate(.search,
                                ratelimitr::rate(10, 60))
</code></pre>
<p>I then wrote two other functions to help me rectangle the API output for<br>
each repository.</p>
<pre><code>empty_null &lt;- function(x){
  if(is.null(x)){
    &quot;&quot;
  }else{
    x
  }
}

rectangle &lt;- function(item){
  tibble::tibble(full_name = item$full_name,
                 language = empty_null(item$language))
}
</code></pre>
<p>I created a function putting these two pieces together.</p>
<pre><code>get_page &lt;- function(page){
  results &lt;- try(search(page), silent = TRUE)

  # an early return
  if(inherits(results, &quot;try-error&quot;)){
    return(NULL)
  }

  purrr::map_df(results$items,
                rectangle)
}
</code></pre>
<p>And I then ran the following pipeline.</p>
<pre><code>total_count &lt;- search(1)$total_count
pages &lt;- 1:(ceiling(total_count/100))

results &lt;- purrr::map_df(pages, get_page)
results &lt;- unique(results)

languages &lt;- unique(results$language)
languages &lt;- languages[languages != &quot;&quot;]
</code></pre>
<p>This got me 814 repos, with 46 non empty languages. Repo names are quite<br>
varied: rdmueller/aoc-2018, petertseng/adventofcode-rb-2018,<br>
NiXXeD/adventofcode, Arxcis/adventofcode2018,<br>
Stupremee/adventofcode-2018, phaazon/advent-of-code-2k18.</p>
<p>With that information obtained, I was able to run a query by language.</p>
<pre><code>.get_one_language_count &lt;- function(language){
  gh::gh(&quot;GET /search/repositories&quot;,
         q = glue::glue(&quot;adventofcode 2018&amp;language:{language}&quot;),
         fork = FALSE)$total_count -> count
  tibble::tibble(language = language,
                 count = count)
}

get_one_language_count &lt;- ratelimitr::limit_rate(.get_one_language_count,
                                 ratelimitr::rate(10, 60))

counts &lt;- purrr::map_df(languages,
                        get_one_language_count)
</code></pre>
<p>In total, the <code>counts</code> table contains information about 2080<br>
repositories, a bit less than half the number of Advent of code 2018<br>
repositories I’d find via the web interface.</p>
<h1>Advent of Code’s languages popularity</h1>
<p>I’ll concentrate on the 15 most popular languages in the sample, which<br>
automatically excludes R with… 8 repositories only.</p>
<pre><code>library(&quot;ggplot2&quot;)
library(&quot;ggalt&quot;)
library(&quot;hrbrthemes&quot;)
library(&quot;magrittr&quot;)

counts %>%
  dplyr::arrange(- count) %>%
  head(n = 15) %>%
  dplyr::mutate(language = reorder(language, count))   %>%
  ggplot() +
  geom_lollipop(aes(language, count),
                size = 2, col = &quot;salmon&quot;) +
  hrbrthemes::theme_ipsum(base_size = 16,
                          axis_title_size = 16) +
  coord_flip() +
  ggtitle(&quot;Advent of Code Languages&quot;,
          subtitle = &quot;Among a sample of GitHub repositories, with language information from GitHub linguist&quot;)
</code></pre>
<p><img alt="popularity of languages" src="https://i2.wp.com/masalmon.eu/figure/source/2018-12-15-adventofcode/adventofcode.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>The results are not surprising after reading e.g. the <a rel="nofollow" href="https://insights.stackoverflow.com/survey/2018/#technology" target="_blank">insights from<br>
Stack Overflow’s 2018<br>
survey</a>, although the Python domination is crazy! I find interesting to reflect on the<br>
fact that Jenny Bryan says that the challenge is best for C or C++, that<br>
are not the most popular languages in these samples… but still more<br>
popular than R, ok.</p>
<h1>Conclusion</h1>
<p>In this post I used GitHub V3 API to get a glimpse at the popularity of languages used to solve the Advent of Code. Further work could include looking at the <em>completion</em> of the challenge by language, potentially using the GitHub activity of each repo as an (imperfect) proxy.</p>
<p>I do not take part in the challenge myself, my principal Advent’s<br>
specific activity being instead the lazy and delightful watching of the<br>
<a rel="nofollow" href="https://sv.wikipedia.org/wiki/Julkalendern_i_Sveriges_Television" target="_blank">Swedish TV channel SVT Adventskalender for<br>
kids</a>.<br>
Incidentally, <a rel="nofollow" href="https://sv.wikipedia.org/wiki/Storm_p%C3%A5_Lugna_gatan" target="_blank">this year’s<br>
storyline</a><br>
includes a Christmas competition, which however features competitive<br>
eating of saffron buns and gingerhouse building rather than programming<br>
puzzles… Do <em>you</em> participate to Advent of Code this year? If so, with<br>
which language and why?</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="https://masalmon.eu/2018/12/15/adventofcode/"> Posts on Maëlle's R blog</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/0W_0h79QfOM" height="1"></a></div>