<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://psychoslave.github.io//feed.xml" rel="self" type="application/atom+xml" /><link href="https://psychoslave.github.io//" rel="alternate" type="text/html" /><updated>2022-06-28T15:16:16+00:00</updated><id>https://psychoslave.github.io//feed.xml</id><title type="html">Phrenorrhea: the weblog of psychoslave</title><subtitle>&quot;Warning: reading can lead to permanent alteration of your mind. Texts on this site come without warranty of any kind, readers accept full responsability of literacy experiment. I hope it might induce some sense of joy though.&quot;</subtitle><entry><title type="html">Exploring algorithmic: swap and bubble sort</title><link href="https://psychoslave.github.io//2022/06/28/bubble.html" rel="alternate" type="text/html" title="Exploring algorithmic: swap and bubble sort" /><published>2022-06-28T15:15:49+00:00</published><updated>2022-06-28T15:15:49+00:00</updated><id>https://psychoslave.github.io//2022/06/28/bubble</id><content type="html" xml:base="https://psychoslave.github.io//2022/06/28/bubble.html">&lt;h1 id=&quot;some-general-context&quot;&gt;Some general context&lt;/h1&gt;

&lt;p&gt;It’s been a while since my two initial posts, and although I progressed on some
other side projects at satisfying pace, I didn’t dedicated the time I wanted
to allocate for this project.&lt;/p&gt;

&lt;p&gt;Well, in the mean time I also became father a second time, so I had other
priorities, and anyway I try to make my attention less scattered on too many
things in parallel. So maybe once I have finished one or two of my current
projects, I’ll have more time to dedicate to writting blog posts.&lt;/p&gt;

&lt;p&gt;One thing I fully finished since my last post was to read &lt;a href=&quot;https://learning.oreilly.com/library/view/polished-ruby-programming/9781801072724/&quot;&gt;Polished Ruby Programming&lt;/a&gt;
by Jeremy Evans. It gave me a deeper knowledge of Ruby echosystem, and filled
me with ideas to create more modular gems. I didn’t have time to apply much
of what I lernt in it so far however. I will surely try to integrate some of
these insights in &lt;a href=&quot;https://github.com/psychoslave/englishest&quot;&gt;Englishest&lt;/a&gt; at some point, but I first want to
focus on delievering a first major version which
&lt;a href=&quot;https://github.com/psychoslave/englishest/issues/2&quot;&gt;provides verbal alias for each ideographic method identifier&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;inspiration-of-this-post&quot;&gt;Inspiration of this post&lt;/h1&gt;

&lt;p&gt;But as I’m determined to keep progress through learning material, I started to
read &lt;a href=&quot;https://learning.oreilly.com/library/view/40-algorithms-every/9781789801217/&quot;&gt;40 Algorithms Every Programmer Should Know&lt;/a&gt; by Imran Ahmad. The book
use Python to provide implementation examples. Altough Python is fine, I clearly
still prefer Ruby. So this gives me a great opportunity to make practical
exercises and implement these algorithm using Ruby.&lt;/p&gt;

&lt;p&gt;The initial material recall basics of algorithmic analysis, especially the
way you can quantify the worst case scenario of an algorithm to evaluate its
performance, and the famous associated big-o notation. It also cover the basic
data structure one can use to implement algorithms, focused on Python, such as
list, tuple, dictionary and sets, as well as some already more advanced such as
DataFrame and Matrix, Vector, Stack, Queue and Tree. The book also provides
complexity of various basic operations on these structures such as time to
access, insert and remove an element in each case. We won’t cover these details
here, although that might be a topic for a later post.&lt;/p&gt;

&lt;p&gt;The first actual algorithm presented in the book is the classical Bubble
Sort.  As the book recall, its worst-case performance is quadratic,
also refered as O(N²), which makes it a poor choice for any production
software, but perfect for didactic purposes. The implementation of Imran
Ahmad is repoduced below with its kind permission.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BubbleSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Exchange the elements to arrange in order
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;lastElementIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;passNo&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lastElementIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;passNo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Of course, neither in Python nor in Ruby you would need to really implement
such a basic algorithm, as they both come natively with a far more efficient
implementation of this operation. In the case of Ruby, there are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array#sort&lt;/code&gt;
and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enumerable#sort&lt;/code&gt;, as well as the more flexible &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#sort_by&lt;/code&gt; flavor, all
coming with their inplace modifying versions suffixed with a bang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Without further ado, here is an alternative self-made implementation in Ruby:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Array&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;swap!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;bubble_sort!&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;downto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;upto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;next&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;next&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;swap!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That’s it, but there is actually a lot of details about this implementation,
 and how it differs from the one proposed by Imran Ahmad.&lt;/p&gt;

&lt;p&gt;First, this implementation use the so called Monkey Patching facility that Ruby
offers, that is it extends directly the Array class to add methods that will
achieve intended goal, and allows later expression like
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[2, 1, 5].bubble_sort!&lt;/code&gt;.
Most object oriented programming langages in constrast come with closed classes:
you can’t modify them on the fly like this. This open class design of course
should be used sparingly in production code, otherwise overweight classes and
identifier collisions with hard to track side effects could easily arise. They
are well known methods to mitigate these issues without losing the benefit of
expressivity, and we shall explore them later on.&lt;/p&gt;

&lt;p&gt;The next thing we can focus on is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!&lt;/code&gt; method. The retained method name
is classical, and probably don’t require much more comment. Wiktionary provides
the following definition: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;To exchange or give (something) in an exchange
(for something else)&lt;/code&gt;, which match perfectly want we intend indeed. Most
implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap&lt;/code&gt; function out there seems to use parameters with dummy
identfiers, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a, b&lt;/code&gt;&lt;sup id=&quot;fnref:cppswap&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:cppswap&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x, y&lt;/code&gt;&lt;sup id=&quot;fnref:cswap&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:cswap&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;, or at best some numbered
couple of a more or less meaningful term like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pos1, pos2&lt;/code&gt;&lt;sup id=&quot;fnref:pyswap&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:pyswap&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; or even
some without any cryptic apocope like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index1, index2&lt;/code&gt;&lt;sup id=&quot;fnref:javaswap&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:javaswap&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;. Those used
in this implementation come out of a more personal approach to use identfiers
with names which are ideally:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;usual English terms, without apocopes&lt;/li&gt;
  &lt;li&gt;meaningful in context&lt;/li&gt;
  &lt;li&gt;terse as long as it doesn’t conflict with previous requirement&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last point on terseness is a bit more weighted in my attention when these
terms are included within a line which include many terms, like the single one
defined in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spot&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;slot&lt;/code&gt; are usual English terms with a locative semantic. The
morpohlogical proximity is more fortuitous, altough they might be etymologically
related just like &lt;em&gt;splot&lt;/em&gt; and &lt;em&gt;splotch&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Regarding the famous unique line of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!&lt;/code&gt; it uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Kernel#tap&lt;/code&gt; to return
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; after due changes, without having to explicitely express it on a second
line. Indeed, an equivalent method body would be:&lt;/p&gt;
&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or even more verbosely using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return self&lt;/code&gt; for the last line. The solution
however doesn’t opt for maximizing brevity, and avoid the shorter but more
cryptic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tap{ _1[spot], _1[slot] = _1[slot], _1[spot] }&lt;/code&gt;, which uses the
&lt;a href=&quot;https://bugs.ruby-lang.org/issues/4475&quot;&gt;implicit numbered arguments introduced in Ruby 2.7&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Moving on, we finally get to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#bubble_sort!&lt;/code&gt; method definition. As the
context provide directly access to the aimed main variable, it doesn’t take any
parameter. This is in contrast with a more bare functional approach where each
parameter is provided explicitely. For exemple in Python, even using an object
oriented implementation, one would write something like
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;def bubble_sort(self):&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In contrast Ruby bind &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; implicitely for you, and even let you call most
methods on self while completely omiting this term. That’s how the first line
can start directly with a call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size&lt;/code&gt;, rather than the more circumlocutory
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self.size&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This first line is somehow dense, so we are going to chunck it, but note that
once you have all the implied acquaintances, all this is really
straightforwardly expressed.&lt;/p&gt;

&lt;p&gt;Basically the goal of this line is to generate a list of index for the last
&lt;em&gt;spot&lt;/em&gt; that will be considered in each pass. In the first pass, the last spot
is the penultimate element in the array, the last one being the &lt;em&gt;slot&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So, since Ruby array indexes start at 0, if we have an Array with 10 elements,
the last &lt;em&gt;spot&lt;/em&gt; of the first pass will have index 8, that is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size-2&lt;/code&gt;, the
last &lt;em&gt;slot&lt;/em&gt; will have index 9. Of course, the algorithm will first analyse if
a swap is required for elements with index 0 and it’s subsequent, and so on
until 8 included for this first circuit round. The next tour will go up to 7,
then 6, and so on until all laps where roamed.&lt;/p&gt;

