Jekyll2020-08-09T22:42:46+02:00http://anamaria.martinezgomez.name/feed.xmlAna María Martínez GómezAna María Martínez Gómez personal page and blogRuby 2.62018-12-21T00:00:00+01:002018-12-21T00:00:00+01:00http://anamaria.martinezgomez.name/2018/12/21/ruby2_6<p>Christmas is around the corner, but I couldn’t wait and I have already been trying the new Ruby release! :christmas_tree: :tada:
Ruby 2.6, apart from efficiency improvements, which include the initial implementation of a just-in-time compiler, brings us many new cool features.
Taking advance of the cold outside, let’s discover some of them! :snowflake:</p>
<h2 id="arrayunion--arraydifference">Array#union & Array#difference</h2>
<p>This Ruby version is particularly special to me because it includes my two new methods for the Array class, which I presented in my talks at <a href="https://youtu.be/jUc8InwoA-E?t=2m54s" target="_blank">EuRuKo</a> and <a href="https://brightonruby.com/2018/lets-refactor-some-ruby-code-ana-martinez" target="_blank">Brighton Ruby</a>. <code class="language-plaintext highlighter-rouge">Array#union</code> and <code class="language-plaintext highlighter-rouge">Array#difference</code> are just readable alias for <code class="language-plaintext highlighter-rouge">Array#|</code> and <code class="language-plaintext highlighter-rouge">Array#-</code> respectively when only having two arrays:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">9</span><span class="p">].</span><span class="nf">union</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span> <span class="c1">#=> [1, 3, 5, 7, 9, 2, 4, 6]</span>
<span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">9</span><span class="p">].</span><span class="nf">difference</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span> <span class="c1">#=> [1, 1, 5, 9]</span>
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">Array#union</code> is also equivalent to combine <code class="language-plaintext highlighter-rouge">Array#concat</code> and <code class="language-plaintext highlighter-rouge">Array#uniq</code> (with the difference that <code class="language-plaintext highlighter-rouge">concat</code> modifies the array), but more readable.
But what is really important about those new methods, are the gains in efficiency when having more than two arrays.
We need some Benchmark now. :wink:</p>
<p>Using <code class="language-plaintext highlighter-rouge">Array.new(num_elements) { Random.rand(20_100_000) }</code> to create four arrays with 20,000,000, 30,000,000, 8,000,000 and 25,000,000 elements, those are the times for the different options:</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">(array1 | array2 | array3 | array4)</code> ~ 20.043 seconds</li>
<li><code class="language-plaintext highlighter-rouge">array1.union(array2, array3, array4)</code> ~ 13.390 seconds</li>
<li><code class="language-plaintext highlighter-rouge">array1.concat(array2, array3, array4).uniq</code> ~ 20.633 seconds</li>
</ul>
<p>So please, stop using <code class="language-plaintext highlighter-rouge">concat</code> + <code class="language-plaintext highlighter-rouge">uniq</code> :pray: and let’s finally refactor some Ruby code! :tada:</p>
<h2 id="hashmerge-with-multiple-parameters">Hash#merge with multiple parameters</h2>
<p><code class="language-plaintext highlighter-rouge">Hash#merge</code> and <code class="language-plaintext highlighter-rouge">Hash#merge!</code> were only able to merge two hashes at the same time.
With Ruby 2.6, we can merge as many hashes as we want at once, which provides an performance improvement similar to <code class="language-plaintext highlighter-rouge">Array#union</code> and <code class="language-plaintext highlighter-rouge">Array#difference</code> when merging several big hashes.</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span> <span class="ss">a: </span><span class="mi">1</span><span class="p">,</span> <span class="ss">b: </span><span class="mi">2</span> <span class="p">}.</span><span class="nf">merge</span><span class="p">({</span> <span class="ss">b: </span><span class="mi">3</span><span class="p">,</span> <span class="ss">c: </span><span class="mi">4</span> <span class="p">},</span> <span class="p">{</span> <span class="ss">d: </span><span class="mi">5</span> <span class="p">})</span> <span class="c1">#=> {:a=>1, :b=>3, :c=>4, :d=>5}</span>
</code></pre></div></div>
<h2 id="enumerableto_h">Enumerable#to_h</h2>
<p><code class="language-plaintext highlighter-rouge">Enumerable#to_h</code> accepts a block which allows to do things that used to require iterating manually or prepending <code class="language-plaintext highlighter-rouge">map</code>, being consequently more efficient.
The following examples illustrate how it works:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">5</span><span class="p">).</span><span class="nf">to_h</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span> <span class="o">%</span> <span class="mi">3</span><span class="p">]</span> <span class="p">}</span> <span class="c1">#=> {1=>1, 2=>2, 3=>0, 4=>1, 5=>2}</span>
<span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">].</span><span class="nf">to_h</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="kp">true</span><span class="p">]</span> <span class="p">}</span> <span class="c1">#=> {1=>true, 2=>true, 4=>true}</span>
</code></pre></div></div>
<h2 id="endless-range">Endless range</h2>
<p>Ruby 2.6 introduces endless ranges like <code class="language-plaintext highlighter-rouge">(1..)</code>, <code class="language-plaintext highlighter-rouge">(74..)</code> and <code class="language-plaintext highlighter-rouge">(1..nil)</code>, whose size is infinite:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="p">).</span><span class="nf">size</span> <span class="o">=></span> <span class="no">Infinity</span>
</code></pre></div></div>
<p>It provides a nice alternative to <code class="language-plaintext highlighter-rouge">[1..-1]</code> to retrieve a slice up to the end of an Array or String:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">][</span><span class="mi">3</span><span class="o">..</span><span class="p">]</span> <span class="o">=></span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="s1">'hello world'</span><span class="p">[</span><span class="mi">6</span><span class="o">..</span><span class="p">]</span> <span class="o">=></span> <span class="s2">"world"</span>
</code></pre></div></div>
<p>It can also be combined with other methods to produce such elegant code:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Selects from an array a range and from an element to the end</span>
<span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">].</span><span class="nf">values_at</span><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="o">..</span><span class="p">)</span> <span class="c1">#=> [1, 2, 3, 5, 6]</span>
<span class="c1"># Iterates over more than one array at the same time with index</span>
<span class="p">[</span><span class="ss">:a</span><span class="p">,</span> <span class="ss">:b</span><span class="p">,</span> <span class="ss">:c</span><span class="p">].</span><span class="nf">zip</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span> <span class="mi">37</span><span class="p">,</span> <span class="mi">30</span><span class="p">],</span> <span class="mi">1</span><span class="o">..</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">index</span><span class="o">|</span> <span class="nb">puts</span> <span class="s2">"</span><span class="si">#{</span><span class="n">index</span><span class="si">}</span><span class="s2">: </span><span class="si">#{</span><span class="n">x1</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">x2</span><span class="si">}</span><span class="s2">"</span> <span class="p">}</span>
<span class="c1"># Multiples of π less than 100</span>
<span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="p">).</span><span class="nf">lazy</span><span class="p">.</span><span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o">*</span> <span class="no">Math</span><span class="o">::</span><span class="no">PI</span> <span class="p">}.</span><span class="nf">take_while</span><span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o"><</span> <span class="mi">100</span> <span class="p">}.</span><span class="nf">force</span>
</code></pre></div></div>
<p>Last, it can be used to write infinit loops with index: <code class="language-plaintext highlighter-rouge">(1..).each { |n| ... }</code>, however we had already several alternatives to do this.
I personally find the following ones more readable:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="mi">1</span><span class="p">.</span><span class="nf">step</span> <span class="p">{</span> <span class="o">|</span><span class="n">n</span><span class="o">|</span> <span class="o">...</span> <span class="p">}</span>
<span class="n">n</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="kp">loop</span> <span class="p">{</span> <span class="o">...</span><span class="p">;</span> <span class="n">n</span> <span class="o">+=</span> <span class="mi">1</span> <span class="p">}</span>
</code></pre></div></div>
<p><small>
<strong>Note:</strong> Be careful when trying infinite ranges, as if you iterate over a range (for example with <code class="language-plaintext highlighter-rouge">map</code>) and forget <code class="language-plaintext highlighter-rouge">lazy</code> (or to stop it for instance with <code class="language-plaintext highlighter-rouge">break</code>), it may consume all the memory of your computer, as it happened to me. :sweat:
You can use <a href="https://ss64.com/bash/ulimit.html" target="_blank"><code class="language-plaintext highlighter-rouge">ulimit</code></a> to limit the memory available for the console where you execute <code class="language-plaintext highlighter-rouge">irb</code> when playing with it to avoid this (on Linux and macOS). :nerd_face:
</small></p>
<h2 id="range-uses-cover-instead-of-include">Range#=== uses cover? instead of include?</h2>
<p>Although Matz always aims to prioritize backwards compatibility, in this case performance has won.
<code class="language-plaintext highlighter-rouge">Range#===</code> uses now <code class="language-plaintext highlighter-rouge">cover?</code> instead of <code class="language-plaintext highlighter-rouge">include?</code> to check if an object is an element of the range.
This is a reasonable but also <strong>breaking</strong> change, which modifies the behaviour of statements like:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="no">Date</span><span class="p">.</span><span class="nf">today</span><span class="o">..</span><span class="p">(</span><span class="no">Date</span><span class="p">.</span><span class="nf">today</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span> <span class="o">===</span> <span class="no">DateTime</span><span class="p">.</span><span class="nf">now</span> <span class="c1">#=> true (false in Ruby 2.5)</span>
</code></pre></div></div>
<p>Take into account that <code class="language-plaintext highlighter-rouge">Range#===</code> is used in <code class="language-plaintext highlighter-rouge">case</code>, so the following example also change its behaviour:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">case</span> <span class="no">DateTime</span><span class="p">.</span><span class="nf">now</span>
<span class="k">when</span> <span class="p">(</span><span class="no">Date</span><span class="p">.</span><span class="nf">today</span><span class="o">..</span><span class="p">(</span><span class="no">Date</span><span class="p">.</span><span class="nf">today</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
<span class="s1">'you are in Ruby 2.6!'</span>
<span class="k">else</span>
<span class="s1">'update to Ruby 2.6'</span>
<span class="k">end</span>
</code></pre></div></div>
<h2 id="proc-proc">Proc#« & Proc#»</h2>
<p>We can now compose procs both from left to right (<code class="language-plaintext highlighter-rouge">>></code>) and from right to left (<code class="language-plaintext highlighter-rouge"><<</code>):</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">double</span> <span class="o">=</span> <span class="nb">proc</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">}</span>
<span class="n">increment</span> <span class="o">=</span> <span class="nb">proc</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span> <span class="p">}</span>
<span class="p">(</span><span class="n">double</span> <span class="o">>></span> <span class="n">increment</span><span class="p">).</span><span class="nf">call</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1">#=> 5</span>
<span class="p">(</span><span class="n">double</span> <span class="o"><<</span> <span class="n">increment</span><span class="p">).</span><span class="nf">call</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1">#=> 6</span>
</code></pre></div></div>
<p>Procs with multiple arguments are also supported:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">f</span> <span class="o">=</span> <span class="nb">proc</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">|</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="p">}</span>
<span class="n">g</span> <span class="o">=</span> <span class="nb">proc</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">|</span> <span class="p">[</span><span class="n">x</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="p">(</span><span class="n">y</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)]</span> <span class="p">}</span>
<span class="p">(</span><span class="n">f</span> <span class="o"><<</span> <span class="n">g</span><span class="p">).</span><span class="nf">call</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1">#=> 1</span>
</code></pre></div></div>
<h2 id="enumerator-and-enumerablechain">Enumerator#+ and Enumerable#chain</h2>
<p>Ruby 2.6 introduces <code class="language-plaintext highlighter-rouge">Enumerator::Chain</code>, a new class to represent a chain of enumerables that works as a single enumerator as well as methods to create chain of enumerables: <code class="language-plaintext highlighter-rouge">Enumerable#chain</code> and <code class="language-plaintext highlighter-rouge">Enumerator#+</code>:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">chain</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">).</span><span class="nf">chain</span><span class="p">([</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span> <span class="c1">#=> #<Enumerator::Chain: [1..3, [7, 8]]></span>
<span class="n">chain</span><span class="p">.</span><span class="nf">to_a</span> <span class="c1">#=> [1, 2, 3, 7, 8]</span>
<span class="n">chain</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">3</span><span class="p">).</span><span class="nf">each</span> <span class="o">+</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span> <span class="c1">#=> #<Enumerator::Chain: [#<Enumerator: 1..3:each>, [7, 8]]></span>
<span class="n">chain</span><span class="p">.</span><span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">}</span> <span class="c1">#=> [2, 4, 6, 14, 16]</span>
</code></pre></div></div>
<h2 id="direach_child--dirchildren">Dir#each_child & Dir#children</h2>
<p>The <code class="language-plaintext highlighter-rouge">Dir</code> class had already the class methods <code class="language-plaintext highlighter-rouge">children</code> and <code class="language-plaintext highlighter-rouge">each_child</code>.
Ruby 2.6 add the equivalent instance methods:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">d</span> <span class="o">=</span> <span class="no">Dir</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="s2">"/home/ana"</span><span class="p">)</span> <span class="c1">#=> #<Dir:/home/ana/></span>
<span class="n">d</span><span class="p">.</span><span class="nf">children</span> <span class="c1">#=> [".config", "bin", ".gitignore", ".vimrc", "github", "cat_pictures", ".bashrc", "VirtualBox VMs"]</span>
</code></pre></div></div>
<h2 id="non-ascii-constant-names">non-ASCII constant names</h2>
<p>Constant names can now start with non-ASCII capital letters.
I am not sure how useful this is, but you can do funny things like:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="err">Σ♥²</span><span class="p">;</span> <span class="k">end</span>
</code></pre></div></div>
<p>In few days, you can update to Ruby 2.6 and have fun too! :wink:</p>Christmas is around the corner, but I couldn’t wait and I have already been trying the new Ruby release! :christmas_tree: :tada: Ruby 2.6, apart from efficiency improvements, which include the initial implementation of a just-in-time compiler, brings us many new cool features. Taking advance of the cold outside, let’s discover some of them! :snowflake:Google Summer of Code 20182018-12-20T00:00:00+01:002018-12-20T00:00:00+01:00http://anamaria.martinezgomez.name/2018/12/20/gsoc-ends<p>One more year, <a href="https://summerofcode.withgoogle.com" target="_blank">Google Summer of Code (GSoC)</a>, a mentoring program in which <a href="https://www.opensuse.org" target="_blank">openSUSE</a> helps university students contribute to open source project, has come to an end. So, before 2018 ends as well and we start preparing for the new edition of GSoC, it is time to speak about all the great things that happened this year. :sparkles:</p>
<h2 id="gsoc-2018">GSoC 2018</h2>
<p>Let’s start by the most important part, our students’ work. Our successful students, <a href="https://github.com/AnkushMalik" target="_blank">Ankush Malik</a> and <a href="https://github.com/lianna07" target="_blank">Liana Xu</a>, have spent 3 months hacking on openSUSE projects, during which they have written a lot of impressive code. But GSoC is much more than code, it is about learning, having fun and becoming part of the openSUSE community. Both Ankush and Liana claim that it has been an inspiring experience and are really thankful for the support they received from their mentors.</p>
<p>Ankush’s improvements in the Hackweek tool are noticeable. In his last weeks of work, he focused on giving all projects the chance to be viewed and on implementing a mailer. Check the last chapter of his GSoC journey: <a href="https://medium.com/@ankushmalik631/gsoc-wrap-up-86bba25bbb6d" target="_blank">https://medium.com/@ankushmalik631/gsoc-wrap-up-86bba25bbb6d</a></p>
<p>Liana has been working on integrating Cloud Input in ibus-libpinyin and she has learnt ton about GNOME developer libraries and functions. Read about her project from her own words in her last blog post: <a href="https://liana.hillwoodhome.net/2018/08/13/about-programming-life-during-gsoc" target="_blank">https://liana.hillwoodhome.net/2018/08/13/about-programming-life-during-gsoc</a></p>
<p>It is also worthwhile mentioning the great collaboration which makes me particularly proud of the openSUSE community. Thanks to the help of contributors all around the world, the blog posts about GSoC were shared, republished and translated to languages like Japanese, Spanish and Indonesian. We also had the help of the openSUSE Indonesian community to design “Thank you” mugs to send to our mentors. Look how cute they are: :cupid:</p>
<p><span class="image-center">
<img src="/img/posts/gsoc-ends-mug-thanks.jpg" alt="GSoC "Trhank you" mug, thanks for mentoring" class="image-2" />
<img src="/img/posts/gsoc-ends-mug-with-love.jpg" alt="GSoc "Thank you" mug", made with love" class="image-2" />
</span></p>
<p>Last but not least, I would like to thank our passionate mentors and admins who took out time from their busy schedules to guide the students, our motivated students for their willingness to learn and good work, Douglas DeMaio who helped with shipping packages and organization, Google and specifically its open source team not only for the program itself but also for the well organized conference, SUSE for their support (especially economically), <a href="https://en.opensuse.org/openSUSE:Travel_Support_Program" target="_blank">TSP</a> which allows our students to attend the openSUSE conference every year, the blog post translators, Pramasta Ramadha and the rest of the designers who helped with the mugs design and everybody else who made this year GSoC amazing. Because of people like you, openSUSE is much more than just software. :green_heart:</p>
<h2 id="gsoc-2019">GSoC 2019</h2>
<p>Now let’s get ready for next year to keep helping new passionate students becoming part of openSUSE! Google has already announced <a href="https://developers.google.com/open-source/gsoc/timeline" target="_blank">Google Summer of Code 2019</a> and openSUSE is looking for mentors and organization admins who would like to help bringing new programmers to our community. We need at least one more organization admin and several openSUSE related projects to be able to participate. The application period for organizations is open from January 15 to February 6, so if you would like to participate as an organization admin please get in touch with <a href="https://github.com/lagartoflojo" target="_blank">Hernán</a>, <a href="https://bruckmayer.net" target="_blank">Christian</a> or <a href="/">me</a> by January 20. For mentors, the deadline to <a href="https://github.com/openSUSE/mentoring/issues/new" target="_blank">create an issue with your project(s) in the mentoring page</a> is January 31. If you want more information about the program and what openSUSE has been doing, check out <a href="/blog/tag/GSoC">last blog posts</a>, our <a href="https://101.opensuse.org" target="_blank">mentoring page</a>, <a href="https://google.github.io/gsocguides/mentor" target="_blank">Google’s Mentor Guide</a> and the following video:</p>
<div class="image-center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/L4JNz6zWzLs" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
<p>See you next year! :wave:</p>
<h2 id="about-me">About me</h2>
<p>My name is <a href="/">Ana</a> and I am a mentor and an organization admin for openSUSE in GSoC, openSUSE Board member, Open Build Service Frontend Engineer at SUSE and open source contributor in projects inside and outside openSUSE.</p>One more year, Google Summer of Code (GSoC), a mentoring program in which openSUSE helps university students contribute to open source project, has come to an end. So, before 2018 ends as well and we start preparing for the new edition of GSoC, it is time to speak about all the great things that happened this year. :sparkles:GSoC 2018 Mentor Summit2018-10-27T00:00:00+02:002018-10-27T00:00:00+02:00http://anamaria.martinezgomez.name/2018/10/27/gsoc-mentor-summit<p><a href="https://github.com/DavidKang">David Kang</a> and <a href="/">I</a> attended two weeks ago (12-14 Oct) the <a href="https://sites.google.com/view/gsoc-mentorsummit-2018">Google Summer of Code (GSoC) Mentor Summit</a> in California representing openSUSE. :sunny: Here is our report of the conference.</p>
<p>It was an incredibly well organized event with a busy schedule. It was our first summit (we try that different openSUSE mentors/org admins go every year) and we enjoyed it a lot and found it really useful. Apart from attending many sessions about open source, mentoring and GSoC, we had the opportunity to meet and have interesting conversations with other org admins and mentors, as well as with the Google open source team and other Googlers. In total 314 mentors and org admins from 42 countries attended the events. This was a great chance to collect chocolate from all around the world for the chocolate bar table, which has already become a tradition at the summit. :chocolate_bar:</p>
<p><span class="image-center">
<img src="/img/posts/gsoc-meetup-chocolate.jpg" alt="chocolate table" class="image-2" />
<img src="/img/posts/gsoc-meetup-we.jpg" alt="David and Ana in San Francisco" class="image-2" />
</span></p>
<p>The summit follows the <a href="https://en.wikipedia.org/wiki/Unconference">unconference</a> format, which means that the sessions are decided and organized by the attendees. Those are the most outstanding sessions from the ones David and I attended:</p>
<h3 id="lightning-talks">Lightning talks</h3>
<p>There were about 2 hours reserved for 3 minutes lightning talks, in which around 50 different organization presented their students’ work. The only rule was that the part about the organization itself couldn’t be longer than 1 minute (ideally 30 seconds). We liked the original idea of clapping when the 3 minutes were over to avoid that the speaker continue speaking - we should steal it for the <a href="https://events.opensuse.org/conference/oSC18/program/proposal/1693">Lightningbeers</a> in the next openSUSE conference :wink:</p>
<p>There were a lot of great talks about successful histories. I especially liked the ones where the students themselves presented their work in a video. I gave a talk focused on the feedback we gave to all our students, including rejected and unsubmitted proposals, and how we try to bring those students in our community and encourage them to keep contributing. I was not sure if the talk was appropriated, taking into account that the rest of the talks were about the students’ projects. But many people come to me after the talk to say they liked it a lot and got some ideas for next year, so it seems it was. :smile:</p>
<p>You can find the slides of all the given lightning talks (including mines) in this <a href="https://drive.google.com/drive/folders/1KiwUfAJQnO6d0QGPCD2bEXqkLiczquhb">Google Drive folder</a>.</p>
<h3 id="gsod">GSoD</h3>
<p>Google is considering starting a new mentoring program: Google Season of Docs, the “GSoC for Documentation”. It was discussed whether mentoring orgs would be interested in a program of this kind and Google asked for feedback on the idea.</p>
<p>Apart from the fact that the program would be focused on documentation and not on code, there are other important differences. The participants would be experience technical writers (>1 year experience) and not students. As it is expected that the participants already have a full time job, the commitment would be less (~10 hours a week). Because of the same reason, the technical writers wouldn’t receive any stipend, as the students do. According to the Google team, it would be the experience they would gain though GSoD and not the money which would motivate them to participate. This was the most unclear and longest discussed part.</p>
<h3 id="recruiting-motivating-and-retaining-mentors-to-your-org">Recruiting, motivating and retaining mentors to your org</h3>
<p>I found this a very appealing session, as the number of mentors in openSUSE has decreased this year to the point that we considered not to participate in GSoC due to the lack of mentors/projects. (Maybe someone reading this wants to get involved next year? - Just write me an email, comment in this blog post or check <a href="https://101.opensuse.org">openSUSE mentoring page</a>!)</p>
<p>The session was driven by Martin from Jenkins, and it was a enriching conversation between different orgs, which presented their problems, solutions and asked questions.It was curious how similar the difficulties of openSUSE and Fedora are (although not surprisingly because of the similarities of the two projects). Both communities are big and diverse, but they do not manage to get a lot of mentors involved in GSoC. Some people gave us some ideas, such as introducing non-technical mentors and having at least 2 mentors per project, but I still don’t have the feeling we found the magic solution. :sweat:</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/178lgZaIKBBSDOud0lqFBjLH-eURxWyTTn8NyDuLNPD4">Google document</a>.</p>
<h3 id="patch-rewards">Patch Rewards</h3>
<p>Aleksandr Dobkin, from Google, gave a talk about the <a href="https://www.google.com/about/appsecurity/patch-rewards/">Patch Reward Program</a>, which rewards proactive security improvements in several open source projects like Chromium and Angular. Rewards for qualifying submissions range from from 500$ to 20000$, depending on the complexity and impact of the patch. In the future, they want to expand the list of in-scope projects and define specifics tasks and bounties for them.</p>
<h3 id="life-after-gsoc">Life after GSoC</h3>
<p>The Googlers Cat and Josh led this session, in which we did some brainstorming and listen to other organizations’ experiences. David found interesting that most of the attendees agreed that responsibilities need to be given to the students in order to keep them motivated and engaged with the project.</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/19sZSEYW9g8twXTiS4X5juOrptYli102DSDEs6aZtr00/edit">Google document</a>.</p>
<h3 id="open-source-licensing">Open Source Licensing</h3>
<p>This session was supposed to be hold by the Googler Hilary Richardson, but she arrived late and it ended being a shared session with the Software Freedom Conservancy. It was an introduction to licenses, but although I had expected it to be more advance, there was some topics (some of which came up thanks to audience questions) which I didn’t know about and which I found interesting. For example, that you shouldn’t use the WTFPL (Do What the Fuck You Want To Public License) as it doesn’t include no-warranty disclaimer.</p>
<h3 id="spanish-mentors-meet-up">Spanish mentors meet-up</h3>
<p>There was a meet-up of GSoC Spanish mentors and as both David and I are from Spain, we couldn’t miss it. We presented our projects, spoke about things we are doing to spread open source in Spain, such as talks at universities, and discussed what else could be done. We set a mailing list up to keep sharing ideas, material, etc.</p>
<h3 id="gsoc-feedback">GSoC Feedback</h3>
<p>Google open source team organized a session where the mentors and org admin could give them feedback about things that could be improved. I suggested something that openSUSE Asian community suggested to me in the last openSUSE.Asia: creating a poster which summarize the reasons to become a GSoC mentor and that should ideally include some visual reinforcement (like an infographic). It should catch people attention so that non-native speakers get interested enough to read the extensive documentation. (BTW, there are two videos from Google in that direction: <a href="https://youtu.be/L4JNz6zWzLs">Organizations Apply</a> and <a href="https://youtu.be/3J_eBuYxcyg">Being a Great Google Summer of Code Mentor</a>). I also suggested that it is clarified in the GSoC documentation that mentors and org admins are volunteers, as we had cases were students were unpolite or impatient and I think it was because they don’t know the conditions in which the mentors are helping them.</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/1aFJSzRUhTOCkV_Y44C044HzJ5PyHSilqfPNgKeYJsS4">Google document</a>.</p>
<h3 id="beyond-gsoc-how-can-google-help-open-source">Beyond GSoC: how can Google help open source?</h3>
<p>Google wanted to know what else they can do for open source. Most of the requests were related to founding and cloud credits. I used the opportunity to ask for a plain text option in the Gmail Android client which allows me to write to this mailing list with my phone (I know there are other clients…) and to mention the poster again when other people requested help from Google to recruit mentors.</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/1UptDgbd29QAo7pc8mxrHOSrosv6B_Cq1hN453QTImYg">Google document</a>.</p>
<h3 id="improving-mentormentee-relations">Improving mentor/mentee relations</h3>
<p>This session was about how to improve the relationships between mentors and mentees, potentiating engagement after GSoC. Most of the attendees were org admins and they gave us some tips to help mentees to get involved in the community and also to improve the communication with his mentor. Some of the concrete suggestions were:</p>
<ul>
<li>Make everything public (conversation with the mentor, doubts, discussion, etc.) using the IRC channel.</li>
<li>Have regular meetings, at least 1 per week.</li>
<li>Set availability time box of the mentor/mentee.</li>
<li>Encourage to ask first to the community.</li>
</ul>
<h3 id="open-source-metrics">Open Source Metrics</h3>
<p>It was a really cool session by CHAOSS and Google about measuring all data we can and how to turn the numbers into something useful. For instance, it was interesting the discussion about how to measure the open source culture in a project: how many people say thank you, time to answer, PRs and issues closed, etc. I also liked some of the original examples presented by Felipe Hoffa (Developer Advocate at Google) such as using number of page visits vs StackOverflow questions. I recommend to check the <a href="https://github.com/fhoffa/analyzing_github">fhoffa/analyzing_github</a> repository.</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/1oSMyq7sdOir_1pb1AywclPtOsgqQAjmapjVaSa3Bo7Q">Google document</a>.</p>
<h3 id="post-mortem-why-a-student-fail-hear-from-an-student-and-org-admin">Post-mortem: why a student fail? Hear from an student and org admin</h3>
<p>Emmanuel from Public Lab told us about his experience when he was a GSoC student and why he succeeded the first year and why not in the second year. The difference was that he had a good guidance: his mentor was very accessible and close to him. The second time, the communication was bad: he didn’t receive any warning about doing something wrong and his mentor wasn’t there for him when he needs him. After all, he ended being a successful GSoC mentor.</p>
<h3 id="failing-students">Failing students</h3>
<p>It was a conversation trying to answer questions like:
Why and how fail a student?
How do you protect the future reputation of the student?
What to do when the problem is the mentor?</p>
<p>We spoke about problems with really difficult solution and it was inspiring to hear other people approaches and ideas. Something that I found useful for us was the fact that some orgs are enforcing having 3 mentors per project. I think it is a good recommendation as it can save a lot of troubles from the admins perspective, it is good for the student and more fun for the mentors. However, I think we should enforce 2 mentors, but not 3. If the mentors think it is doable with 2 mentors, we should trust them. It would anyway be difficult to get 3 mentors for some of the project. Another great idea is that, in case the mentors disappear by any reason and you don’t know where to get more mentors from, write the GSoC mailing list. There are a lot of people working in diverse projects and someone may be able to help.</p>
<p>Notes of the session can be found in this <a href="https://docs.google.com/document/d/1dogr1PqMefpmRRTycwLVbp_gzlnKBwnx3oHSksFolHg">Google document</a>.</p>
<h3 id="quality-of-the-software-when-should-we-release">Quality of the software, when should we release?</h3>
<p>This session was held by people from MuseScore, who wanted to discuss when a product is good enough to release. One of procedures that David founded interesting two approaches mentioned to release:</p>
<ul>
<li>Time box: having a LTS version (~ 1 year) and a monthly one. The monthly one includes the most recent changes although the bugs are also backported to the LTS version. (Tumbleweed vs Leap :stuck_out_tongue_winking_eye:)</li>
<li>Feature based</li>
</ul>
<h3 id="burnout">Burnout</h3>
<p>In this session, conducted by Valorie from KDE, we discussed how to identify a burnout in others and in ourselves and what to do when it happens (in general and in the GSoC context). Burnout is severe and we need to help our colleagues/mentors if we realise of it (signs: stressed, angry, grumpy, territorial, drowsy) and to step out when it happens to us (if it is important someone else will do it).</p>
<h1 id="suggestions-for-next-year">Suggestions for next year</h1>
<p>All in all, those are my suggestions for next GSoC (they come from diverse places: the sessions, conversations with other people, etc.), in case openSUSE participates again (I hope so :wink:):</p>
<ul>
<li>Make a call for mentors sharing the video and other material from Google</li>
<li>Make compulsory to have at least two mentors per project. It is more fun and secure (in case the mentor disappear for any reason, the organization need to look for another mentor)</li>
<li>For projects too specialized or which require concrete knowledge, ask for a third person who could help with the mentoring in case something happens (just as backup and not being compulsory).</li>
<li>Make compulsory that the students blog posts have a CC license (preferably CC-BY)</li>
<li>Encourage collaboration between students and mentors in the same org, for example doing video conference with several students working in similar projects.</li>
<li>Ask the mentors to complete evaluations 24 before the evaluation closes. This way the admins can complete the evaluation in the last day if the mentors haven’t done it.</li>
</ul>
<p>Hope you have enjoyed reading the report. Remember that if you want to mentor next year in GSoC, you are more than welcome! Just write me an email, comment in this blog post or check <a href="https://101.opensuse.org">openSUSE mentoring page</a>.</p>
<h1 id="about-me">About me</h1>
<p>My name is Ana and I am mentor and organization admin for openSUSE at GSoC, openSUSE Board member, Open Build Service Frontend Engineer at SUSE and open source contributor in projects inside and outside openSUSE.</p>David Kang and I attended two weeks ago (12-14 Oct) the Google Summer of Code (GSoC) Mentor Summit in California representing openSUSE. :sunny: Here is our report of the conference.openSUSE.Asia Summit2018-09-05T00:00:00+02:002018-09-05T00:00:00+02:00http://anamaria.martinezgomez.name/2018/09/05/opensuse-asia-summit<p>openSUSE.Asia Summit is an annual conference organized since 2014 every time in a different Asian city. Although it is a really successful event, which plays a really important role in spreading openSUSE all around the world, it is not an event everybody in openSUSE knows about. Because of that I would like to tell you about my experience attending the last openSUSE.Asia Summit, which took place on August 10-12 in Taipei, Taiwan.</p>
<p><span class="image-center">
<img src="/img/posts/asia2018-openSUSE-community.jpg" alt="openSUSE.Asia Summit 2018 group picture" />
</span></p>
<p><small class="image-center">
Picture by <a href="https://www.flickr.com/photos/coscup" target="_blank">COSCUP</a> under <a href="https://creativecommons.org/licenses/by-sa/2.0" target="_blank">CC BY-SA</a> from <a href="https://flic.kr/p/2ay7hBD">https://flic.kr/p/2ay7hBD</a>
</small></p>
<h1 id="opensuseasia-summit-2018">openSUSE.Asia Summit 2018</h1>
<p>This year, openSUSE.Asia was co-hosted with COSCUP, a major open source conference held annually in Taiwan since 2006, and GNOME.Asia. It was an incredible good organized conference with a really involved community and a lot of volunteers.</p>
<h2 id="community-day">Community day</h2>
<p>On August 11, we had the openSUSE community day at the SUSE office. We had lunch together and those who like beer (not me :stuck_out_tongue_winking_eye:) could try the openSUSE taiwanese beer. We also had some nice conversations. I especially liked the proposals during the discussion with the Board session to get both more students and mentors involved in the mentoring in Asia and to solve the translations problems. In the evening, we joined the COSCUP and GNOME community for the welcome party.</p>
<h2 id="talks">Talks</h2>
<p>On Saturday and Sunday was when the conference itself took place. Specially the first day it was really crowded (with 1400 people registered! :scream:) Both days and from early in the morning, there were several talks simultaneously, some of them in Chinese, about a wide range of FOSS topics. Appart from the opening and closing, I gave a talk about mentoring and how I started in open source. I am really happy that in the room there were a lot of young people, many of them not involved (yet) in openSUSE. I hope I managed to inspire some of them! :wink: In fact the conference was full of inspiring talks, remarkably:</p>
<ul>
<li>
<p>The keynote by Audrey Tang, Taiwan’s Digital Minister, full of quotes to reflect on: <em>When we see internet of things, let’s make it an internet of beings.</em></p>
</li>
<li>
<p><em>We are openSUSE.Asia</em> emotive talk by Sunny from Beijing, in which she explained how her desire to spread open source in Asia took her to organise the first openSUSE.Asia Summit.</p>
</li>
<li>
<p><em>“The bright future of SUSE and openSUSE”</em> by Ralf Flaxa, SUSE’s president of engineering, which surprised me because of being really different to other of his talks I have attended.</p>
</li>
<li>
<p>Simon motivating talk about his experience in open source, packaging and the board activities.</p>
</li>
</ul>
<p><span class="image-center">
<img src="/img/posts/asia2018-ana-speaking.jpg" alt="Ana enthusiastically speaking" class="image-2" />
<img src="/img/posts/asia2018-audience.jpg" alt="Conference audience" class="image-2" />
</span></p>
<p><small class="image-center">
Pictures by <a href="https://www.flickr.com/photos/coscup" target="_blank">COSCUP</a> under <a href="https://creativecommons.org/licenses/by-sa/2.0" target="_blank">CC BY-SA</a> from <a href="https://flic.kr/p/29sJhHq">https://flic.kr/p/29sJhHq</a> and <a href="https://flic.kr/p/LPGjaF">https://flic.kr/p/LPGjaF</a> respectively
</small></p>
<p>Apart from the talks, we had the BoF sessions on Saturday evening, in which we could get together surrounded by A LOT of pizza. In the session, there was a presentation of the two proposals for next year openSUSE.Asia Summit: India, with a really well prepared proposal, and Indonesia, whose team organized the biggest openSUSE.Asia Summit in 2016. There was also the exchange of the openSUSE Asia photo album, preserving the tradition that every organizing team should add some more pages to this album. It is getting heavy! :muscle:</p>
<p><span class="image-center">
<img src="/img/posts/asia2018-photo-album.jpg" alt="Photo album exchange" />
</span></p>
<h2 id="one-day-tour">One day tour</h2>
<p>The conference ended with another tradition, the one day tour for speaker and organizers. We went to the National Palace Museum, to the Taipei 101 tower and to eat dumplings and other typical food. It was a great opportunity to get together in a different and fun environment.</p>
<h1 id="see-you-next-year">See you next year</h1>
<p>As you see, we had a lot of fun at openSUSE.Asia Summit 2018. From a more personal point of view, I enjoyed a lot meeting our Chinese mentors I normally write emails to. I had also the chance to meet some members of the GNOME board, exchange with them experiences, problems and solutions, and discuss ways in which both communities can keep collaborating in the future. The conference was full of fun moments like seeing a pyramid of pizza (and a hundred of people making pictures to it) and being amused by someone wearing a Geeko costume with 35 degrees and 70% humidity. :hotsprings:</p>
<p><span class="image-center">
<img src="/img/posts/asia2018-geeko.jpg" alt="Geeko in front of fan" class="image-2" />
<img src="/img/posts/asia2018-pizza.jpg" alt="People taking pictures to pizza" class="image-2" />
</span></p>
<p><small class="image-center">
Geeko’s picture by <a href="https://www.flickr.com/photos/coscup" target="_blank">COSCUP</a> under <a href="https://creativecommons.org/licenses/by-sa/2.0" target="_blank">CC BY-SA</a> from <a href="https://flic.kr/p/2atN6KE">https://flic.kr/p/2atN6KE</a>
</small></p>
<p>To finish, this is what attendees said to liked the most about the conference in the closing session:</p>
<p><span class="image-center">
<img src="/img/posts/asia2018-words-cloud.png" alt="Words cloud" />
</span></p>
<p>See you next year!</p>
<h1 id="about-me">About me</h1>
<p>My name is Ana and I am mentor and organization admin for openSUSE at GSoC, openSUSE Board member, Open Build Service Frontend Engineer at SUSE and open source contributor in projects inside and outside openSUSE.</p>openSUSE.Asia Summit is an annual conference organized since 2014 every time in a different Asian city. Although it is a really successful event, which plays a really important role in spreading openSUSE all around the world, it is not an event everybody in openSUSE knows about. Because of that I would like to tell you about my experience attending the last openSUSE.Asia Summit, which took place on August 10-12 in Taipei, Taiwan.GSoC Half Way Throug2018-07-21T00:00:00+02:002018-07-21T00:00:00+02:00http://anamaria.martinezgomez.name/2018/07/21/gsoc-half-way-through<p>As you may already know, <a href="/2018/02/15/gsoc-in-indonesia.html">openSUSE participates again in GSoC</a>, an international program that awards stipends to university students who contribute to real-world open source projects during three months in summer. <a href="/2018/05/23/gsoc-students-are-already-hacking.html">Our students started working already</a> two months ago. Ankush, Liana and Matheus have passed the two evaluations successfully and they are busy hacking to finish their projects. Go on reading to find out what they have to say about their experience, their projects and the missing work for the few more weeks. :grinning:</p>
<h2 id="ankush-malik">Ankush Malik</h2>
<p>Ankush is improving people collaboration in the <a href="https://github.com/SUSE/Hackweek" target="_blank">Hackweek tool</a> and he has already made many great contributions like the emoticons, similar project section and notifications features. In fact, the <a href="https://hackweek.suse.com/17/projects" target="_blank">Hackweek 17</a> was just last week, so in the last days a lot of people have already been using these great new features. There were a lot of good comments about his work! :cupid: and we also received a lot of feedback, as you can for example see in the <a href="https://github.com/SUSE/hackweek/issues?utf8=%E2%9C%93&q=is%3Aissue" target="_blank">issues list</a>.</p>
<p>But even more important than all the functionality, is all Ankush is learning while coding and working with his mentors and the openSUSE community, such as working with AJAX in Ruby on Rails, good coding practices and better coding style.</p>
<p>The last part of his project will include some more new features. If you want to find out more about his project and the challenges that Ankush expects to have, read his interesting blog post: <a href="https://medium.com/@ankushmalik631/how-my-gsoc-project-is-going-4942614132a2">https://medium.com/@ankushmalik631/how-my-gsoc-project-is-going-4942614132a2</a></p>
<p><span class="image-center">
<img src="/img/posts/gsoc-hackweek.png" style="max-width: 600px" />
</span></p>
<h2 id="xu-liana">Xu Liana</h2>
<p>Liana is working on integrating Cloud Pinyin (the most popular input method in China) on ibus-libpinyin. For her, GSoC is being an enjoyable learning process full of challenges. With the help of her mentors she has learnt about autotools and she builds now her code without graphical build tools :muscle: For the few more weeks, she plans to learn about algorithmics that are useful for the project and, after finish the coding part, she would like to go deeper in the fundamentals of compiling. Read it from her owns word in her blog post: <a href="https://liana.hillwoodhome.net/2018/07/14/the-first-half-of-the-project-during-gsoc-libpinyin">https://liana.hillwoodhome.net/2018/07/14/the-first-half-of-the-project-during-gsoc-libpinyin</a></p>
<h2 id="matheus-de-sousa-bernardo">Matheus de Sousa Bernardo</h2>
<p>Matheus is working in <a href="https://github.com/openSUSE/trollolo" target="_blank">Trollolo</a>, a cli-tool which helps teams using Trello to organize their work. He has been mainly focused on the restructuring of commands and the incomplete backup feature. The discussion with his mentors made him take different implementation paths than the ones he had in mind at the beginning, learning the importance of keeping things simple. It has been complicated for Matheus to find time for both the GSoC project and his university duties. But he still has some more weeks to implement the more challenging feature, the automation of Trollolo! :boom:</p>
<p>Check his blog post with more details about the project: <a href="https://matheussbernardo.me/gsoc/2018/07/08/midterm">https://matheussbernardo.me/gsoc/2018/07/08/midterm</a></p>
<p><br /></p>
<p>I hope you enjoyed reading about the work and experiences of the openSUSE students and mentors. Keep tuned as there are still some more hacking weeks and the students will write a last blog post summarizing their GSoC experience. :wink:</p>As you may already know, openSUSE participates again in GSoC, an international program that awards stipends to university students who contribute to real-world open source projects during three months in summer. Our students started working already two months ago. Ankush, Liana and Matheus have passed the two evaluations successfully and they are busy hacking to finish their projects. Go on reading to find out what they have to say about their experience, their projects and the missing work for the few more weeks. :grinning:GSoC students are already hacking!2018-05-23T00:00:00+02:002018-05-23T00:00:00+02:00http://anamaria.martinezgomez.name/2018/05/23/gsoc-students-are-already-hacking<p>We always enjoy that new people join openSUSE community and help them in their first steps. Because of that, <a href="/2018/02/15/gsoc-in-indonesia.html">openSUSE participates again in GSoC</a>, an international program in which stipends are awarded to students who hack on open source projects during the summer. We are really excited to announce that this year four students will learn about open source development while hacking on openSUSE projects. The coding period started last week, so our students are already busy hacking and they have written some nice articles about their projects. :blush:</p>
<p><span class="image-center">
<img src="/img/posts/gsoc-opensuse.jpg" />
</span></p>
<h2 id="matheus-de-sousa-bernardo">Matheus de Sousa Bernardo</h2>
<p>Matheus is a Software Engineering student in the University of Brasília. He will be working in <a href="https://github.com/openSUSE/trollolo" target="_blank">Trollolo</a>, together with his mentors <a href="/">Ana Martínez</a> (me :stuck_out_tongue_winking_eye:) and <a href="http://blog.cornelius-schumacher.de/" target="_blank">Cornelius Schumacher</a>. Trollolo is a cli-tool which helps teams using Trello to organize their work. Matheus’ project includes improving Trollolo’s API and workflow. If you want to know more about him and his project, check his beginning blog post: <a href="https://matheussbernardo.me/gsoc/2018/04/24/hello-internet-gsoc">https://matheussbernardo.me/gsoc/2018/04/24/hello-internet-gsoc</a></p>
<h2 id="xu-liana">Xu Liana</h2>
<p>Xu is a Software Engineering student in the Chongqing Normal University, China. She will work, together with her mentors <a href="https://github.com/qiangzhao" target="_blank">ZhaoQiang</a>, <a href="https://github.com/epico" target="_blank">epico</a> and <a href="https://github.com/hillwoodroc" target="_blank">Hillwood Yang</a>, in integrating Cloud Pinyin (the most popular input method in China) on ibus-libpinyin. Check her beginning blog post with more details about her and the project: <a href="https://liana.hillwoodhome.net/2018/05/20/the-blog-for-the-first-week-during-gsoc-libpinyin-project-coding">https://liana.hillwoodhome.net/2018/05/20/the-blog-for-the-first-week-during-gsoc-libpinyin-project-coding</a></p>
<h2 id="ankush-malik">Ankush Malik</h2>
<p>Ankush is pursuing a Bachelor of Technology in Computer Science in the Maharaja Agrasen Institute of Technology, India. He will be working on improving people collaboration in the <a href="https://github.com/SUSE/Hackweek" target="_blank">Hackweek tool</a>, together with his mentors <a href="https://github.com/davidkang" target="_blank">David Kang</a> and <a href="https://github.com/differentreality" target="_blank">Stella Rouzi</a>. He just released his GSoC Journey blog post which you can find here: <a href="https://medium.com/@ankushmalik631/my-gsoc-journey-4f02818fdb8d">https://medium.com/@ankushmalik631/my-gsoc-journey-4f02818fdb8d</a></p>
<h2 id="asad-syed">Asad Syed</h2>
<p>Asad is from Pakistan and is studying a Masters degree in Informatics at the Technical University of Munich, Germany. He will develop a container-based backend for <a href="https://github.com/os-autoinst" target="_blank">openQA</a> with the help of his mentors <a href="https://github.com/foursixnine" target="_blank">Santiago Zarate</a>, <a href="https://github.com/mudler" target="_blank">Ettore Di Giacinto</a> and <a href="https://github.com/coolo" target="_blank">Stephan Kulow</a>. Read here about his experiences with openSUSE and past participations in Google Summer of Code: <a href="https://medium.com/asadpiz/google-summer-of-code-2018-with-opensuse-part-1-9f514ac2e7ae">https://medium.com/asadpiz/google-summer-of-code-2018-with-opensuse-part-1-9f514ac2e7ae</a></p>
<p>As you see, there is a lot of great work coming in from our new talented contributors. Stay tuned because they will keep blogging about their GSoC experience! :wink:</p>We always enjoy that new people join openSUSE community and help them in their first steps. Because of that, openSUSE participates again in GSoC, an international program in which stipends are awarded to students who hack on open source projects during the summer. We are really excited to announce that this year four students will learn about open source development while hacking on openSUSE projects. The coding period started last week, so our students are already busy hacking and they have written some nice articles about their projects. :blush:Running for openSUSE Board2018-03-19T00:00:00+01:002018-03-19T00:00:00+01:00http://anamaria.martinezgomez.name/2018/03/19/opensuse-board<p>Hi! I am running as <a href="https://en.opensuse.org/openSUSE:Board_election" target="_blank">openSUSE Board member</a> and I would like to let you know more about me, my view of what openSUSE is and why I want to be in the Board. :raised_hands:</p>
<h3 id="about-myself">About myself</h3>
<p>I’m Ana María Martínez, 24 years old, from Madrid, Spain and living in Nuremberg, Germany. I studied Computer Science Engineering and Mathematics in Madrid. During my last year at university, I started in open source development contributing to a local open government project. At the end of my university studies (2016), I participated in Google Summer of Code (GSoC) as a student for openSUSE. I fell in love with the open source development and the openSUSE community. Because of that, after GSoC, I moved to Nuremberg to work as a Software Engineer at SUSE in the Open Build Service frontend team.</p>
<p>I’m currently writing a lot of Ruby code. As I can not avoid taking a look to every code that crosses my path, apart from my work at SUSE, I contribute to several open source projects inside and outside openSUSE. In some cases becoming active contributor, or even maintainer, for some of them. Some people say I am addicted to <a href="https://github.com/Ana06" target="_blank">GitHub</a>! :wink: In openSUSE, I maintain projects like <a href="https://github.com/openSUSE/open-build-service" target="_blank">Open Build Service</a> (<a href="https://build.opensuse.org" target="_blank">build.opensuse.org</a>), <a href="https://github.com/openSUSE/osem" target="_blank">OSEM</a> (<a href="https://events.opensuse.org" target="_blank">events.opensuse.org</a>), <a href="https://github.com/openSUSE/trollolo" target="_blank">Trollolo</a>, <a href="https://github.com/openSUSE/mentoring" target="_blank">mentoring</a> (<a href="http://101.opensuse.org" target="_blank">101.opensuse.org</a>) and <a href="https://github.com/openSUSE/software-o-o" target="_blank">software-o-o</a> (<a href="https://software.opensuse.org" target="_blank">software.opensuse.org</a>). Outside openSUSE, I have recently contributed to <a href="https://github.com/jekyll/jekyll" target="_blank">Jekyll</a>, the <a href="https://github.com/ruby/ruby" target="_blank">Ruby core</a>, <a href="https://github.com/bbatsov/rubocop" target="_blank">Rubocop</a>, <a href="https://github.com/rantly-rb/rantly" target="_blank">Rantly</a>, etc.</p>
<p>What I like the most of openSUSE and working in open source is that it is fun, I learn a lot and I have the chance to work with a lot of talented people interested in the same things as me all around the world. I think it is really important that everybody who is interested can join openSUSE development and community. Because of that I help newcomers to open source, for example by participating as a mentor and organization admin in GSoC for openSUSE.</p>
<p>I have also happily spoken at openSUSE events (openSUSE conference, openSUSE.Asia Summit) about topics like mentoring and Open Build Service and I try to contribute to make those events as fun as possible.</p>
<p>You will find me in <a href="https://github.com/Ana06" target="_blank">Github</a>, IRC and some other places as @Ana06. You can contact me in Twitter as well (<a href="https://twitter.com/anamma_06" target="_blank">@anamma_06</a>).</p>
<h3 id="goals-and-values">Goals and values</h3>
<p>I have heard from previous Board members that the board needs to become more approachable and improve communication. I also think this is important and that there is still room for improvement in this regard.
In addition, I find really important that the board works as transparent as possible, so that every openSUSE member is aware of the things that are done and the decisions that are made and how they are made. In openSUSE we like to say that those who does, decide. And I also think that those who does, should be as informed as possible.
I consider really important as well that openSUSE contributors are valued and have fun, and we should promote this fun spirit from the board.
Last but not least, I think we have to improve as a community on encouraging new people to join us, keeping always fun and advertising openSUSE as much and spread as possible.</p>
<h3 id="why-should-you-vote-for-me">Why should you vote for me?</h3>
<p>I think it is important that there are openSUSE developers in the board and openSUSE developer is a term that defines myself quite well. :joy:
Most of the candidates to the board will probably mention here that they are using openSUSE since more than a decade. This is not something I can say. I am using openSUSE distribution and contributing to openSUSE since less than 2 years. Without forgetting that there are people in openSUSE that know much more than me, that I need to hear and learn from, I think that my point of view can be really valuable for the board. I bring new ideas and energy and a great desire to learn and improve things.
And of course the reason why you should vote me is because you share my ideas and concept of what openSUSE is and the things that need to be improved.</p>Hi! I am running as openSUSE Board member and I would like to let you know more about me, my view of what openSUSE is and why I want to be in the Board. :raised_hands:Students from Indonesia, openSUSE participates in GSoC!2018-02-15T00:00:00+01:002018-02-15T00:00:00+01:00http://anamaria.martinezgomez.name/2018/02/15/gsoc-in-indonesia<p><a href="https://www.opensuse.org" target="_blank">openSUSE</a> participates again in <a href="https://summerofcode.withgoogle.com" target="_blank">Google Summer of Code</a> (GSoC), a program that awards stipends to university students who contribute to real-world open source projects during three months in summer. :sunny: With this article, I will provide my experience as a former GSoC student and mentor, give you more details about the program and try to encourage Indonesian students to get involved in openSUSE development through GSoC.</p>
<h3 id="why-open-source-and-opensuse">Why open source and openSUSE?</h3>
<p>First of all, you may wonder why you should want to get involved in open source development. Everybody has their own reasons, but for me there are three main ones:</p>
<ul>
<li><strong>I have fun:</strong> The most important reason is that it is fun. At openSUSE, we have great conferences, geekos everywhere, geeko cookies,… and the most important part: we have fun when working!</li>
<li><strong>I learn a lot:</strong> In most of the projects, every single line of code is reviewed. That means not only that the code quality is better, but also that every time you write something wrong or that can be improved, someone will tell you. In open source, we think that making mistakes is perfectly fine. That people correct you is the best way to learn.</li>
<li><strong>People:</strong> I have the chance to work with really skilled people all around the world, who are interested in the same things as me.</li>
</ul>
<p><span class="image-center">
<img src="/img/posts/gsoc-in-indonesia-cookies.jpg" class="image-2" />
<img src="/img/posts/gsoc-in-indonesia-geeko.jpg" class="image-2" />
</span></p>
<h3 id="why-gsoc">Why GSoC?</h3>
<p>Starting is always difficult, but you don’t have to do it alone! In openSUSE, you will always find people to help you, and with GSoC this is even easier. The best feature of the program is that you will always have at least one mentor (most likely two) who will lead you through it. In addition, you will work in a project used in real word by many users and all your code will be released under an open source license, so everybody can access, use, change and share it. Last, you will receive a stipend, 2400 dollars in Indonesia.</p>
<h3 id="projects">Projects</h3>
<p>At openSUSE, you can find projects written in <a href="http://rubyonrails.org" target="_blank">Ruby on Rails</a>, <a href="https://www.perl.org" target="_blank">Perl</a>, <a href="https://www.ruby-lang.org/en" target="_blank">Ruby</a>, <a href="https://www.w3schools.com/html/html_scripts.asp" target="_blank">HTML/JavaScript</a>, <a href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank">C/C++</a> and much more. This year you can work during GSoC in some of the most central and biggest projects in openSUSE: <a href="https://github.com/openSUSE/open-build-service" target="_blank">OpenBuildService</a>, <a href="https://github.com/os-autoinst/openQA" target="_blank">openQA</a> and <a href="https://github.com/yast" target="_blank">YaST</a>. They will for sure be challenging projects to work in, but don’t get scared, as that means that you will learn a lot from it too. And remember that your mentors and other openSUSE contributors will be there to help you!</p>
<p>But we also have simpler projects such as <a href="https://github.com/openSUSE/trollolo" target="_blank">Trollolo</a>, where any computer science university student could get started with Ruby. The desire to learn is much more important than the previous experience and knowledge.</p>
<p>You can find all the projects and more information in our mentoring page: <strong><a href="http://101.opensuse.org" target="_blank">http://101.opensuse.org</a></strong>. And if the projects at openSUSE doesn’t match your expectations, you can check other organizations: <a href="https://summerofcode.withgoogle.com/organizations" target="_blank">https://summerofcode.withgoogle.com/organizations</a>. You should look for a project that you consider interesting and that will allow you to learn as much as possible.</p>
<h3 id="lets-do-it">Let’s do it!</h3>
<p>When I travelled to <a href="https://events.opensuse.org/conference/summitasia17" target="_blank">openSUSE Asia</a> in October, I had the chance to speak with some members of the Indonesian community and I found out that we have a huge community of openSUSE users in Indonesia. And a big part of this community are university students of Computer Science. However, those students don’t get involved in the development of openSUSE. I also heard many times during the conference that students in Indonesia and in Asia in general are shy and that they find the open source development scary. I hope that with this blog post I can achieve that Indonesian students lose their fear and encourage them to get involved in openSUSE development.</p>
<p>The GSoC application period starts on March 12th, but you can already take a look at the organizations and projects and find the best one for you. Approaching the people in the project is also important, as you will be working with them for three months. We recommend to make at least one contribution to the project you want to apply for as that will help you to find out if this is the right project for you and to write a good proposal, but you do not need to send a lot of pull requests.</p>
<p>And if you have doubts do not hesitate to contact us. You can tweet us at <a href="https://twitter.com/@opensusementors" target="_blank">@opensusementors</a>, write in our mailing list (<a href="mailto:opensuse-project@opensuse.org">opensuse-project@opensuse.org</a>) or directly contact the mentors. We are looking forward to hear from you, so don’t be shy! :green_heart:</p>
<p><span class="image-center">
<img src="/img/posts/gsoc-in-indonesia-meetup.jpg" alt="GSoC meetup at openSUSE conference 2016" />
</span></p>
<h3 id="about-me">About me</h3>
<p>My name is <a href="/">Ana María Martínez</a> and I started with openSUSE as a GSoC student. Since then I keep contributing in open source projects inside and outside openSUSE. I am currently working at SUSE in the <a href="http://openbuildservice.org" target="_blank">Open Build Service</a> Frontend Team and I am a mentor for openSUSE at GSoC. You can find me in Github(<a href="https://github.com/Ana06" target="_blank">@Ana06</a>) and contact me by <a href="">email</a>, Twitter (<a href="https://twitter.com/anamma_06" target="_blank">@anamma_06</a>), IRC (@Ana06) and by writting a comment in this blog post. :wink:</p>openSUSE participates again in Google Summer of Code (GSoC), a program that awards stipends to university students who contribute to real-world open source projects during three months in summer. :sunny: With this article, I will provide my experience as a former GSoC student and mentor, give you more details about the program and try to encourage Indonesian students to get involved in openSUSE development through GSoC.Why nobody speaks about dig2018-01-07T00:00:00+01:002018-01-07T00:00:00+01:00http://anamaria.martinezgomez.name/2018/01/07/ruby-dig<p>It is already 2 years since Ruby 2.3 was released. While the controversial <code class="language-plaintext highlighter-rouge">&.</code>, which is claimed to allow writing incomprehensible code, has become really popular in blog post and conferences, we have heard very little about the <code class="language-plaintext highlighter-rouge">Hash#dig</code> and <code class="language-plaintext highlighter-rouge">Array#dig</code> methods. Those methods were mentioned together in the <a href="https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released" target="_blank">release notes</a>, as both try to make easier dealing with <code class="language-plaintext highlighter-rouge">nil</code> values. But why is then the <code class="language-plaintext highlighter-rouge">dig</code> method not that “popular”? Can we after two years say something new about it? And the most important part, should we start using it, if we haven’t use it until now? :thinking:</p>
<h3 id="what-is-it">What is it?</h3>
<p>First things, first, what the method does? It is normal in Ruby that we have nested fields in hashes, for example in Rails parameters, and that we need to ensure that a parameter exits before navigating to the next one. Normally we would do something like:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:address</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:address</span><span class="p">][</span><span class="ss">:street</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:address</span><span class="p">][</span><span class="ss">:street</span><span class="p">][</span><span class="ss">:number</span><span class="p">]</span>
</code></pre></div></div>
<p>We have to admit that is not very elegant. But with the new <code class="language-plaintext highlighter-rouge">Hash#dig</code> we can just write:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span><span class="p">.</span><span class="nf">dig</span><span class="p">(</span><span class="ss">:user</span><span class="p">,</span> <span class="ss">:address</span><span class="p">,</span> <span class="ss">:street</span><span class="p">,</span> <span class="ss">:number</span><span class="p">)</span>
</code></pre></div></div>
<p>So, as the <a href="http://ruby-doc.org/core-2.3.0_preview1/Hash.html#method-i-dig" target="_blank">Ruby documentation</a> says it retrieves the value object corresponding to the each key objects repeatedly. And similarly for the <code class="language-plaintext highlighter-rouge">Array#dig</code> method. We would write <code class="language-plaintext highlighter-rouge">array.dig(0, 1, 1)</code> instead of <code class="language-plaintext highlighter-rouge">array[0][1][1]</code>.</p>
<h3 id="what-else-can-we-say">What else can we say?</h3>
<p>The first thing I wondered is if they are really equivalent to what we previously had. For example:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">"user"</span><span class="p">:</span> <span class="p">{</span> <span class="ss">name: </span><span class="s2">"Nicolas Cage"</span><span class="p">,</span> <span class="ss">married: </span><span class="kp">false</span> <span class="p">}</span> <span class="p">}</span>
<span class="o">=></span> <span class="p">{</span><span class="ss">:user</span><span class="o">=></span><span class="p">{</span><span class="ss">:name</span><span class="o">=></span><span class="s2">"Nicolas Cage"</span><span class="p">,</span> <span class="ss">:married</span><span class="o">=></span><span class="kp">false</span><span class="p">}}</span>
<span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:married</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:married</span><span class="p">][</span><span class="ss">:date</span><span class="p">]</span>
<span class="o">=></span> <span class="kp">false</span>
<span class="n">params</span><span class="p">.</span><span class="nf">dig</span><span class="p">(</span><span class="ss">:user</span><span class="p">,</span> <span class="ss">:married</span><span class="p">,</span> <span class="ss">:date</span><span class="p">)</span>
<span class="o">=></span> <span class="no">TypeError</span><span class="p">:</span> <span class="no">FalseClass</span> <span class="n">does</span> <span class="n">not</span> <span class="n">have</span> <span class="c1">#dig method</span>
<span class="n">from</span> <span class="p">(</span><span class="n">irb</span><span class="p">):</span><span class="mi">6</span><span class="ss">:in</span> <span class="sb">`dig'
from (irb):6
from /usr/bin/irb.ruby2.4:11:in `</span><span class="o"><</span><span class="n">main</span><span class="o">></span><span class="err">'</span>
</code></pre></div></div>
<p>You can see in this example, that our new method raised an exception, when our code used to work. But I would say that the fact that this work for the old case is unexpected and can cause that we miss bugs in our code. We wanted to return the date of the marriage, and we hadn’t go so far in the nested hash but we have got a result anyway. But it is even worse, because the first option could also raise an exception for a similar case while <code class="language-plaintext highlighter-rouge">Hash#dig</code> keeps the same behaviour:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">"user"</span><span class="p">:</span> <span class="p">{</span> <span class="ss">name: </span><span class="s2">"Nicolas Cage"</span><span class="p">,</span> <span class="ss">married: </span><span class="kp">true</span> <span class="p">}</span> <span class="p">}</span>
<span class="o">=></span> <span class="p">{</span><span class="ss">:user</span><span class="o">=></span><span class="p">{</span><span class="ss">:name</span><span class="o">=></span><span class="s2">"Nicolas Cage"</span><span class="p">,</span> <span class="ss">:married</span><span class="o">=></span><span class="kp">true</span><span class="p">}}</span>
<span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:married</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="ss">:user</span><span class="p">][</span><span class="ss">:married</span><span class="p">][</span><span class="ss">:date</span><span class="p">]</span>
<span class="o">=></span> <span class="no">NoMethodError</span><span class="p">:</span> <span class="n">undefined</span> <span class="nb">method</span> <span class="sb">`[]' for true:TrueClass
from (irb):9
from /usr/bin/irb.ruby2.4:11:in `</span><span class="o"><</span><span class="n">main</span><span class="o">></span><span class="s1">'
params.dig(:user, :married, :date)
=> TypeError: TrueClass does not have #dig method
from (irb):10:in `dig'</span>
<span class="n">from</span> <span class="p">(</span><span class="n">irb</span><span class="p">):</span><span class="mi">10</span>
<span class="n">from</span> <span class="sr">/usr/</span><span class="n">bin</span><span class="o">/</span><span class="n">irb</span><span class="p">.</span><span class="nf">ruby2</span><span class="o">.</span><span class="mi">4</span><span class="p">:</span><span class="mi">11</span><span class="ss">:in</span> <span class="sb">`<main>'
</span></code></pre></div></div>
<p>And we can even find more strange cases. The method <code class="language-plaintext highlighter-rouge">str[match_str]</code> allow us to find curious examples when using strings as key, such as:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">"user"</span> <span class="o">=></span> <span class="s2">"Nicolas Cage"</span> <span class="p">}</span> <span class="o">=></span> <span class="p">{</span><span class="s2">"user"</span><span class="o">=></span><span class="s2">"Nicolas Cage"</span><span class="p">}</span>
<span class="n">params</span><span class="p">.</span><span class="nf">dig</span><span class="p">(</span><span class="s2">"user"</span><span class="p">,</span><span class="s2">"age"</span><span class="p">)</span> <span class="o">=></span> <span class="no">TypeError</span><span class="p">:</span> <span class="no">String</span> <span class="n">does</span> <span class="n">not</span> <span class="n">have</span> <span class="c1">#dig method</span>
<span class="n">params</span><span class="p">[</span><span class="s2">"user"</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="s2">"user"</span><span class="p">][</span><span class="s2">"age"</span><span class="p">]</span> <span class="o">=></span> <span class="s2">"age"</span>
</code></pre></div></div>
<p>and the same happens when using integers as key:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span><span class="p">.</span><span class="nf">dig</span><span class="p">(</span><span class="s2">"user"</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="o">=></span> <span class="no">TypeError</span><span class="p">:</span> <span class="no">String</span> <span class="n">does</span> <span class="n">not</span> <span class="n">have</span> <span class="c1">#dig method</span>
<span class="n">params</span><span class="p">[</span><span class="s2">"user"</span><span class="p">]</span> <span class="o">&&</span> <span class="n">params</span><span class="p">[</span><span class="s2">"user"</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=></span> <span class="s2">"i"</span>
</code></pre></div></div>
<p>And arrays also suffer from this strange differences in the case of numbers:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">array</span><span class="o">=</span><span class="p">[</span><span class="s2">"hola"</span><span class="p">]</span> <span class="o">=></span> <span class="p">[</span><span class="s2">"hola"</span><span class="p">]</span>
<span class="n">array</span><span class="p">.</span><span class="nf">dig</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="o">=></span> <span class="no">TypeError</span><span class="p">:</span> <span class="no">String</span> <span class="n">does</span> <span class="n">not</span> <span class="n">have</span> <span class="c1">#dig method</span>
<span class="n">array</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&&</span> <span class="n">array</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=></span> <span class="s2">"o"</span>
</code></pre></div></div>
<p><br />
And how does <code class="language-plaintext highlighter-rouge">try</code> behave? It always returns <code class="language-plaintext highlighter-rouge">nil</code> without letting us knowing how deep in the hash it failed:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">params</span><span class="p">.</span><span class="nf">try</span><span class="p">(</span><span class="ss">:user</span><span class="p">).</span><span class="nf">try</span><span class="p">(</span><span class="ss">:married</span><span class="p">).</span><span class="nf">try</span><span class="p">(</span><span class="ss">:date</span><span class="p">)</span>
<span class="o">=></span> <span class="kp">nil</span>
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">try</code> is coherent, but take into account that it is only available in Rails.</p>
<p>This all show us that refactoring the code won’t be straightforward as this three options, some time presented as equivalent, are not exactly equivalent.</p>
<h3 id="why-is-it-not-popular">Why is it not popular?</h3>
<p>As we have seen, this new methods can be really useful. But why are they then not popular?</p>
<p>The first reason is the one we have already elaborated in, it is not equivalent to what we had before, which implies that things could start failing if we refactor old code.</p>
<p>Another problem can be the lack of the documentation, what we can see illustrated in the following Stack Overflow post: <a href="https://stackoverflow.com/questions/34346653/how-do-i-use-arraydig-and-hashdig-introduced-in-ruby-2-3" target="_blank">How do I use <code class="language-plaintext highlighter-rouge">Array#dig</code> and <code class="language-plaintext highlighter-rouge">Hash#dig</code> introduced in Ruby 2.3?</a> :joy: And to be honest even the <a href="https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released" target="_blank">release notes</a> seem to be confusing to me. What is meant by “<em><code class="language-plaintext highlighter-rouge">Array#dig</code> and <code class="language-plaintext highlighter-rouge">Hash#dig</code> are also added. Note that this behaves like <code class="language-plaintext highlighter-rouge">try!</code> of Active Support, which specially handles only nil.</em>”?</p>
<p>And another good reason that can cause that this method has been unnoticed, is what I already mentioned at the beginning, that the controversial <code class="language-plaintext highlighter-rouge">&.</code> has made that almost nobody has noticed this beautiful method. And this just because we as humans tend to put more emphasis on complains.</p>
<h3 id="conclusion">Conclusion</h3>
<p>It seems that the <code class="language-plaintext highlighter-rouge">Hash#dig</code> and <code class="language-plaintext highlighter-rouge">Array#dig</code> methods can make our lives easier and help us to detect errors. The best way to increase their use and to ensure we use them when possible in our projects is to create a <a href="https://github.com/bbatsov/rubocop" target="_blank">Rubocop</a> cop which supports autocorrection. :grimacing: I already opened an <a href="https://github.com/bbatsov/rubocop/issues/5332" target="_blank">issue</a> for it, but the fact that both implementations are not equivalent makes that the autocorrection or even the implementation of the cop are not possible. However, it seems that this was already implemented in <a href="https://github.com/salsify/salsify_rubocop/blob/master/lib/rubocop/cop/salsify/style_dig.rb" target="_blank">salsify_rubocop</a>. In this gem, <a href="https://github.com/bbatsov/rubocop" target="_blank">Rubocop</a> is extended with a new <code class="language-plaintext highlighter-rouge">Dig</code> cop. This cop enforces <code class="language-plaintext highlighter-rouge">my_hash.dig('foo', 'bar')</code> over <code class="language-plaintext highlighter-rouge">my_hash['foo']['bar']</code> and <code class="language-plaintext highlighter-rouge">my_hash['foo'] && my_hash['foo']['bar']</code>. It also support autocorrection.</p>
<p>Last but not least, I would like to share another blog post about <code class="language-plaintext highlighter-rouge">Hash#dig</code>, which discusses diferent topics to the ones here, such as the efficiency of <code class="language-plaintext highlighter-rouge">Hash#dig</code>: <a href="https://www.tiagoamaro.com.br/2016/08/27/ruby-2-3-dig" target="_blank">Ruby 2.3 dig Method - Thoughts and Examples</a>.</p>
<p>And that was all. Start taking profit of the already old <code class="language-plaintext highlighter-rouge">Hash#dig</code> and <code class="language-plaintext highlighter-rouge">Array#dig</code> methods and it may be that soon they become as popular as they deserve! :wink:</p>It is already 2 years since Ruby 2.3 was released. While the controversial &., which is claimed to allow writing incomprehensible code, has become really popular in blog post and conferences, we have heard very little about the Hash#dig and Array#dig methods. Those methods were mentioned together in the release notes, as both try to make easier dealing with nil values. But why is then the dig method not that “popular”? Can we after two years say something new about it? And the most important part, should we start using it, if we haven’t use it until now? :thinking:A failing test for Christmas2018-01-01T00:00:00+01:002018-01-01T00:00:00+01:00http://anamaria.martinezgomez.name/2018/01/01/christmas-failure<p>It seems I have really well behaved on 2017, because Santa Claus brought me a failing test for Christmas. :stuck_out_tongue_winking_eye: I found out a piece of code, that was only wrong from 26th to 31st December. :christmas_tree:</p>
<h3 id="the-code">The code</h3>
<p>Imagine you want to write a Ruby method for a Rails project, where you want to get all the users of the database that have birthday today or in the next 6 days, given that the birth date is stored in the database for all users. How would you do it?</p>
<p>As for the birthday you don’t care of the year of the dates, you could just replace the users’ birth years by the current one and check if they are in the range you want. So, the code I found looked something like:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">next_birthdays_1</span><span class="p">(</span><span class="n">number_days</span><span class="p">)</span>
<span class="n">today</span> <span class="o">=</span> <span class="no">Date</span><span class="p">.</span><span class="nf">current</span>
<span class="no">User</span><span class="p">.</span><span class="nf">select</span> <span class="k">do</span> <span class="o">|</span><span class="n">user</span><span class="o">|</span>
<span class="p">(</span><span class="n">today</span><span class="o">..</span><span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span><span class="p">).</span><span class="nf">cover?</span><span class="p">(</span><span class="n">user</span><span class="p">.</span><span class="nf">birthday</span><span class="p">.</span><span class="nf">change</span><span class="p">(</span><span class="ss">year: </span><span class="n">today</span><span class="p">.</span><span class="nf">year</span><span class="p">))</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>This code seemed to work. There was even a test for it and it passed. But on 26th December, the new year coming broke the test, showing that the code was wrong. For example, if a user was born on <code class="language-plaintext highlighter-rouge">01/01/1960</code>, the range <code class="language-plaintext highlighter-rouge">26/12/2017</code> to <code class="language-plaintext highlighter-rouge">01/01/2018</code> doesn’t cover <code class="language-plaintext highlighter-rouge">01/01/2017</code>.</p>
<p>Let’s fix the code! :muscle:</p>
<p>We can stop trying to be too smart and just testing if the day and month of the users birth dates match any of the dates in the range:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">next_birthdays_2</span><span class="p">(</span><span class="n">number_days</span><span class="p">)</span>
<span class="n">today</span> <span class="o">=</span> <span class="no">Date</span><span class="p">.</span><span class="nf">current</span>
<span class="nb">select</span> <span class="k">do</span> <span class="o">|</span><span class="n">user</span><span class="o">|</span>
<span class="p">(</span><span class="n">today</span><span class="o">..</span><span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span><span class="p">).</span><span class="nf">any?</span> <span class="k">do</span> <span class="o">|</span><span class="n">date</span><span class="o">|</span>
<span class="n">user</span><span class="p">.</span><span class="nf">birthday</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%d%m'</span><span class="p">)</span> <span class="o">==</span> <span class="n">date</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%d%m'</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>This code works and it works the whole year. :rofl: But what happens if now we want to get the birthdays of the next 30 days and we have for example 30000 users. Would this code be efficient enough? Can we do it better? :thinking:</p>
<p>One thing I come up with was reusing the original idea, that we do not care about the year, but using two dates instead. So to know if a user was born in <code class="language-plaintext highlighter-rouge">01/01/1960</code>, the range <code class="language-plaintext highlighter-rouge">26/12/2017</code> to <code class="language-plaintext highlighter-rouge">01/01/2018</code> should cover <code class="language-plaintext highlighter-rouge">01/01/2017</code> or <code class="language-plaintext highlighter-rouge">01/01/2018</code>. As for both dates, the birthday is the same one. So, we can write this as follows:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">next_birthdays_3</span><span class="p">(</span><span class="n">number_days</span><span class="p">)</span>
<span class="n">today</span> <span class="o">=</span> <span class="no">Date</span><span class="p">.</span><span class="nf">current</span>
<span class="no">User</span><span class="p">.</span><span class="nf">select</span> <span class="k">do</span> <span class="o">|</span><span class="n">user</span><span class="o">|</span>
<span class="p">(</span><span class="n">today</span><span class="o">..</span><span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span><span class="p">).</span><span class="nf">cover?</span><span class="p">(</span><span class="n">user</span><span class="p">.</span><span class="nf">birthday</span><span class="p">.</span><span class="nf">change</span><span class="p">(</span><span class="ss">year: </span><span class="n">today</span><span class="p">.</span><span class="nf">year</span><span class="p">))</span> <span class="o">||</span>
<span class="p">(</span><span class="n">today</span><span class="o">..</span><span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span><span class="p">).</span><span class="nf">cover?</span><span class="p">(</span><span class="n">user</span><span class="p">.</span><span class="nf">birthday</span><span class="p">.</span><span class="nf">change</span><span class="p">(</span><span class="ss">year: </span><span class="p">(</span><span class="n">today</span><span class="p">.</span><span class="nf">year</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)))</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>But <strong>this method is wrong, as it has a problem which also had the first one</strong>. What happens if the user was born the 29th February of a leap year? <code class="language-plaintext highlighter-rouge">birthday.change(year: 2017)</code> would fail, as 2017 was not a leap year and 29th February of 2017 doesn’t exist. :see_no_evil: But we can do a smart trick to keep using the same idea: using string comparison without taking into account the leap years! :smile: It would look like:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">next_birthdays_4</span><span class="p">(</span><span class="n">number_days</span><span class="p">)</span>
<span class="n">today</span> <span class="o">=</span> <span class="no">Date</span><span class="p">.</span><span class="nf">current</span>
<span class="n">today_str</span> <span class="o">=</span> <span class="n">today</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%Y%m%d'</span><span class="p">)</span>
<span class="n">limit</span> <span class="o">=</span> <span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span>
<span class="n">limit_str</span> <span class="o">=</span> <span class="n">limit</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%Y%m%d'</span><span class="p">)</span>
<span class="no">User</span><span class="p">.</span><span class="nf">select</span> <span class="k">do</span> <span class="o">|</span><span class="n">user</span><span class="o">|</span>
<span class="n">birthday_str</span> <span class="o">=</span> <span class="n">user</span><span class="p">.</span><span class="nf">birthday</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%m%d'</span><span class="p">)</span>
<span class="n">birthday_today_year</span> <span class="o">=</span> <span class="s2">"</span><span class="si">#{</span><span class="n">today</span><span class="p">.</span><span class="nf">year</span><span class="si">}#{</span><span class="n">birthday_str</span><span class="si">}</span><span class="s2">"</span>
<span class="n">birthday_limit_year</span> <span class="o">=</span> <span class="s2">"</span><span class="si">#{</span><span class="n">limit</span><span class="p">.</span><span class="nf">year</span><span class="si">}#{</span><span class="n">birthday_str</span><span class="si">}</span><span class="s2">"</span>
<span class="n">birthday_today_year</span><span class="p">.</span><span class="nf">between?</span><span class="p">(</span><span class="n">today_str</span><span class="p">,</span> <span class="n">limit_str</span><span class="p">)</span> <span class="o">||</span> <span class="n">birthday_limit_year</span><span class="p">.</span><span class="nf">between?</span><span class="p">(</span><span class="n">today_str</span><span class="p">,</span> <span class="n">limit_str</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>Note that this method is not equivalent to <code class="language-plaintext highlighter-rouge">next_birthdays_2</code>, as it returns the users that have birthday in 29th February if the range includes this date even if it is not a leap year. But I would say this is an advantage, as we do not want that the people who were born on 29th February do not have birthday party some years. :wink:</p>
<p>But remember that this is a Rails project, so we can do it even better if we reuse this idea to build an SQL query! :tada: For example, for <a href="https://www.postgresql.org" target="_blank">PostgreSQL</a> 9.4:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">next_birthdays_5</span><span class="p">(</span><span class="n">number_days</span><span class="p">)</span>
<span class="n">today</span> <span class="o">=</span> <span class="no">Date</span><span class="p">.</span><span class="nf">current</span>
<span class="n">today_str</span> <span class="o">=</span> <span class="n">today</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%Y%m%d'</span><span class="p">)</span>
<span class="n">limit</span> <span class="o">=</span> <span class="n">today</span> <span class="o">+</span> <span class="n">number_days</span><span class="p">.</span><span class="nf">days</span>
<span class="n">limit_str</span> <span class="o">=</span> <span class="n">limit</span><span class="p">.</span><span class="nf">strftime</span><span class="p">(</span><span class="s1">'%Y%m%d'</span><span class="p">)</span>
<span class="no">User</span><span class="p">.</span><span class="nf">where</span><span class="p">(</span>
<span class="s2">"(('</span><span class="si">#{</span><span class="n">today</span><span class="p">.</span><span class="nf">year</span><span class="si">}</span><span class="s2">' || to_char(birthday, 'MMDD')) between '</span><span class="si">#{</span><span class="n">today_str</span><span class="si">}</span><span class="s2">' and '</span><span class="si">#{</span><span class="n">limit_str</span><span class="si">}</span><span class="s2">')"</span> <span class="p">\</span>
<span class="s1">'or'</span> <span class="p">\</span>
<span class="s2">"(('</span><span class="si">#{</span><span class="n">limit</span><span class="p">.</span><span class="nf">year</span><span class="si">}</span><span class="s2">' || to_char(birthday, 'MMDD')) between '</span><span class="si">#{</span><span class="n">today_str</span><span class="si">}</span><span class="s2">' and '</span><span class="si">#{</span><span class="n">limit_str</span><span class="si">}</span><span class="s2">')"</span>
<span class="p">)</span>
<span class="k">end</span>
</code></pre></div></div>
<p>As it already happened in <code class="language-plaintext highlighter-rouge">next_birthdays_4</code>, this method returns the users that have birthday in 29th February if the range includes this date even if it is not a leap year.</p>
<p>In PostgreSQL we have the <code class="language-plaintext highlighter-rouge">Date</code> type and from PostgreSQL 9.2 also <code class="language-plaintext highlighter-rouge">daterange</code> which we could have use to make this query more efficient. This would have been equivalent to <code class="language-plaintext highlighter-rouge">next_birthdays_3</code> and would have had the same problem, it fails with leap years.</p>
<h3 id="efficiency">Efficiency</h3>
<p>And now it is time to try it! Let check how efficient are the methods number 2, 4 and 5 (as the the other two doesn’t work properly as we had already analysed).</p>
<p>I have created 30000 users with different birth dates using <a href="https://github.com/stympy/faker" target="_blank">Faker</a>. I have executed the different methods to know the number of people with birthday in the next 31 days and I have measured the execution time using <code class="language-plaintext highlighter-rouge">Benchmark.measured</code>. Those are elapsed real times for every of the method in my computer:</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">next_birthdays_2(30)</code> ~ <strong>3.3 seconds</strong></li>
<li><code class="language-plaintext highlighter-rouge">next_birthdays_4(30)</code> ~ <strong>0.9 seconds</strong></li>
<li><code class="language-plaintext highlighter-rouge">next_birthdays_5(30)</code> ~ <strong>0.0003 seconds</strong></li>
</ul>
<p>Take into account that <code class="language-plaintext highlighter-rouge">next_birthdays_2</code> is much more affected by the number of days than the other two methods. But even for 6 days it is really slow, as the elapsed real time in my computer for <code class="language-plaintext highlighter-rouge">next_birthdays_2(6)</code> is arround <strong>1.45 seconds</strong>.</p>
<h3 id="conclusion">Conclusion</h3>
<p>And the funny thing of all this is that, as it is already 2018, even if I haven’t fixed the test yet, the Christmas failing test doesn’t fail anymore. :joy: This is because we forgot to add test cases for the limit cases and help us to learn that when working with dates we have to pay special attention to the changes of year and to the 29th of February and the leap years. And of course all this should be properly tested.</p>
<p>Another thing we can learn from the post is that as Rails developers we should never forget that the database queries are always way more efficient than the Ruby code we write.</p>
<p>Last but not least, we may consider if the effort to write a method worths the time you need to invest to write it. For example, in this case we could have considered if we could have lived with a method which returns the birthdays this month, which is much easier to implement, instead of this more complicate option. Or, if we do not expect that out application has a lot of users, we could have even used <code class="language-plaintext highlighter-rouge">next_birthdays_2</code>.</p>
<p>And if you want to take a look at the original code which inspired this post, you can find it in the following PR: <a href="https://github.com/openSUSE/agile-team-dashboard/pull/100" target="_blank">https://github.com/openSUSE/agile-team-dashboard/pull/100</a></p>
<p>Happy new year! :christmas_tree: :champagne:</p>It seems I have really well behaved on 2017, because Santa Claus brought me a failing test for Christmas. :stuck_out_tongue_winking_eye: I found out a piece of code, that was only wrong from 26th to 31st December. :christmas_tree: