💾 Archived View for foo.zone › gemfeed › atom.xml captured on 2023-04-26 at 13:00:13.
⬅️ Previous capture (2022-06-03)
-=-=-=-=-=-=-
<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <updated>2023-04-09T23:03:53+03:00</updated> <title>foo.zone feed</title> <subtitle>To be in the .zone!</subtitle> <link href="gemini://foo.zone/gemfeed/atom.xml" rel="self" /> <link href="gemini://foo.zone/" /> <id>gemini://foo.zone/</id> <entry> <title>Algorithms and Data Structures in Go - Part 1</title> <link href="gemini://foo.zone/gemfeed/2023-04-09-algorithms-and-data-structures-in-golang-part-1.gmi" /> <id>gemini://foo.zone/gemfeed/2023-04-09-algorithms-and-data-structures-in-golang-part-1.gmi</id> <updated>2023-04-09T22:31:42+03:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>This is the first blog post about my Algorithms and Data Structures in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1 style='display: inline'>Algorithms and Data Structures in Go - Part 1</h1><br /> <br /> <span class='quote'>Published at 2023-04-09T22:31:42+03:00</span><br /> <br /> <pre> ,_---~~~~~----._ _,,_,*^____ _____``*g*\"*, / __/ /' ^. / \ ^@q f [ @f | @)) | | @)) l 0 _/ \`/ \~____ / __ \_____/ \ | _l__l_ I } [______] I ] | | | | ] ~ ~ | | | | | </pre> <br /> <span>This is the first blog post about my Algorithms and Data Structures in Go series. I am not a Software Developer in my day job. In my current role, programming and scripting skills are desirable but not mandatory. I have been learning about Data Structures and Algorithms many years ago at University. I thought it would be fun to revisit/refresh my knowledge here and implement many of the algorithms in Go.</span><br /> <br /> <a class='textlink' href='./2023-04-09-algorithms-and-data-structures-in-golang-part-1.html'>2023-04-09 Algorithms and Data Structures in Go - Part 1 (You are currently reading this)</a><br /> <br /> <span>This post is about setting up some basic data structures and methods for this blog series. I promise, everything will be easy to follow in this post. It will become more interesting later in this series.</span><br /> <br /> <h2 style='display: inline'>Type constraints</h2><br /> <br /> <span>First, the package <span class='inlinecode'>ds</span> (data structures) defines the <span class='inlinecode'>types.go</span>. All examples will either operate on the <span class='inlinecode'>Integer</span> or <span class='inlinecode'>Number</span> type:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">package</font></b> ds <b><font color="#0000FF">import</font></b> <font color="#990000">(</font> <font color="#FF0000">"golang.org/x/exp/constraints"</font> <font color="#990000">)</font> <b><font color="#0000FF">type</font></b> Integer <b><font color="#0000FF">interface</font></b> <font color="#FF0000">{</font> constraints<font color="#990000">.</font>Integer <font color="#FF0000">}</font> <b><font color="#0000FF">type</font></b> Number <b><font color="#0000FF">interface</font></b> <font color="#FF0000">{</font> constraints<font color="#990000">.</font>Integer <font color="#990000">|</font> constraints<font color="#990000">.</font>Float <font color="#FF0000">}</font> </pre> <br /> <h2 style='display: inline'>ArrayList</h2><br /> <br /> <span>Next comes the <span class='inlinecode'>arraylist.go</span>, which defines the underlying data structure all the algorithms of this series will use. <span class='inlinecode'>ArrayList</span> is just a type alias of a Go array (or slice) with custom methods on it:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">package</font></b> ds <b><font color="#0000FF">import</font></b> <font color="#990000">(</font> <font color="#FF0000">"fmt"</font> <font color="#FF0000">"math/rand"</font> <font color="#FF0000">"strings"</font> <font color="#990000">)</font> <b><font color="#0000FF">type</font></b> ArrayList<font color="#990000">[</font>V Number<font color="#990000">]</font> <font color="#990000">[]</font>V <b><font color="#0000FF">func</font></b> NewArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font> <b><font color="#0000FF">return</font></b> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font> <font color="#FF0000">}</font> </pre> <br /> <span>As you can see, the code uses Go generics, which I refactored recently. Besides the default constructor (which only returns an empty <span class='inlinecode'>ArrayList</span> with a given capacity), there are also a bunch of special constructors. <span class='inlinecode'>NewRandomArrayList</span> is returning an <span class='inlinecode'>ArrayList</span> with random numbers, <span class='inlinecode'>NewAscendingArrayList</span> and <span class='inlinecode'>NewDescendingArrayList</span> are returning <span class='inlinecode'>ArrayList</span>s in either ascending or descending order. They all will be used later on for testing and benchmarking the algorithms.</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">func</font></b> NewRandomArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l<font color="#990000">,</font> max int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font> a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font> <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000"><</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font> <b><font color="#0000FF">if</font></b> max <font color="#990000">></font> <font color="#993399">0</font> <font color="#FF0000">{</font> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>rand<font color="#990000">.</font><b><font color="#000000">Intn</font></b><font color="#990000">(</font>max<font color="#990000">))</font> <b><font color="#0000FF">continue</font></b> <font color="#FF0000">}</font> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>rand<font color="#990000">.</font><b><font color="#000000">Int</font></b><font color="#990000">())</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> a <font color="#FF0000">}</font> <b><font color="#0000FF">func</font></b> NewAscendingArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font> a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font> <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000"><</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>i<font color="#990000">)</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> a <font color="#FF0000">}</font> <b><font color="#0000FF">func</font></b> NewDescendingArrayList<font color="#990000">[</font>V Number<font color="#990000">](</font>l int<font color="#990000">)</font> ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font> a <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font>ArrayList<font color="#990000">[</font>V<font color="#990000">],</font> l<font color="#990000">)</font> j <font color="#990000">:=</font> l <font color="#990000">-</font> <font color="#993399">1</font> <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000"><</font> l<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> <b><font color="#000000">V</font></b><font color="#990000">(</font>j<font color="#990000">)</font> j<font color="#990000">--</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> a <font color="#FF0000">}</font> </pre> <br /> <h2 style='display: inline'>Helper methods</h2><br /> <br /> <span>The <span class='inlinecode'>FirstN</span> method only returns the first N elements of the <span class='inlinecode'>ArrayList</span>. This is useful for printing out only parts of the data structure:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">FirstN</font></b><font color="#990000">(</font>n int<font color="#990000">)</font> <font color="#009900">string</font> <font color="#FF0000">{</font> <b><font color="#0000FF">var</font></b> sb strings<font color="#990000">.</font>Builder j <font color="#990000">:=</font> n l <font color="#990000">:=</font> <b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">)</font> <b><font color="#0000FF">if</font></b> j <font color="#990000">></font> l <font color="#FF0000">{</font> j <font color="#990000">=</font> l <font color="#FF0000">}</font> <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000"><</font> j<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#FF0000">{</font> fmt<font color="#990000">.</font><b><font color="#000000">Fprintf</font></b><font color="#990000">(&</font>sb<font color="#990000">,</font> <font color="#FF0000">"%v "</font><font color="#990000">,</font> a<font color="#990000">[</font>i<font color="#990000">])</font> <font color="#FF0000">}</font> <b><font color="#0000FF">if</font></b> j <font color="#990000"><</font> l <font color="#FF0000">{</font> fmt<font color="#990000">.</font><b><font color="#000000">Fprintf</font></b><font color="#990000">(&</font>sb<font color="#990000">,</font> <font color="#FF0000">"... "</font><font color="#990000">)</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> sb<font color="#990000">.</font><b><font color="#000000">String</font></b><font color="#990000">()</font> <font color="#FF0000">}</font> </pre> <br /> <span>The <span class='inlinecode'>Sorted</span> method checks whether the <span class='inlinecode'>ArrayList</span> is sorted. This will be used by the unit tests later on:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">Sorted</font></b><font color="#990000">()</font> <font color="#009900">bool</font> <font color="#FF0000">{</font> <b><font color="#0000FF">for</font></b> i <font color="#990000">:=</font> <b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">)</font> <font color="#990000">-</font> <font color="#993399">1</font><font color="#990000">;</font> i <font color="#990000">></font> <font color="#993399">0</font><font color="#990000">;</font> i<font color="#990000">--</font> <font color="#FF0000">{</font> <b><font color="#0000FF">if</font></b> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000"><</font> a<font color="#990000">[</font>i<font color="#990000">-</font><font color="#993399">1</font><font color="#990000">]</font> <font color="#FF0000">{</font> <b><font color="#0000FF">return</font></b> false <font color="#FF0000">}</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> true <font color="#FF0000">}</font> </pre> <br /> <span>And the last utility method used is <span class='inlinecode'>Swap</span>, which allows swapping the values of two indices in the <span class='inlinecode'>ArrayList</span>:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">func</font></b> <font color="#990000">(</font>a ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> <b><font color="#000000">Swap</font></b><font color="#990000">(</font>i<font color="#990000">,</font> j int<font color="#990000">)</font> <font color="#FF0000">{</font> aux <font color="#990000">:=</font> a<font color="#990000">[</font>i<font color="#990000">]</font> a<font color="#990000">[</font>i<font color="#990000">]</font> <font color="#990000">=</font> a<font color="#990000">[</font>j<font color="#990000">]</font> a<font color="#990000">[</font>j<font color="#990000">]</font> <font color="#990000">=</font> aux <font color="#FF0000">}</font> </pre> <br /> <h2 style='display: inline'>Sleep sort</h2><br /> <br /> <span>Let's implement our first algorithm, sleep sort. Sleep sort is a non-traditional and unconventional sorting algorithm based on the idea of waiting a certain amount of time corresponding to the value of each element in the input <span class='inlinecode'>ArrayList</span>. It's more of a fun, creative concept rather than an efficient or practical sorting technique. This is not a sorting algorithm you would use in any production code. As you can imagine, it is quite an inefficient sorting algorithm (it's only listed here as a warm-up exercise). This sorting method may also return false results depending on how the Goroutines are scheduled by the Go runtime. </span><br /> <br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">package</font></b> sort <b><font color="#0000FF">import</font></b> <font color="#990000">(</font> <font color="#FF0000">"codeberg.org/snonux/algorithms/ds"</font> <font color="#FF0000">"sync"</font> <font color="#FF0000">"time"</font> <font color="#990000">)</font> <b><font color="#0000FF">func</font></b> Sleep<font color="#990000">[</font>V ds<font color="#990000">.</font>Integer<font color="#990000">](</font>a ds<font color="#990000">.</font>ArrayList<font color="#990000">[</font>V<font color="#990000">])</font> ds<font color="#990000">.</font>ArrayList<font color="#990000">[</font>V<font color="#990000">]</font> <font color="#FF0000">{</font> sorted <font color="#990000">:=</font> ds<font color="#990000">.</font>NewArrayList<font color="#990000">[</font>V<font color="#990000">](</font><b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">))</font> numCh <font color="#990000">:=</font> <b><font color="#000000">make</font></b><font color="#990000">(</font><b><font color="#0000FF">chan</font></b> V<font color="#990000">)</font> <b><font color="#0000FF">var</font></b> wg sync<font color="#990000">.</font>WaitGroup wg<font color="#990000">.</font><b><font color="#000000">Add</font></b><font color="#990000">(</font><b><font color="#000000">len</font></b><font color="#990000">(</font>a<font color="#990000">))</font> <b><font color="#0000FF">go</font></b> <b><font color="#0000FF">func</font></b><font color="#990000">()</font> <font color="#FF0000">{</font> wg<font color="#990000">.</font><b><font color="#000000">Wait</font></b><font color="#990000">()</font> <b><font color="#000000">close</font></b><font color="#990000">(</font>numCh<font color="#990000">)</font> <font color="#FF0000">}</font><font color="#990000">()</font> <b><font color="#0000FF">for</font></b> _<font color="#990000">,</font> num <font color="#990000">:=</font> <b><font color="#0000FF">range</font></b> a <font color="#FF0000">{</font> <b><font color="#0000FF">go</font></b> <b><font color="#0000FF">func</font></b><font color="#990000">(</font>num V<font color="#990000">)</font> <font color="#FF0000">{</font> <b><font color="#0000FF">defer</font></b> wg<font color="#990000">.</font><b><font color="#000000">Done</font></b><font color="#990000">()</font> time<font color="#990000">.</font><b><font color="#000000">Sleep</font></b><font color="#990000">(</font>time<font color="#990000">.</font><b><font color="#000000">Duration</font></b><font color="#990000">(</font>num<font color="#990000">)</font> <font color="#990000">*</font> time<font color="#990000">.</font>Second<font color="#990000">)</font> numCh <font color="#990000"><-</font> num <font color="#FF0000">}</font><font color="#990000">(</font>num<font color="#990000">)</font> <font color="#FF0000">}</font> <b><font color="#0000FF">for</font></b> num <font color="#990000">:=</font> <b><font color="#0000FF">range</font></b> numCh <font color="#FF0000">{</font> sorted <font color="#990000">=</font> <b><font color="#000000">append</font></b><font color="#990000">(</font>sorted<font color="#990000">,</font> num<font color="#990000">)</font> <font color="#FF0000">}</font> <b><font color="#0000FF">return</font></b> sorted <font color="#FF0000">}</font> </pre> <br /> <span>This Go code implements the sleep sort algorithm using generics and goroutines. The main function <span class='inlinecode'>Sleep[V ds.Integer](a ds.ArrayList[V]) ds.ArrayList[V]</span> takes a generic <span class='inlinecode'>ArrayList</span> as input and returns a sorted <span class='inlinecode'>ArrayList</span>. The code creates a separate goroutine for each element in the input array, sleeps for a duration proportional to the element's value, and then sends the element to a channel. Another goroutine waits for all the sleeping goroutines to finish and then closes the channel. The sorted result <span class='inlinecode'>ArrayList</span> is constructed by appending the elements received from the channel in the order they arrive. The <span class='inlinecode'>sync.WaitGroup</span> is used to synchronize goroutines and ensure that all of them have completed before closing the channel.</span><br /> <br /> <h3 style='display: inline'>Testing</h3><br /> <br /> <span>For testing, we only allow values up to 10, as otherwise, it would take too long to finish:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">package</font></b> sort <b><font color="#0000FF">import</font></b> <font color="#990000">(</font> <font color="#FF0000">"fmt"</font> <font color="#FF0000">"testing"</font> <font color="#FF0000">"codeberg.org/snonux/algorithms/ds"</font> <font color="#990000">)</font> <b><font color="#0000FF">func</font></b> <b><font color="#000000">TestSleepSort</font></b><font color="#990000">(</font>t <font color="#990000">*</font>testing<font color="#990000">.</font>T<font color="#990000">)</font> <font color="#FF0000">{</font> a <font color="#990000">:=</font> ds<font color="#990000">.</font>NewRandomArrayList<font color="#990000">[</font>int<font color="#990000">](</font><font color="#993399">10</font><font color="#990000">,</font> <font color="#993399">10</font><font color="#990000">)</font> a <font color="#990000">=</font> <b><font color="#000000">Sleep</font></b><font color="#990000">(</font>a<font color="#990000">)</font> <b><font color="#0000FF">if</font></b> <font color="#990000">!</font>a<font color="#990000">.</font><b><font color="#000000">Sorted</font></b><font color="#990000">()</font> <font color="#FF0000">{</font> t<font color="#990000">.</font><b><font color="#000000">Errorf</font></b><font color="#990000">(</font><font color="#FF0000">"Array not sorted: %v"</font><font color="#990000">,</font> a<font color="#990000">)</font> <font color="#FF0000">}</font> <font color="#FF0000">}</font> </pre> <br /> <span>As you can see, it takes <span class='inlinecode'>9s</span> here for the algorithm to finish (which is the highest value in the <span class='inlinecode'>ArrayList</span>):</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre>❯ go <b><font color="#0000FF">test</font></b> <font color="#990000">.</font>/sort -v -run SleepSort <font color="#990000">===</font> RUN TestSleepSort --- PASS<font color="#990000">:</font> TestSleepSort <font color="#990000">(</font><font color="#993399">9</font><font color="#990000">.</font>00s<font color="#990000">)</font> PASS ok codeberg<font color="#990000">.</font>org/snonux/algorithms/sort <font color="#993399">9</font><font color="#990000">.</font>002s </pre> <br /> <span>I won't write any benchmark for sleep sort; that will be done for the algorithms to come in this series :-).</span><br /> <br /> <span>E-Mail your comments to hi@paul.cyou :-)</span><br /> <br /> <a class='textlink' href='../'>Back to the main site</a><br /> </div> </content> </entry> <entry> <title>'Never split the difference' book notes</title> <link href="gemini://foo.zone/gemfeed/2023-04-01-never-split-the-difference-book-notes.gmi" /> <id>gemini://foo.zone/gemfeed/2023-04-01-never-split-the-difference-book-notes.gmi</id> <updated>2023-04-01T20:00:17+03:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>These are my personal takeaways after reading 'Never split the difference' by Chris Voss. Note that the book contains much more knowledge wisdom and that these notes only contain points I personally found worth writing down. This is mainly for my own use, but you might find it helpful too.</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1 style='display: inline'>"Never split the difference" book notes</h1><br /> <br /> <span class='quote'>Published at 2023-04-01T20:00:17+03:00</span><br /> <br /> <span>These are my personal takeaways after reading "Never split the difference" by Chris Voss. Note that the book contains much more knowledge wisdom and that these notes only contain points I personally found worth writing down. This is mainly for my own use, but you might find it helpful too.</span><br /> <br /> <pre> ,.......... .........., ,..,' '.' ',.., ,' ,' : ', ', ,' ,' : ', ', ,' ,' : ', ', ,' ,'............., : ,.............', ', ,' '............ '.' ............' ', '''''''''''''''''';''';'''''''''''''''''' ''' </pre> <br /> <h2 style='display: inline'>Tactical listening, spreading empathy</h2><br /> <br /> <span>Be a mirror, copy each other to be comfy with each other to build up trust. Mirroring is mainly body language. A mirror is to repeat the words the other just said. Simple but effective.</span><br /> <br /> <ul> <li>A mirror needs space and silence between the words. At least 4 seconds.</li> <li>A mirror might be awkward to be used at first, especially with a question coupled to it.</li> <li>We fear what's different and are drawn to what is similar.</li> </ul><br /> <span>Mirror training is like Jedi training. Simple but effective. A mirror needs space. Be silent after "you want this?" </span><br /> <br /> <h2 style='display: inline'>Mindset of discovery</h2><br /> <br /> <span>Try to have multiple realities in your mind and use facts to distinguish between real and false.</span><br /> <br /> <ul> <li>Focus on what the counterpart has to say and what he needs and wants. Understanding him makes him vulnerable.</li> <li>Empathy understanding the other person from his perspective, but it does not mean agreeing with him.</li> <li>Detect and label the emotions of others for your powers. </li> <li>To be understood seems to solve all problems magically.</li> </ul><br /> <span>Try: to put a label on someone's emotion and then be silent. Wait for the other to reveal himself. "You seem unhappy about this?"</span><br /> <br /> <h3 style='display: inline'>More tips </h3><br /> <br /> <ul> <li>Put on a poker face and don't show emotions.</li> <li>Slow things down. Don't be a problem solver.</li> <li>Smile while you are talking, even on the phone. Be easy and encouraging.</li> <li>Being right is not the key to successful negotiation; being mindful is.</li> <li>Be in the safe zone of empathy and acknowledge bad news.</li> </ul><br /> <h2 style='display: inline'>"No" starts the conversation</h2><br /> <br /> <span>When the opponent starts with a "no", he feels in control and comfortable. That's why he has to start with "no".</span><br /> <br /> <ul> <li>"Yes" and "maybe" might be worthless, but "no" starts the conversation.</li> <li>If someone is saying "no" to you, he will be open to what you have to say next.</li> <li>"No" is not stopping the negotiation but will open up opportunities you were not thinking about before.</li> <li>Start with "no". Great negotiators seek "no" because that's when the great discussions begin.</li> <li>A "no" can be scary if you are not used to it. If your biggest fear is "no", then you can't negotiate.</li> </ul><br /> <span>Get a "That's right" when negotiating. Don't get a "you're right". You can summarise the opponent to get a "that's right".</span><br /> <br /> <h2 style='display: inline'>Win-win</h2><br /> <br /> <span>Win-win is a naive approach when encountering the win-lose counterpart, but always cooperate. Don't compromise, and don't split the difference. We don't compromise because it's right; we do it because it is easy. You must embrace the hard stuff; that's where the great deals are.</span><br /> <br /> <h2 style='display: inline'>On Deadlines</h2><br /> <br /> <ul> <li>All deadlines are imaginary.</li> <li>Most of the time, deadlines unsettle us without a good reason.</li> <li>They push a deal to a conclusion.</li> <li>They rush the counterpart to cause pressure and anxiety.</li> </ul><br /> <h2 style='display: inline'>Analyse the opponent</h2><br /> <br /> <ul> <li>Understand the motivation of people behind the table as well.</li> <li>Ask how affected they will be.</li> <li>Determine your and the opposite negotiation style. Accommodation, analyst, assertive.</li> <li>Treat them how they need to be treated.</li> </ul><br /> <span>The person on the other side is never the issue; the problem is the issue. Keep this in mind to avoid emotional issues with the person and focus on the problem, not the person. The bond is essential; never create an enemy.</span><br /> <br /> <h2 style='display: inline'>Use different ways of saying "no."</h2><br /> <br /> <span class='quote'>I had paid my rent always in time. I had positive experiences with the building and would be sad for the landlord to lose a good tenant. I am looking for a win-win agreement between us. Pulling out the research, other neighbours offer much lower prices even if your building is a better location and services. How can I effort 200 more.... </span><br /> <br /> <span>...then put an extreme anker.</span><br /> <br /> <span>You always have to embrace thoughtful confrontation for good negotiation and life. Don't avoid honest, clear conflict. It will give you the best deals. Compromises are mostly bad deals for both sides. Most people don't negotiate a win-win but a win-lose. Know the best and worst outcomes and what is acceptable for you.</span><br /> <br /> <h2 style='display: inline'>Calibrated question</h2><br /> <br /> <span>Calibrated questions. Give the opponent a sense of power. Ask open-how questions to get the opponent to solve your problem and move him in your direction. Calibrated questions are the best tools. Summarise everything, and then ask, "how I am supposed to do that?". Asking for help this way with a calibrated question is a powerful tool for joint problem solving</span><br /> <br /> <span>Being calm and respectful is essential. Without control of your emotions, it won't work. The counterpart will have no idea how constrained they are with your question. Avoid questions which get a yes or short answers. Use "why?".</span><br /> <br /> <span>Counterparts are more involved if these are their solutions. The counterpart must answer with "that's right", not "you are right". He has to own the problem. If not, then add more why questions.</span><br /> <br /> <ul> <li>Tone and body language need to align with what people are saying.</li> <li>Deal with it via a labelled question. </li> <li>Liers tend to talk with "them" and "their" and not with "I".</li> <li>Also, liars tend to talk in complex sentences.</li> </ul><br /> <span>Prepare 3 to 5 calibrated questions for your counterpart. Be curious what is really motivating the other side. You can get out the "Black Swan".</span><br /> <br /> <h2 style='display: inline'>The black swan </h2><br /> <br /> <span>What we don't know can break our deal. Uncovering it can bring us unexpected success. You get what you ask for in this world, but you must learn to ask correctly. Reveal the black swan by asking questions.</span><br /> <br /> <h2 style='display: inline'>More</h2><br /> <br /> <span>Establish a range at top places like corp. I get... (e.g. remote London on a project basis). Set a high salary range and not a number. Also, check on LinkedIn premium for the salaries.</span><br /> <br /> <ul> <li>Give an unexpected gift, e.g. show them my pet project and publicity for engineering.</li> <li>Use an odd number, which makes you seem to have thought a lot about the sum and calculated it.</li> <li>Define success and metrics for your next raise.</li> <li>What does it take to be successful here? Ask the question, and they will tell you and guide you.</li> <li>Set an extreme anker. Make the counterpart the illusion of losing something.</li> <li>Hope-based deals. Hope is not a strategy.</li> <li>Tactical empathy, listening as a martial art. It is emotional intelligence on steroids.</li> <li>Being right isn't the key to a successful negotiation, but having the correct mindset is.</li> <li>Don't shop the groceries when you are hungry.</li> </ul><br /> <span>Slow.... it.... down....</span><br /> <br /> <span>Other book notes of mine are:</span><br /> <br /> <a class='textlink' href='./2023-04-01-never-split-the-difference-book-notes.html'>2023-04-01 "Never split the difference" book notes (You are currently reading this)</a><br /> <a class='textlink' href='./2023-03-16-the-pragmatic-programmer-book-notes.html'>2023-03-16 "The Pragmatic Programmer" book notes</a><br /> <br /> <span>E-Mail your comments to hi@paul.cyou :-)</span><br /> <br /> <a class='textlink' href='../'>Back to the main site</a><br /> </div> </content> </entry> <entry> <title>Gemtexter 2.0.0 - Let's Gemtext again^2</title> <link href="gemini://foo.zone/gemfeed/2023-03-25-gemtexter-2.0.0-lets-gemtext-again-2.gmi" /> <id>gemini://foo.zone/gemfeed/2023-03-25-gemtexter-2.0.0-lets-gemtext-again-2.gmi</id> <updated>2023-03-25T17:50:32+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>I proudly announce that I've released Gemtexter version `2.0.0`. What is Gemtexter? It's my minimalist static site generator for Gemini Gemtext, HTML and Markdown written in GNU Bash.</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1 style='display: inline'>Gemtexter 2.0.0 - Let's Gemtext again^2</h1><br /> <br /> <span class='quote'>Published at 2023-03-25T17:50:32+02:00</span><br /> <br /> <pre> -=[ typewriters ]=- 1/98 .-------. _|~~ ~~ |_ .-------. =(_|_______|_)= _|~~ ~~ |_ |:::::::::| =(_|_______|_) |:::::::[]| |:::::::::| |o=======.| |:::::::[]| jgs `"""""""""` |o=======.| mod. by Paul Buetow `"""""""""` </pre> <br /> <span>I proudly announce that I've released Gemtexter version <span class='inlinecode'>2.0.0</span>. What is Gemtexter? It's my minimalist static site generator for Gemini Gemtext, HTML and Markdown written in GNU Bash.</span><br /> <br /> <a class='textlink' href='https://codeberg.org/snonux/gemtexter'>https://codeberg.org/snonux/gemtexter</a><br /> <br /> <span>This is a new major release, so it contains a breaking change (see "Meta cache made obsolete").</span><br /> <br /> <span>Let's list what's new!</span><br /> <br /> <h2 style='display: inline'>Minimal template engine</h2><br /> <br /> <span>Gemtexter now supports templating, enabling dynamically generated content to <span class='inlinecode'>.gmi</span> files before converting anything to any output format like HTML and Markdown.</span><br /> <br /> <span>A template file name must have the suffix <span class='inlinecode'>gmi.tpl</span>. A template must be put into the same directory as the Gemtext <span class='inlinecode'>.gmi</span> file to be generated. Gemtexter will generate a Gemtext file <span class='inlinecode'>index.gmi</span> from a given template <span class='inlinecode'>index.gmi.tpl</span>. A <span class='inlinecode'><<<</span> and <span class='inlinecode'>>>></span> encloses a multiline template. All lines starting with <span class='inlinecode'><< </span> will be evaluated as a single line of Bash code and the output will be written into the resulting Gemtext file.</span><br /> <br /> <span>For example, the template <span class='inlinecode'>index.gmi.tpl</span>:</span><br /> <br /> <pre> # Hello world << echo "> This site was generated at $(date --iso-8601=seconds) by \`Gemtexter\`" Welcome to this capsule! <<< for i in {1..10}; do echo Multiline template line $i done >>> </pre> <br /> <span>... results into the following <span class='inlinecode'>index.gmi</span> after running <span class='inlinecode'>./gemtexter --generate</span> (or <span class='inlinecode'>./gemtexter --template</span>, which instructs to do only template processing and nothing else):</span><br /> <br /> <pre> # Hello world > This site was generated at 2023-03-15T19:07:59+02:00 by `Gemtexter` Welcome to this capsule! Multiline template line 1 Multiline template line 2 Multiline template line 3 Multiline template line 4 Multiline template line 5 Multiline template line 6 Multiline template line 7 Multiline template line 8 Multiline template line 9 Multiline template line 10 </pre> <br /> <span>Another thing you can do is insert an index with links to similar blog posts. E.g.:</span><br /> <br /> <pre> See more entries about DTail and Golang: << template::inline::index dtail golang Blablabla... </pre> <br /> <span>... scans all other post entries with <span class='inlinecode'>dtail</span> and <span class='inlinecode'>golang</span> in the file name and generates a link list like this:</span><br /> <br /> <pre> See more entries about DTail and Golang: => ./2022-10-30-installing-dtail-on-openbsd.gmi 2022-10-30 Installing DTail on OpenBSD => ./2022-04-22-programming-golang.gmi 2022-04-22 The Golang Programming language => ./2022-03-06-the-release-of-dtail-4.0.0.gmi 2022-03-06 The release of DTail 4.0.0 => ./2021-04-22-dtail-the-distributed-log-tail-program.gmi 2021-04-22 DTail - The distributed log tail program (You are currently reading this) Blablabla... </pre> <br /> <h2 style='display: inline'>Added hooks</h2><br /> <br /> <span>You can configure <span class='inlinecode'>PRE_GENERATE_HOOK</span> and <span class='inlinecode'>POST_PUBLISH_HOOK</span> to point to scripts to be executed before running <span class='inlinecode'>--generate</span>, or after running <span class='inlinecode'>--publish</span>. E.g. you could populate some of the content by an external script before letting Gemtexter do its thing or you could automatically deploy the site after running <span class='inlinecode'>--publish</span>.</span><br /> <br /> <span>The sample config file <span class='inlinecode'>gemtexter.conf</span> includes this as an example now; these scripts will only be executed when they actually exist:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">declare</font></b> -xr <font color="#009900">PRE_GENERATE_HOOK</font><font color="#990000">=.</font>/pre_generate_hook<font color="#990000">.</font>sh <b><font color="#0000FF">declare</font></b> -xr <font color="#009900">POST_PUBLISH_HOOK</font><font color="#990000">=.</font>/post_publish_hook<font color="#990000">.</font>sh </pre> <br /> <h2 style='display: inline'>Use of safer Bash options</h2><br /> <br /> <span>Gemtexter now does <span class='inlinecode'>set -euf -o pipefile</span>, which helps to eliminate bugs and to catch scripting errors sooner. Previous versions only <span class='inlinecode'>set -e</span>.</span><br /> <br /> <h2 style='display: inline'>Meta cache made obsolete</h2><br /> <br /> <span>Here is the breaking change to older versions of Gemtexter. The <span class='inlinecode'>$BASE_CONTENT_DIR/meta</span> directory was made obsolete. <span class='inlinecode'>meta</span> was used to store various information about all the blog post entries to make generating an Atom feed in Bash easier. Especially the publishing dates of each post were stored there. Instead, the publishing date is now encoded in the <span class='inlinecode'>.gmi</span> file. And if it is missing, Gemtexter will set it to the current date and time at first run.</span><br /> <br /> <span>An example blog post without any publishing date looks like this:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><font color="#990000">%</font> cat gemfeed<font color="#990000">/</font><font color="#993399">2023</font>-<font color="#993399">02</font>-<font color="#993399">26</font>-title-here<font color="#990000">.</font>gmi <i><font color="#9A1900"># Title here</font></i> The remaining content of the Gemtext file<font color="#990000">...</font> </pre> <br /> <span>Gemtexter will add a line starting with <span class='inlinecode'>> Published at ...</span> now. Any subsequent Atom feed generation will then use that date.</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><font color="#990000">%</font> cat gemfeed<font color="#990000">/</font><font color="#993399">2023</font>-<font color="#993399">02</font>-<font color="#993399">26</font>-title-here<font color="#990000">.</font>gmi <i><font color="#9A1900"># Title here</font></i> <font color="#990000">></font> Published at <font color="#993399">2023</font>-<font color="#993399">02</font>-26T21<font color="#990000">:</font><font color="#993399">43</font><font color="#990000">:</font><font color="#993399">51</font><font color="#990000">+</font><font color="#993399">01</font><font color="#990000">:</font><font color="#993399">00</font> The remaining content of the Gemtext file<font color="#990000">...</font> </pre> <br /> <h2 style='display: inline'>XMLLint support</h2><br /> <br /> <span>Optionally, when the <span class='inlinecode'>xmllint</span> binary is installed, Gemtexter will perform a simple XML lint check against the Atom feed generated. This is a double-check of whether the Atom feed is a valid XML.</span><br /> <br /> <h2 style='display: inline'>More</h2><br /> <br /> <span>Additionally, there were a couple of bug fixes, refactorings and overall improvements in the documentation made. </span><br /> <br /> <span>Other related posts are:</span><br /> <br /> <a class='textlink' href='./2023-03-25-gemtexter-2.0.0-lets-gemtext-again-2.html'>2023-03-25 Gemtexter 2.0.0 - Let's Gemtext again^2 (You are currently reading this)</a><br /> <a class='textlink' href='./2022-08-27-gemtexter-1.1.0-lets-gemtext-again.html'>2022-08-27 Gemtexter 1.1.0 - Let's Gemtext again</a><br /> <a class='textlink' href='./2021-06-05-gemtexter-one-bash-script-to-rule-it-all.html'>2021-06-05 Gemtexter - One Bash script to rule it all</a><br /> <a class='textlink' href='./2021-04-24-welcome-to-the-geminispace.html'>2021-04-24 Welcome to the Geminispace</a><br /> <br /> <span>E-Mail your comments to hi@paul.cyou :-)</span><br /> <br /> <a class='textlink' href='../'>Back to the main site</a><br /> </div> </content> </entry> <entry> <title>'The Pragmatic Programmer' book notes</title> <link href="gemini://foo.zone/gemfeed/2023-03-16-the-pragmatic-programmer-book-notes.gmi" /> <id>gemini://foo.zone/gemfeed/2023-03-16-the-pragmatic-programmer-book-notes.gmi</id> <updated>2023-03-16T00:55:20+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>These are my personal takeaways after reading 'The Pragmatic Programmer' by David Thomas and Andrew Hunt. Note that the book contains much more knowledge wisdom and that these notes only contain points I personally found worth writing down. This is mainly for my own use, but you might find it helpful too.</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1 style='display: inline'>"The Pragmatic Programmer" book notes</h1><br /> <br /> <span class='quote'>Published at 2023-03-16T00:55:20+02:00</span><br /> <br /> <span>These are my personal takeaways after reading "The Pragmatic Programmer" by David Thomas and Andrew Hunt. Note that the book contains much more knowledge wisdom and that these notes only contain points I personally found worth writing down. This is mainly for my own use, but you might find it helpful too.</span><br /> <br /> <pre> ,.......... .........., ,..,' '.' ',.., ,' ,' : ', ', ,' ,' : ', ', ,' ,' : ', ', ,' ,'............., : ,.............', ', ,' '............ '.' ............' ', '''''''''''''''''';''';'''''''''''''''''' ''' </pre> <br /> <span>Think about your work while doing it - every day on every project. Have a feeling of continuous improvement. </span><br /> <br /> <ul> <li>Be a realist.</li> <li>Smell challenges.</li> <li>Care about your craft.</li> <li>Code can always be flawed, but it can meet the requirements.</li> <li>You should be proud of your code, though.</li> </ul><br /> <span>No one writes perfect code, including you. However:</span><br /> <br /> <ul> <li>Paranoia is good thinking.</li> <li>Practice defensive programming and crash early.</li> <li>Crashing is often the best thing you can do. </li> <li>Changes should be reversible.</li> </ul><br /> <span>Erlang: Defensive programming is a waste of time. Let it crash. "This can never happen" - don't practise that kind of self-deception when programming. </span><br /> <br /> <span>Leave assertions in the code, even in production. Only leave out the assertions causing the performance issues.</span><br /> <br /> <span>Take small steps, always. Get feedback, too, for each of the steps the code does. Avoid fortune telling. If you have to involve in it, then the step is too large.</span><br /> <br /> <span>Decouple the code (e.g. OOP or functional programming). Prefer interfaces for types and mixins for a class extension over class inheritance.</span><br /> <br /> <ul> <li>Refactor now and not later.</li> <li>Later, it will be even more painful.</li> </ul><br /> <span>Don't think outside the box. Find the box. The box is more extensive than you think. Think about the hard problem at hand. Do you have to do it a certain way, or do you have to do it at all?</span><br /> <br /> <span>Do what works and not what's fashionable. E.g. does SCRUM make sense? The goal is to deliver deliverables and not to "become" agile.</span><br /> <br /> <h2 style='display: inline'>Continuous learning</h2><br /> <br /> <span>Add new tools to your repertoire every day and keep the momentum up. Learning new things is your most crucial aspect. Invest regularly in your knowledge portfolio. The learning process extends your thinking. It does not matter if you will never use it.</span><br /> <br /> <ul> <li>Learn a new programming language every year.</li> <li>Read a technical book every month.</li> <li>Take courses.</li> </ul><br /> <span>Think critically about everything you learn. Use paper for your notes. There is something special about it.</span><br /> <br /> <h2 style='display: inline'>Stay connected</h2><br /> <br /> <span>It's your life, and you own it. Bruce Lee once said: </span><br /> <br /> <span class='quote'>"I am not on the world to life after your expectations, neither are you to life after mine."</span><br /> <br /> <ul> <li>Go to meet-ups and actively engage.</li> <li>Stay current.</li> <li>Dealing with computers is hard. Dealing with people is harder. </li> </ul><br /> <span>It's your life. Share it, celebrate it, be proud and have fun.</span><br /> <br /> <h2 style='display: inline'>The story of stone soup</h2><br /> <br /> <span>How to motivate others to contribute something (e.g. ideas to a startup):</span><br /> <br /> <span class='quote'>A kindly, old stranger was walking through the land when he came upon a village. As he entered, the villagers moved towards their homes, locking doors and windows. The stranger smiled and asked, why are you all so frightened. I am a simple traveler, looking for a soft place to stay for the night and a warm place for a meal. "There's not a bite to eat in the whole province," he was told. "We are weak and our children are starving. Better keep moving on." "Oh, I have everything I need," he said. "In fact, I was thinking of making some stone soup to share with all of you." He pulled an iron cauldron from his cloak, filled it with water, and began to build a fire under it. Then, with great ceremony, he drew an ordinary-looking stone from a silken bag and dropped it into the water. By now, hearing the rumor of food, most of the villagers had come out of their homes or watched from their windows. As the stranger sniffed the "broth" and licked his lips in anticipation, hunger began to overcome their fear. "Ahh," the stranger said to himself rather loudly, "I do like a tasty stone soup. Of course, stone soup with cabbage -- that's hard to beat." Soon a villager approached hesitantly, holding a small cabbage he'd retrieved from its hiding place, and added it to the pot. "Wonderful!!" cried the stranger. "You know, I once had stone soup with cabbage and a bit of salt beef as well, and it was fit for a king." The village butcher managed to find some salt beef . . . And so it went, through potatoes, onions, carrots, mushrooms, and so on, until there was indeed a delicious meal for everyone in the village to share. The village elder offered the stranger a great deal of money for the magic stone, but he refused to sell it and traveled on the next day. As he left, the stranger came upon a group of village children standing near the road. He gave the silken bag containing the stone to the youngest child, whispering to a group, "It was not the stone, but the villagers that had performed the magic." </span><br /> <br /> <span>By working together, everyone contributes what they can, achieving a greater good together.</span><br /> <br /> <span>Other book notes of mine are:</span><br /> <br /> <a class='textlink' href='./2023-04-01-never-split-the-difference-book-notes.html'>2023-04-01 "Never split the difference" book notes</a><br /> <a class='textlink' href='./2023-03-16-the-pragmatic-programmer-book-notes.html'>2023-03-16 "The Pragmatic Programmer" book notes (You are currently reading this)</a><br /> <br /> <span>E-Mail your comments to hi@paul.cyou :-)</span><br /> <br /> <a class='textlink' href='../resources.html'>More books and other resources I found useful.</a><br /> <a class='textlink' href='../'>Back to the main site</a><br /> </div> </content> </entry> <entry> <title>How to shut down after work</title> <link href="gemini://foo.zone/gemfeed/2023-02-26-how-to-shut-down-after-work.gmi" /> <id>gemini://foo.zone/gemfeed/2023-02-26-how-to-shut-down-after-work.gmi</id> <updated>2023-02-26T23:48:01+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>Do you need help fully discharging from work in the evenings or for the weekend? Shutting down from work won't just improve your work-life balance; it will also significantly improve the quality of your personal life and work. After a restful weekend, you will be much more energized and productive the next working day. So it should not just be in your own, but also your employers' interest that you fully relax and shut down after work. </summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1>How to shut down after work</h1> <p class="quote"><i>Published at 2023-02-26T23:48:01+02:00</i></p> <pre> |\ "Music should be heard not only with the ears, but also the soul." |---|--\-----------------------|-----------------------------------------| | | |\ | |@ |\ | |---|---|--\-------------------|-------------/|----|------|--\----|------| | @| | |\ |O | 3 / | |@ | | | |---|--@|---|--\--------|------|---------/----|----|------|-------|------| | @| @| \ |O | / | | |@ @| @|. | |-----------|-----|-----|------|-----/---|---@|----|--------------|------| | @| | |O | | | | @|. | |-----------|----@|-----|------|----|---@|------------------------|------| @| | | Larry Komro @|. -@- [kom...@uwec.edu] </pre><br /> <p>Do you need help fully discharging from work in the evenings or for the weekend? Shutting down from work won't just improve your work-life balance; it will also significantly improve the quality of your personal life and work. After a restful weekend, you will be much more energized and productive the next working day. So it should not just be in your own, but also your employers' interest that you fully relax and shut down after work. </p> <h2>Have a shutdown routine</h2> <p>Have a routine. Try to finish work around the same time every day. Write any outstanding tasks down for the next day, so you are sure you will remember them. Writing them down brings wonders as you can remove them from your mind for the remainder of the day (or the upcoming weekend) as you know you will surely pick them up the next working day. Tidying up your workplace could also count toward your daily shutdown routine. </p> <p>A commute home from the office also greatly helps, as it disconnects your work from your personal life. Don't work on your commute home, though! If you don't commute but work from home, then it helps to walk around the block or in a nearby park to disconnect from work. </p> <h2>Don't work when you officially don't work</h2> <p>Unless you are self-employed, you have likely signed an N-hour per week contract with your employer, and your regular working times are from X o'clock in the morning to Y o'clock in the evening (with M minutes lunch break in the middle). And there might be some flexibility in your working times, too. But that kind of flexibility (e.g. extending the lunch break so that there is time to pick up a family member from the airport) will be agreed upon, and you will counteract it, for example, by starting working earlier the next day or working late, that one exception. But overall, your weekly working time will stay N hours. </p> <p>Another exception would be when you are on an on-call schedule and are expected to watch your work notifications out-of-office times. But that is usually only a few days per month and, therefore, not the norm. And it should also be compensated accordingly. </p> <p>There might be some maintenance work you must carry out, which can only be done over the weekend, but it should be explicitly agreed upon and compensated for. Also, there might be a scenario that a production incident comes up shortly before the end of the work day, requiring you (and your colleagues) to stay a bit longer. But this should be an exceptional case.</p> <p>Other than that, there is no reason why you should work out-of-office hours. I know many people who suffer "the fear of missing out", so slack messages and E-Mails are checked until late in the evening, during weekends or holidays. I have been improving here personally a lot over the last couple of months, but still, I fall into this trap occasionally. </p> <p>Also, when you respond to slack messages and E-Mails, your colleagues can think that you have nothing better to do. They also will take it for granted and keep slacking and messaging you out of regular office times. </p> <p>Checking for your messages constantly outside of regular office times makes it impossible to shut down and relax from work altogether. </p> <h2>Distract your mind</h2> <p>Often, your mind goes back to work-related stuff even after work. That's normal as you concentrated highly on your work throughout the day. The brain unconsciously continues to work and will automatically present you with random work-related thoughts. You can counteract this by focusing on non-work stuff, which may include:</p> <ul> <li>Exercise. A half an hour workout or yoga session, followed by some stretching, helps to calm your mind after work. </li> <li>Play (with your family, pets, friends, or video game)</li> <li>Mindfully listen to music. When have you ever "really" listened to music? I mean, not just as a background stimulation but really paid attention to the melody, rhythm, voice and lyrics? That requires focused attention and distracts you from other thoughts. </li> <li>Think of or work on that fun passion project. I currently, for example, like to learn and code a bit in Rakulang. </li> <li>Read. Nothing beats reading a good Science Fiction Novel (or whatever you prefer) before falling asleep.</li> </ul> <p>Some of these can be habit-stacked: Exercise could be combined with watching videos about your passion project (e.g. watching lectures about that new programming language you are currently learning for fun). With walking, for example, you could combine listening to an Audiobook or music, or you could also think about your passion project during that walk. </p> <h2>Get a pet</h2> <p>Even if you have children, it helps wonders to get a pet. My cat, for example, will remind me a few times daily to take a few minute's breaks to pet, play or give food. So my cat not only helps me after work but throughout the day.</p> <p>My neighbour also works from home, and he has dogs, which he regularly has to take out to the park.</p> <h2>Journal your day</h2> <p>If you are upset about something, making it impossible to shut down from work, write down everything (e.g., with a pen in a paper journal). Writing things down helps you to "get rid" of the negative. Especially after conflicts with colleagues or company decisions, you don't agree on. This kind of self-therapy is excellent. Brainstorm all your emotions and (even if opinionated) opinions so you have everything on paper. Once done, you don't think about it so much anymore, as you know you can access that information if required. But stopping ruminating about it will be much easier now. You will likely never access that information again, though. But at least writing the thoughts down saved your day. </p> <p>Write down three things which went well for the day. This helps you to appreciate the day. </p> <h2>Don't stress about what your employer expects from you</h2> <p>Think about what's fun and motivates you. Maybe the next promotion to Principal or a Manager role isn't for you. Many fall into the trap of stressing themselves out to satisfy the employer so that the next upgrade will happen and think about it constantly, even after work. But it is more important that you enjoy your craftsmanship. Work on what you expect from yourself. Ideally, your goals should be aligned with your employer. I am not saying you should abandon everything what your manager is asking you to do, but it is, after all, your life. And you have to decide where and on what you want to work. But don't sell yourself short. Keep track of your accomplishments.</p> <h2>Call it a day</h2> <p>Every day you gave your best was good; the day's outcome doesn't matter. What matters is that you know you gave your best and are closer to your goals than the previous day. This gives you a sense of progress and accomplishment.</p> <p>There are some days at work you feel drained afterwards and think you didn't progress towards your goals at all. It's more challenging to shut down from work after such a day. A quick hack is to work on a quick win before the end of the day, giving you a sense of accomplishment after all. Another way is to make progress on your fun passion project after work. It must not be work-related, but a sense of accomplishment will still be there.</p> <p> </p> <p>E-Mail your comments to hi@paul.cyou :-)</p> <a class="textlink" href="../">Back to the main site</a><br /> </div> </content> </entry> <entry> <title>Why GrapheneOS rox</title> <link href="gemini://foo.zone/gemfeed/2023-01-23-why-grapheneos-rox.gmi" /> <id>gemini://foo.zone/gemfeed/2023-01-23-why-grapheneos-rox.gmi</id> <updated>2023-01-23T15:31:52+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>Art by Joan Stark</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1>Why GrapheneOS rox</h1> <p class="quote"><i>Published at 2023-01-23T15:31:52+02:00</i></p> <pre> Art by Joan Stark _.===========================._ .'` .- - __- - - -- --__--- -. `'. __ / ,'` _|--|_________|--|_ `'. \ /'--| ; _.'\ | ' ' | /'._ ; | // | |_.-' .-'.' ___ '.'-. '-._| | (\) \"` _.-` / .-'`_ `'-. \ `-._ `"/ (\) `-' | .' .-'" "'-. '. | `-` (\) | / .'(3)(2)(1)'. \ | (\) | / / (4) .-. \ \ | (\) | | |(5) ( )'==,J | | (\) | \ \ (6) '-' (0) / / | (\) | \ '.(7)(8)(9).' / | (\) ___| '. '-.._..-' .' | (\) /.--| '-._____.-' | (\) (\) |\_ _ __ _ __ __/| (\) (\) | | (\)_._._.__(\) | | (\\\\jgs\\\) '.___________________.' '-'-'-'--' </pre><br /> <p>In 2021 I wrote "On Being Pedantic about Open-Source", and there was a section "What about mobile?" where I expressed the dilemma about the necessity of using proprietary mobile operating systems. With GrapheneOS, I found my perfect solution for personal mobile phone use. </p> <a class="textlink" href="https://foo.zone/gemfeed/2021-08-01-on-being-pedantic-about-open-source.html">On Being Pedantic about Open-Source</a><br /> <p>What is GrapheneOS?</p> <p class="quote"><i>GrapheneOS is a privacy and security-focused mobile OS with Android app compatibility developed as a non-profit open-source project. It's focused on the research and development of privacy and security technologies, including substantial improvements to sandboxing, exploits mitigations and the permission model.</i></p> <p>GrapheneOS is an independent Android distribution based on the Android Open Source Project (AOSP) but hardened in multiple ways. Other independent Android distributions, like LineageOS, are also based on AOSP, but GrapheneOS takes it further so that it can be my daily driver on my phone.</p> <a class="textlink" href="https://GrapheneOS.org">https://GrapheneOS.org</a><br /> <a class="textlink" href="https://LineageOS.org">https://LineageOS.org</a><br /> <h2>User Profiles</h2> <p>GrapheneOS allows configuring up to 32 user profiles (including a guest profile) on a single phone. A profile is a completely different environment within the phone, and it is possible to switch between them instantly. Sessions of a profile can continue running in the background or be fully terminated. Each profile can have completely different settings and different applications installed.</p> <p>I use my default profile with primarily open-source applications installed, which I trust. I use another profile for banking (PayPal, various proprietary bank apps, Amazon store app, etc.) and another profile for various Google services (which I try to avoid, but I have to use once in a while). Furthermore, I have configured a profile for Social Media use (that one isn't in my default profile, as otherwise I am tempted to scroll social media all the time, which I try to avoid and only want to do intentionally when switching to the corresponding profile!).</p> <p>The neat thing about the profiles is that some can run a sandboxed version of Google Play (see later in this post), while others don't. So some profiles can entirely operate without any Google Play, and only some profiles (to which I rarely switch) have Google Play enabled. </p> <p>You notice how much longer (multiple days) your phone can be on a single charge when Google Play Services isn't running in the background. This tells a lot about the background activities and indicates that using Google Play shouldn't be the norm.</p> <h2>Proxying some of the Google offerings </h2> <p>There's also the case that I am using an app from the Google Play store (as the app isn't available from F-Droid), which doesn't require Google Play Services to run in the background. Here's where I use the Aurora Android store. The Aurora store can be installed through F-Droid. Aurora acts as an anonymous proxy from your phone to the Google Play Store and lets you install apps from there. No Google credentials are required for that!</p> <a class="textlink" href="https://f-droid.org">https://f-droid.org</a><br /> <p>There's a similar solution for watching videos on YouTube. You can use the NewPipe app (also from F-Droid), which acts as an anonymous proxy for watching videos from YouTube. So there isn't any need to install the official YouTube app, and there isn't any need to login to your Google account. What's so bad about the official app? You don't know which data it is sending about you to Google, so it is a privacy concern. </p> <h2>Google Play Sandboxing </h2> <p>Before switching to GrapheneOS, I had been using LineageOS on one of my phones for a couple of years. Still, I always had to have a secondary personal phone with all of these proprietary apps which (partially) only work with Google Play on the phone (e.g. Banking, Navigation, various travel apps from various Airlines, etc.) somewhere around as I didn't install Google Play on my LineageOS phone due to privacy concerns and only installed apps from the F-Droid store on it. When travelling, I always had to carry around a second phone with Google Play on it, as without it; life would become inconvenient pretty soon. </p> <p>With GrapheneOS, it is different. Here, I do not just have a separate user profile, "Google", for various Google apps where Google Play runs, but Google Play also runs in a sandbox!!!</p> <p class="quote"><i>GrapheneOS has a compatibility layer providing the option to install and use the official releases of Google Play in the standard app sandbox. Google Play receives no special access or privileges on GrapheneOS instead of bypassing the app sandbox and receiving a massive amount of highly privileged access. Instead, the compatibility layer teaches it how to work within the full app sandbox. It also isn't used as a backend for the OS services as it would be elsewhere since GrapheneOS doesn't use Google Play even when it's installed.</i></p> <p>When I need to access Google Play, I can switch to the "Google" profile. Even there, Google is sandboxed to the absolute minimum permissions required to be operational, which gives additional privacy protection.</p> <p>The sad truth is that Google Maps is still the best navigation app. When driving unknown routes, I can switch to my Google profile to use Google Maps. I don't need to do that when going streets I know about, but it is crucial (for me) to have Google Maps around when driving to a new destination.</p> <p>Also, Google Translate and Google Lens are still the best translation apps I know. I just recently relocated to another country, where I am still learning the language, so Google Lens has been proven very helpful on various occasions by ad-hoc translating text into English or German for me.</p> <p>The same applies to banking. Many banking apps require Google Play to be available (It might be even more secure to only use banking apps from the Google Play store due to official support and security updates). I rarely need to access my mobile banking app, but once in a while, I need to. As you have guessed by now, I can switch to my banking profile (with Google Play enabled), do what I need to do, and then terminate the session and go back to my default profile, and then my life can go on :-). </p> <p>It is great to have the flexibility to use any proprietary Android app when needed. That only applies to around 1% of my phone usage time, but you often don't always know when you need "that one app now". So it's perfect that it's covered with the phone you always have with you. </p> <h2>The camera and the cloud </h2> <p>I really want my phone to shoot good looking pictures, so that I can later upload them to the Irregular Ninja:</p> <a class="textlink" href="https://irregular.ninja">https://irregular.ninja</a><br /> <p>The stock camera app of the OASP could be better. Photos usually look washed out, and the app lacks features. With GrapheneOS, there are two options:</p> <ul> <li>Use the official Google camera app with sandboxed Google Play Services running. You will get the full Google experience here.</li> <li>Or, just use the default GrapheneOS camera app.</li> </ul> <p>The GrapheneOS camera app is much better than the stock OASP camera app. I have been comparing the photo quality of my Pixel phone under LineageOS and GrapheneOS, and the differences are pronounced. I didn't compare the quality with the official Google camera app, but I have seen some comparison videos and the differences seem like they aren't groundbreaking. </p> <p>For automatic backups of my photos, I am relying on a self-hosted instance of NextCloud (with a client app available via F-Droid). So there isn't any need to rely on any Google apps and services (Google Play Photos or Google Camera app) anymore, and that's great!</p> <a class="textlink" href="https://nextcloud.com">https://nextcloud.com</a><br /> <p>I also use NextCloud to synchronize my notes (NextCloud Notes), my RSS news feeds (NextCloud News) and contacts (DAVx5). All apps required are available in the F-Droid store.</p> <h2>Fine granular permissions</h2> <p>Another great thing about GrapheneOS is that, besides putting your apps into different profiles, you can also restrict network access and configure storage scopes per app individually.</p> <p>For example, let's say you are installing that one proprietary app from the Google Play Store through the Aurora store, and then you want to ensure that the app doesn't send data "home" through the internet. Nothing is easier to do than that. Just remove network access permissions from that only app.</p> <p>The app also wants to store and read some data from your phone (e.g. it could be a proprietary app for enhancing photos, and therefore storage access to a photo folder would be required). In GrapheneOS, you can configure a storage scope for that particular app, e.g. only read and write from one folder but still forbid access to all other folders on your phone.</p> <h2>Termux</h2> <p>Termux can be installed on any Android phone through F-Droid, so it doesn't need to be a GrapheneOS phone. But I have to mention Termux here as it significantly adds value to my phone experience. </p> <p class="quote"><i>Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager.</i></p> <a class="textlink" href="https://termux.dev">https://termux.dev</a><br /> <p>In short, Termux is an entire Linux environment running on your Android phone. Just pair your phone with a Bluetooth keyboard, and you will have the whole Linux experience. I am only using terminal Linux applications with Termux, though. What makes it especially great is that I could write on a new blog post (in Neovim through Termux on my phone) or do some coding whilst travelling (e.g. during a flight), or look up my passwords or some other personal documents (through my terminal-based password manager). All changes I commit to Git can be synced to the server with a simple <span class="inlinecode">git push</span> once online (e.g. after the plane landed) again.</p> <p>There are Pixel phones with a screen size of 6", and that's decent enough for occasional use like that, and everything (the phone, the BT keyboard, maybe an external battery pack) all fit nicely in a small travel pocket.</p> <h2>So, why not use a pure Linux phone?</h2> <p>Strictly speaking, an Android phone is a Linux phone, but it's heavily modified and customized. For me, a "pure" Linux phone is a more streamlined Linux kernel running in a distribution like Ubuntu Touch or Mobian. </p> <p>A pure Linux phone, e.g. with Ubuntu Touch installed, e.g. on a PinePhone, Fairphone, the Librem 5 or the Volla phone, is very appealing to me. And they would also provide an even better Linux experience than Termux does. Some support running LineageOS within an Anbox, enabling you to run various proprietary Android apps occasionally within Linux.</p> <a class="textlink" href="https://ubuntu-touch.io/">Ubuntu Touch</a><br /> <a class="textlink" href="https://en.wikipedia.org/wiki/Linux_for_mobile_devices">More Linux distributions for mobile devices </a><br /> <p>But here, Google Play would not be sandboxed; you could not configure individual network permissions and storage scopes like in GrapheneOS. Pure Linux-compatible phones usually come with a crappy camera, and the battery life is generally pretty bad (only a few hours). Also, no big tech company pushes the development of Linux phones. Everything relies on hobbyists, whereas multiple big tech companies put a lot of effort into the Android project, and a lot of code also goes into the Android Open-Source project. </p> <p>Currently, pure Linux phones are only a nice toy to tinker with but are still not ready (will they ever?) to be the daily driver. SailfishOS may be an exception; I played around with it in the past. It is pretty usable, but it's not an option for me as it is partial a proprietary operating system.</p> <a class="textlink" href="https://sailfishos.org">SailfishOS</a><br /> <h2>Small GrapheneOS downsides </h2> <p>Sometimes, switching a profile to use a different app is annoying, and you can't copy and paste from the system clipboard from one profile to another. But that's a small price I am willing to pay!</p> <p>Another thing is that GrapheneOS can only run on Google Pixel phones, whereas LineageOS can be installed on a much larger variety of hardware. But on the other hand, GrapheneOS works very well on Pixel phones. The GrapheneOS team can concentrate their development efforts on a smaller set of hardware which then improves the software's quality (best example: The camera app).</p> <p>And, of course, GrapheneOS is an open-source project. This is a good thing; however, on the other side, nobody can guarantee that the OS will not break or will not damage your phone. You have to trust the GrapheneOS project and donate to the project so they can keep up with the great work. But I rather trust the GrapheneOS team than big tech. </p> <p>E-Mail your comments to hi@paul.cyou :-)</p> <a class="textlink" href="../">Back to the main site</a><br /> </div> </content> </entry> <entry> <title>(Re)learning Java - My takeaways</title> <link href="gemini://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways.gmi" /> <id>gemini://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways.gmi</id> <updated>2022-12-24T23:18:40+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>As a regular participant in the annual Pet Project competition at work, I always try to find a project where I can learn something new. In this post, I would like to share my takeaways after revisiting Java. You can read about my motivations in my 'Creative universe' post:</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1>(Re)learning Java - My takeaways</h1> <p class="quote"><i>Published at 2022-12-24T23:18:40+02:00</i></p> <a href="https://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways/learnjava.jpg"><img src="https://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways/learnjava.jpg" /></a><br /> <p>As a regular participant in the annual Pet Project competition at work, I always try to find a project where I can learn something new. In this post, I would like to share my takeaways after revisiting Java. You can read about my motivations in my "Creative universe" post:</p> <a class="textlink" href="https://foo.zone/gemfeed/2022-04-10-creative-universe.html">Creative universe</a><br /> <p>I have been programming in Java back in the days as a university student, and even my Diploma Thesis I implemented in Java (it would require some overhaul so that it is fully compatible with a recent version of Java, though - It still compiles and runs, but with a lot of warnings, though!):</p> <a class="textlink" href="https://codeberg.org/snonux/vs-sim">VS-Sim: Distributed systems simulator</a><br /> <p>However, after that, I became a Linux Sysadmin and mainly continued programming in Perl, Puppet, bash, and a little Python. For personal use, I also programmed a bit in Haskell and C. After my Sysadmin role, I moved to London and became a Site Reliability Engineer (SRE), where I mainly programmed in Ruby, bash, Puppet and Golang and a little bit of C. </p> <p>At my workplace, as an SRE, I don't do Java a lot. I have been reading Java code to understand the software better so I can apply and suggest workarounds or fixes to existing issues and bugs. However, most of our stack is in Java, and our Software Engineers use Java as their primary programming language.</p> <h2>Stuck at Java 1.4</h2> <p>Over time, I had been missing out on many new features that were added to the language since Java 1.4, so I decided to implement my next Pet Project in Java and learn every further aspect of the language as my main goal. Of course, I still liked the idea of winning a Pet Project Prize, but my main objective was to level up my Java skills.</p> <h2>(Re)learning & upskilling to Java 18</h2> <h3>Effective Java</h3> <p>This book was recommended by my brother and also by at least another colleague at work to be one of the best, if not the best, book about Java programming. I read the whole book from the beginning to the end and immersed myself in it. I fully agree; this is a great book. Every Java developer or Java software engineer should read it!</p> <a href="https://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways/effective-java.jpg"><img src="https://foo.zone/gemfeed/2022-12-24-ultrarelearning-java-my-takeaways/effective-java.jpg" /></a><br /> <p>I recommend reading the 90-part effective Java Series on <span class="inlinecode">dev.to</span>. It's a perfect companion to the book as it explains all the chapters again but from a slightly different perspective and helps you to really understand the content.</p> <a class="textlink" href="https://dev.to/kylec32/series/2292">Kyle Carter's 90-part Effective Java Series </a><br /> <h3>Java Pub House</h3> <p>During my lunch breaks, I usually have a walk around the block or in a nearby park. I used that time to listen to the Java Pub House podcast. I listened to *every* episode and learned tons of new stuff. I can highly recommend this podcast. Especially GraalVM, a high-performance JDK distribution written for Java and other JVM languages, captured my attention. GraalVM can compile Java code into native binaries, improving performance and easing the distribution of Java programs. Because of the latter, I should release a VS-Sim GraalVM edition one day through a Linux AppImage ;-).</p> <a class="textlink" href="https://www.javapubhouse.com">https://www.javapubhouse.com</a><br /> <a class="textlink" href="https://www.graalvm.org">https://www.graalvm.org</a><br /> <h3>Java Concurrency course</h3> <p>I also watched a course on O'Reilly Safari Books online about Java Concurrency. That gave an excellent refresher on how the Java thread pools work and what were the concurrency primitives available in the standard library.</p> <h3>Read a lot of Java code</h3> <p>First, the source code is often the best documentation (if programmed nicely), and second, it helps to get the hang of the language and standard practices. I started to read more and more Java code at work. I did that whenever I had to understand how something, in particular, worked (e.g. while troubleshooting and debugging an issue). </p> <h3>Observed Java code reviews</h3> <p>Another great way to get the hang of Java again was to sneak into the code reviews of the Software Engineer colleagues. They are the expert on the matter and are a great source to copy knowledge. It's OK to stay passive and only follow the reviews. Sometimes, it's OK to step up and take ownership of the review. The developers will also always be happy to answer any naive questions which come up.</p> <h3>Took ownership of a roadmap-Java project</h3> <p>Besides my Pet Project, I also took ownership of a regular roadmap Java project at work, making an internal Java service capable of running in Kubernetes. This was a bunch of minor changes and adding a bunch of classes and unit tests dealing with the statelessness and a persistent job queue in Redis. The job also involved reading and understanding a lot of already existing Java code. It wasn't part of my job description, but it was fun, and I learned a lot. The service runs smoothly in production now. Of course, all of my code got reviewed by my Software Engineering colleagues.</p> <h2>The good</h2> <p>From the new language features and syntaxes, there are many personal takeaways, and I can't possibly list them all, but here are some of my personal highlights:</p> <ul> <li>Static factory methods and public constructors both have their uses, and it pays to understand their relative merits. Often static factories are preferable (cleaner and easier to read), so avoid the reflex to provide public constructors without first considering static factories.</li> <li>Java streams were utterly new to me. I love how they can help to produce more compact code. But it's challenging to set the line of when enough is enough. Overusing streams can have the opposite effect: Code becomes more complex and challenging to understand. And it is so easy to parallelize the computation of streams by "just" marking the stream as <span class="inlinecode">.parallel()</span> (more on that later in this post).</li> <li>Overall, object-oriented languages tend to include more and more functional paradigms. The functional interfaces, which Java provides now, are fantastic. Their full powers shine in combination with the use of streams. An entire book can be written about Java functional interfaces, so I leave it to you to do any further digging.</li> <li>Local type inference help to reduce even more boilerplate code. E.g. instead of <span class="inlinecode">Hash<String,Hash<String,String>> foo = new Hash<String,Hash<String,String>>();</span> it's possible to just write <span class="inlinecode">var foo = new Hash<String,Hash<String,String>>();</span></li> <li>Class inheritance isn't the preferred way anymore to structure reusable code. Now, it's composition over inheritance. E.g. use dependency injection (inject one object to another object through its constructor) or prefer interfaces (which now also support default implementations of methods) over class inheritance. This makes sense to me as I do that already when I program in Ruby. </li> <li>I learned the <span class="inlinecode">try-with-resources</span> pattern. Very useful in ensuring closing resources again correctly. No need anymore for complicated and nested <span class="inlinecode">finally</span>-blocks, which used to be almost impossible to get right previously in case of an error condition (e.g. I/O error somewhere deeply nested in an input or output stream).</li> <li>Optimize only when required. It's considered to be cleaner to prefer immutable variables (declaring them as <span class="inlinecode">final</span>). I knew that already, but for Java, it always seemed to be a waste of resources (creating entirely new objects whenever states change), but apparently, it's okay. Java also does many internal tricks for performance optimization here, e.g. interning strings.</li> <li>I learned about the concept of static member classes and the difference between non-static member classes (also sometimes known as inner classes). Non-static member classes have full access to all members of their outer class (think of closure). In contrast, static member classes act like completely separate classes without such access but provide the benefit of a nested name that can help group functionality in the code.</li> <li>I learned about the existence of thread-local variables. These are only available to the current thread and aren't shared with other threads.</li> <li>I learned about the concept of Java modules, which help to structure larger code bases better. The traditional Java packages are different. </li> <li>I learned to love the new <span class="inlinecode">Optional</span> type. I already knew the concept from Haskell, where <span class="inlinecode">Maybe</span> would be the corresponding type. <span class="inlinecode">Optional</span> helps to avoid <span class="inlinecode">null</span>-pointers but comes with some (minimal) performance penalty. So, in the end, you end up with both <span class="inlinecode">Optional</span> types and <span class="inlinecode">null</span>-pointers in your code (depending on the requirements). But I like to prefer <span class="inlinecode">Optional</span> over <span class="inlinecode">null</span>-pointer when "no result" is a valid return value from a method.</li> <li>The <span class="inlinecode">enum</span> type is way more powerful than I thought. Initially, I felt an <span class="inlinecode">enum</span> could only be used to define a list of constants and then to compare an instance to another instance of the same. An <span class="inlinecode">enum</span> is still there to define a list of constants, but it's also almost like a <span class="inlinecode">class</span> (you can implement constructors, and methods, inherit from other enums). There are quite a lot of possible use cases.</li> <li>A small but almost the most helpful thing I learned is always to use the <span class="inlinecode">@Override</span> annotation when overriding a method from a parent class. If done, Java helps to detect any typos or type errors when overriding methods. That's useful and spares a lot of time debugging where a method was mistakenly overloaded but not overridden.</li> <li>Lambdas are much cleaner, shorter and easier to read than anonymous classes. Many Java libraries require passing instances of (anonymous) classes (e.g. in Swing) to other objects. Lambdas are so lovely because they are primarily compatible with the passing of anonymous classes, so they are a 1:1 replacement in many instances. Lambdas also play very nicely together with the Java functional interfaces, as each Lambda got a type, and the type can be an already existing functional interface (or, if you got a particular case, you could define your custom functional interface for your own set of Lambdas, of course).</li> <li>I love the concept of Java records. You can think of a record as an immutable object holding some data (as members). They are ideal for pipe and stream processing. They are much easier to define (with much less boilerplate) and come with write protection out of the box.</li> </ul> <h2>The bad and the ugly</h2> <p>There are also many ugly corners in Java. Many are doomed to stay there forever due to historical decisions and ensuring backward compatibility with older versions of the Java language and the Java standard library. </p> <ul> <li>Finalizers and cleaners seem obsolete, fragile and still, you can use them.</li> <li>In many cases, extreme caution needs to be taken to minimize the accessibility of class members. You might think that Java provides the best "out-of-the-box" solution for proper encapsulation, but the language has many loopholes.</li> <li>In the early days, Java didn't support generics yet. So what you would use is to cast everything to <span class="inlinecode">Object</span>. Java now fully supports generics (for a while already), but you can still cast everything to <span class="inlinecode">Object</span> and back to whatever type you want. That can lead to nasty runtime errors. Also, there's a particular case to convert between an Array of Object to an Array of String or from an Array of String to a List of String. Java can't convert between these types automatically, and extreme caution needs to be taken when enforcing so (e.g. through explicit type casts). In many of these cases, Java would print out warnings that need to be manually suppressed via annotations. Programming that way, converting data between old and new best practices, is clunky.</li> <li>If you don't know what you do, Java streams can be all wrong. Side effects in functions used in streams can be nasty to debug. Also, don't just blindly add a <span class="inlinecode">.parallel()</span> to your stream. You need to understand what the stream does and how it exactly works; otherwise, parallelizing a stream can impact the performance drastically (in a negative way). There need to be language constructs preventing you from doing the wrong things. That's so much easier to do it right in a purely functional programming language like Haskell.</li> <li>Java is a pretty old language (already), so there are many obstacles to consider. There are too many exceptions and different outcomes of how Java code can behave. In most cases, when you write an API, every method you program needs to be documented so the user won't encounter any surprises using your code. Writing and reading a lot of documentation seems to be quite the overhead when the method name is already descriptive.</li> <li>Java serialization is broken. It works, and the language still supports it, but you better not use Java's native way of object serialization and deserialization. Unbelievable how much can get wrong here, especially regarding security (injecting arbitrary code).</li> <li>Being a bit spoiled by Golang's Goroutines, I was shocked about the limitations of the Java threads. They are resource hungry, and you can't just spin up millions of them as you would with Goroutines. I knew this limitation of threads already (as it's not a problem of the language but of how threads work in the OS), but still, I was pretty shocked when I got reminded of them again. Of course, there's a workaround: Use asynchronous sockets so that you don't waste a whole thread on a single I/O operation (in my case, waiting for a network response). Golang's runtime does that automatically for you: An OS thread will be re-used for other tasks until the network socket unblocks. Every modern programming language should support lightweight threads or Coroutines like Go's Goroutines. </li> </ul> <h2>Conclusion</h2> <p>While (re)learning Java, I felt like a student again and was quite enthusiastic about it initially. I invested around half a year, immersing myself intensively in Java (again). The last time I did that was many years ago as a university student. I even won a Silver Prize at work, implementing a project this year (2022 as of writing this). I feel confident now with understanding, debugging and patching Java code at work, which boosted my debugging and troubleshooting skills. </p> <p>I don't hate Java, but I don't love programming in it, either. I will, I guess, always see Java as the necessary to get stuff done (reading code to understand how the service works, adding a tiny feature to make my life easier, adding a quick bug fix to overcome an obstacle...).</p> <p>Although Java has significantly improved since 1.4, its code still tends to be more boilerplate. Not mainly because due to lines of code (Golang code tends to be quite repetitive, primarily when no generics are used), but due to the levels of abstractions it uses. Class hierarchies can be ten classes or deeper, and it is challenging to understand what the code is doing. Good test coverage and much documentation can mitigate the problem partially. Big enterprises use Java, and that also reflects to the language. There are too many libraries and too many abstractions that are bundled with too many legacy abstractions and interfaces and too many exceptions in the library APIs. There's even an external library named Lombok, which aims to reduce Java boilerplate code. Why is there a need for an external library? It should be all part of Java itself.</p> <a class="textlink" href="https://projectlombok.org/">https://projectlombok.org/</a><br /> <p>Java needs a clean cut. The clean cut shall be incompatible with previous versions of Java and only promote modern best practices without all the legacy burden carried around. The same can be said for other languages, e.g. Perl, but in Perl, they already attack the problem with the use of flags which change the behaviour of the language to more modern standards. Or do it like Python, where they had a hard (incompatible) cut from version 2 to version 3. It will be painful, for sure. But that would be the only way I would enjoy using that language as one of my primary languages to code new stuff regularly. Currently, my Java will stay limited to very few projects and the more minor things already mentioned in this post. </p> <p>Am I a Java expert now? No, by far not. But I am better now than before :-).</p> <p>E-Mail your comments to hi@paul.cyou :-)</p> <a class="textlink" href="../">Back to the main site</a><br /> </div> </content> </entry> <entry> <title>I tried (Doom) Emacs, but I switched back to (Neo)Vim</title> <link href="gemini://foo.zone/gemfeed/2022-11-24-i-tried-emacs-but-i-switched-back-to-neovim.gmi" /> <id>gemini://foo.zone/gemfeed/2022-11-24-i-tried-emacs-but-i-switched-back-to-neovim.gmi</id> <updated>2022-11-24T11:17:15+02:00</updated> <author> <name>Paul Buetow</name> <email>hi@paul.cyou</email> </author> <summary>Art by \ \_! / __!</summary> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <h1 style='display: inline'>I tried (Doom) Emacs, but I switched back to (Neo)Vim</h1><br /> <br /> <span class='quote'>Published at 2022-11-24T11:17:15+02:00; Updated at 2022-11-26</span><br /> <br /> <pre> _/ \ _(\(o / \ / _ ^^^o / ! \/ ! '!!!v' ! ! \ _' ( \____ ! . \ _!\ \===^\) Art by \ \_! / __! Gunnar Z. \! / \ <--- Emacs is a giant dragon (\_ _/ _\ ) \ ^^--^^ __-^ /(__ ^^----^^ "^--v' </pre> <br /> <span>As a long-lasting user of Vim (and NeoVim), I always wondered what GNU Emacs is really about, so I decided to try it. I didn't try vanilla GNU Emacs, but Doom Emacs. I chose Doom Emacs as it is a neat distribution of Emacs with Evil mode enabled by default. Evil mode allows Vi(m) key bindings (so to speak, it's emulating Vim within Emacs), and I am pretty sure I won't be ready to give up all the muscle memory I have built over more than a decade.</span><br /> <br /> <a class='textlink' href='https://www.gnu.org/software/emacs/'>GNU Emacs</a><br /> <a class='textlink' href='https://github.com/doomemacs/'>Doom Emacs</a><br /> <br /> <span>I used Doom Emacs for around two months. Still, ultimately I decided to switch back to NeoVim as my primary editor and IDE and Vim (usually pre-installed on Linux-based systems) and Nvi (usually pre-installed on *BSD systems) as my "always available editor" for quick edits. (It is worth mentioning that I don't have a high opinion on whether Vim or NeoVim is the better editor, I prefer NeoVim as it comes with better defaults out of the box, but there is no real blocker to use Vim instead).</span><br /> <br /> <a class='textlink' href='https://www.vim.org'>Vim</a><br /> <a class='textlink' href='https://neovim.io'>NeoVim</a><br /> <br /> <span>So why did I switch back to the Vi-family?</span><br /> <br /> <h2 style='display: inline'>Emacs is a giant dragon</h2><br /> <br /> <span>Emacs feels like a giant dragon as it is much more than an editor or an integrated development environment. Emacs is a whole platform on its own. There's an E-Mail client, an IRC client, or even games you can run within Emacs. And you can also change Emacs within Emacs using its own Lisp dialect, Emacs Lisp (Emacs is programmed in Emacs Lisp). Therefore, Emacs is also its own programming language. You can change every aspect of Emacs within Emacs itself. People jokingly state Emacs is an operating system and that you should directly use it as the <span class='inlinecode'>init 1</span> process (if you don't know what the <span class='inlinecode'>init 1</span> process is: Under UNIX and similar operating systems, it's the very first userland processed launched. That's usually <span class='inlinecode'>systemd</span> on Linux-based systems, <span class='inlinecode'>launchd</span> on macOS, or any other init script or init system used by the OS)!</span><br /> <br /> <span>In many aspects, Emacs is like shooting at everything with a bazooka! However, I prefer it simple. I only wanted Emacs to be a good editor (which it is, too), but there's too much other stuff in Emacs that I don't need to care about! Vim and NeoVim do one thing excellent: Being great text editors and, when loaded with plugins, decent IDEs, too. </span><br /> <br /> <h2 style='display: inline'>Magit love</h2><br /> <br /> <span>I almost fell in love with Magit, an integrated Git client for Emacs. But I think the best way to interact with Git is to use the <span class='inlinecode'>git</span> command line directly. I don't worry about typing out all the commands, as the most commonly used commands are in my shell history. Other useful Git programs I use frequently are <span class='inlinecode'>bit</span> and <span class='inlinecode'>tig</span>. Also, get a mechanical keyboard that makes hammering whole commands into the terminal even more enjoyable.</span><br /> <br /> <a class='textlink' href='https://magit.vc/'>Magit</a><br /> <a class='textlink' href='https://github.com/jonas/tig'>Tig</a><br /> <br /> <span>Magit is pretty neat for basic Git operations, but I found myself searching the internet for the correct sub-commands to do the things I wanted to do in Git. Mainly, the way how branches are managed is confusing. Often, I fell back to the command line to fix up the mess I produced with Magit (e.g. accidentally pushing to the wrong remote branch, so I found myself fixing things manually on the terminal with the <span class='inlinecode'>git</span> command with forced pushes....). Magit is hotkey driven, and common commands are quickly explorable through built-in hotkey menus. Still, I found it challenging to navigate to more advanced Git sub-commands that way which was much easier accomplished by using the <span class='inlinecode'>git</span> command directly.</span><br /> <br /> <h2 style='display: inline'>Graphical UI</h2><br /> <br /> <span>If there is one thing I envy about Emacs is that it's a graphical program, whereas the Vi-family of editors are purely terminal-based. I see the benefits of being a graphical program as this enables the use of multiple fonts simultaneously to embed pictures and graphs (that would be neat as a Markdown preview, for example). There's also GVim (Vim with GTK UI), but that's more of an afterthought.</span><br /> <br /> <span>There are now graphical front-end clients for NeoVim, but I still need to dig into them. Let me know your experience if you have one. Luckily, I don't rely on something graphical in my text editor, but it would improve how the editor looks and feels. UTF8 can already do a lot in the terminal, and terminal emulators also allow you to use TrueType fonts. Still, you will always be limited to one TTF font for the whole terminal, and it isn't possible to have, for example, a different font for headings, paragraphs, etc... you get the idea. TTF+UTF8 can't beat authentic graphics. </span><br /> <br /> <h2 style='display: inline'>Scripting it</h2><br /> <br /> <span>It is possible to customize every aspect of Emacs through Emacs Lisp. I have done some Elk Scheme programming in the past (a dialect of Lisp), but that was a long time ago, and I am not willing to dive here again to customize my environment. I would instead take the pragmatic approach and script what I need in VimScript (a terrible language, but it gets the job done!). I watched Damian Conway's VimScript course on O'Reilly Safari Books Online, which I greatly recommend. Yes, VimScript feels clunky, funky and weird and is far less elegant than Lisp, but it gets its job done - in most cases! (That reminds me that the Vim team has announced a new major version of VimScript with improvements and language changes made - I haven't gotten to it yet - but I assume that VimScript will always stay VimScript).</span><br /> <br /> <a class='textlink' href='https://en.wikipedia.org/wiki/Emacs_Lisp'>Emacs Lisp</a><br /> <a class='textlink' href='http://sam.zoy.org/elk/'>Elk Scheme</a><br /> <a class='textlink' href='http://vimscript.org/'>VimScript</a><br /> <a class='textlink' href='https://www.oreilly.com/library/view/scripting-vim/9781491996287/'>Scripting Vim by Damian Conway</a><br /> <br /> <span>NeoVim is also programmable with Lua, which seems to be a step up and Vim comes with a Perl plugin API (which was removed from NeoVim, but that is a different story - why would someone remove the most potent mature text manipulation programming language from one of the most powerful text editors?).</span><br /> <br /> <a class='textlink' href='https://neovim.io/doc/user/lua.html'>NeoVim Lua API</a><br /> <br /> <span>One example is my workflow of how I compose my blog articles (e.g. this one you are currently reading): I am writing everything in NeoVim, but I also want to have every paragraph checked against Grammarly (as English is not my first language). So I write a whole paragraph, then I select the entire paragraph via visual selection with <span class='inlinecode'>SHIFT+v</span>, and then I press <span class='inlinecode'>,y</span> to yank the paragraph to the systems clipboard, then I paste the paragraph to Grammarly's browser window with <span class='inlinecode'>CTRL+v</span>, let Grammarly suggest the improvements, and then I copy the result back with <span class='inlinecode'>CTRL+c</span> to the system clipboard and in NeoVim I type <span class='inlinecode'>,i</span> to insert the result back overriding the old paragraph (which is still selected in visual mode) with the new content. That all sounds a bit complicated, but it's surprisingly natural and efficient.</span><br /> <br /> <span>To come back to the example, for the clipboard integration, I use this small VimScript snippet, and I didn't have to dig into any Lisp or Perl for this:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><i><font color="#9A1900">" Clipboard</font></i> vnoremap ,<b><font color="#0000FF">y</font></b> !pbcopy<font color="#FF6600"><CR></font>ugv vnoremap ,<b><font color="#0000FF">i</font></b> !pbpaste<font color="#FF6600"><CR></font> nmap ,<b><font color="#0000FF">i</font></b> !wpbpaste<font color="#FF6600"><CR></font> </pre> <br /> <span>That's only a very few lines and does precisely what I want. It's quick and dirty but get's the job done! If VimScript becomes too cumbersome, I can use Lua for NeoVim scripting.</span><br /> <br /> <h2 style='display: inline'>The famous Emacs Org mode</h2><br /> <br /> <span>Org-mode is an Emacs mode for keeping notes, authoring documents, computational notebooks, literate programming, maintaining to-do lists, planning projects, and more — in a fast and effective plain-text system. There's even a dedicated website for it:</span><br /> <br /> <a class='textlink' href='https://orgmode.org/'>https://orgmode.org/</a><br /> <br /> <span>In short, Org-mode is an "interactive markup language" that helps you organize everything mentioned above. I rarely touched the surface during my two-month experiment with Emacs, and I am impressed by it, so I see the benefits of having that. But it's not for me.</span><br /> <br /> <span>I use "Dead Tree Mode" to organize my work and notes. Dead tree? Yeah, I use an actual pen and a real paper journal (Leuchtturm or a Moleskine and a set of coloured <span class='inlinecode'>0.5</span> Muji Pens are excellent choices). That's far more immersive and flexible than a computer program can ever be. Yes, some automation and interaction with the computer (like calendar scheduling etc.) are missing. Still, an actual paper journal forces you to stay simple and focus on the actual work rather than tinkering with your computer program. (But I could not resist, and I wrote a VimScript which parses a table of contents page in Markdown format of my scanned paper journals, and NeoVim allows me to select a topic so that the corresponding PDF scan on the right journal page gets opened in an external PDF viewer (the PDF viewer is <span class='inlinecode'>zathura</span>, it uses Vi-keybindings, of course) :-). (See the appendix of this blog post for that script).</span><br /> <br /> <a class='textlink' href='https://pwmt.org/projects/zathura/'>Zathura</a><br /> <br /> <span>On the road, I also write some of my notes in Markdown format to NextCloud Notes, which is editable from my phone and via NeoVim on my computers. Markdown is much less powerful than Org-mode, but I prefer it the simple way. There's a neat terminal application, <span class='inlinecode'>ranger</span>, which I use to browse my NextCloud Notes when they are synced to a local folder on my machine. <span class='inlinecode'>ranger</span> is a file manager inspired by Vim and therefore makes use of Vim keybindings and it feels just natural to me. </span><br /> <br /> <a class='textlink' href='https://github.com/ranger/ranger'>Ranger - A Vim inspired file manager</a><br /> <span>Did I mention that I also use my <span class='inlinecode'>zsh</span> (my default shell) and my <span class='inlinecode'>tmux</span> (terminal multiplexer) in Vi-mode?</span><br /> <br /> <a class='textlink' href='https://zsh.sourceforge.io/'>Z shell</a><br /> <a class='textlink' href='https://github.com/tmux/tmux'>tmux terminal multiplexer</a><br /> <br /> <h2 style='display: inline'>Seeking simplicity</h2><br /> <br /> <span>I am not ready to dive deep into the whole world of Emacs. I prefer small and simple tools as opposed to complex tools. Emacs comes with many features out of the box, whereas in Vim/NeoVim, you would need to install many plugins to replicate some of the behaviour. Yes, I need to invest time managing all the Vim/NeoVim plugins I use, but I feel more in control compared to Doom Emacs, where a framework around vanilla Emacs manages all the plugins. I could use vanilla Emacs and manage all my plugins the vanilla way, but for me, it's not worth the effort to learn and dive into that as all that I want to do I can already do with Vim/NeoVim.</span><br /> <br /> <span>I am not saying that Vim/NeoVim are simple programs, but they are much simpler than Emacs with much smaller footprints; furthermore, they appear to be more straightforward as I am used to them. I only need Vim/NeoVim to be an editor, an IDE (through some plugins), and nothing more.</span><br /> <br /> <h2 style='display: inline'>Conclusion</h2><br /> <br /> <span>I understand the Emacs users now. Emacs is an incredibly powerful platform for almost everything, not just text editing. With Emacs, you can do nearly everything (Writing, editing, programming, calendar scheduling and note taking, Jira integration, playing games, listening to music, reading/writing emails, browsing the web, using as a calculator, generating HTML pages, configuring interactive menus, jumping around between every feature and every file within one single session, chat on IRC, surf the Gopherspace, ... the options are endless....). If you want to have one piece of software which rules it all and you are happy to invest a large part of your time in your platform: Pick Emacs, and over time Emacs will become "your" Emacs, customized to your own needs and change the way it works, which makes the Emacs users stick even more to it.</span><br /> <br /> <span>Vim/NeoVim also comes with a very high degree of customization options, but to a lesser extreme than Emacs (but still, a much higher degree than most other editors out there). If you want the best text editor in the world, which can also be tweaked to be a decent IDE, you are only looking for: Pick Vim or NeoVim! You would also need to invest a lot of time in learning, tweaking and customizing Vim/NeoVim, but that's a little more straightforward, and the result is much more lightweight once you get used to the "Vi way of doing things" you never would want to change back. I haven't tried the Emacs vanilla keystrokes, but they are terrible (that's probably one of the reasons why Doom Emacs uses Vim keybindings by default).</span><br /> <br /> <span class='quote'>Update: One reader recommended to have a look at NvChad. NvChad is a NeoVim config written in Lua aiming to provide a base configuration with very beautiful UI and blazing fast startuptime (around <span class='inlinecode'>0.02</span> secs ~ <span class='inlinecode'>0.07</span> secs). They tweak UI plugins such as telescope, nvim-tree, bufferline etc well to provide an aesthetic UI experience. That sounds interesting!</span><br /> <br /> <a class='textlink' href='https://github.com/NvChad/NvChad'>https://github.com/NvChad/NvChad</a><br /> <br /> <span>E-Mail your comments to hi@paul.cyou :-)</span><br /> <br /> <a class='textlink' href='../'>Back to the main site</a><br /> <br /> <h1 style='display: inline'>Appendix</h1><br /> <br /> <span>This is the VimScript I mentioned earlier, which parses a table of contents index of my scanned paper journals and opens the corresponding PDF at the right page in <span class='inlinecode'>zathura</span>:</span><br /> <br /> <!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><b><font color="#0000FF">function</font></b>! ReadJournalPageNumber<font color="#990000">()</font> <b><font color="#0000FF">let</font></b> page <font color="#990000">=</font> <b><font color="#000080">expand</font></b><font color="#990000">(</font><font color="#FF0000">"<cword>"</font><font color="#990000">)</font> <b><font color="#0000FF">if</font></b> page <font color="#990000">!~</font># <font color="#FF0000">'^</font><font color="#CC33CC">\d\+</font><font color="#FF0000">