&lt;p&gt;The first line start with rather unusual way to call the minus operator, that is
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size.-(2)&lt;/code&gt;. This allows to chain directly with a call to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Integer#downto&lt;/code&gt;
method. An other way to do that would be to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#pred&lt;/code&gt; twice: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size.pred.pred̀ .
Using latest development version of Englishest, it would be possible to express
it as &lt;/code&gt;size.minus(2)&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; or &lt;/code&gt;size.mow(2)` which would have my preference, but here
I wanted to stay on bare Ruby facilities. All the more it gives the opportunity
to recall how in Ruby operators are mostly regular methods which are given some
syntactic sugar privileges allowing them to be called in a different manner than
through the usual &lt;a href=&quot;https://www.britannica.com/science/linguistics/Tagmemics&quot;&gt;tagememic&lt;/a&gt; &lt;a href=&quot;https://cs.stackexchange.com/questions/89031/what-is-the-origin-of-dot-notation&quot;&gt;dot notation&lt;/a&gt; which act as a
&lt;a href=&quot;https://en.wikipedia.org/wiki/Syncategorematic_term&quot;&gt;syncategorema&lt;/a&gt;, also called &lt;a href=&quot;https://doi.org/10.3406/hel.2003.2210&quot;&gt;syncategoremata&lt;/a&gt;.
Of course you don’t need to understand any of this abstruse linguistic matter to
happily hack with this kind of stuff, but surely it might have a nice effect if
throwed at the appropriate audience. Don’t use them at your next familly dinner
though. 🤣&lt;/p&gt;

&lt;p&gt;The code might be a bit clearer with a named variable assigned, as
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;penultimate_index = size - 2&lt;/code&gt;, so that the first loop would look like
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;penultimate_index.downto(1).each…&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With that in mind, the first line of this implementation is hopefully crystal
clear: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;size.-(2)&lt;/code&gt; compute the index of the last spot, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;downto(1)&lt;/code&gt; generate
an Enumerator that start with this integer and counts down to 1. Those elements
are taken as cap of new enumerators starting from 0. Thus the inner loop will
be given the current spot to consider upfront, and the slot is simply the
following integer. The loop can jump to the next iteration if no swap is
required on the current pair, otherwise the swap is done. Note that in this
implementation, we fully take advantage of Ruby flexible syntax, inherited from
Perl, and put the condition &lt;em&gt;after&lt;/em&gt; the instruction to execute. This can
arguable sometime lead to code whose flow is harder to track, but when the
instruction is a flow control command, this result in a code that stick better
to how you might reason about the code, rather than how the machine instruction
set constraints your thought flow. This consideration partly explain why I chose
to put the condition on a separate line rather than using something like
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!(spot, slot) if self[spot] &amp;gt; self[slot]&lt;/code&gt;. We could also replace the three
lines of the inner loop with a single one like
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_1&amp;gt;(_=_1+1) &amp;amp;&amp;amp; swap!(_1,_)&lt;/code&gt; if we would like to be especially cryptic.
&lt;!-- --&gt;_&lt;/p&gt;

&lt;p&gt;Finally, once all loops where traversed, the method return the array
instance for conviniency: this allow to chain method in a fluent way. The
same result could be achieved using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tap&lt;/code&gt; as in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!&lt;/code&gt;, however this
would add one more block level depth that was judged undesirable here.&lt;/p&gt;

&lt;h1 id=&quot;the-bangless-version&quot;&gt;The bangless version&lt;/h1&gt;

&lt;p&gt;As you might have notice, so far we provided only methods with a bang, that
denotes &lt;em&gt;some danger&lt;/em&gt; in Ruby, like inplace modification of an instance. But
this is not a consistent garanty: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array#push&lt;/code&gt; will change the instance object
even it doesn’t have a bang suffix.
And as &lt;a href=&quot;https://stackoverflow.com/questions/25293302/why-do-some-ruby-methods-need-a-bang-and-others-dont-to-be-a-destructive-method&quot;&gt;Nick McCurdy famously report it&lt;/a&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActiveRecord::Base#save!&lt;/code&gt; is a
version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActiveRecord::Base#save&lt;/code&gt; that performs validations… and
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; is only needed when there is a more dangerous version of a method that already
exists, and this does not necessarily mean that the dangerous method edits in place.&lt;/p&gt;

&lt;p&gt;So let’s have &lt;em&gt;safe&lt;/em&gt; versions for both methods &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap!&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bubble_sort!&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;The easy way to do it, is to simply apply the changes on a copied version.
There are some points that worth our attention tough:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;this will impact performance as the whole list will have to be copied first;&lt;/li&gt;
  &lt;li&gt;depending on object types in the list, a shallow copy could be insufficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Provided that we are fine with these aspects, the implementation could be as
easy as:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# within class Array&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;clone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;swap!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;bubble_sort&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;clone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;bubble_sort!&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For list of direct value like small numbers, that is enough, and for composed
values, it would ask to &lt;a href=&quot;https://stackoverflow.com/questions/8206523/how-to-create-a-deep-copy-of-an-object-in-ruby&quot;&gt;create deep copy&lt;/a&gt; whose
&lt;a href=&quot;https://stackoverflow.com/questions/5643432/whats-the-most-efficient-way-to-deep-copy-an-object-in-ruby&quot;&gt;efficient implementation&lt;/a&gt; won’t be covered here.&lt;/p&gt;

&lt;h1 id=&quot;modularization&quot;&gt;Modularization&lt;/h1&gt;

&lt;p&gt;As mentionned above, in practice you would rather avoid to directly integrate
your methods within a basic class. At the very least, you would first implement
them in a module, and extend the target class with this module like this:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Endopermutable&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;swap!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Endopermutable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With that, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array.instance_method(:swap!)&lt;/code&gt; will output a String which contains
something like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array(Endopermutable)#swap!&lt;/code&gt;, unless an other module override it
in the same manner: that makes code tracking far easier.&lt;/p&gt;

&lt;p&gt;But there is more. You don’t actually need to directly include a module into
a basic class to benefit from its features in Ruby. Of course, you might create
a subclass, like in most object oriented language and include the module in this
subclass. But there is an other option in Ruby that allows for a thinner
granularity, which is mixing in a module directly into an object instance,
so that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1,2].extend(Endopermutable).swap!(0,1)&lt;/code&gt; will work as expected while
leaving the raw Array class unchanged, avoiding any side effect this might
generate.&lt;/p&gt;

&lt;h1 id=&quot;generalizing-the-swap-method&quot;&gt;Generalizing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swap&lt;/code&gt; method&lt;/h1&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:cppswap&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;https://www.cplusplus.com/reference/algorithm/swap/ &lt;a href=&quot;#fnref:cppswap&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:cswap&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;https://www.delftstack.com/howto/c/swap-function-in-c/ &lt;a href=&quot;#fnref:cswap&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:pyswap&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;https://www.geeksforgeeks.org/python-program-to-swap-two-elements-in-a-list/ &lt;a href=&quot;#fnref:pyswap&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:javaswap&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;https://stackoverflow.com/questions/64189589/how-to-swap-two-numbers-of-index1-and-index2-in-my-array &lt;a href=&quot;#fnref:javaswap&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;</content><author><name></name></author><category term="algorithmic" /><category term="Ruby" /><summary type="html">Some general context</summary></entry><entry><title type="html">My motivation to write a blog</title><link href="https://psychoslave.github.io//2022/02/10/motivation.html" rel="alternate" type="text/html" title="My motivation to write a blog" /><published>2022-02-10T17:06:21+00:00</published><updated>2022-02-10T17:06:21+00:00</updated><id>https://psychoslave.github.io//2022/02/10/motivation</id><content type="html" xml:base="https://psychoslave.github.io//2022/02/10/motivation.html">&lt;p&gt;So as I cheated yesterday writing my first blog post a day after the “official”
publication date, and as I wasn’t able to write a second post in the same day,
I’ll just skip 2022-02-09 unlogged. Not a big lost for humankind I guess, and
this seems a better approach for &lt;a href=&quot;https://en.wikipedia.org/wiki/Cognitive_load&quot;&gt;cognitive load&lt;/a&gt;,
rather than trying to catch with every gap here and there.&lt;/p&gt;

&lt;p&gt;I think that one thing that played a motivation role into starting this blog
was simply time that pass, and will to have a more clear narative of my life,
be it for myself alone. Incidently, 8 Februabry is my birthday. As I was born
in &lt;a href=&quot;https://en.wikipedia.org/wiki/1984&quot;&gt;1984&lt;/a&gt; (yes, like the title of
&lt;a href=&quot;https://en.wikipedia.org/wiki/Nineteen_Eighty-Four&quot;&gt;the famous dystopian book of Orwell&lt;/a&gt;), that was my 13,880 circadian
cycle. I know it because I asked Ruby:&lt;/p&gt;
&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Date'&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2022&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1984&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;How neatly it makes easy computationnal tasks easier! I love it! ❤️&lt;/p&gt;

&lt;p&gt;As we are with some geekery, did you know that 1984 spells &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;11111000000&lt;/code&gt; in
binary notation? That’s 5 ones and 6 zeros. I don’t know for you, but for me
it immediately catches the will to know what are the previsous number in this
sery of n ones and n+1 zeros. And is this series already registered in the
&lt;a href=&quot;https://oeis.org/&quot;&gt;The On-Line Encyclopedia of Integer Sequences® (OEIS®)&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;So the series start like this: 100 (4), 11000 (24), 1110000 (112),
111100000 (480), 11111000000 (1984), 1111110000000 (8064)”.
Obviously, I’ll be dead by 8064. Probably no one
of this far away year will ever read this. Actually, I wonder if anyone
will read it during my lifetime? 😅
Also, by current evidences of
the life and death of calendars, by 8064 Common Era, whatever human civilization
will still roam around – if any –, it will have probably moved to another one.
By the way, you get the previous series in Ruby with,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.upto(6).map{|n| &quot;1&quot;*n + &quot;0&quot;*(n+1)}.map{|n| &quot;#{n} (#{n.to_i(2)})&quot;}.join(', ')&lt;/code&gt;.
And it is registered as &lt;a href=&quot;https://oeis.org/A059153&quot;&gt;A059153&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;13,880 is of course also an &lt;a href=&quot;https://en.wikipedia.org/wiki/Interesting_number_paradox&quot;&gt;interesting number&lt;/a&gt; about which
&lt;a href=&quot;https://math.tools/numbers/13880&quot;&gt;a lot of statements can be uttered&lt;/a&gt;. But none that catched my attention
though. 😆&lt;/p&gt;

&lt;p&gt;Back to motivation, an other thing is that a few years ago I red
&lt;a href=&quot;https://miraclemorning.com/&quot;&gt;The miracle morning&lt;/a&gt; by &lt;a href=&quot;https://en.wikipedia.org/wiki/Hal_Elrod&quot;&gt;Hal Elrod&lt;/a&gt;. From it I kept the habit
to wake up early, but didn’t fully followed the whole method, especially I never
started a diary. So far.&lt;/p&gt;

&lt;p&gt;Finally there seems to be some interest from recruiters that ask if you do have
a blog. Until know I just had nothing to drop in for this kind of demand. But
to be honnest, I was more embarrassed with the state of my Github account which
didn’t show as much as open contributions as I would like. Indeed, I spent most
of my professional career working on inhouse software building and maintenance,
which often don’t let you release much things in the wild. This is all somehow
ironic as in my spare time I’m a firm defensor of Free Libre Open Works (FLOW),
as I like to call them. So as this blog can be hosted on Github, this will make
more wild contribution, although that is still not as contributive to the
software side of things.&lt;/p&gt;

&lt;p&gt;Oh, one more thing regarding motivation.
I recently stopped, again, to use &lt;a href=&quot;https://timewarrior.net/&quot;&gt;Timewarrior&lt;/a&gt; to track everything in my life.
It was marginally useful to know where I was at some point and to who I paid
attention, how much time I had spent on some project, but in the end this wasn’t
so useful insight, at least I never got oh great WOW from looking at it.
I feel like writing prose like this one will better contribute to my personal
fulfillment than seizing tag centric chronometries, which poorly synthesis
the luxuriance of thoughts and feelings.&lt;/p&gt;</content><author><name></name></author><category term="motivation" /><category term="ruby" /><category term="arithmophilia" /><summary type="html">So as I cheated yesterday writing my first blog post a day after the “official” publication date, and as I wasn’t able to write a second post in the same day, I’ll just skip 2022-02-09 unlogged. Not a big lost for humankind I guess, and this seems a better approach for cognitive load, rather than trying to catch with every gap here and there.</summary></entry><entry><title type="html">My discovery of Jekyll and the world of writing a blog</title><link href="https://psychoslave.github.io//2022/02/08/meet-Dr-Jekyll-and-mister-psychoslave.html" rel="alternate" type="text/html" title="My discovery of Jekyll and the world of writing a blog" /><published>2022-02-08T16:46:30+00:00</published><updated>2022-02-08T16:46:30+00:00</updated><id>https://psychoslave.github.io//2022/02/08/meet-Dr-Jekyll-and-mister-psychoslave</id><content type="html" xml:base="https://psychoslave.github.io//2022/02/08/meet-Dr-Jekyll-and-mister-psychoslave.html">&lt;p&gt;So this is a first post. It’s actually more a training field for me to play
with Jekyll.&lt;/p&gt;

&lt;p&gt;I will let the orignal engine documentation bellow, it might serve me well in
the near future, and who knows, maybe others?&lt;/p&gt;

&lt;p&gt;Anyway I don’t have yet precise topics I want to discuss on my very own blog,
and to be honnest this is rather an alien practice to me. I’m more accustomed
to publish things on the form of “research project” with unpersonal tone. Like
the &lt;a href=&quot;https://fr.wikiversity.org/wiki/Recherche:Sur_l%E2%80%99extension_des_genres_grammaticaux_en_fran%C3%A7ais&quot;&gt;&lt;em&gt;Sur l’extension des genres grammaticaux en français&lt;/em&gt;&lt;/a&gt;.
Oh, yes, since French is my mother tongue it is also the one I most often write
into my prose. I might switch here and there, but since chances are good that
I write here to unleash opinions and share experiences on CS/IT stuffs, whose
vehicular language is English, I will probably mainly stick with that.&lt;/p&gt;

&lt;p&gt;So yesterday, as I’m actually writing that on the 9 February, editing the first
blog post Jekyll created for me, while making my daily &lt;a href=&quot;https://news.ycombinator.com/&quot;&gt;HN&lt;/a&gt;
watch, my eyes where catched by the entry &lt;a href=&quot;https://boris-marinov.github.io/text/&quot;&gt;Human technology: Text files&lt;/a&gt;.
In this blog post by Boris Marinov made me discover Jekyll and how easy it was
to maintain and publish a blog using my familiar dev tools. So this is it, I
can write some Markdown in my beloved Vim/Neovim and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git push&lt;/code&gt; to Github to
get there. To be honnest, it took me a bit more of perseverance, as I was sitting
at the time before an almost naked Windows box. So I had first to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;install Ruby – one of my favorite programming language anyway&lt;/li&gt;
  &lt;li&gt;setup a descent command line, with &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/wsl/about&quot;&gt;WSL2&lt;/a&gt;, &lt;a href=&quot;https://alacritty.org/&quot;&gt;Alacritty&lt;/a&gt;, &lt;a href=&quot;https://fishshell.com/&quot;&gt;Fish&lt;/a&gt;, and so on&lt;/li&gt;
  &lt;li&gt;fix an issue that prevented to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll serve&lt;/code&gt; from a git bash prompt with Ruby 3.0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyway, all in all it worked, and here we are, a few commits later, ready to
publish something.&lt;/p&gt;

&lt;h2 id=&quot;bellow-is-the-original-post-prefilled-by-jekyll&quot;&gt;Bellow is the original post, prefilled by Jekyll&lt;/h2&gt;

&lt;p&gt;You’ll find this post in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jekyll serve&lt;/code&gt;, which launches a web server and auto-regenerates your site when a file is updated.&lt;/p&gt;

&lt;p&gt;Jekyll requires blog post files to be named according to the following format:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YEAR-MONTH-DAY-title.MARKUP&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YEAR&lt;/code&gt; is a four-digit number, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MONTH&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DAY&lt;/code&gt; are both two-digit numbers, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MARKUP&lt;/code&gt; is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.&lt;/p&gt;

&lt;p&gt;Jekyll also offers powerful support for code snippets:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hi, &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Tom'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; prints 'Hi, Tom' to STDOUT.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Check out the &lt;a href=&quot;https://jekyllrb.com/docs/home&quot;&gt;Jekyll docs&lt;/a&gt; for more info on how to get the most out of Jekyll. File all bugs/feature requests at &lt;a href=&quot;https://github.com/jekyll/jekyll&quot;&gt;Jekyll’s GitHub repo&lt;/a&gt;. If you have questions, you can ask them on &lt;a href=&quot;https://talk.jekyllrb.com/&quot;&gt;Jekyll Talk&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="hack" /><summary type="html">So this is a first post. It’s actually more a training field for me to play with Jekyll.</summary></entry></feed>