<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Senior Software Engineer Reads</title><link>https://llcawthorne.github.io/</link><description>Recent content on Senior Software Engineer Reads</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 23 Nov 2026 06:00:00 -0500</lastBuildDate><atom:link href="https://llcawthorne.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>100 Exercises to Learn Rust</title><link>https://llcawthorne.github.io/posts/100-exercises-to-learn-rust/</link><pubDate>Mon, 23 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/100-exercises-to-learn-rust/</guid><description>&lt;p&gt;&lt;img alt="100 Exercises to Learn Rust cover" loading="lazy" src="https://llcawthorne.github.io/posts/100-exercises-to-learn-rust/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rust-exercises.com/100-exercises/"&gt;&lt;em&gt;100 Exercises to Learn Rust&lt;/em&gt;&lt;/a&gt; by
Luca Palmieri was easily the most effective, hands-on resource I encountered
while learning Rust. While &lt;em&gt;Rustlings&lt;/em&gt; has its place for drilling isolated
compiler errors, its exercises often feel too trivial and fragmented to build
genuine architectural intuition. Luca&amp;rsquo;s course, by contrast, anchors the
language mechanics to a continuous, realistic project that forces you to
grapple with how Rust features fit together in practice. (Working through it in
RustRover with inline AI completion turned off also kept me honest, since I
had to actually reason through every borrow-checker error myself.)&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="100 Exercises to Learn Rust cover" loading="lazy" src="/posts/100-exercises-to-learn-rust/images/cover.jpg"></p>
<p><a href="https://rust-exercises.com/100-exercises/"><em>100 Exercises to Learn Rust</em></a> by
Luca Palmieri was easily the most effective, hands-on resource I encountered
while learning Rust. While <em>Rustlings</em> has its place for drilling isolated
compiler errors, its exercises often feel too trivial and fragmented to build
genuine architectural intuition. Luca&rsquo;s course, by contrast, anchors the
language mechanics to a continuous, realistic project that forces you to
grapple with how Rust features fit together in practice. (Working through it in
RustRover with inline AI completion turned off also kept me honest, since I
had to actually reason through every borrow-checker error myself.)</p>
<p>The running project, building a ticket management system, was great motivation.
Virtually every software developer has professional experience living inside
ticket trackers, making the problem domain immediately intuitive without
requiring any domain onboarding. We certainly didn&rsquo;t build Jira; the domain
model stayed intentionally lean with titles, descriptions, IDs, and statuses.
That lightweight scope was an asset rather than a drawback: it gave just enough
structural meat to naturally motivate constructor validation, state transitions,
collection trade-offs (<code>Vec</code> to <code>HashMap</code> to <code>BTreeMap</code>), <code>Index</code> and <code>IndexMut</code>
mechanics, and eventually multi-threaded client-server channels without getting
bogged down in domain trivia:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Chapter 3 starts with basic struct encapsulation and invariant validation:
</span></span></span><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Ticket</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">title</span>: <span class="nb">String</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">description</span>: <span class="nb">String</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">status</span>: <span class="nb">String</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">Ticket</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">title</span>: <span class="nb">String</span><span class="p">,</span><span class="w"> </span><span class="n">description</span>: <span class="nb">String</span><span class="p">,</span><span class="w"> </span><span class="n">status</span>: <span class="nb">String</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">title</span><span class="p">.</span><span class="n">is_empty</span><span class="p">()</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">title</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">50</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="fm">panic!</span><span class="p">(</span><span class="s">&#34;Title must not be empty and cannot exceed 50 bytes&#34;</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">description</span><span class="p">.</span><span class="n">is_empty</span><span class="p">()</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">description</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">500</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="fm">panic!</span><span class="p">(</span><span class="s">&#34;Description must not be empty and cannot exceed 500 bytes&#34;</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s">&#34;To-Do&#34;</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s">&#34;In Progress&#34;</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s">&#34;Done&#34;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="fm">panic!</span><span class="p">(</span><span class="s">&#34;Only `To-Do`, `In Progress`, and `Done` statuses are allowed&#34;</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">Ticket</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">title</span><span class="p">,</span><span class="w"> </span><span class="n">description</span><span class="p">,</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">title</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">str</span> <span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="o">&amp;</span><span class="bp">self</span><span class="p">.</span><span class="n">title</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>I know Luca also has a dedicated <em>Build Your Own Jira with Rust</em> workshop, and I
wonder if that repository builds out a more fully functional system. Given how
clean and approachable his explanations and architectural style are, it&rsquo;s
definitely something I want to skim on GitHub.</p>
<p>Where this resource really shines is as a companion to
<a href="https://rust-book.cs.brown.edu"><em>The Rust Programming Language</em> (TRPL)</a>.
TRPL is indispensable for theory and foundational language semantics, but it
is theory-heavy and its hands-on projects are sparse. <em>100 Exercises</em> fills
that exact void. It bridges the gap between reading about ownership and
actually fighting the borrow checker across thread boundaries, interior
mutability (<code>RefCell</code>, <code>Mutex</code>, <code>RwLock</code>), and scoped threads.</p>
<p>Chapter 7 (Threads) was the highlight of the second half, even if its ending
felt a little anti-climactic: after spending nearly the entire chapter building
out a channel-based client/server architecture, the final exercise swaps it out
entirely for <code>Arc&lt;RwLock&lt;TicketStore&gt;&gt;</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Chapter 7 builds out a multi-threaded client-server architecture using channels:
</span></span></span><span class="line"><span class="cl"><span class="k">enum</span> <span class="nc">Command</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">Insert</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">draft</span>: <span class="nc">TicketDraft</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">response_channel</span>: <span class="nc">SyncSender</span><span class="o">&lt;</span><span class="n">TicketId</span><span class="o">&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">},</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">Get</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">id</span>: <span class="nc">TicketId</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">response_channel</span>: <span class="nc">SyncSender</span><span class="o">&lt;</span><span class="nb">Option</span><span class="o">&lt;</span><span class="n">Ticket</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">},</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">TicketStoreClient</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">sender</span>: <span class="nc">SyncSender</span><span class="o">&lt;</span><span class="n">Command</span><span class="o">&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">TicketStoreClient</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">insert</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">draft</span>: <span class="nc">TicketDraft</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">TicketId</span><span class="p">,</span><span class="w"> </span><span class="n">OverloadedError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">response_sender</span><span class="p">,</span><span class="w"> </span><span class="n">response_receiver</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span>::<span class="n">sync</span>::<span class="n">mpsc</span>::<span class="n">sync_channel</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">sender</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="p">.</span><span class="n">try_send</span><span class="p">(</span><span class="n">Command</span>::<span class="n">Insert</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="n">draft</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="n">response_channel</span>: <span class="nc">response_sender</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="p">})</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="p">.</span><span class="n">map_err</span><span class="p">(</span><span class="o">|</span><span class="n">_</span><span class="o">|</span><span class="w"> </span><span class="n">OverloadedError</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="n">response_receiver</span><span class="p">.</span><span class="n">recv</span><span class="p">().</span><span class="n">unwrap</span><span class="p">())</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>In Go or Elixir, the channel implementation would have been the final word, so
pivoting to locks at the last minute felt abrupt, and we barely got to spend any
time with that final concurrent design before moving on. Still, it drove home an
important Rust distinction: because <code>Send</code> and <code>Sync</code> guarantee
data-race freedom at compile time, <code>Arc&lt;RwLock&lt;T&gt;&gt;</code> is often the cleaner,
lower-overhead choice for shared in-memory state, leaving channels for work
queues and decoupled tasks:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// The final concurrent iteration swaps out channels for an in-memory lock:
</span></span></span><span class="line"><span class="cl"><span class="cp">#[derive(Clone)]</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">TicketStore</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">tickets</span>: <span class="nc">Arc</span><span class="o">&lt;</span><span class="n">RwLock</span><span class="o">&lt;</span><span class="n">BTreeMap</span><span class="o">&lt;</span><span class="n">TicketId</span><span class="p">,</span><span class="w"> </span><span class="n">Ticket</span><span class="o">&gt;&gt;&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">TicketStore</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="n">tickets</span>: <span class="nc">Arc</span>::<span class="n">new</span><span class="p">(</span><span class="n">RwLock</span>::<span class="n">new</span><span class="p">(</span><span class="n">BTreeMap</span>::<span class="n">new</span><span class="p">())),</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">get</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">id</span>: <span class="nc">TicketId</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Ticket</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">store</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">tickets</span><span class="p">.</span><span class="n">read</span><span class="p">().</span><span class="n">unwrap</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">store</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="o">&amp;</span><span class="n">id</span><span class="p">).</span><span class="n">cloned</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Chapter 8 (Futures), by comparison, felt much thinner. Instead of continuing to
evolve <code>TicketStore</code>, it drops down to small, contrived <code>TcpListener</code> echo
examples (even looping back to threads via <code>spawn_blocking</code>), and leaves async
primitives like <code>Semaphore</code> and <code>tokio::sync</code> channels as concepts rather than
real exercises. You come away with the core mental model (<code>Future</code> state
machines, <code>Send</code> across <code>.await</code> yield points, async-aware locks, and
cancellation), but not much muscle memory.</p>
<p>The book wraps up with a Final Challenge to put an HTTP API in front of the
ticket store. I really liked that Luca provided the spec as a <code>requests.http</code>
file rather than rigid unit tests, because it gives you a clear contract while
leaving the implementation completely open. Rather than guessing my way through
<code>axum</code>, <code>serde</code>, and <code>tokio</code> all at once, though, I&rsquo;m shelving the Final
Challenge for now and heading straight into Luca&rsquo;s <em>Zero to Production in Rust</em>.
Once I have a proper foundation in Tokio and Rust web services, I&rsquo;ll come back
and tackle it from a place of knowledge rather than trial and error.</p>
<p>Full <a href="https://github.com/llcawthorne/book-notes/blob/main/rust/100-exercises/book-notes.md">book notes</a>.</p>
]]></content:encoded></item><item><title>Rustlings</title><link>https://llcawthorne.github.io/posts/rustlings/</link><pubDate>Fri, 20 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/rustlings/</guid><description>&lt;p&gt;I worked through &lt;a href="https://rustlings.rust-lang.org/"&gt;Rustlings&lt;/a&gt; as a companion to
&lt;em&gt;The Rust Programming Language&lt;/em&gt; (TRPL), specifically the
&lt;a href="https://rust-book.cs.brown.edu"&gt;Brown University interactive version&lt;/a&gt;. TRPL is
notoriously theory-heavy and practice-light, and you can easily spend an hour
reading dense chapters on ownership, lifetimes, or trait bounds without writing
a single line of standalone code. Rustlings exists to bridge that specific gap.
It&amp;rsquo;s a 94-exercise compiler-driven drill where you run the watcher in a
terminal, it fails on an exercise, and you edit the file until the compiler and
tests go green.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I worked through <a href="https://rustlings.rust-lang.org/">Rustlings</a> as a companion to
<em>The Rust Programming Language</em> (TRPL), specifically the
<a href="https://rust-book.cs.brown.edu">Brown University interactive version</a>. TRPL is
notoriously theory-heavy and practice-light, and you can easily spend an hour
reading dense chapters on ownership, lifetimes, or trait bounds without writing
a single line of standalone code. Rustlings exists to bridge that specific gap.
It&rsquo;s a 94-exercise compiler-driven drill where you run the watcher in a
terminal, it fails on an exercise, and you edit the file until the compiler and
tests go green.</p>
<p>If you&rsquo;re reading TRPL or another conceptual text, it&rsquo;s a useful companion. It
serves roughly the same purpose as the comprehension quizzes in Brown&rsquo;s
interactive edition to keep you honest and prove you were actually paying
attention to the chapter you just finished. The early sections start very
lightly, drilling ownership moves and mutability:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Early exercises drill elementary syntax, mutability, and ownership moves:
</span></span></span><span class="line"><span class="cl"><span class="k">fn</span> <span class="nf">fill_vec</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">vec</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vec</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">vec</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="mi">88</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">vec</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>If you&rsquo;re learning Rust through a project-oriented book like <em>Command-Line Rust</em>
or <em>100 Exercises to Learn Rust</em>, those early exercises are completely trivial
and you&rsquo;ll already be doing much heavier lifting in real projects.</p>
<p>Where Rustlings genuinely earned its keep was in the later sections,
particularly the conversion exercises. TRPL barely touches <code>From</code> and <code>Into</code>,
which is a notable omission for beginners, and Rustlings forces you to implement
<code>From</code>, <code>FromStr</code>, <code>TryFrom</code>, <code>TryInto</code>, <code>AsRef</code>, and <code>AsMut</code>. You quickly see
how standard library conventions click together, like how implementing <code>FromStr</code>
unlocks <code>.parse::&lt;YourType&gt;()</code> everywhere for free, and implementing <code>From</code> on
error types unlocks clean <code>?</code> operator propagation without nested match
pyramids:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// The conversions section drills standard library traits TRPL glosses over:
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">TryFrom</span><span class="o">&lt;&amp;</span><span class="p">[</span><span class="kt">i16</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Color</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">type</span> <span class="nc">Error</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">IntoColorError</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">fn</span> <span class="nf">try_from</span><span class="p">(</span><span class="n">slice</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">i16</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="bp">Self</span><span class="p">,</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Error</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="n">red</span><span class="p">,</span><span class="w"> </span><span class="n">green</span><span class="p">,</span><span class="w"> </span><span class="n">blue</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">slice</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="k">return</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="n">IntoColorError</span>::<span class="n">BadLen</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">};</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">(</span><span class="n">red</span><span class="p">,</span><span class="w"> </span><span class="n">green</span><span class="p">,</span><span class="w"> </span><span class="n">blue</span><span class="p">).</span><span class="n">try_into</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">fn</span> <span class="nf">byte_counter</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">AsRef</span><span class="o">&lt;</span><span class="kt">str</span><span class="o">&gt;&gt;</span><span class="p">(</span><span class="n">arg</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">arg</span><span class="p">.</span><span class="n">as_ref</span><span class="p">().</span><span class="n">len</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>The exercises also highlight subtle differences that books often gloss over,
like how <code>as</code> integer casting silently truncates high bits while <code>.try_into()</code>
uses the type system to catch out-of-range values and return a <code>Result</code>, or how
multi-arm macros require semicolons rather than commas between arms, and how
<code>collect()</code> infers the destination container purely from return type
annotations:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Late exercises drill declarative macro syntax and iterator transpositions:
</span></span></span><span class="line"><span class="cl"><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">my_macro</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="fm">println!</span><span class="p">(</span><span class="s">&#34;Check out my macro!&#34;</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">};</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">(</span><span class="cp">$val</span>:<span class="nc">expr</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="fm">println!</span><span class="p">(</span><span class="s">&#34;Look at this other macro: </span><span class="si">{}</span><span class="s">&#34;</span><span class="p">,</span><span class="w"> </span><span class="cp">$val</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">};</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// Transposing a collection of Results using collect&#39;s type inference:
</span></span></span><span class="line"><span class="cl"><span class="k">fn</span> <span class="nf">list_of_results</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">DivisionError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">numbers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">27</span><span class="p">,</span><span class="w"> </span><span class="mi">297</span><span class="p">,</span><span class="w"> </span><span class="mi">38502</span><span class="p">,</span><span class="w"> </span><span class="mi">81</span><span class="p">];</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">division_results</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">numbers</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="n">n</span><span class="o">|</span><span class="w"> </span><span class="n">divide</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="mi">27</span><span class="p">));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">division_results</span><span class="p">.</span><span class="n">collect</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>The tooling itself is completely frictionless. The watcher compiles on save,
advances automatically when tests pass, and it&rsquo;s a nice touch that the solutions
stay empty until after you solve the problem yourself. Most exercises take
thirty seconds, and the few that took longer weren&rsquo;t conceptually difficult so
much as exercises in getting used to Rust&rsquo;s strictness, like learning when slice
destructuring binds an element as <code>&amp;&amp;str</code> instead of <code>&amp;str</code> and balancing
references until the compiler is happy. It&rsquo;s not going to teach you software
architecture or how to structure large crates, but as a quick drill to build
syntactic muscle memory and get comfortable reading <code>rustc</code> diagnostics
alongside TRPL, it does its job well.</p>
<p>Full <a href="https://github.com/llcawthorne/book-notes/blob/main/rust/rustlings/book-notes.md">book notes</a>.</p>
]]></content:encoded></item><item><title>The Rust Programming Language</title><link>https://llcawthorne.github.io/posts/the-rust-programming-language/</link><pubDate>Mon, 16 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/the-rust-programming-language/</guid><description>&lt;p&gt;&lt;img alt="The Rust Programming Language cover" loading="lazy" src="https://llcawthorne.github.io/posts/the-rust-programming-language/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;I just wrapped up &lt;em&gt;The Rust Programming Language&lt;/em&gt;, specifically the
&lt;a href="https://rust-book.cs.brown.edu"&gt;Brown University interactive version&lt;/a&gt;, and the
sheer volume of notes I ended up taking says a lot about how much substance is
packed into it. It isn&amp;rsquo;t often that an introductory language book doubles as a
long-term reference you know you&amp;rsquo;ll keep returning to, but this one definitely
earns that spot, and I think it&amp;rsquo;s easily the best starting point for anyone
serious about learning Rust.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="The Rust Programming Language cover" loading="lazy" src="/posts/the-rust-programming-language/images/cover.jpg"></p>
<p>I just wrapped up <em>The Rust Programming Language</em>, specifically the
<a href="https://rust-book.cs.brown.edu">Brown University interactive version</a>, and the
sheer volume of notes I ended up taking says a lot about how much substance is
packed into it. It isn&rsquo;t often that an introductory language book doubles as a
long-term reference you know you&rsquo;ll keep returning to, but this one definitely
earns that spot, and I think it&rsquo;s easily the best starting point for anyone
serious about learning Rust.</p>
<p>The biggest strength of the book is how directly and thoroughly it tackles the
genuinely hard parts of the language. It doesn&rsquo;t hand-wave ownership, borrowing,
lifetimes, trait objects, or smart pointers. Instead of giving you a quick
overview and leaving you to battle the compiler on your own, it takes the time
to build a clear mental model of how the language manages memory.</p>
<p>The early chapters introduce ownership and borrowing from first principles,
contrasting brittle manual index tracking with safe string slices:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Chapter 4 introduces ownership and borrowing by contrasting index tracking
</span></span></span><span class="line"><span class="cl"><span class="c1">// with safe string slices:
</span></span></span><span class="line"><span class="cl"><span class="k">fn</span> <span class="nf">first_word</span><span class="p">(</span><span class="n">s</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="kt">str</span> <span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">bytes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">as_bytes</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">item</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">bytes</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">enumerate</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">item</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="sa">b</span><span class="sc">&#39; &#39;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="k">return</span><span class="w"> </span><span class="o">&amp;</span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="o">..</span><span class="n">i</span><span class="p">];</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="o">&amp;</span><span class="n">s</span><span class="p">[</span><span class="o">..</span><span class="p">]</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>If there&rsquo;s any real annoyance, it&rsquo;s that the authors explain almost everything
from first principles, which means if you already have experience in other
languages, you&rsquo;ll spend some time skimming through exhaustive explanations of
elementary concepts that feel pretty self-explanatory. They definitely go into
too much detail on some of the easy stuff in the early chapters, but that&rsquo;s
easy enough to forgive once you get to the meat of what makes Rust unique.</p>
<p>By the middle of the book, you dive into smart pointers and interior
mutability, using <code>RefCell&lt;T&gt;</code> to mutate data behind an immutable borrow:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// Chapter 15 introduces interior mutability with RefCell&lt;T&gt; for mock objects
</span></span></span><span class="line"><span class="cl"><span class="c1">// where values must be mutated through an immutable reference:
</span></span></span><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Messenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">fn</span> <span class="nf">send</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">msg</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">struct</span> <span class="nc">MockMessenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">sent_messages</span>: <span class="nc">RefCell</span><span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">MockMessenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">fn</span> <span class="nf">new</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">MockMessenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">MockMessenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="n">sent_messages</span>: <span class="nc">RefCell</span>::<span class="n">new</span><span class="p">(</span><span class="fm">vec!</span><span class="p">[]),</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">Messenger</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">MockMessenger</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">fn</span> <span class="nf">send</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">message</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">sent_messages</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">().</span><span class="n">push</span><span class="p">(</span><span class="nb">String</span>::<span class="n">from</span><span class="p">(</span><span class="n">message</span><span class="p">));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Reading the Brown University edition felt like the right call, even if I&rsquo;m only
comparing it against what I imagine the standard text would be like without the
interactive elements. The memory permission diagrams, which visually track
read, write, and own permissions as variables move through their lifetimes,
helped turn abstract borrow-checker rules into concrete states you can actually
picture.</p>
<p>The ownership quizzes and design inventories were tough, too. They aren&rsquo;t
multiple-choice softballs, and they demand precise reasoning about the exact
lines where borrows begin and end. Knowing they were constructed from real
stumbling blocks on Stack Overflow makes the difficulty understandable, even
when you get tripped up by a subtle edge case, and they really force you to
confront your misconceptions before you carry them into a real project.</p>
<p>By the time I finished the final project, building a multi-threaded web server
with a worker thread pool, I felt completely comfortable moving on to more
hands-on, project-driven material:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// The capstone project builds a multi-threaded web server with a worker
</span></span></span><span class="line"><span class="cl"><span class="c1">// thread pool and a channel-based job queue:
</span></span></span><span class="line"><span class="cl"><span class="k">type</span> <span class="nc">Job</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="k">dyn</span><span class="w"> </span><span class="nb">FnOnce</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">Send</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">&#39;static</span><span class="o">&gt;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">ThreadPool</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">workers</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="n">Worker</span><span class="o">&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">sender</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">mpsc</span>::<span class="n">Sender</span><span class="o">&lt;</span><span class="n">Job</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">struct</span> <span class="nc">Worker</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">id</span>: <span class="kt">usize</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">thread</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">thread</span>::<span class="n">JoinHandle</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="k">impl</span><span class="w"> </span><span class="n">Worker</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">id</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="n">receiver</span>: <span class="nc">Arc</span><span class="o">&lt;</span><span class="n">Mutex</span><span class="o">&lt;</span><span class="n">mpsc</span>::<span class="n">Receiver</span><span class="o">&lt;</span><span class="n">Job</span><span class="o">&gt;&gt;&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Worker</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">thread</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">thread</span>::<span class="n">spawn</span><span class="p">(</span><span class="k">move</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">message</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">receiver</span><span class="p">.</span><span class="n">lock</span><span class="p">().</span><span class="n">unwrap</span><span class="p">().</span><span class="n">recv</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="k">match</span><span class="w"> </span><span class="n">message</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="nb">Ok</span><span class="p">(</span><span class="n">job</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                    </span><span class="n">job</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="nb">Err</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                    </span><span class="k">break</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">                </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">});</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">Worker</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="n">id</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="n">thread</span>: <span class="nb">Some</span><span class="p">(</span><span class="n">thread</span><span class="p">),</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Overall, it&rsquo;s a demanding book, but it&rsquo;s a remarkably effective foundation. If
you can sit through the elementary explanations with a little patience, it gives
you the conceptual grounding you need to stop fighting the compiler and
actually start building things in Rust.</p>
<p>Full <a href="https://github.com/llcawthorne/book-notes/blob/main/rust/trpl/book-notes.md">book notes</a>.</p>
]]></content:encoded></item><item><title>Software Engineering at Google</title><link>https://llcawthorne.github.io/posts/software-engineering-at-google/</link><pubDate>Mon, 09 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/software-engineering-at-google/</guid><description>&lt;p&gt;&lt;img alt="Software Engineering at Google cover" loading="lazy" src="https://llcawthorne.github.io/posts/software-engineering-at-google/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;At over 23 hours, this was a massive audiobook, but I think it&amp;rsquo;s one of the
better books of software engineering advice I&amp;rsquo;ve read. The core framing is that
programming is just the immediate act of producing code, while software
engineering is what you have to do to keep that code sustainable over time and
across a team, or as they put it, it&amp;rsquo;s programming if clever is a compliment and
software engineering if clever is an accusation. Hyrum Wright is one of the
co-authors, and you can tell he&amp;rsquo;s proud of Hyrum&amp;rsquo;s Law since it gets cited at
least three times. It&amp;rsquo;s a solid observation though: with enough users, every
observable quirk of your system becomes a contract someone depends on, and while
Google obviously sees that at an extreme scale, I&amp;rsquo;ve seen it crop up even in my
own smaller applications.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Software Engineering at Google cover" loading="lazy" src="/posts/software-engineering-at-google/images/cover.jpg"></p>
<p>At over 23 hours, this was a massive audiobook, but I think it&rsquo;s one of the
better books of software engineering advice I&rsquo;ve read. The core framing is that
programming is just the immediate act of producing code, while software
engineering is what you have to do to keep that code sustainable over time and
across a team, or as they put it, it&rsquo;s programming if clever is a compliment and
software engineering if clever is an accusation. Hyrum Wright is one of the
co-authors, and you can tell he&rsquo;s proud of Hyrum&rsquo;s Law since it gets cited at
least three times. It&rsquo;s a solid observation though: with enough users, every
observable quirk of your system becomes a contract someone depends on, and while
Google obviously sees that at an extreme scale, I&rsquo;ve seen it crop up even in my
own smaller applications.</p>
<p>While it&rsquo;s true that not everyone works at the scale of Google or has the same
need for code longevity, they tend to point out when their considerations are
primarily scale-driven, and they share a lot of hard-won advice. They don&rsquo;t shy
away from making lessons out of where they&rsquo;ve made mistakes either, offering
several case studies where they openly admit they wish they had handled things
better. A huge chunk of the book is about testing, and I really liked their
emphasis on testing public behavior and outcomes rather than implementation
details. They lean heavily toward using real dependencies or high-fidelity fakes
instead of mocking everything out, which matches my own experience with
mock-heavy tests becoming brittle and useless.</p>
<p>The chapters on Google’s internal tooling were interesting too, even if most of
us don&rsquo;t have the luxury of having thousands of software engineers around to
develop custom build systems, code search tools, and entire languages just to
support our core products. Still, their arguments for simple trunk-based
development, short-lived branches, and relying on fast rollbacks rather than
fear of releasing felt grounded in reality.</p>
<p>Since this was another audiobook, my notes aren&rsquo;t quite as filled out as normal,
since I mostly just try to jot down core ideas when I&rsquo;m listening on a run.
There were plenty of good observations in here that I didn&rsquo;t get down, but I
think I managed to capture the main points that really struck me. It&rsquo;s a long
listen, but well worth the time.</p>
]]></content:encoded></item><item><title>The Storm Before the Storm</title><link>https://llcawthorne.github.io/posts/the-storm-before-the-storm/</link><pubDate>Fri, 06 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/the-storm-before-the-storm/</guid><description>&lt;p&gt;&lt;img alt="The Storm Before the Storm cover" loading="lazy" src="https://llcawthorne.github.io/posts/the-storm-before-the-storm/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The Storm Before the Storm&lt;/em&gt; should have just been called &lt;em&gt;Sulla: A History&lt;/em&gt;.
Mike Duncan covers the decades from 146 BC to Sulla&amp;rsquo;s death in 78 BC, the
stretch where the Roman Republic&amp;rsquo;s norms started breaking long before Caesar
arrived, and while it spends a little time on the Gracchi and enough on Marius
to set the stage, at least half the book belongs to Sulla. That isn&amp;rsquo;t really a
complaint, though. Once Sulla shows up he dominates the period, and I learned a
lot about a man I barely knew going in.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="The Storm Before the Storm cover" loading="lazy" src="/posts/the-storm-before-the-storm/images/cover.jpg"></p>
<p><em>The Storm Before the Storm</em> should have just been called <em>Sulla: A History</em>.
Mike Duncan covers the decades from 146 BC to Sulla&rsquo;s death in 78 BC, the
stretch where the Roman Republic&rsquo;s norms started breaking long before Caesar
arrived, and while it spends a little time on the Gracchi and enough on Marius
to set the stage, at least half the book belongs to Sulla. That isn&rsquo;t really a
complaint, though. Once Sulla shows up he dominates the period, and I learned a
lot about a man I barely knew going in.</p>
<p>I&rsquo;m reading Tom Holland&rsquo;s <em>Rubicon</em> now, and it probably covers enough of Sulla
to pick up the story of Pompey, Crassus, and Caesar, but what <em>Storm</em> gave me
was the grounding. <em>Rubicon</em> introduces Marius as a man in his sixties leading
armies in the Social War, shortly before he comes out of retirement and starts
his workout regimen, and without the earlier arc you lose the new man who saved
Rome, held five consecutive consulships, and reorganized the army. Everyone
comments on old Marius training with the young men on the Campus Martius,
desperate for one more command. Coming from <em>Storm</em>, that reads as a fall from
grace, but in <em>Rubicon</em> it mostly reads as stubbornness.</p>
<p><em>Storm</em> follows Marius all the way back to the war against Jugurtha, the
Numidian king whose defeat made his name, and that showed me how far back the
rivalry between Marius and Sulla goes. It starts at the very beginning of
Marius&rsquo;s career as a general. Sulla, serving under Marius, arranged Jugurtha&rsquo;s
capture and then put the scene on his personal seal ring, which was a brash move
when Marius was the one commanding the army. Those early chapters are the parts
left out of <em>Rubicon</em> that I valued most. <em>Storm</em> also gives more background on
the Gracchi and a real grounding in the Italian citizenship problem, and its
elaboration on the conditions that led to the Social War made the later story
much easier to follow.</p>
<p>Sulla was the first Roman general to march his army on Rome, and he did it
twice. He used that power and the proscriptions to restore the Senate&rsquo;s
traditional authority, a revolutionary acting in the service of conservatism,
and then he took the dictatorship with no fixed end date, gave it up anyway, and
retired to write his memoirs. It seems like such a bad idea to grab that much
power and then not keep it. His reforms only rolled the clock back a little on
the Senate&rsquo;s decline, and his real legacy was the precedent that an army loyal
to its general could take Rome. Caesar learned that lesson but not the
resignation, and Suetonius has him joking that Sulla didn&rsquo;t know his political
ABCs. Augustus learned both lessons and was far shrewder, keeping the real power
while making a great show of honoring the Senate.</p>
<p>I hate to say it as a Cicero fan, but I suspect a lot of the populares&rsquo; bad
reputation comes from our conservative sources. Cicero is our richest witness,
and he was firmly on the optimate side. Grain for the poor, land for farmers,
and citizenship for the Italians are all good causes. Granted, some of the men
promising them were after power rather than acting out of good-heartedness, and
Cinna doesn&rsquo;t sound particularly admirable, but I like the Gracchi, and I&rsquo;m
sorry about how it ended for them.</p>
<p>Anytime debates are decided by armed gangs instead of the truth and strength of
ideas, things have gone badly wrong, and Sulla&rsquo;s purges were the natural,
unfortunate outcome of a politics that had already moved from the Forum to the
battlefield. At least he didn&rsquo;t roll back citizenship and voting rights for the
Italians. Then again, I suspect he would have if he hadn&rsquo;t been forced to give
his word to honor them so he wouldn&rsquo;t have to fight his way back to Rome through
all of Italy, and even with that promise, the Samnites fought him to the end at
the Colline Gate.</p>
<p>If you&rsquo;re planning to read <em>Rubicon</em> or anything else on Caesar, <em>The Storm
Before the Storm</em> is a worthwhile ten-hour prequel. Duncan&rsquo;s case that the
Republic broke well before Caesar crossed the Rubicon makes the later story make
more sense. I&rsquo;ll cover Holland&rsquo;s trilogy in one post once I finish it.</p>
]]></content:encoded></item><item><title>Haskell Programming from First Principles</title><link>https://llcawthorne.github.io/posts/haskell-programming-from-first-principles/</link><pubDate>Mon, 02 Nov 2026 06:00:00 -0500</pubDate><guid>https://llcawthorne.github.io/posts/haskell-programming-from-first-principles/</guid><description>&lt;p&gt;&lt;img alt="Haskell Programming from First Principles cover" loading="lazy" src="https://llcawthorne.github.io/posts/haskell-programming-from-first-principles/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Haskell Programming from First Principles&lt;/em&gt; by Chris Allen and Julie Moronuki,
better known as &lt;em&gt;The Haskell Book&lt;/em&gt;, is a massive book. My copy runs around 1,200
pages, and I worked through all of it, exercises and all, minus a few at the
very end. This was actually my second attempt. The first time I fell off
somewhere around page 300, since the pace was slow and nothing in the book had
me building things, so I lost momentum. This time I paired it with &lt;em&gt;Learn
Haskell by Example&lt;/em&gt; for projects and &lt;em&gt;Learn You a Haskell&lt;/em&gt; as light reading on
the side, and that combination is what got me through, with &lt;em&gt;The Haskell Book&lt;/em&gt;
building up the theory and &lt;em&gt;Learn Haskell by Example&lt;/em&gt; giving me a wide variety
of places to apply it.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Haskell Programming from First Principles cover" loading="lazy" src="/posts/haskell-programming-from-first-principles/images/cover.jpg"></p>
<p><em>Haskell Programming from First Principles</em> by Chris Allen and Julie Moronuki,
better known as <em>The Haskell Book</em>, is a massive book. My copy runs around 1,200
pages, and I worked through all of it, exercises and all, minus a few at the
very end. This was actually my second attempt. The first time I fell off
somewhere around page 300, since the pace was slow and nothing in the book had
me building things, so I lost momentum. This time I paired it with <em>Learn
Haskell by Example</em> for projects and <em>Learn You a Haskell</em> as light reading on
the side, and that combination is what got me through, with <em>The Haskell Book</em>
building up the theory and <em>Learn Haskell by Example</em> giving me a wide variety
of places to apply it.</p>
<p>Normally my personal notes distill a book down to a third or a half of the
original size, but with <em>The Haskell Book</em>, it turned a 1,200-page volume into
about 100 pages of dense prose. Even having finished the book, I wouldn&rsquo;t say I
fully understand Haskell, but at least the 100 pages of dense notes I took still
make sense. It&rsquo;s really like taking notes on a math book: once you skip all the
exercises, the amount of material leftover is short but dense.</p>
<p>The explanations are excellent, if somewhat longwinded, and the book is really
good at taking complicated concepts and making them understandable. It&rsquo;s slow,
and in the early chapters on types and type classes it&rsquo;s almost mind-numbingly
slow, since those concepts are fairly straightforward, but the slow style pays
off once you hit the stuff that&rsquo;s actually hard. Folding is a good example. Most
books show you how to sum a list with a fold, maybe implement <code>map</code> and <code>filter</code>
with one, and call folding a learned concept. <em>The Haskell Book</em> gives it 40
solid pages, which is kind of a big deal if you come from a language where you&rsquo;d
normally just reach for a while loop.</p>
<p>The early chapters build up recursion and list processing from first principles,
showing that every function is curried before taking a deep dive into explicit
spine traversal and folding:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Early chapters build up functions and recursion from basic pattern matching:</span>
</span></span><span class="line"><span class="cl"><span class="nf">myZipWith</span> <span class="ow">::</span> <span class="p">(</span><span class="n">a</span> <span class="ow">-&gt;</span> <span class="n">b</span> <span class="ow">-&gt;</span> <span class="n">c</span><span class="p">)</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">b</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">c</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nf">myZipWith</span> <span class="kr">_</span> <span class="kt">[]</span> <span class="kr">_</span>          <span class="ow">=</span> <span class="kt">[]</span>
</span></span><span class="line"><span class="cl"><span class="nf">myZipWith</span> <span class="kr">_</span> <span class="kr">_</span> <span class="kt">[]</span>          <span class="ow">=</span> <span class="kt">[]</span>
</span></span><span class="line"><span class="cl"><span class="nf">myZipWith</span> <span class="n">f</span> <span class="p">(</span><span class="n">x</span><span class="kt">:</span><span class="n">xs</span><span class="p">)</span> <span class="p">(</span><span class="n">y</span><span class="kt">:</span><span class="n">ys</span><span class="p">)</span> <span class="ow">=</span> <span class="n">f</span> <span class="n">x</span> <span class="n">y</span> <span class="kt">:</span> <span class="n">myZipWith</span> <span class="n">f</span> <span class="n">xs</span> <span class="n">ys</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- Folding gets an exhaustive 40-page treatment, demonstrating spine traversal:</span>
</span></span><span class="line"><span class="cl"><span class="nf">foldr</span> <span class="ow">::</span> <span class="p">(</span><span class="n">a</span> <span class="ow">-&gt;</span> <span class="n">b</span> <span class="ow">-&gt;</span> <span class="n">b</span><span class="p">)</span> <span class="ow">-&gt;</span> <span class="n">b</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="n">b</span>
</span></span><span class="line"><span class="cl"><span class="nf">foldr</span> <span class="kr">_</span> <span class="n">z</span> <span class="kt">[]</span>     <span class="ow">=</span> <span class="n">z</span>
</span></span><span class="line"><span class="cl"><span class="nf">foldr</span> <span class="n">f</span> <span class="n">z</span> <span class="p">(</span><span class="n">x</span><span class="kt">:</span><span class="n">xs</span><span class="p">)</span> <span class="ow">=</span> <span class="n">f</span> <span class="n">x</span> <span class="p">(</span><span class="n">foldr</span> <span class="n">f</span> <span class="n">z</span> <span class="n">xs</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- Defining standard operations in terms of foldr:</span>
</span></span><span class="line"><span class="cl"><span class="nf">myFilter</span> <span class="ow">::</span> <span class="p">(</span><span class="n">a</span> <span class="ow">-&gt;</span> <span class="kt">Bool</span><span class="p">)</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="n">a</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="nf">myFilter</span> <span class="n">p</span> <span class="ow">=</span> <span class="n">foldr</span> <span class="p">(</span><span class="nf">\</span><span class="n">x</span> <span class="n">acc</span> <span class="ow">-&gt;</span> <span class="kr">if</span> <span class="n">p</span> <span class="n">x</span> <span class="kr">then</span> <span class="n">x</span> <span class="kt">:</span> <span class="n">acc</span> <span class="kr">else</span> <span class="n">acc</span><span class="p">)</span> <span class="kt">[]</span>
</span></span></code></pre></div><p>The type class chapters were the best part of the book for me. Semigroup,
Monoid, Functor, Applicative, Monad, Foldable, and Traversable each get a full
treatment, laws included, and you write a lot of instances yourself. It was the
first resource I&rsquo;d read that pressed hard on the monoidal part of Applicative.
<em>Advanced Functional Programming with Elixir</em> had already shown me <code>ap</code>
collecting all your validation errors instead of stopping at the first one, but
it never pointed out that the collecting comes from the monoidal side of
Applicative, combining the structures themselves rather than just applying
functions inside them, so I didn&rsquo;t really understand why it worked. That&rsquo;s the
piece that made <code>Validation</code> finally make sense to me:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Validation behaves like Either, but accumulates errors monoidally:</span>
</span></span><span class="line"><span class="cl"><span class="kr">data</span> <span class="kt">Validation</span> <span class="n">e</span> <span class="n">a</span>
</span></span><span class="line"><span class="cl">  <span class="ow">=</span> <span class="kt">Failure</span> <span class="n">e</span>
</span></span><span class="line"><span class="cl">  <span class="o">|</span> <span class="kt">Success</span> <span class="n">a</span>
</span></span><span class="line"><span class="cl">  <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">instance</span> <span class="kt">Functor</span> <span class="p">(</span><span class="kt">Validation</span> <span class="n">e</span><span class="p">)</span> <span class="kr">where</span>
</span></span><span class="line"><span class="cl">  <span class="n">fmap</span> <span class="kr">_</span> <span class="p">(</span><span class="kt">Failure</span> <span class="n">err</span><span class="p">)</span> <span class="ow">=</span> <span class="kt">Failure</span> <span class="n">err</span>
</span></span><span class="line"><span class="cl">  <span class="n">fmap</span> <span class="n">f</span> <span class="p">(</span><span class="kt">Success</span> <span class="n">a</span><span class="p">)</span>   <span class="ow">=</span> <span class="kt">Success</span> <span class="p">(</span><span class="n">f</span> <span class="n">a</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- The monoidal side of Applicative: combining failures with (&lt;&gt;):</span>
</span></span><span class="line"><span class="cl"><span class="kr">instance</span> <span class="kt">Monoid</span> <span class="n">e</span> <span class="ow">=&gt;</span> <span class="kt">Applicative</span> <span class="p">(</span><span class="kt">Validation</span> <span class="n">e</span><span class="p">)</span> <span class="kr">where</span>
</span></span><span class="line"><span class="cl">  <span class="n">pure</span> <span class="ow">=</span> <span class="kt">Success</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kt">Failure</span> <span class="n">e1</span> <span class="o">&lt;*&gt;</span> <span class="kt">Failure</span> <span class="n">e2</span> <span class="ow">=</span> <span class="kt">Failure</span> <span class="p">(</span><span class="n">e1</span> <span class="o">&lt;&gt;</span> <span class="n">e2</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="kt">Failure</span> <span class="n">e1</span> <span class="o">&lt;*&gt;</span> <span class="kr">_</span>          <span class="ow">=</span> <span class="kt">Failure</span> <span class="n">e1</span>
</span></span><span class="line"><span class="cl">  <span class="kr">_</span>          <span class="o">&lt;*&gt;</span> <span class="kt">Failure</span> <span class="n">e2</span> <span class="ow">=</span> <span class="kt">Failure</span> <span class="n">e2</span>
</span></span><span class="line"><span class="cl">  <span class="kt">Success</span> <span class="n">f</span>  <span class="o">&lt;*&gt;</span> <span class="kt">Success</span> <span class="n">a</span>  <span class="ow">=</span> <span class="kt">Success</span> <span class="p">(</span><span class="n">f</span> <span class="n">a</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- Collecting all validation errors instead of short-circuiting on the first:</span>
</span></span><span class="line"><span class="cl"><span class="nf">validatePerson</span> <span class="ow">::</span> <span class="kt">Validation</span> <span class="p">[</span><span class="kt">String</span><span class="p">]</span> <span class="kt">Person</span>
</span></span><span class="line"><span class="cl"><span class="nf">validatePerson</span> <span class="ow">=</span>
</span></span><span class="line"><span class="cl">  <span class="kt">Person</span> <span class="o">&lt;$&gt;</span> <span class="n">validateName</span> <span class="s">&#34;Chris&#34;</span>
</span></span><span class="line"><span class="cl">         <span class="o">&lt;*&gt;</span> <span class="n">validateAge</span> <span class="mi">30</span>
</span></span><span class="line"><span class="cl">         <span class="o">&lt;*&gt;</span> <span class="n">validateEmail</span> <span class="s">&#34;chris@example.com&#34;</span>
</span></span></code></pre></div><p>By the end, &ldquo;follow the types&rdquo; had become my main problem-solving strategy. Most
of the time, once I figured out what the types required, there was only one
sensible thing I could write that would compile. It sometimes felt a bit like
quantum mechanics, where I could trust the equations the same way I trust the
types, even when I wasn&rsquo;t totally sure what it all <em>meant</em>. The book also cites
research papers, which is unusual for an introductory programming book (<em>Head
First Go</em> sure didn&rsquo;t point me at any current research). It&rsquo;s a quirk of the
Haskell community, and while I&rsquo;m not sure I&rsquo;ll ever make it through Wadler &lsquo;89,
I appreciated the pointers.</p>
<p>There are a lot of exercises, more than in any other programming book I&rsquo;ve read.
They normally reach a little past what the chapter covered, but I could work
through everything except maybe a challenge problem at the end without needing
help. Some were just typing practice, since once you&rsquo;ve written a Semigroup
instance for <code>Two a b</code>, <code>Three a b c</code> and <code>Four a b c d</code> don&rsquo;t teach you
anything new. Others were genuinely hard, like writing a Semigroup for a type
that wraps a function, which took my whole reading session.</p>
<p>My biggest complaint is that, for all the time it spends explaining concepts,
the book is pretty light on using them in anger. I came out of the Monad and
Transformers chapters knowing how to build a monad or a transformer from
scratch, but without much sense of how to use them in a real program. I even had
to write <code>StateT</code> myself as an exercise, supposedly the most obnoxious of the
standard transformers, without ever seeing much of it in action, so <em>Learn
Haskell by Example</em> is where I&rsquo;m going to get that practice.</p>
<p>Testing follows a similar pattern. The testing chapter is solid, it covers
<code>hspec</code> and QuickCheck, explains generators well (including the difference
between product and sum types), and points you to a real project to see tests in
the wild, and the book goes on to reuse QuickCheck and <code>checkers</code> to test the
type class laws, which is great. But it mostly used tests to show off <code>checkers</code>
for testing laws and never really embraced testing ordinary, run-of-the-mill
code. There were no tests for roughly the last ten chapters, and none in the
final project, and it isn&rsquo;t much of a project without tests.</p>
<p>The Parsers chapter was the big outlier. I understood all of the material as it
was presented, it just wasn&rsquo;t an adequate build-up to the exercises: &ldquo;Here&rsquo;s how
to parse a char. Cool, now figure out a log file.&rdquo; It used <code>&lt;|&gt;</code> in an exercise
several pages before introducing it, told you to &ldquo;try <code>try</code>&rdquo; without explaining
it, and introduced tokenization mostly through examples of doing it wrong. Then
it asked for a SemVer parser, IPv4 and IPv6 parsers, and a parser for Graphviz&rsquo;s
DOT language, and that chapter took me about a week.</p>
<p>Quality control seems to slip a bit as you go, too. Somewhere past page 900 the
explanations got thinner. The JSON section switched examples halfway through and
barely spent time on either, so I&rsquo;ve seen <code>aeson</code> parse JSON, but I wouldn&rsquo;t say
I&rsquo;m ready to use it. The exceptions chapter was all toy examples, never
mentioned <code>bracket</code> or <code>finally</code>, and used catching <code>SomeException</code> as an
example. The Composing Types chapter opened with a &ldquo;warmup&rdquo; that had me write
the Applicative instance for <code>Compose</code>, and that was anything but a warmup. I
also found a handful of errata. The State chapter has <code>runState f &gt;&gt; f 0</code> where
it needs parentheses. The book claims <code>zipWith</code> is just <code>liftA2</code> specialized to
lists, then immediately shows them producing different results. One Applicative
exercise looks like it&rsquo;s setting you up to produce <code>Just 11</code> but can only ever
produce <code>Just 5</code>. And it has you name constructors <code>Success</code> and <code>Failure</code> right
after telling you to import QuickCheck, which already exports both.</p>
<p>The book is about ten years old, and you&rsquo;ll feel it. The original project files
pin GHC 8.6.5, which doesn&rsquo;t even exist for Apple Silicon, the <code>checkers</code> tuple
shapes for testing Traversable had changed, an old version of <code>trifecta</code> wanted
a decade-old set of dependencies, and the final project uses <code>network</code> functions
that have since been renamed, so I spent a fair amount of time fighting
dependencies. I don&rsquo;t hold version drift against a ten-year-old book, though,
just expect to update some resolvers and function names as you go. The Basic
Libraries chapter was like a museum trip, but most of the exhibits are still
alive.</p>
<p>The final project is a finger daemon backed by SQLite. Honestly, it didn&rsquo;t feel
like much of a final project, since I mostly typed in the code from the book,
but most of the prose explaining it felt unnecessary, which tells me the book
did a good job preparing me, and it could have just been a code listing. The
chapter starts out with a simple socket debug program that logs and echoes
incoming bytes:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Chapter 31 starts with a basic socket program that logs and echoes input:</span>
</span></span><span class="line"><span class="cl"><span class="nf">logAndEcho</span> <span class="ow">::</span> <span class="kt">Socket</span> <span class="ow">-&gt;</span> <span class="kt">IO</span> <span class="nb">()</span>
</span></span><span class="line"><span class="cl"><span class="nf">logAndEcho</span> <span class="n">sock</span> <span class="ow">=</span> <span class="n">forever</span> <span class="o">$</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="p">(</span><span class="n">soc</span><span class="p">,</span> <span class="kr">_</span><span class="p">)</span> <span class="ow">&lt;-</span> <span class="n">accept</span> <span class="n">sock</span>
</span></span><span class="line"><span class="cl">  <span class="n">printAndKickback</span> <span class="n">soc</span>
</span></span><span class="line"><span class="cl">  <span class="n">close</span> <span class="n">soc</span>
</span></span><span class="line"><span class="cl">  <span class="kr">where</span>
</span></span><span class="line"><span class="cl">    <span class="n">printAndKickback</span> <span class="n">conn</span> <span class="ow">=</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">      <span class="n">msg</span> <span class="ow">&lt;-</span> <span class="n">recv</span> <span class="n">conn</span> <span class="mi">1024</span>
</span></span><span class="line"><span class="cl">      <span class="n">print</span> <span class="n">msg</span>
</span></span><span class="line"><span class="cl">      <span class="n">sendAll</span> <span class="n">conn</span> <span class="n">msg</span>
</span></span></code></pre></div><p>From there, it builds up into a full-fledged, SQLite-backed modern finger
daemon, using the applicative combinators from Chapter 17 to decode database
rows:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Building up to a full SQLite-backed network finger daemon:</span>
</span></span><span class="line"><span class="cl"><span class="kr">data</span> <span class="kt">User</span> <span class="ow">=</span> <span class="kt">User</span>
</span></span><span class="line"><span class="cl">  <span class="p">{</span> <span class="n">userId</span>        <span class="ow">::</span> <span class="kt">Integer</span>
</span></span><span class="line"><span class="cl">  <span class="p">,</span> <span class="n">username</span>      <span class="ow">::</span> <span class="kt">Text</span>
</span></span><span class="line"><span class="cl">  <span class="p">,</span> <span class="n">shell</span>         <span class="ow">::</span> <span class="kt">Text</span>
</span></span><span class="line"><span class="cl">  <span class="p">,</span> <span class="n">homeDirectory</span> <span class="ow">::</span> <span class="kt">Text</span>
</span></span><span class="line"><span class="cl">  <span class="p">,</span> <span class="n">realName</span>      <span class="ow">::</span> <span class="kt">Text</span>
</span></span><span class="line"><span class="cl">  <span class="p">,</span> <span class="n">phone</span>         <span class="ow">::</span> <span class="kt">Text</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- Using the applicative combinators from Chapter 17 to decode database rows:</span>
</span></span><span class="line"><span class="cl"><span class="kr">instance</span> <span class="kt">FromRow</span> <span class="kt">User</span> <span class="kr">where</span>
</span></span><span class="line"><span class="cl">  <span class="n">fromRow</span> <span class="ow">=</span> <span class="kt">User</span> <span class="o">&lt;$&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">                 <span class="o">&lt;*&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">                 <span class="o">&lt;*&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">                 <span class="o">&lt;*&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">                 <span class="o">&lt;*&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">                 <span class="o">&lt;*&gt;</span> <span class="n">field</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">getUser</span> <span class="ow">::</span> <span class="kt">Connection</span> <span class="ow">-&gt;</span> <span class="kt">Text</span> <span class="ow">-&gt;</span> <span class="kt">IO</span> <span class="p">(</span><span class="kt">Maybe</span> <span class="kt">User</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nf">getUser</span> <span class="n">conn</span> <span class="n">username</span> <span class="ow">=</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="n">results</span> <span class="ow">&lt;-</span> <span class="n">query</span> <span class="n">conn</span> <span class="n">getUserQuery</span> <span class="p">(</span><span class="kt">Only</span> <span class="n">username</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="kr">case</span> <span class="n">results</span> <span class="kr">of</span>
</span></span><span class="line"><span class="cl">    <span class="kt">[]</span>     <span class="ow">-&gt;</span> <span class="n">return</span> <span class="kt">Nothing</span>
</span></span><span class="line"><span class="cl">    <span class="p">[</span><span class="n">user</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="n">return</span> <span class="p">(</span><span class="kt">Just</span> <span class="n">user</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="kr">_</span>      <span class="ow">-&gt;</span> <span class="n">throwIO</span> <span class="kt">DuplicateData</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">handleQuery</span> <span class="ow">::</span> <span class="kt">Connection</span> <span class="ow">-&gt;</span> <span class="kt">Socket</span> <span class="ow">-&gt;</span> <span class="kt">IO</span> <span class="nb">()</span>
</span></span><span class="line"><span class="cl"><span class="nf">handleQuery</span> <span class="n">dbConn</span> <span class="n">soc</span> <span class="ow">=</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="n">msg</span> <span class="ow">&lt;-</span> <span class="n">recv</span> <span class="n">soc</span> <span class="mi">1024</span>
</span></span><span class="line"><span class="cl">  <span class="kr">case</span> <span class="n">msg</span> <span class="kr">of</span>
</span></span><span class="line"><span class="cl">    <span class="s">&#34;</span><span class="se">\r\n</span><span class="s">&#34;</span> <span class="ow">-&gt;</span> <span class="n">returnUsers</span> <span class="n">dbConn</span> <span class="n">soc</span>
</span></span><span class="line"><span class="cl">    <span class="n">name</span>   <span class="ow">-&gt;</span> <span class="n">returnUser</span> <span class="n">dbConn</span> <span class="n">soc</span> <span class="p">(</span><span class="n">decodeUtf8</span> <span class="n">name</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">handleQueries</span> <span class="ow">::</span> <span class="kt">Connection</span> <span class="ow">-&gt;</span> <span class="kt">Socket</span> <span class="ow">-&gt;</span> <span class="kt">IO</span> <span class="nb">()</span>
</span></span><span class="line"><span class="cl"><span class="nf">handleQueries</span> <span class="n">dbConn</span> <span class="n">sock</span> <span class="ow">=</span> <span class="n">forever</span> <span class="o">$</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="p">(</span><span class="n">soc</span><span class="p">,</span> <span class="kr">_</span><span class="p">)</span> <span class="ow">&lt;-</span> <span class="n">accept</span> <span class="n">sock</span>
</span></span><span class="line"><span class="cl">  <span class="n">handleQuery</span> <span class="n">dbConn</span> <span class="n">soc</span>
</span></span><span class="line"><span class="cl">  <span class="n">close</span> <span class="n">soc</span>
</span></span></code></pre></div><p>The exercises at the end go from &ldquo;use the <code>sqlite3</code> CLI to add a user&rdquo; to &ldquo;build
a control socket on another port while the server runs,&rdquo; which is basically &ldquo;go
read Marlow&rsquo;s book on concurrency and come back to this project.&rdquo; I skipped
straight to the last step: celebrate completing this massive book.</p>
<p>Overall, <em>The Haskell Book</em> is the best resource I&rsquo;ve found for actually
understanding Haskell. If you want to know why Applicative works the way it
does, or what the Functor laws are for, this is the book. Just don&rsquo;t expect it
to teach you to build things. It&rsquo;s light on putting its concepts to work, it
drops testing for the last third, and the later chapters have a lot less polish
than the early ones, so I wouldn&rsquo;t have finished it without a project book
alongside it. With one, it was well worth the 1,200 pages.</p>
]]></content:encoded></item><item><title>Learn Haskell by Building a Blog Generator</title><link>https://llcawthorne.github.io/posts/learn-haskell-by-building-a-blog-generator/</link><pubDate>Fri, 30 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/learn-haskell-by-building-a-blog-generator/</guid><description>&lt;p&gt;&lt;a href="https://learn-haskell.blog/"&gt;&lt;em&gt;Learn Haskell by Building a Blog Generator&lt;/em&gt;&lt;/a&gt; is a
free online book that teaches Haskell through a single project, a small static
blog generator. It&amp;rsquo;s short, around 150 pages if you export it to PDF, and that&amp;rsquo;s
a big part of its appeal. I read it during a week when my laptop was in the
shop, as a bounded, finishable side project to fill the gap while my main
Haskell books (&lt;em&gt;The Haskell Book&lt;/em&gt; and &lt;em&gt;Haskell by Example&lt;/em&gt;) were on hold.&lt;/p&gt;</description><content:encoded><![CDATA[<p><a href="https://learn-haskell.blog/"><em>Learn Haskell by Building a Blog Generator</em></a> is a
free online book that teaches Haskell through a single project, a small static
blog generator. It&rsquo;s short, around 150 pages if you export it to PDF, and that&rsquo;s
a big part of its appeal. I read it during a week when my laptop was in the
shop, as a bounded, finishable side project to fill the gap while my main
Haskell books (<em>The Haskell Book</em> and <em>Haskell by Example</em>) were on hold.</p>
<p>Instead of teaching concepts in a neat progression and then applying them, the
book introduces Haskell features only when the project needs them. You build an
HTML printer library, design a small custom markup language and a parser for it,
glue the two together into a working converter, and then add error handling and
support for multiple files, pass configuration through an environment, and
finish up with tests and generated documentation. The HTML side is built as a
small embedded domain-specific language (EDSL), and it&rsquo;s really pleasant to use.
Along the way the book makes some smart, practical design points, like keeping
implementation details in an <code>Html.Internal</code> module while exposing a clean
public API with an explicit export list, and using <code>newtype</code> to keep raw strings
and HTML from getting mixed up:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Chapter 3 starts by creating a type-safe HTML domain-specific language:</span>
</span></span><span class="line"><span class="cl"><span class="kr">newtype</span> <span class="kt">Html</span> <span class="ow">=</span> <span class="kt">Html</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl"><span class="kr">newtype</span> <span class="kt">Structure</span> <span class="ow">=</span> <span class="kt">Structure</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl"><span class="kr">newtype</span> <span class="kt">Title</span> <span class="ow">=</span> <span class="kt">Title</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">html_</span> <span class="ow">::</span> <span class="kt">Title</span> <span class="ow">-&gt;</span> <span class="kt">Structure</span> <span class="ow">-&gt;</span> <span class="kt">Html</span>
</span></span><span class="line"><span class="cl"><span class="nf">html_</span> <span class="p">(</span><span class="kt">Title</span> <span class="n">title</span><span class="p">)</span> <span class="p">(</span><span class="kt">Structure</span> <span class="n">content</span><span class="p">)</span> <span class="ow">=</span>
</span></span><span class="line"><span class="cl">  <span class="kt">Html</span>
</span></span><span class="line"><span class="cl">    <span class="p">(</span> <span class="n">el</span> <span class="s">&#34;html&#34;</span>
</span></span><span class="line"><span class="cl">      <span class="p">(</span> <span class="n">el</span> <span class="s">&#34;head&#34;</span> <span class="p">(</span><span class="n">el</span> <span class="s">&#34;title&#34;</span> <span class="p">(</span><span class="n">escape</span> <span class="n">title</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">        <span class="o">&lt;&gt;</span> <span class="n">el</span> <span class="s">&#34;body&#34;</span> <span class="n">content</span>
</span></span><span class="line"><span class="cl">      <span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">p_</span> <span class="ow">::</span> <span class="kt">String</span> <span class="ow">-&gt;</span> <span class="kt">Structure</span>
</span></span><span class="line"><span class="cl"><span class="nf">p_</span> <span class="ow">=</span> <span class="kt">Structure</span> <span class="o">.</span> <span class="n">el</span> <span class="s">&#34;p&#34;</span> <span class="o">.</span> <span class="n">escape</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">h1_</span> <span class="ow">::</span> <span class="kt">String</span> <span class="ow">-&gt;</span> <span class="kt">Structure</span>
</span></span><span class="line"><span class="cl"><span class="nf">h1_</span> <span class="ow">=</span> <span class="kt">Structure</span> <span class="o">.</span> <span class="n">el</span> <span class="s">&#34;h1&#34;</span> <span class="o">.</span> <span class="n">escape</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">render</span> <span class="ow">::</span> <span class="kt">Html</span> <span class="ow">-&gt;</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl"><span class="nf">render</span> <span class="p">(</span><span class="kt">Html</span> <span class="n">str</span><span class="p">)</span> <span class="ow">=</span> <span class="n">str</span>
</span></span></code></pre></div><p>What worked best is that you end up with a real, working tool instead of a pile
of toy exercises, and that makes the concepts stick in a way pure explanation
doesn&rsquo;t. Records, recursion, <code>Either</code> for error handling, and passing an
environment through a program all show up because the project needs them, so
their purpose is obvious. The custom markup parser in the middle of the book
gives a very practical demonstration of recursive list processing and stateful
pattern matching across text lines:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- The middle chapters design a custom markup parser using recursive pattern matching:</span>
</span></span><span class="line"><span class="cl"><span class="kr">type</span> <span class="kt">Document</span> <span class="ow">=</span> <span class="p">[</span><span class="kt">Structure</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">data</span> <span class="kt">Structure</span>
</span></span><span class="line"><span class="cl">  <span class="ow">=</span> <span class="kt">Heading</span> <span class="kt">Natural</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl">  <span class="o">|</span> <span class="kt">Paragraph</span> <span class="kt">String</span>
</span></span><span class="line"><span class="cl">  <span class="o">|</span> <span class="kt">UnorderedList</span> <span class="p">[</span><span class="kt">String</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="o">|</span> <span class="kt">CodeBlock</span> <span class="p">[</span><span class="kt">String</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nf">parseLines</span> <span class="ow">::</span> <span class="kt">Maybe</span> <span class="kt">Structure</span> <span class="ow">-&gt;</span> <span class="p">[</span><span class="kt">String</span><span class="p">]</span> <span class="ow">-&gt;</span> <span class="kt">Document</span>
</span></span><span class="line"><span class="cl"><span class="nf">parseLines</span> <span class="n">context</span> <span class="n">txts</span> <span class="ow">=</span>
</span></span><span class="line"><span class="cl">  <span class="kr">case</span> <span class="n">txts</span> <span class="kr">of</span>
</span></span><span class="line"><span class="cl">    <span class="kt">[]</span> <span class="ow">-&gt;</span> <span class="n">maybeToList</span> <span class="n">context</span>
</span></span><span class="line"><span class="cl">    <span class="p">(</span><span class="sc">&#39;*&#39;</span> <span class="kt">:</span> <span class="sc">&#39; &#39;</span> <span class="kt">:</span> <span class="n">line</span><span class="p">)</span> <span class="kt">:</span> <span class="n">rest</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">      <span class="n">maybe</span> <span class="n">id</span> <span class="p">(</span><span class="kt">:</span><span class="p">)</span> <span class="n">context</span> <span class="p">(</span><span class="kt">Heading</span> <span class="mi">1</span> <span class="p">(</span><span class="n">trim</span> <span class="n">line</span><span class="p">)</span> <span class="kt">:</span> <span class="n">parseLines</span> <span class="kt">Nothing</span> <span class="n">rest</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">(</span><span class="sc">&#39;-&#39;</span> <span class="kt">:</span> <span class="sc">&#39; &#39;</span> <span class="kt">:</span> <span class="n">line</span><span class="p">)</span> <span class="kt">:</span> <span class="n">rest</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">      <span class="kr">case</span> <span class="n">context</span> <span class="kr">of</span>
</span></span><span class="line"><span class="cl">        <span class="kt">Just</span> <span class="p">(</span><span class="kt">UnorderedList</span> <span class="n">list</span><span class="p">)</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">          <span class="n">parseLines</span> <span class="p">(</span><span class="kt">Just</span> <span class="p">(</span><span class="kt">UnorderedList</span> <span class="p">(</span><span class="n">list</span> <span class="o">&lt;&gt;</span> <span class="p">[</span><span class="n">trim</span> <span class="n">line</span><span class="p">])))</span> <span class="n">rest</span>
</span></span><span class="line"><span class="cl">        <span class="kr">_</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">          <span class="n">maybe</span> <span class="n">id</span> <span class="p">(</span><span class="kt">:</span><span class="p">)</span> <span class="n">context</span> <span class="p">(</span><span class="n">parseLines</span> <span class="p">(</span><span class="kt">Just</span> <span class="p">(</span><span class="kt">UnorderedList</span> <span class="p">[</span><span class="n">trim</span> <span class="n">line</span><span class="p">]))</span> <span class="n">rest</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">currentLine</span> <span class="kt">:</span> <span class="n">rest</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">      <span class="kr">let</span> <span class="n">line</span> <span class="ow">=</span> <span class="n">trim</span> <span class="n">currentLine</span>
</span></span><span class="line"><span class="cl">      <span class="kr">in</span> <span class="kr">if</span> <span class="n">line</span> <span class="o">==</span> <span class="s">&#34;&#34;</span>
</span></span><span class="line"><span class="cl">           <span class="kr">then</span> <span class="n">maybe</span> <span class="n">id</span> <span class="p">(</span><span class="kt">:</span><span class="p">)</span> <span class="n">context</span> <span class="p">(</span><span class="n">parseLines</span> <span class="kt">Nothing</span> <span class="n">rest</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">           <span class="kr">else</span> <span class="kr">case</span> <span class="n">context</span> <span class="kr">of</span>
</span></span><span class="line"><span class="cl">                  <span class="kt">Just</span> <span class="p">(</span><span class="kt">Paragraph</span> <span class="n">p</span><span class="p">)</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">                    <span class="n">parseLines</span> <span class="p">(</span><span class="kt">Just</span> <span class="p">(</span><span class="kt">Paragraph</span> <span class="p">(</span><span class="n">unwords</span> <span class="p">[</span><span class="n">p</span><span class="p">,</span> <span class="n">line</span><span class="p">])))</span> <span class="n">rest</span>
</span></span><span class="line"><span class="cl">                  <span class="kr">_</span> <span class="ow">-&gt;</span>
</span></span><span class="line"><span class="cl">                    <span class="n">maybe</span> <span class="n">id</span> <span class="p">(</span><span class="kt">:</span><span class="p">)</span> <span class="n">context</span> <span class="p">(</span><span class="n">parseLines</span> <span class="p">(</span><span class="kt">Just</span> <span class="p">(</span><span class="kt">Paragraph</span> <span class="n">line</span><span class="p">))</span> <span class="n">rest</span><span class="p">)</span>
</span></span></code></pre></div><p>Threading configuration through the program was my first hands-on look at the
Reader pattern and monad transformers, well before my other books covered them
in depth. Chapter 7 replaces manual <code>Env</code> parameter passing with <code>Reader</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-haskell" data-lang="haskell"><span class="line"><span class="cl"><span class="c1">-- Chapter 7 replaces manual Env threading with Reader:</span>
</span></span><span class="line"><span class="cl"><span class="c1">-- Before:</span>
</span></span><span class="line"><span class="cl"><span class="nf">txtsToRenderedHtml</span> <span class="ow">::</span> <span class="kt">Env</span> <span class="ow">-&gt;</span> <span class="p">[(</span><span class="kt">FilePath</span><span class="p">,</span> <span class="kt">String</span><span class="p">)]</span> <span class="ow">-&gt;</span> <span class="p">[(</span><span class="kt">FilePath</span><span class="p">,</span> <span class="kt">String</span><span class="p">)]</span>
</span></span><span class="line"><span class="cl"><span class="nf">txtsToRenderedHtml</span> <span class="n">env</span> <span class="n">txtFiles</span> <span class="ow">=</span>
</span></span><span class="line"><span class="cl">  <span class="kr">let</span> <span class="n">txtOutputFiles</span> <span class="ow">=</span> <span class="n">map</span> <span class="n">toOutputMarkupFile</span> <span class="n">txtFiles</span>
</span></span><span class="line"><span class="cl">      <span class="n">index</span> <span class="ow">=</span> <span class="p">(</span><span class="s">&#34;index.html&#34;</span><span class="p">,</span> <span class="n">buildIndex</span> <span class="n">env</span> <span class="n">txtOutputFiles</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">      <span class="n">htmlPages</span> <span class="ow">=</span> <span class="n">map</span> <span class="p">(</span><span class="n">convertFile</span> <span class="n">env</span><span class="p">)</span> <span class="n">txtOutputFiles</span>
</span></span><span class="line"><span class="cl">  <span class="kr">in</span> <span class="n">map</span> <span class="p">(</span><span class="n">fmap</span> <span class="kt">Html</span><span class="o">.</span><span class="n">render</span><span class="p">)</span> <span class="p">(</span><span class="n">index</span> <span class="kt">:</span> <span class="n">htmlPages</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- After: Reader threads Env implicitly through do notation:</span>
</span></span><span class="line"><span class="cl"><span class="nf">txtsToRenderedHtml</span> <span class="ow">::</span> <span class="p">[(</span><span class="kt">FilePath</span><span class="p">,</span> <span class="kt">String</span><span class="p">)]</span> <span class="ow">-&gt;</span> <span class="kt">Reader</span> <span class="kt">Env</span> <span class="p">[(</span><span class="kt">FilePath</span><span class="p">,</span> <span class="kt">String</span><span class="p">)]</span>
</span></span><span class="line"><span class="cl"><span class="nf">txtsToRenderedHtml</span> <span class="n">txtFiles</span> <span class="ow">=</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="kr">let</span> <span class="n">txtOutputFiles</span> <span class="ow">=</span> <span class="n">map</span> <span class="n">toOutputMarkupFile</span> <span class="n">txtFiles</span>
</span></span><span class="line"><span class="cl">  <span class="n">index</span> <span class="ow">&lt;-</span> <span class="p">(,)</span> <span class="s">&#34;index.html&#34;</span> <span class="o">&lt;$&gt;</span> <span class="n">buildIndex</span> <span class="n">txtOutputFiles</span>
</span></span><span class="line"><span class="cl">  <span class="n">htmlPages</span> <span class="ow">&lt;-</span> <span class="n">traverse</span> <span class="n">convertFile</span> <span class="n">txtOutputFiles</span>
</span></span><span class="line"><span class="cl">  <span class="n">pure</span> <span class="o">$</span> <span class="n">map</span> <span class="p">(</span><span class="n">fmap</span> <span class="kt">Html</span><span class="o">.</span><span class="n">render</span><span class="p">)</span> <span class="p">(</span><span class="n">index</span> <span class="kt">:</span> <span class="n">htmlPages</span><span class="p">)</span>
</span></span></code></pre></div><p>The testing chapter uses <code>hspec</code> with automatic test discovery, which was nice
to work with, and it left me with a much better impression of Haskell testing
than the cruder harness in another book I was reading at the time. It also takes
a worthwhile detour into <code>optparse-applicative</code> instead of hand-rolling
argument parsing.</p>
<p>The later chapters thin out, though. The testing chapter only tests one module
and leaves the rest as optional practice, and the documentation chapter is
brief, so both feel like they were written in more of a hurry than the core
project chapters. At least one example didn&rsquo;t compile as written either, since
the Reader chapter needed an <code>mtl</code> import the text never mentions, which is easy
to fix but is the kind of thing that stalls a beginner. The generator also reads
its own simple markup language instead of Markdown. For a tutorial this short,
that&rsquo;s the practical choice, since writing a full Markdown parser would swallow
the book, but it does limit how useful the finished tool is. And I read it in a
three-day binge, which it&rsquo;s short enough to allow, but I&rsquo;d recommend spreading
it out so the material has time to sink in.</p>
<p>I wouldn&rsquo;t replace Hugo with the generator. It lacks the stuff you take for
granted in a mature static site generator, like nice themes and extensions, and
all my existing posts are written in Markdown instead of its custom markup, so
porting them over would be a pain. That&rsquo;s not really the point, though. The
point is learning Haskell by building something real, and the book does that
well.</p>
<p>Overall it&rsquo;s a short, practical, and enjoyable introduction to building a real
program in Haskell. Its biggest strength is that every concept shows up attached
to a reason to use it, and its weaknesses are mostly at the end, where testing
and documentation get thinner treatment, plus the occasional example that
doesn&rsquo;t compile as written. It works best alongside a more thorough book that
explains the theory the project leans on.</p>
]]></content:encoded></item><item><title>Learn You a Haskell for Great Good!</title><link>https://llcawthorne.github.io/posts/learn-you-a-haskell/</link><pubDate>Mon, 26 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/learn-you-a-haskell/</guid><description>&lt;p&gt;&lt;img alt="Learn You a Haskell for Great Good! cover" loading="lazy" src="https://llcawthorne.github.io/posts/learn-you-a-haskell/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Learn You a Haskell&lt;/em&gt; (LYAH) is the friendly, illustrated, free online Haskell
introduction that a lot of people start with. I read it as the third track in my
Haskell study, alongside &lt;em&gt;The Haskell Book&lt;/em&gt; for the deep theory and laws and
&lt;em&gt;Haskell by Example&lt;/em&gt; for project-driven practice, and I own it in print, mostly
to support the author.&lt;/p&gt;
&lt;p&gt;LYAH ended up being my &amp;ldquo;medium&amp;rdquo; book. It wasn&amp;rsquo;t demanding enough to need my
protected morning focus time, but it wasn&amp;rsquo;t throwaway reading either. It moves
fast and covers an enormous amount of ground in relatively few pages, and it
rarely gives you exercises, so it was easy to pick up between chapters of my
heavier books, but I also retained less from it than from the books where I was
typing and testing code. More than once I described it as a book where you&amp;rsquo;re
lucky to keep anything, but you&amp;rsquo;ll recognize the topic when it comes up again
somewhere else, and that turned out to be worth a lot, since plenty of concepts
were already familiar by the time &lt;em&gt;The Haskell Book&lt;/em&gt; covered them properly.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Learn You a Haskell for Great Good! cover" loading="lazy" src="/posts/learn-you-a-haskell/images/cover.jpg"></p>
<p><em>Learn You a Haskell</em> (LYAH) is the friendly, illustrated, free online Haskell
introduction that a lot of people start with. I read it as the third track in my
Haskell study, alongside <em>The Haskell Book</em> for the deep theory and laws and
<em>Haskell by Example</em> for project-driven practice, and I own it in print, mostly
to support the author.</p>
<p>LYAH ended up being my &ldquo;medium&rdquo; book. It wasn&rsquo;t demanding enough to need my
protected morning focus time, but it wasn&rsquo;t throwaway reading either. It moves
fast and covers an enormous amount of ground in relatively few pages, and it
rarely gives you exercises, so it was easy to pick up between chapters of my
heavier books, but I also retained less from it than from the books where I was
typing and testing code. More than once I described it as a book where you&rsquo;re
lucky to keep anything, but you&rsquo;ll recognize the topic when it comes up again
somewhere else, and that turned out to be worth a lot, since plenty of concepts
were already familiar by the time <em>The Haskell Book</em> covered them properly.</p>
<p>Some of its explanations are really excellent, good enough that I thought about
a second pass just to capture them in notes. Its treatment of IO and functors
pushed back on the &ldquo;IO is a magic box&rdquo; idea I&rsquo;d picked up elsewhere and reframed
IO as just one more thing that supports <code>fmap</code>. Folding a tree with <code>foldMap</code>
into any monoid was the first time Monoid felt useful to me. Toy examples like
<code>Sum</code> and <code>Product</code> never sold it, since <code>+</code> and <code>*</code> are already right there,
but one traversal that can collapse the structure in different ways depending
only on which monoid you pick is the real pitch. The State monad clicked here
too, and it made it clear that State solves a problem you mostly only have in a
pure language. Using <code>filterM</code> with a Writer to log was intuitive, and using it
with <code>[True, False]</code> to generate a power set was a great &ldquo;aha&rdquo; moment for how
the list monad branches. The Monads and Zippers chapters are the standouts, and
if someone only read two chapters of LYAH, I&rsquo;d point them there.</p>
<p>It does have some weak spots. Without exercises, a lot slides by, so it&rsquo;s more
of a tour than a workout. It uses some functions before explaining them, like
leaning on <code>sequenceA</code> and comparing it to <code>sequence</code> without ever properly
introducing <code>sequence</code>, which is easy enough to fill in but adds friction. And
it just stops, with no wrap-up or sense of where to go next, so it reads like an
online tutorial that got bound into a book, which is basically what it is.</p>
<p>LYAH is a good read and a great companion book, but not a primary one. Its best
explanations (IO, Functor, Monoid via <code>foldMap</code>, State, Monads, and Zippers)
make it worth reading on their own, and its breadth gives you a mental map of
the territory, but if you want Haskell to stick, pair it with something that
makes you write code. For me, <em>The Haskell Book</em> supplied the depth and the
laws, <em>Haskell by Example</em> supplied the projects, and LYAH supplied friendly
first encounters and a few explanations I still think are the best I&rsquo;ve seen.</p>
]]></content:encoded></item><item><title>Agile Web Development with Rails 8</title><link>https://llcawthorne.github.io/posts/agile-web-development-with-rails-8/</link><pubDate>Fri, 23 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/agile-web-development-with-rails-8/</guid><description>&lt;p&gt;&lt;img alt="Agile Web Development with Rails 8 cover" loading="lazy" src="https://llcawthorne.github.io/posts/agile-web-development-with-rails-8/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;I read this as evening light reading alongside a much more deliberate Haskell
push, and built the whole Depot/Storefront tutorial along the way, with auth,
i18n, Action Mailer/Mailbox, and hundreds of fast passing tests. Coming from a
mostly JEE/JSF background (with a little Angular thrown in), I expected Rails'
&amp;ldquo;Cadillac, all-bells-and-whistles&amp;rdquo; reputation to feel dated by 2026. It didn&amp;rsquo;t.
It&amp;rsquo;s still the batteries-included framework, and the batteries are good ones: a
rich text editor built in, which I had to bolt onto my own JEE app; a full email
system in both directions, Action Mailer for outgoing with genuinely
well-thought-out test-mode delivery support, Action Mailbox for incoming routed
like a controller. I don&amp;rsquo;t expect a web framework to check my email for me, and
I&amp;rsquo;m not sure I&amp;rsquo;d trust it over something like Mailchimp once you need real
deliverability at scale, but as a &amp;ldquo;we already thought of that&amp;rdquo; touch I was
impressed, and the testing support around it is A+.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Agile Web Development with Rails 8 cover" loading="lazy" src="/posts/agile-web-development-with-rails-8/images/cover.jpg"></p>
<p>I read this as evening light reading alongside a much more deliberate Haskell
push, and built the whole Depot/Storefront tutorial along the way, with auth,
i18n, Action Mailer/Mailbox, and hundreds of fast passing tests. Coming from a
mostly JEE/JSF background (with a little Angular thrown in), I expected Rails'
&ldquo;Cadillac, all-bells-and-whistles&rdquo; reputation to feel dated by 2026. It didn&rsquo;t.
It&rsquo;s still the batteries-included framework, and the batteries are good ones: a
rich text editor built in, which I had to bolt onto my own JEE app; a full email
system in both directions, Action Mailer for outgoing with genuinely
well-thought-out test-mode delivery support, Action Mailbox for incoming routed
like a controller. I don&rsquo;t expect a web framework to check my email for me, and
I&rsquo;m not sure I&rsquo;d trust it over something like Mailchimp once you need real
deliverability at scale, but as a &ldquo;we already thought of that&rdquo; touch I was
impressed, and the testing support around it is A+.</p>
<p>On views, I think my team&rsquo;s move to JSF was a step backward, and Rails
reinforced that. ERB is happy to just be light HTML with a little programmatic
output sprinkled in, the same way JSP is fine if you use it with a light touch
and don&rsquo;t let logic creep in, and the book gives the same DRY warning I&rsquo;d give
myself. Slim was in there as an option and genuinely looked like an upgrade in
conciseness, but I stayed away from it deliberately, once you step away from raw
HTML you sometimes tie your own hands, and direct HTML access is one of the
places JSF shoots itself in the foot. Turbo and Stimulus impressed me more than
expected too. As a longtime JSF developer I&rsquo;m instinctively wary of anything
promising to hide JavaScript from you, but Turbo/Stimulus make JS a first-class
citizen without demanding you write obnoxious amounts of it.</p>
<p>The early application iterations start by generating the product maintenance
scaffolding, defining model associations, and enforcing validation rules right
on ActiveRecord models:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Chapters 6 and 7 establish ActiveRecord models, migrations, and validations:</span>
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Product</span> <span class="o">&lt;</span> <span class="no">ApplicationRecord</span>
</span></span><span class="line"><span class="cl">  <span class="n">has_many</span> <span class="ss">:line_items</span>
</span></span><span class="line"><span class="cl">  <span class="n">before_destroy</span> <span class="ss">:ensure_not_referenced_by_any_line_item</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="n">validates</span> <span class="ss">:title</span><span class="p">,</span> <span class="ss">:description</span><span class="p">,</span> <span class="ss">:image_url</span><span class="p">,</span> <span class="ss">presence</span><span class="p">:</span> <span class="kp">true</span>
</span></span><span class="line"><span class="cl">  <span class="n">validates</span> <span class="ss">:title</span><span class="p">,</span> <span class="ss">uniqueness</span><span class="p">:</span> <span class="kp">true</span>
</span></span><span class="line"><span class="cl">  <span class="n">validates</span> <span class="ss">:price</span><span class="p">,</span> <span class="ss">numericality</span><span class="p">:</span> <span class="p">{</span> <span class="ss">greater_than_or_equal_to</span><span class="p">:</span> <span class="mi">0</span><span class="o">.</span><span class="mo">01</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kp">private</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">ensure_not_referenced_by_any_line_item</span>
</span></span><span class="line"><span class="cl">    <span class="k">unless</span> <span class="n">line_items</span><span class="o">.</span><span class="n">empty?</span>
</span></span><span class="line"><span class="cl">      <span class="n">errors</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="ss">:base</span><span class="p">,</span> <span class="s2">&#34;Line Items present&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">      <span class="kp">throw</span> <span class="ss">:abort</span>
</span></span><span class="line"><span class="cl">    <span class="k">end</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>Testing was the sharpest contrast with JEE. Heavyweight containers make fast
test cycles a real problem, and Capybara spinning up a lightweight server
against headless Chrome, backed by Minitest that&rsquo;s actually fast, means I&rsquo;ve got
hundreds of tests now and still don&rsquo;t think twice about running the whole suite,
or just a relevant subset. System tests were occasionally flaky without retries
though, which brought back some uncomfortable memories of flaky Selenium and Geb
tests from my Java days. I&rsquo;m a BDD fan, so RSpec being a real drop-in swap for
Minitest mattered to me, same reason I liked Geb (Groovy) back when I was
Groovy-curious and why I already love hspec in Haskell:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># System tests drive headless Chrome via Capybara to verify live UI workflows:</span>
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">OrdersTest</span> <span class="o">&lt;</span> <span class="no">ApplicationSystemTestCase</span>
</span></span><span class="line"><span class="cl">  <span class="nb">test</span> <span class="s2">&#34;check routing and payment type dynamic selection&#34;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="n">visit</span> <span class="n">store_index_url</span>
</span></span><span class="line"><span class="cl">    <span class="n">click_on</span> <span class="s2">&#34;Add to Cart&#34;</span><span class="p">,</span> <span class="ss">match</span><span class="p">:</span> <span class="ss">:first</span>
</span></span><span class="line"><span class="cl">    <span class="n">click_on</span> <span class="s2">&#34;Checkout&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">fill_in</span> <span class="s2">&#34;Name&#34;</span><span class="p">,</span> <span class="ss">with</span><span class="p">:</span> <span class="s2">&#34;Dave Thomas&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">fill_in</span> <span class="s2">&#34;Address&#34;</span><span class="p">,</span> <span class="ss">with</span><span class="p">:</span> <span class="s2">&#34;123 Main Street&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">fill_in</span> <span class="s2">&#34;E-mail&#34;</span><span class="p">,</span> <span class="ss">with</span><span class="p">:</span> <span class="s2">&#34;dave@example.com&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">assert_no_field</span> <span class="s2">&#34;Routing number&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="nb">select</span> <span class="s2">&#34;Check&#34;</span><span class="p">,</span> <span class="ss">from</span><span class="p">:</span> <span class="s2">&#34;Pay type&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">assert_field</span> <span class="s2">&#34;Routing number&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">click_button</span> <span class="s2">&#34;Place Order&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">assert_text</span> <span class="s2">&#34;Thank you for your order&#34;</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>The middle chapters hotwire the storefront using Turbo Streams to replace the
cart partial in the sidebar asynchronously without requiring full page
reloads:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Chapter 11 hotwires the storefront cart using Turbo Streams:</span>
</span></span><span class="line"><span class="cl"><span class="c1"># app/controllers/line_items_controller.rb</span>
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">create</span>
</span></span><span class="line"><span class="cl">  <span class="n">product</span> <span class="o">=</span> <span class="no">Product</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:product_id</span><span class="o">]</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="vi">@line_item</span> <span class="o">=</span> <span class="vi">@cart</span><span class="o">.</span><span class="n">add_product</span><span class="p">(</span><span class="n">product</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="vi">@line_item</span><span class="o">.</span><span class="n">save</span>
</span></span><span class="line"><span class="cl">      <span class="nb">format</span><span class="o">.</span><span class="n">turbo_stream</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">render</span> <span class="ss">turbo_stream</span><span class="p">:</span> <span class="o">[</span>
</span></span><span class="line"><span class="cl">          <span class="n">turbo_stream</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="ss">:cart</span><span class="p">,</span> <span class="ss">partial</span><span class="p">:</span> <span class="s2">&#34;layouts/cart&#34;</span><span class="p">,</span> <span class="ss">locals</span><span class="p">:</span> <span class="p">{</span> <span class="ss">cart</span><span class="p">:</span> <span class="vi">@cart</span> <span class="p">}),</span>
</span></span><span class="line"><span class="cl">          <span class="n">turbo_stream</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&#34;notice&#34;</span><span class="p">,</span> <span class="ss">partial</span><span class="p">:</span> <span class="s2">&#34;store/notice&#34;</span><span class="p">,</span> <span class="ss">locals</span><span class="p">:</span> <span class="p">{</span> <span class="ss">notice</span><span class="p">:</span> <span class="s2">&#34;Added to cart.&#34;</span> <span class="p">})</span>
</span></span><span class="line"><span class="cl">        <span class="o">]</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">      <span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">redirect_to</span> <span class="n">store_index_url</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">end</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>ActiveRecord&rsquo;s reflection-based models were a big step up coming from Java: no
verbose POJO to wire up for every new table, no middleware class you&rsquo;re forced
to add just to have somewhere to put nothing. It even writes most of the
migration for you. I assume most modern frameworks have caught up on this front
by now, but coming from the old-fashioned way, it&rsquo;s slick. I also appreciated
that Rails doesn&rsquo;t force a heavy middleware layer on you; MVC is enough
separation for most of what I do, and in my JEE app that middle tier tends to be
a repetitive passthrough. Rails is comfortable letting the controller hold
logic, or pushing it down to the model as the last line of enforcement, which is
the better default.</p>
<p>i18n was convenient too: wrapping things in <code>t()</code> calls is a bit of a chore, but
I&rsquo;ve done worse to a frontend, and having everything, including ActiveRecord&rsquo;s
own validation error messages, live in the same YAML files beats splitting your
translations from the framework&rsquo;s built-in ones the way Java properties files
tend to.</p>
<p>The advanced iterations build out full inbound email routing with Action
Mailbox, routing incoming support inquiries directly to a mailbox controller
that links them to customer orders:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Chapter 16 processes incoming emails using Action Mailbox:</span>
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">SupportMailbox</span> <span class="o">&lt;</span> <span class="no">ApplicationMailbox</span>
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">process</span>
</span></span><span class="line"><span class="cl">    <span class="n">recent_order</span> <span class="o">=</span> <span class="no">Order</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="ss">email</span><span class="p">:</span> <span class="n">mail</span><span class="o">.</span><span class="n">from_address</span><span class="o">.</span><span class="n">to_s</span><span class="p">)</span><span class="o">.</span><span class="n">order</span><span class="p">(</span><span class="s2">&#34;created_at desc&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">first</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="no">SupportRequest</span><span class="o">.</span><span class="n">create!</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">      <span class="ss">email</span><span class="p">:</span> <span class="n">mail</span><span class="o">.</span><span class="n">from_address</span><span class="o">.</span><span class="n">to_s</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="ss">subject</span><span class="p">:</span> <span class="n">mail</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="ss">body</span><span class="p">:</span> <span class="n">mail</span><span class="o">.</span><span class="n">decoded</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="ss">order</span><span class="p">:</span> <span class="n">recent_order</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>Most of my reactions here are colored by the JEE lens, and most things look good
next to JEE, it&rsquo;s an old, overcomplicated, designed-by-committee way of building
web apps. But Rails earned its reputation independent of that comparison: an
all-inclusive framework that stays flexible everywhere except right at its core
(try ripping out Active Record and ask whether you&rsquo;re still using Rails).
Django&rsquo;s next on the list, then a pure JavaScript frontend, then something
slimmed down like a Go microservice or a Compojure backend, to see what the
batteries-included approach actually costs you once the batteries are gone.</p>
]]></content:encoded></item><item><title>The Foundations of Western Civilization</title><link>https://llcawthorne.github.io/posts/the-foundations-of-western-civilization/</link><pubDate>Wed, 21 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/the-foundations-of-western-civilization/</guid><description>&lt;p&gt;The first thing that struck me about &lt;em&gt;The Foundations of Western Civilization&lt;/em&gt;
was how abnormally fast it moved before it got to Greek history. The biggest
Bronze Age civilizations got a lecture, and in five lectures or so we were in
Greece and things slowed down. For Egypt in particular, it felt like they summed
up the entirety of Egyptian history with a sentence or two each about the Old
Kingdom, Middle Kingdom, and New Kingdom, then talked a little about Egyptian
life and were done.&lt;/p&gt;</description><content:encoded><![CDATA[<p>The first thing that struck me about <em>The Foundations of Western Civilization</em>
was how abnormally fast it moved before it got to Greek history. The biggest
Bronze Age civilizations got a lecture, and in five lectures or so we were in
Greece and things slowed down. For Egypt in particular, it felt like they summed
up the entirety of Egyptian history with a sentence or two each about the Old
Kingdom, Middle Kingdom, and New Kingdom, then talked a little about Egyptian
life and were done.</p>
<p>The lecturer&rsquo;s background in religious history really shows in his topics.
Religion got a lot of time, and not that it wasn&rsquo;t big in history, but the
course especially got bogged down comparing the Reformation and
Counter-Reformation over three lectures. I would much rather have had more
detail on Egypt than three lectures on the differences between Luther and Calvin
and the specifics of how the Catholics chose to counter them. But then again,
I&rsquo;m an atheist, and every time the course touched on religion it reminded me how
long religion has held us back and distracted us with imaginary concerns. It
also spent a whole lecture each on the Hebrews, Jesus and the New Testament, the
Christian Church in Late Antiquity, Scholasticism in Monasteries, and Mohammed
and Islam. To think that theology was once the Queen of the Sciences, the
highest subject taught in universities. It also felt like he downplayed the
Inquisition, just mentioning as an aside that it was a thing while telling us so
much else about the Catholic Church.</p>
<p>The lecturer also had a bone to pick with the way history is commonly taught.
His claim was that the Roman Empire never really had a Fall, except in Edward
Gibbon&rsquo;s imagination looking back from the 18th century. Likewise, there were no
Dark Ages. What we call the Dark Ages was a great time of expansion in Europe
and hundreds of years where it was happily not held back by plagues. By my own
reckoning, that holds up only for the later part of the period. The Plague of
Justinian struck in 541 and recurred for about two centuries, but from around
750 until the Black Death arrived in 1347, Europe was largely plague free. So at
least 750 to 1000, which falls within the traditional Dark Ages, really was a
time of plenty. Indeed, Charlemagne&rsquo;s kingdom was viewed as a new Rome by
contemporaries, even though it unfortunately didn&rsquo;t survive his grandsons.
Scholars now usually call the whole period the Early Middle Ages anyway. The one
era still commonly called a Dark Age and truly deserving of the term is the
Greek Dark Ages, when the Greeks lost writing.</p>
<p>He also disagreed with the idea of the Renaissance, even though he gave a
completely acceptable description of what characterized it and how it started in
Florence and radiated outward. His argument was that Greek and Roman traditions
never vanished during the Middle Ages, only became less prominent, so history is
more continuous than the neat divisions we usually teach. I find that a tougher
case to make than his Dark Ages argument, since there clearly was a resurgence
of classical inspiration after the Middle Ages, even if it wasn&rsquo;t the first.
Indeed, some would say there was a Carolingian Renaissance in the 800s and a
&ldquo;Renaissance of the Twelfth Century&rdquo; as well, and that the Italian Renaissance
was just the best-known occurrence of a recurring theme.</p>
<p>This is the first of two Western Civilization courses, and it went quite a bit
longer than I expected. I didn&rsquo;t expect much after Rome, but it covered the
Middle Ages, the Renaissance, and the Age of Exploration and Empire, so it was a
broad sweep that went all the way to the New World. It&rsquo;s kind of a fun point
that I didn&rsquo;t know Canute was a real king when I watched <em>Vinland Saga</em>, but
this series of lectures educated me on the Danelaw and the Danish conquest of
Britain.</p>
<p>A few ideas stuck with me along the way. The lectures framed Sparta&rsquo;s wars,
Athens&rsquo; trade, and Corinth&rsquo;s colonies as responses to the same land shortage,
and while war and trade looked stronger at the time, I think colonization had
the biggest long-term impact, since that&rsquo;s what spread Greek culture. I also
noticed that Sparta and Rome were both devoted to ancestral custom (Lycurgus in
Sparta, the mos maiorum in Rome) and both deeply militaristic, though
innovative, democratic Athens was just as violent and just as willing to embrace
&ldquo;might makes right,&rdquo; so tradition isn&rsquo;t the whole story. Rome&rsquo;s conquests were
often framed as defensive, since fear of Rome pushed its neighbors to aid Rome&rsquo;s
enemies, which gave Rome its next target, though historians debate whether
&ldquo;defensive imperialism&rdquo; is accurate or just Roman self-justification. And it&rsquo;s
remarkable that so many lasting political ideas came from Greece and Rome, which
were both prone to demagogues and strongmen, maybe because later thinkers
learned as much from their failures as from their successes.</p>
<p>The best thing I came away with wasn&rsquo;t in the lectures themselves but came from
thinking about them. Sparta and Rome both looked to their ancestors for
guidance, which got me wondering how progress happens in societies that revere
the past. My conclusion is that progress often comes from holding a nation to
its founders&rsquo; ideals. Abolitionists and suffragists succeeded largely by
demanding the nation live up to its stated principles, which is in a sense a
conservative argument in service of progress. The flip side is that people who
believe in change can be too sure they know how to steer it, which is a real
argument for caution, and it pairs well with Chesterton&rsquo;s fence.</p>
<p>I&rsquo;ve picked out a good follow-up course that dedicates 48 lectures just to
Egypt, Bob Brier&rsquo;s <em>The History of Ancient Egypt</em>, but I&rsquo;m not sure where I&rsquo;ll
fit it in. Perhaps on my eclectic topics pass at the end of the wide sweep of
history. If I can fit in a course on Victorian Britain, surely I have time for
one on Egypt.</p>
]]></content:encoded></item><item><title>Technical Blogging</title><link>https://llcawthorne.github.io/posts/technical-blogging/</link><pubDate>Mon, 19 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/technical-blogging/</guid><description>&lt;p&gt;&lt;img alt="Technical Blogging cover" loading="lazy" src="https://llcawthorne.github.io/posts/technical-blogging/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Technical Blogging&lt;/em&gt; talked a lot more about SEO, blog promotion, how to benefit
from being a blogger, and how to scale; all good problems to have but a little
early to worry about when you don&amp;rsquo;t have a blog yet. There was maybe a chapter
on the actual act of blogging, but it was mostly watered-down &lt;em&gt;Getting Things
Done&lt;/em&gt; advice and a brief sketch of the pomodoro technique. It did remind me that
I always wanted to check out the Things app for managing to-dos and projects,
and it made me notice that Pragmatic Bookshelf has another entire book on the
Pomodoro Technique (I can&amp;rsquo;t imagine what they have to say about it at book
length, but several authors have managed to talk about the Pomodoro Technique
for an entire book, judging from my Amazon results).&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Technical Blogging cover" loading="lazy" src="/posts/technical-blogging/images/cover.jpg"></p>
<p><em>Technical Blogging</em> talked a lot more about SEO, blog promotion, how to benefit
from being a blogger, and how to scale; all good problems to have but a little
early to worry about when you don&rsquo;t have a blog yet. There was maybe a chapter
on the actual act of blogging, but it was mostly watered-down <em>Getting Things
Done</em> advice and a brief sketch of the pomodoro technique. It did remind me that
I always wanted to check out the Things app for managing to-dos and projects,
and it made me notice that Pragmatic Bookshelf has another entire book on the
Pomodoro Technique (I can&rsquo;t imagine what they have to say about it at book
length, but several authors have managed to talk about the Pomodoro Technique
for an entire book, judging from my Amazon results).</p>
<p>It also made me realize that it&rsquo;s been fifteen years since I read <em>Getting
Things Done</em>. I don&rsquo;t have as much stuff to get done as I did back in school
when I was working on a PhD and teaching classes too, but maybe I&rsquo;ll re-read it
anyway. It had useful productivity advice. I didn&rsquo;t learn anything about
productivity from what was in the <em>Technical Blogging</em> book. I also don&rsquo;t plan
to blog like it&rsquo;s another job where I find myself spending 3-4 hours a week
writing posts and need to schedule it in; I&rsquo;m mostly reviewing books - when I
finish a book, I can write a blogpost. I want to blog, but I&rsquo;d rather spend most
of my productive time reading and coding and when I am feeling creative put my
thoughts out there.</p>
<p>One good idea from this book that was worth the price of admission was
submitting a blog to Planet Haskell and/or Planet Clojure. You can submit just
the proper tag feed to them so you are free to get off topic without getting
into trouble, and they can push your posts out there for the world. It would be
so cool to be featured by one of the Planets, as I&rsquo;ve been subscribed to their
RSS feeds for as long as I&rsquo;ve had an RSS reader, even if I didn&rsquo;t keep up for a
time.</p>
]]></content:encoded></item><item><title>Grokking Simplicity</title><link>https://llcawthorne.github.io/posts/grokking-simplicity/</link><pubDate>Fri, 16 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/grokking-simplicity/</guid><description>&lt;p&gt;&lt;img alt="Grokking Simplicity cover" loading="lazy" src="https://llcawthorne.github.io/posts/grokking-simplicity/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Grokking Simplicity&lt;/em&gt; by Eric Normand teaches the difference between actions,
calculations, and data as a way to reason about mutation and side effects, and
it works better as a vocabulary book than a technique book. If you&amp;rsquo;ve already
internalized what &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, and &lt;code&gt;reduce&lt;/code&gt; are for, and I mean really
internalized it and not just being able to write the syntax, most of the core
material is going to read as confirmation of things you already believe instead
of new information. The higher-order function chapters and the copy-on-write
chapters fall right into that bucket. They&amp;rsquo;re clearly and patiently explained,
and useful for someone who&amp;rsquo;s never had the difference between mutating and
copying spelled out, but they&amp;rsquo;re slow going if you&amp;rsquo;ve been burned by shared
mutable state enough times to already distrust it on instinct.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Grokking Simplicity cover" loading="lazy" src="/posts/grokking-simplicity/images/cover.jpg"></p>
<p><em>Grokking Simplicity</em> by Eric Normand teaches the difference between actions,
calculations, and data as a way to reason about mutation and side effects, and
it works better as a vocabulary book than a technique book. If you&rsquo;ve already
internalized what <code>map</code>, <code>filter</code>, and <code>reduce</code> are for, and I mean really
internalized it and not just being able to write the syntax, most of the core
material is going to read as confirmation of things you already believe instead
of new information. The higher-order function chapters and the copy-on-write
chapters fall right into that bucket. They&rsquo;re clearly and patiently explained,
and useful for someone who&rsquo;s never had the difference between mutating and
copying spelled out, but they&rsquo;re slow going if you&rsquo;ve been burned by shared
mutable state enough times to already distrust it on instinct.</p>
<p>The best material is outside that core. The architecture chapters cover both
stratified design and the onion model, and they were solid and worth having
read, though not so revelatory that I&rsquo;m in a hurry to go through them again. The
concurrency chapters were the standout. They introduce a diagramming technique
for reasoning about timelines and ordering that I hadn&rsquo;t run into before and
thought was really creative, and it&rsquo;s a lot different from the usual &ldquo;just use
locks or actors and hope&rdquo; approach most books take. Those are the chapters I&rsquo;d
go back to if a project involving concurrency comes up, since it&rsquo;s the kind of
technique you have to actually apply before it sticks.</p>
<p>The biggest miss for me was the immutable data chapters. I went in hoping for
advice on using immutable data structures in single-binding languages, the
discipline of writing code where a name, once bound, stays bound. What I got was
mostly copy-on-write technique, demonstrated with JavaScript objects that get
rebound on every update. That&rsquo;s a reasonable way to teach it in a language like
Elixir where rebinding is idiomatic, but it doesn&rsquo;t really carry over to the
habit I was actually after, which is reaching for <code>val</code> by default in Kotlin, or
treating a Haskell declaration as a one-time mathematical definition instead of
a variable that just happens not to change. The chapter shows you how to build
the immutable structure, but it doesn&rsquo;t really show you how to live in a
codebase that treats bindings as permanent.</p>
<p>Overall, it&rsquo;s a fast, well-explained, easy read that&rsquo;s clearly aimed at someone
running into these ideas for the first time. If that&rsquo;s not you, you&rsquo;ll skim more
than you expect, but the concurrency material deserves a second look, and the
architecture chapters were worth reading once, even if they weren&rsquo;t essential.</p>
]]></content:encoded></item><item><title>Fundamentals of Software Architecture</title><link>https://llcawthorne.github.io/posts/fundamentals-of-software-architecture/</link><pubDate>Wed, 14 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/fundamentals-of-software-architecture/</guid><description>&lt;p&gt;&lt;img alt="Fundamentals of Software Architecture cover" loading="lazy" src="https://llcawthorne.github.io/posts/fundamentals-of-software-architecture/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;The best part of the book was section 2, where it described different
architecture styles and gave each one star ratings across a variety of
characteristics, which I&amp;rsquo;m sure come from the authors&amp;rsquo; experience with each
style. I also liked how it framed microservices as part of a trend pendulum,
reacting against the reuse pain that SOA left behind, since I like noticing when
a new trend is really just correcting for the last one&amp;rsquo;s mistakes. I&amp;rsquo;m not an
architect currently, so I have no need for architecture decision records (ADRs),
except maybe for technical decisions made on personal projects so I can go back
and remember the thought that went into them. I may start using
&lt;a href="https://github.com/npryce/adr-tools"&gt;adr-tools&lt;/a&gt; on my own for that. Since I
mostly listened to this on runs, my notes don&amp;rsquo;t really do it justice. I want to
go back sometime when I&amp;rsquo;m not out of breath and write proper summaries of the
ratings for each architecture style.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Fundamentals of Software Architecture cover" loading="lazy" src="/posts/fundamentals-of-software-architecture/images/cover.jpg"></p>
<p>The best part of the book was section 2, where it described different
architecture styles and gave each one star ratings across a variety of
characteristics, which I&rsquo;m sure come from the authors&rsquo; experience with each
style. I also liked how it framed microservices as part of a trend pendulum,
reacting against the reuse pain that SOA left behind, since I like noticing when
a new trend is really just correcting for the last one&rsquo;s mistakes. I&rsquo;m not an
architect currently, so I have no need for architecture decision records (ADRs),
except maybe for technical decisions made on personal projects so I can go back
and remember the thought that went into them. I may start using
<a href="https://github.com/npryce/adr-tools">adr-tools</a> on my own for that. Since I
mostly listened to this on runs, my notes don&rsquo;t really do it justice. I want to
go back sometime when I&rsquo;m not out of breath and write proper summaries of the
ratings for each architecture style.</p>
]]></content:encoded></item><item><title>The Pragmatic Programmer</title><link>https://llcawthorne.github.io/posts/the-pragmatic-programmer/</link><pubDate>Mon, 12 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/the-pragmatic-programmer/</guid><description>&lt;p&gt;&lt;img alt="The Pragmatic Programmer cover" loading="lazy" src="https://llcawthorne.github.io/posts/the-pragmatic-programmer/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;I first read &lt;em&gt;The Pragmatic Programmer&lt;/em&gt; years ago, and the 20th anniversary
edition holds up really well. It isn&amp;rsquo;t just a nostalgia lap, since the updates
feel necessary, folding in ideas like ETC (&amp;ldquo;Easier to Change&amp;rdquo;), functional-style
data pipelines, and more modern concurrency patterns without losing the voice
that made the original a classic. It reads less like a list of rules and more
like advice from people who have actually shipped things and learned from what
went wrong.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="The Pragmatic Programmer cover" loading="lazy" src="/posts/the-pragmatic-programmer/images/cover.jpg"></p>
<p>I first read <em>The Pragmatic Programmer</em> years ago, and the 20th anniversary
edition holds up really well. It isn&rsquo;t just a nostalgia lap, since the updates
feel necessary, folding in ideas like ETC (&ldquo;Easier to Change&rdquo;), functional-style
data pipelines, and more modern concurrency patterns without losing the voice
that made the original a classic. It reads less like a list of rules and more
like advice from people who have actually shipped things and learned from what
went wrong.</p>
<p>I listened to it as an audiobook, and it worked better than I expected for a
book this dense with concepts. The narration keeps a good pace, and the material
is conversational enough that it doesn&rsquo;t need diagrams on every page to land. If
you&rsquo;ve read the original, it&rsquo;s worth a revisit, and if you haven&rsquo;t, this is the
version to start with.</p>
]]></content:encoded></item><item><title>Advanced Functional Programming with Elixir</title><link>https://llcawthorne.github.io/posts/advanced-functional-programming-with-elixir/</link><pubDate>Fri, 09 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/advanced-functional-programming-with-elixir/</guid><description>&lt;p&gt;&lt;img alt="Advanced Functional Programming with Elixir cover" loading="lazy" src="https://llcawthorne.github.io/posts/advanced-functional-programming-with-elixir/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Advanced Functional Programming with Elixir&lt;/em&gt; turned out to be a pretty good,
easy introduction to functional programming concepts, and it uses good domain
examples instead of math. It walks through Elixir&amp;rsquo;s protocol system with a DDD
slant, using a theme park domain with rides, patrons, and Fast Passes instead of
the numbers-only examples you get in most Haskell books. The code is built
around a companion library called &lt;code&gt;FunPark&lt;/code&gt;, a teaching-scale version of Koski&amp;rsquo;s
real production package, &lt;code&gt;Funx&lt;/code&gt;. The theme park was a good choice, and it paid
off most in the &lt;code&gt;Eq&lt;/code&gt;/&lt;code&gt;FastPass&lt;/code&gt; chapter, where a real business rule (two Fast
Passes with the same datetime conflict, but should still be equal by &lt;code&gt;id&lt;/code&gt;)
motivated &lt;code&gt;contramap&lt;/code&gt; far better than an abstract definition ever could have:&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Advanced Functional Programming with Elixir cover" loading="lazy" src="/posts/advanced-functional-programming-with-elixir/images/cover.jpg"></p>
<p><em>Advanced Functional Programming with Elixir</em> turned out to be a pretty good,
easy introduction to functional programming concepts, and it uses good domain
examples instead of math. It walks through Elixir&rsquo;s protocol system with a DDD
slant, using a theme park domain with rides, patrons, and Fast Passes instead of
the numbers-only examples you get in most Haskell books. The code is built
around a companion library called <code>FunPark</code>, a teaching-scale version of Koski&rsquo;s
real production package, <code>Funx</code>. The theme park was a good choice, and it paid
off most in the <code>Eq</code>/<code>FastPass</code> chapter, where a real business rule (two Fast
Passes with the same datetime conflict, but should still be equal by <code>id</code>)
motivated <code>contramap</code> far better than an abstract definition ever could have:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapter 2 defines contramap as a plain comparator map so types can have</span>
</span></span><span class="line"><span class="cl"><span class="c1"># more than one domain-specific notion of equality:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">FunPark.Eq.Utils</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kn">alias</span> <span class="nc">FunPark.Eq</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">contramap</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="p">%{</span>
</span></span><span class="line"><span class="cl">      <span class="ss">eq?</span><span class="p">:</span> <span class="k">fn</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">-&gt;</span> <span class="nc">Eq</span><span class="o">.</span><span class="n">eq?</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">f</span><span class="o">.</span><span class="p">(</span><span class="n">b</span><span class="p">))</span> <span class="k">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="ss">not_eq?</span><span class="p">:</span> <span class="k">fn</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">-&gt;</span> <span class="nc">Eq</span><span class="o">.</span><span class="n">not_eq?</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">f</span><span class="o">.</span><span class="p">(</span><span class="n">b</span><span class="p">))</span> <span class="k">end</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>The quality was uneven, but in a predictable way. Eq, Ord, and Predicates were a
low bar that the book cleared easily. Monoid was the standout chapter, and the
one place where all the abstract machinery (<code>Eq.All</code>, comparators built with
<code>contramap</code>) paid off concretely enough to justify the ceremony:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapter 4 combines comparators monoidally using Eq.All:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">FunPark.Monoid.Eq.All</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kd">defstruct</span> <span class="ss">eq?</span><span class="p">:</span> <span class="o">&amp;</span><span class="nc">FunPark.Monoid.Eq.All</span><span class="o">.</span><span class="n">default_eq?</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="ss">not_eq?</span><span class="p">:</span> <span class="o">&amp;</span><span class="nc">FunPark.Monoid.Eq.All</span><span class="o">.</span><span class="n">default_not_eq?</span><span class="o">/</span><span class="mi">2</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">default_eq?</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">),</span> <span class="ss">do</span><span class="p">:</span> <span class="no">true</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">default_not_eq?</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">),</span> <span class="ss">do</span><span class="p">:</span> <span class="no">false</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">defimpl</span> <span class="nc">FunPark.Monoid</span><span class="p">,</span> <span class="ss">for</span><span class="p">:</span> <span class="nc">FunPark.Monoid.Eq.All</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kn">alias</span> <span class="nc">FunPark.Monoid.Eq.All</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">empty</span><span class="p">(</span><span class="n">_</span><span class="p">),</span> <span class="ss">do</span><span class="p">:</span> <span class="p">%</span><span class="nc">All</span><span class="p">{}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">append</span><span class="p">(%</span><span class="nc">All</span><span class="p">{}</span> <span class="o">=</span> <span class="n">eq1</span><span class="p">,</span> <span class="p">%</span><span class="nc">All</span><span class="p">{}</span> <span class="o">=</span> <span class="n">eq2</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="p">%</span><span class="nc">All</span><span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="ss">eq?</span><span class="p">:</span> <span class="k">fn</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">-&gt;</span> <span class="n">eq1</span><span class="o">.</span><span class="n">eq?</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="n">eq2</span><span class="o">.</span><span class="n">eq?</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="k">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="ss">not_eq?</span><span class="p">:</span> <span class="k">fn</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">-&gt;</span> <span class="n">eq1</span><span class="o">.</span><span class="n">not_eq?</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="o">||</span> <span class="n">eq2</span><span class="o">.</span><span class="n">not_eq?</span><span class="o">.</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="k">end</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>The monad theory was thin and abstract on its own and only came together once
Maybe and Either gave it somewhere to land. The one real gap was motivation for
Reader and Effect, which never quite sold me. The mechanics were fine, but no
example was compelling enough to answer &ldquo;why bother wrapping this?&rdquo;</p>
<p>The Eq and Ord chapters are straightforward once you accept that Elixir
protocols dispatch on struct type only, which forces workarounds like
<code>contramap</code> and <code>to_eq_map</code> (comparators as plain maps, not just protocol
implementations) the moment your domain needs more than one valid notion of
equality for a type. That ties into DDD nicely, since equality isn&rsquo;t structural,
it depends on the bounded context, so the same type can have different valid
comparators depending on which part of the domain is asking.</p>
<p>The Predicates and Foldable chapter introduced <code>Foldable</code> for <code>Function</code> (a
predicate as a fold, with zero-arity thunk dispatch) with almost no explanation,
and I had to do some real reconstruction before it landed. It turned out to be a
catamorphism (one function per fixed shape) hiding under a name that sounds like
list reduction. I also caught a bug in the protocol declaration there.
<code>defprotocol</code> declared <code>fold_l(structure, transform_fn, base)</code>, but every real
implementation and call site used <code>(structure, acc, func)</code>, so the protocol&rsquo;s
own docs had the argument names reversed. It&rsquo;s harmless, since protocol callback
names aren&rsquo;t enforced, but it&rsquo;s misleading on a cold read.</p>
<p>Monoid was the best chapter. <code>Sum</code> is the toy case, and <code>Eq.All</code> and <code>Eq.Any</code>
are the real payoff, equality combinators as monoids, with <code>&amp;&amp;</code> and <code>||</code> doing
the combining. I caught one real typo there too (<code>default_not_eq</code> vs.
<code>default_not_eq?</code>), and it confirmed a design tension worth remembering: this
machinery is worth it once you have multiple domain-meaningful comparators that
need combining and reusing, but not for a one-off comparison you could write
with <code>&amp;&amp;</code> directly.</p>
<p>The monad theory chapter is careful to say it&rsquo;s &ldquo;inspired by category theory,
not a direct implementation.&rdquo; The laws (left identity, right identity, and
associativity) landed fine once I reverse-engineered <code>pure</code>, which shows up
without explanation, as the same idea as <code>Monoid</code>&rsquo;s <code>wrap</code>/<code>empty</code>, just
Monad-flavored. There&rsquo;s no dedicated Functor chapter, and <code>map</code> gets treated as
a free consequence of <code>bind</code> and <code>pure</code> instead of getting its own build-up,
unlike <em>From Objects to Functions</em>, which used Functor as the on-ramp to Monad.</p>
<p>Reader was clean mechanically (the environment as a deferred function,
<code>ask</code>/<code>asks</code>, and <code>run</code> as the escape hatch), but the worked examples were too
small to justify the ceremony over just passing an argument. The one clear win
was swapping <code>run(computation, prod_env)</code> for <code>run(computation, test_env)</code>,
which is a real dependency injection payoff, independent of the toy examples
around it.</p>
<p>Maybe and Either are where the book actually sold itself. You chain <code>bind</code>-based
computations and only check for failure once at the end, instead of doing
constant nil checks, which is a direct answer to how much Go&rsquo;s manual <code>err != nil</code> checking grates on me. <code>Either</code> wins over <code>Maybe</code> when you need to carry
<em>why</em> something failed. Choosing <code>bind</code> to fail fast versus <code>ap</code> to collect all
the errors was the most concrete moment in the whole book where an abstraction
proved its worth, since the same operations give you two different validation
strategies with one shared vocabulary:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapters 8 and 9 contrast fail-fast binding with error-accumulating validation:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">FunPark.Ride.FastLane</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kn">import</span> <span class="nc">FunPark.Monad.Either</span><span class="p">,</span> <span class="ss">only</span><span class="p">:</span> <span class="p">[</span><span class="ss">bind</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="ss">right</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="ss">left</span><span class="p">:</span> <span class="mi">1</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="c1"># Fail-fast pipeline: aborts at the first failing condition:</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">ensure_fast_pass_lane</span><span class="p">(%</span><span class="nc">Patron</span><span class="p">{}</span> <span class="o">=</span> <span class="n">patron</span><span class="p">,</span> <span class="p">%</span><span class="nc">Ride</span><span class="p">{}</span> <span class="o">=</span> <span class="n">ride</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="n">patron</span>
</span></span><span class="line"><span class="cl">    <span class="o">|&gt;</span> <span class="n">ensure_height</span><span class="p">(</span><span class="n">ride</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="o">|&gt;</span> <span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ensure_age</span><span class="p">(</span><span class="ni">&amp;1</span><span class="p">,</span> <span class="n">ride</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="o">|&gt;</span> <span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ensure_ticket</span><span class="p">(</span><span class="ni">&amp;1</span><span class="p">,</span> <span class="n">ride</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="c1"># Applicative traversal: accumulates all validation errors simultaneously:</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">validate_eligibility</span><span class="p">(%</span><span class="nc">Patron</span><span class="p">{}</span> <span class="o">=</span> <span class="n">patron</span><span class="p">,</span> <span class="p">%</span><span class="nc">Ride</span><span class="p">{}</span> <span class="o">=</span> <span class="n">ride</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="n">validators</span> <span class="o">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">      <span class="o">&amp;</span><span class="n">ensure_height</span><span class="p">(</span><span class="ni">&amp;1</span><span class="p">,</span> <span class="n">ride</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">      <span class="o">&amp;</span><span class="n">ensure_age</span><span class="p">(</span><span class="ni">&amp;1</span><span class="p">,</span> <span class="n">ride</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">      <span class="o">&amp;</span><span class="n">ensure_ticket</span><span class="p">(</span><span class="ni">&amp;1</span><span class="p">,</span> <span class="n">ride</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nc">FunPark.Monad.Either</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">patron</span><span class="p">,</span> <span class="n">validators</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>Effect never made a compelling case for why actions specifically need to be
trapped in a monad, though the ride repository example was believable as a real
pattern. It was the weakest chapter at justifying its own existence.</p>
<p>I&rsquo;m not convinced the full ceremony is worth it over Kotlin&rsquo;s null safety for
the <code>Maybe</code> case, since that comparison feels close to a wash. Either doesn&rsquo;t
have an equally clean stand-in in Kotlin, though. Kotlin&rsquo;s <code>Result&lt;T&gt;</code> is tied
to <code>Throwable</code>, so a hand-rolled <code>Outcome</code> type or Arrow&rsquo;s <code>Either</code> are the real
equivalents, and that&rsquo;s the one idea from this book most likely to actually
change how I write Kotlin.</p>
<p>Overall, it&rsquo;s a good, easy introduction to FP for someone with some prior
exposure who wants examples grounded in a domain instead of math. I&rsquo;m glad I had
AI on hand to work through the parts the book left underexplained, especially
the Foldable predicate case, since it would&rsquo;ve been a rougher read alone.</p>
]]></content:encoded></item><item><title>The Programmer's Brain</title><link>https://llcawthorne.github.io/posts/the-programmers-brain/</link><pubDate>Wed, 07 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/the-programmers-brain/</guid><description>&lt;p&gt;&lt;img alt="The Programmer&amp;rsquo;s Brain cover" loading="lazy" src="https://llcawthorne.github.io/posts/the-programmers-brain/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;rsquo;t find a lot of the advice in this book terribly useful. It mostly seemed
like common sense backed by a bit of research. The onboarding advice was
probably the most useful part, if only because I&amp;rsquo;m senior enough now that it
might come in handy with junior colleagues. The idea is basically to focus on
single activities at first, starting with concrete code instead of diagrams, and
remembering that everything is new to them. It is easy to forget once you&amp;rsquo;ve
been steeped in a codebase for years.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="The Programmer&rsquo;s Brain cover" loading="lazy" src="/posts/the-programmers-brain/images/cover.jpg"></p>
<p>I didn&rsquo;t find a lot of the advice in this book terribly useful. It mostly seemed
like common sense backed by a bit of research. The onboarding advice was
probably the most useful part, if only because I&rsquo;m senior enough now that it
might come in handy with junior colleagues. The idea is basically to focus on
single activities at first, starting with concrete code instead of diagrams, and
remembering that everything is new to them. It is easy to forget once you&rsquo;ve
been steeped in a codebase for years.</p>
<p>The Roles of Variables Framework was new to me too. I actually paused my run to
jot down the key ideas since it felt worth remembering, even though I wasn&rsquo;t
sure how valuable it would be in practice. Looking at my own code though, I
mostly stick to &ldquo;fixed value&rdquo; variables over any of the other roles (<code>val</code>s in
Kotlin, and I&rsquo;m trying to do some Haskell on the side for fun). I also liked the
advice on dealing with interruptions by offloading as much of your thought
process as possible instead of trying to hold it all in your head. That&rsquo;s
basically what I use Obsidian for at home, and at work I&rsquo;ve had the same
<code>notes.txt</code> file open for ten years that&rsquo;s probably 50 pages long by now.</p>
]]></content:encoded></item><item><title>Learn Functional Programming with Elixir</title><link>https://llcawthorne.github.io/posts/learn-functional-programming-with-elixir/</link><pubDate>Mon, 05 Oct 2026 06:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/learn-functional-programming-with-elixir/</guid><description>&lt;p&gt;&lt;img alt="Learn Functional Programming with Elixir cover" loading="lazy" src="https://llcawthorne.github.io/posts/learn-functional-programming-with-elixir/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;A perfectly good introduction to the Elixir language, although it didn&amp;rsquo;t have
anything specific to learning functional programming in it beyond getting used
to doing things the Elixir way. I guess it had more recursion than most
introductory programming books&amp;hellip; It feels like a terrible introduction in
comparison to Dave Thomas&amp;rsquo; &lt;em&gt;Programming Elixir&lt;/em&gt; though, since it stops totally
short of introducing the Actor model and OTP, which are unique strengths of
Elixir, but that&amp;rsquo;s obviously a longer book to read.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Learn Functional Programming with Elixir cover" loading="lazy" src="/posts/learn-functional-programming-with-elixir/images/cover.jpg"></p>
<p>A perfectly good introduction to the Elixir language, although it didn&rsquo;t have
anything specific to learning functional programming in it beyond getting used
to doing things the Elixir way. I guess it had more recursion than most
introductory programming books&hellip; It feels like a terrible introduction in
comparison to Dave Thomas&rsquo; <em>Programming Elixir</em> though, since it stops totally
short of introducing the Actor model and OTP, which are unique strengths of
Elixir, but that&rsquo;s obviously a longer book to read.</p>
<p>The book starts with Elixir fundamentals: immutable variables, the pipe operator
(<code>|&gt;</code>), and pattern matching with <code>case</code> and tuples to control flow without
relying on imperative reassignment:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapters 2 and 3 build intuition for immutability and pattern matching:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">AbilityScore</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">parse_score</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="k">case</span> <span class="nc">Integer</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">      <span class="ss">:error</span> <span class="o">-&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="s2">&#34;Invalid score: </span><span class="si">#{</span><span class="n">input</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">      <span class="p">{</span><span class="n">score</span><span class="p">,</span> <span class="n">_remainder</span><span class="p">}</span> <span class="o">-&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="n">modifier</span> <span class="o">=</span> <span class="p">(</span><span class="n">score</span> <span class="o">-</span> <span class="mi">10</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
</span></span><span class="line"><span class="cl">        <span class="p">{</span><span class="ss">:ok</span><span class="p">,</span> <span class="n">modifier</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">end</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>The middle chapters spend significant time on recursive functions, demonstrating
how list head-tail decomposition handles unbounded loops before transitioning to
the <code>Enum</code> module&rsquo;s higher-order functions:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapter 4 leans into recursive list traversal and pattern matching heads/tails:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">StringList</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">upcase</span><span class="p">([]),</span> <span class="ss">do</span><span class="p">:</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">upcase</span><span class="p">([</span><span class="n">head</span> <span class="o">|</span> <span class="n">tail</span><span class="p">]),</span> <span class="ss">do</span><span class="p">:</span> <span class="p">[</span><span class="nc">String</span><span class="o">.</span><span class="n">upcase</span><span class="p">(</span><span class="n">head</span><span class="p">)</span> <span class="o">|</span> <span class="n">upcase</span><span class="p">(</span><span class="n">tail</span><span class="p">)]</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Chapter 5 replaces explicit recursion with higher-order functions and capture syntax:</span>
</span></span><span class="line"><span class="cl"><span class="n">total_cost</span> <span class="o">=</span>
</span></span><span class="line"><span class="cl">  <span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">25</span><span class="p">,</span> <span class="mi">40</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="o">|&gt;</span> <span class="nc">Enum</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="o">&amp;</span><span class="p">(</span><span class="ni">&amp;1</span> <span class="o">*</span> <span class="mf">1.08</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">  <span class="o">|&gt;</span> <span class="nc">Enum</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">&amp;+/</span><span class="mi">2</span><span class="p">)</span>
</span></span></code></pre></div><p>The final chapters move toward application design with typed structs, guard
clauses, and separating pure domain logic from impure I/O boundaries:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1"># Chapters 6 and 7 structure domain data using structs and boundary functions:</span>
</span></span><span class="line"><span class="cl"><span class="kd">defmodule</span> <span class="nc">Character</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="na">@enforce_keys</span> <span class="p">[</span><span class="ss">:name</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="kd">defstruct</span> <span class="p">[</span><span class="ss">:name</span><span class="p">,</span> <span class="ss">health</span><span class="p">:</span> <span class="mi">100</span><span class="p">,</span> <span class="ss">mana</span><span class="p">:</span> <span class="mi">50</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">attack</span><span class="p">(%</span><span class="nc">Character</span><span class="p">{</span><span class="ss">health</span><span class="p">:</span> <span class="n">hp</span><span class="p">}</span> <span class="o">=</span> <span class="n">target</span><span class="p">,</span> <span class="n">damage</span><span class="p">)</span> <span class="ow">when</span> <span class="n">damage</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">    <span class="n">new_hp</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">hp</span> <span class="o">-</span> <span class="n">damage</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">%{</span><span class="n">target</span> <span class="o">|</span> <span class="ss">health</span><span class="p">:</span> <span class="n">new_hp</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kd">def</span> <span class="n">alive?</span><span class="p">(%</span><span class="nc">Character</span><span class="p">{</span><span class="ss">health</span><span class="p">:</span> <span class="n">hp</span><span class="p">}),</span> <span class="ss">do</span><span class="p">:</span> <span class="n">hp</span> <span class="o">&gt;</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div>]]></content:encoded></item><item><title>Two Great Courses on Existentialism</title><link>https://llcawthorne.github.io/posts/existentialism-great-courses/</link><pubDate>Thu, 01 Oct 2026 16:50:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/existentialism-great-courses/</guid><description>&lt;p&gt;I listened to two Great Courses lecture series on existentialism, &lt;em&gt;No Excuses:
Existentialism and the Meaning of Life&lt;/em&gt; by Robert C. Solomon and &lt;em&gt;Existentialism
and the Authentic Life&lt;/em&gt; by Skye C. Cleary.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;No Excuses&lt;/em&gt; had a lot of lectures devoted to fictional works, more than I
expected from a philosophy course. The title comes from Sartre&amp;rsquo;s idea of
Absolute Freedom, that even chained in a dungeon you&amp;rsquo;re still free to choose
your own interpretation of the facts and how you react to them. The Bad Faith
concept stuck with me too, the idea that you&amp;rsquo;re acting in bad faith any time
your aspirations ignore the actual facts of your situation. I could aspire to be
a champion basketball player, but the facts say I&amp;rsquo;m 5'11&amp;quot; and almost 50, so
aspiring to that would be bad faith.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I listened to two Great Courses lecture series on existentialism, <em>No Excuses:
Existentialism and the Meaning of Life</em> by Robert C. Solomon and <em>Existentialism
and the Authentic Life</em> by Skye C. Cleary.</p>
<p><em>No Excuses</em> had a lot of lectures devoted to fictional works, more than I
expected from a philosophy course. The title comes from Sartre&rsquo;s idea of
Absolute Freedom, that even chained in a dungeon you&rsquo;re still free to choose
your own interpretation of the facts and how you react to them. The Bad Faith
concept stuck with me too, the idea that you&rsquo;re acting in bad faith any time
your aspirations ignore the actual facts of your situation. I could aspire to be
a champion basketball player, but the facts say I&rsquo;m 5'11&quot; and almost 50, so
aspiring to that would be bad faith.</p>
<p><em>Existentialism and the Authentic Life</em> covered a wide variety of existentialist
authors I hadn&rsquo;t heard of before, along with the generally expected ones. My
favorite was already Camus, since I&rsquo;ve read some of his works before, and his
idea of the Absurd, the tension between wanting the universe to have inherent
meaning and it flatly refusing to provide any. I&rsquo;ll admit my own notes on it
were thin though, since I was working out at the time, so I ended up going to
Gemini afterward to help me reconstruct the Myth of Sisyphus material properly.</p>
<p>Heidegger and Ortega were both phenomenologists that liked to make up words,
which is about the most accurate one-line summary I can give either of them.
When the lecture asked me to fill in the blank on &ldquo;I am ___,&rdquo; I immediately
reached for &ldquo;Senior Software Engineer,&rdquo; which was exactly the trap Sartre was
pointing at: you&rsquo;re always more than your vocation, no matter how many labels
you stack up.</p>
]]></content:encoded></item><item><title>Build Websites with Hugo</title><link>https://llcawthorne.github.io/posts/build-websites-with-hugo/</link><pubDate>Thu, 01 Oct 2026 16:45:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/build-websites-with-hugo/</guid><description>&lt;p&gt;&lt;img alt="Build Websites with Hugo cover" loading="lazy" src="https://llcawthorne.github.io/posts/build-websites-with-hugo/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;I picked up &lt;em&gt;Build Websites with Hugo&lt;/em&gt; because I&amp;rsquo;m a PragProg loyalist with
plans to revive my old blog, and if they have a book on something I&amp;rsquo;m using, I
like to have an opinion on it. My opinion is that it&amp;rsquo;s fine, but barely. The
book is from 2020, and Hugo has changed enough since then that half the
examples either don&amp;rsquo;t work or generate deprecation warnings. I was running Hugo
0.164 against a book written for 0.68, and the scaffolding generated by
&lt;code&gt;hugo new theme&lt;/code&gt; is completely different now, so it actively conflicted with
the book&amp;rsquo;s instructions at nearly every step.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Build Websites with Hugo cover" loading="lazy" src="/posts/build-websites-with-hugo/images/cover.jpg"></p>
<p>I picked up <em>Build Websites with Hugo</em> because I&rsquo;m a PragProg loyalist with
plans to revive my old blog, and if they have a book on something I&rsquo;m using, I
like to have an opinion on it. My opinion is that it&rsquo;s fine, but barely. The
book is from 2020, and Hugo has changed enough since then that half the
examples either don&rsquo;t work or generate deprecation warnings. I was running Hugo
0.164 against a book written for 0.68, and the scaffolding generated by
<code>hugo new theme</code> is completely different now, so it actively conflicted with
the book&rsquo;s instructions at nearly every step.</p>
<p>Worse, the entire book has you building a custom theme from scratch, which is a
reasonable way to teach, except that anyone graduating from this book is going
to immediately throw that theme away for something maintained by people who
actually know CSS, so you spend 200 pages building something disposable. What
you do get out of it is an understanding of how Hugo thinks, with the template
hierarchy, partials, taxonomies, front matter, and the asset pipeline, and that
did turn out to be worth something, so just go in knowing you&rsquo;re reading it for
the concepts and not the site. Honestly, you&rsquo;d probably learn as much in an
afternoon of playing with Hugo directly and asking an AI assistant when you get
stuck.</p>
<p>There wasn&rsquo;t much else in it worth remembering, except maybe how to make a cool
&ldquo;This page will take X minutes to read&rdquo; summary.</p>
]]></content:encoded></item><item><title>From Objects to Functions</title><link>https://llcawthorne.github.io/posts/from-objects-to-functions/</link><pubDate>Sun, 27 Sep 2026 15:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/from-objects-to-functions/</guid><description>&lt;p&gt;&lt;img alt="From Objects to Functions cover" loading="lazy" src="https://llcawthorne.github.io/posts/from-objects-to-functions/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;This was one of the better books I&amp;rsquo;ve read recently for actually changing how I
think about programming. It combines domain-driven design, test-first
development, and functional programming into one coherent story, which is pretty
rare, since most books only tackle one of those at a time. Unlike some of my
other recent reads, the Kotlin itself was well-structured and idiomatic
throughout, not just functional-flavored Java.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="From Objects to Functions cover" loading="lazy" src="/posts/from-objects-to-functions/images/cover.jpg"></p>
<p>This was one of the better books I&rsquo;ve read recently for actually changing how I
think about programming. It combines domain-driven design, test-first
development, and functional programming into one coherent story, which is pretty
rare, since most books only tackle one of those at a time. Unlike some of my
other recent reads, the Kotlin itself was well-structured and idiomatic
throughout, not just functional-flavored Java.</p>
<p>The book builds a real app, a to-do list called Zettai, outside-in with TDD,
starting from acceptance tests and working down to the domain core. It uses
http4k, which the author picked specifically for its &ldquo;everything is a function&rdquo;
philosophy (an <code>HttpHandler</code> is just <code>(Request) -&gt; Response</code>), and Exposed for
persistence. The book&rsquo;s repo only has the start and end states for each step
(step1 through step7, spread loosely across 13 chapters) rather than the
intermediate changes, so I had to lean on the book&rsquo;s prose to follow <em>why</em> the
code evolved the way it did and not just <em>what</em> it ended up as:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Early chapters model web handling and outside-in testing purely as functions:
</span></span></span><span class="line"><span class="cl"><span class="k">val</span> <span class="py">app</span><span class="p">:</span> <span class="n">HttpHandler</span> <span class="p">=</span> <span class="n">routes</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;/todo/{user}/{list}&#34;</span> <span class="n">bind</span> <span class="nc">Method</span><span class="p">.</span><span class="n">GET</span> <span class="n">to</span> <span class="o">::</span><span class="n">showList</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;/todo/{user}&#34;</span> <span class="n">bind</span> <span class="nc">Method</span><span class="p">.</span><span class="n">POST</span> <span class="n">to</span> <span class="o">::</span><span class="n">createList</span>
</span></span><span class="line"><span class="cl"><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// In http4k, an HttpHandler is simply a function: (Request) -&gt; Response:
</span></span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">showList</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">Request</span><span class="p">):</span> <span class="n">Response</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">user</span> <span class="p">=</span> <span class="n">request</span><span class="p">.</span><span class="n">path</span><span class="p">(</span><span class="s2">&#34;user&#34;</span><span class="p">)</span><span class="o">?.</span><span class="n">let</span><span class="p">(</span><span class="o">::</span><span class="n">User</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">listName</span> <span class="p">=</span> <span class="n">request</span><span class="p">.</span><span class="n">path</span><span class="p">(</span><span class="s2">&#34;list&#34;</span><span class="p">)</span><span class="o">?.</span><span class="n">let</span><span class="p">(</span><span class="o">::</span><span class="n">ListName</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="k">if</span> <span class="p">(</span><span class="n">user</span> <span class="o">!=</span> <span class="k">null</span> <span class="o">&amp;&amp;</span> <span class="n">listName</span> <span class="o">!=</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">Response</span><span class="p">(</span><span class="nc">Status</span><span class="p">.</span><span class="n">OK</span><span class="p">).</span><span class="n">body</span><span class="p">(</span><span class="s2">&#34;Showing list </span><span class="si">$listName</span><span class="s2"> for </span><span class="si">${user.name}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">Response</span><span class="p">(</span><span class="nc">Status</span><span class="p">.</span><span class="n">BAD_REQUEST</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The book starts with actor-based domain-driven testing and works its way through
receiver-typed lambdas and extension functions, higher-order functions and
purity, and a hub-and-spokes (ports and adapters) architecture before it gets
into the theory. From there it covers monoids (with a door state machine
example), functors, monads, and applicatives, then event sourcing and
profunctors, and it finishes with a logging and JSON capstone that pulls
everything together. The theory was mostly motivated with real code before the
abstraction got a name, which I appreciated. Functors come out of <code>Holder</code>,
<code>List</code>, and <code>Outcome</code>, and then <code>ProjectionQuery</code> deliberately breaks the
container idea to push you into thinking of them as computations instead of
containers. Monads come from a concrete <code>TxReader&lt;TxReader&lt;T&gt;&gt;</code> nesting problem
instead of being introduced abstractly, and applicatives show up through
error-accumulating validation with <code>`!`</code> and <code>`*`</code> operators,
contrasted against the way monads short-circuit:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Chapters 7 and 11 replace exceptions with Outcome&lt;E, T&gt;, contrasting
</span></span></span><span class="line"><span class="cl"><span class="c1">// monadic bind (short-circuiting) with applicative failure accumulation:
</span></span></span><span class="line"><span class="cl"><span class="k">sealed</span> <span class="k">class</span> <span class="nc">Outcome</span><span class="p">&lt;</span><span class="k">out</span> <span class="n">E</span> <span class="p">:</span> <span class="n">OutcomeError</span><span class="p">,</span> <span class="k">out</span> <span class="n">T</span> <span class="p">:</span> <span class="n">Any</span><span class="p">&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">data</span> <span class="k">class</span> <span class="nc">Success</span><span class="p">&lt;</span><span class="k">out</span> <span class="n">T</span> <span class="p">:</span> <span class="n">Any</span><span class="p">&gt;(</span><span class="k">val</span> <span class="py">value</span><span class="p">:</span> <span class="n">T</span><span class="p">)</span> <span class="p">:</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">Nothing</span><span class="p">,</span> <span class="n">T</span><span class="p">&gt;()</span>
</span></span><span class="line"><span class="cl">    <span class="k">data</span> <span class="k">class</span> <span class="nc">Failure</span><span class="p">&lt;</span><span class="k">out</span> <span class="n">E</span> <span class="p">:</span> <span class="n">OutcomeError</span><span class="p">&gt;(</span><span class="k">val</span> <span class="py">error</span><span class="p">:</span> <span class="n">E</span><span class="p">)</span> <span class="p">:</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">Nothing</span><span class="p">&gt;()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="p">&lt;</span><span class="nc">U</span> <span class="p">:</span> <span class="nc">Any</span><span class="p">&gt;</span> <span class="nf">transform</span><span class="p">(</span><span class="n">f</span><span class="p">:</span> <span class="p">(</span><span class="n">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">U</span><span class="p">):</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">U</span><span class="p">&gt;</span> <span class="p">=</span> <span class="k">when</span> <span class="p">(</span><span class="k">this</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="n">Success</span> <span class="o">-&gt;</span> <span class="n">Success</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="k">value</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="n">Failure</span> <span class="o">-&gt;</span> <span class="k">this</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="p">&lt;</span><span class="nc">E</span> <span class="p">:</span> <span class="nc">OutcomeError</span><span class="p">,</span> <span class="nc">T</span> <span class="p">:</span> <span class="nc">Any</span><span class="p">,</span> <span class="nc">U</span> <span class="p">:</span> <span class="nc">Any</span><span class="p">&gt;</span> <span class="nf">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">T</span><span class="p">&gt;.</span><span class="n">bind</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="n">f</span><span class="p">:</span> <span class="p">(</span><span class="n">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">U</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">):</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">U</span><span class="p">&gt;</span> <span class="p">=</span> <span class="k">when</span> <span class="p">(</span><span class="k">this</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Success</span> <span class="o">-&gt;</span> <span class="n">f</span><span class="p">(</span><span class="k">value</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Failure</span> <span class="o">-&gt;</span> <span class="k">this</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="p">&lt;</span><span class="nc">E</span> <span class="p">:</span> <span class="nc">OutcomeError</span><span class="p">,</span> <span class="nc">T</span> <span class="p">:</span> <span class="nc">Any</span><span class="p">&gt;</span> <span class="nf">combineFailures</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="n">first</span><span class="p">:</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">T</span><span class="p">&gt;,</span>
</span></span><span class="line"><span class="cl">    <span class="n">second</span><span class="p">:</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">T</span><span class="p">&gt;,</span>
</span></span><span class="line"><span class="cl">    <span class="n">combine</span><span class="p">:</span> <span class="p">(</span><span class="n">E</span><span class="p">,</span> <span class="n">E</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">E</span>
</span></span><span class="line"><span class="cl"><span class="p">):</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">E</span><span class="p">,</span> <span class="n">T</span><span class="p">&gt;</span> <span class="p">=</span> <span class="k">when</span> <span class="p">(</span><span class="n">first</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Success</span> <span class="o">-&gt;</span> <span class="n">second</span>
</span></span><span class="line"><span class="cl">    <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Failure</span> <span class="o">-&gt;</span> <span class="k">when</span> <span class="p">(</span><span class="n">second</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Success</span> <span class="o">-&gt;</span> <span class="n">first</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Failure</span> <span class="o">-&gt;</span> <span class="nc">Outcome</span><span class="p">.</span><span class="n">Failure</span><span class="p">(</span><span class="n">combine</span><span class="p">(</span><span class="n">first</span><span class="p">.</span><span class="n">error</span><span class="p">,</span> <span class="n">second</span><span class="p">.</span><span class="n">error</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The exceptions were the door monoid section and parts of chapter 7, where the
vocabulary showed up before the payoff did. That was disorienting in the
moment, even though the payoff did eventually arrive by the end of the chapter.</p>
<p>The latter half of the book evolves the architecture into full event sourcing,
turning domain operations into commands that produce immutable events, which are
then projected into queryable in-memory views:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// The latter half develops full event sourcing, generating immutable events
</span></span></span><span class="line"><span class="cl"><span class="c1">// from commands and updating projections for query handling:
</span></span></span><span class="line"><span class="cl"><span class="k">data</span> <span class="k">class</span> <span class="nc">ToDoListCreated</span><span class="p">(</span><span class="k">val</span> <span class="py">id</span><span class="p">:</span> <span class="n">ListId</span><span class="p">,</span> <span class="k">val</span> <span class="py">owner</span><span class="p">:</span> <span class="n">User</span><span class="p">,</span> <span class="k">val</span> <span class="py">name</span><span class="p">:</span> <span class="n">ListName</span><span class="p">)</span> <span class="p">:</span> <span class="n">EntityEvent</span>
</span></span><span class="line"><span class="cl"><span class="k">data</span> <span class="k">class</span> <span class="nc">ItemAddedToList</span><span class="p">(</span><span class="k">val</span> <span class="py">id</span><span class="p">:</span> <span class="n">ListId</span><span class="p">,</span> <span class="k">val</span> <span class="py">item</span><span class="p">:</span> <span class="n">ToDoItem</span><span class="p">)</span> <span class="p">:</span> <span class="n">EntityEvent</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Executing domain commands into events:
</span></span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">handle</span><span class="p">(</span><span class="n">command</span><span class="p">:</span> <span class="n">CreateToDoList</span><span class="p">):</span> <span class="n">Outcome</span><span class="p">&lt;</span><span class="n">DomainError</span><span class="p">,</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">EntityEvent</span><span class="p">&gt;&gt;</span> <span class="p">=</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">command</span><span class="p">.</span><span class="n">name</span><span class="p">.</span><span class="n">isValid</span><span class="p">())</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nc">Outcome</span><span class="p">.</span><span class="n">Success</span><span class="p">(</span><span class="n">listOf</span><span class="p">(</span><span class="n">ToDoListCreated</span><span class="p">(</span><span class="nc">ListId</span><span class="p">.</span><span class="n">mint</span><span class="p">(),</span> <span class="n">command</span><span class="p">.</span><span class="n">owner</span><span class="p">,</span> <span class="n">command</span><span class="p">.</span><span class="n">name</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nc">Outcome</span><span class="p">.</span><span class="n">Failure</span><span class="p">(</span><span class="n">InvalidListName</span><span class="p">(</span><span class="n">command</span><span class="p">.</span><span class="n">name</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Projecting events into a read-only queryable view:
</span></span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">ListProjection</span> <span class="p">:</span> <span class="n">Projection</span><span class="p">&lt;</span><span class="n">ListRow</span><span class="p">,</span> <span class="n">EntityEvent</span><span class="p">&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">rows</span> <span class="p">=</span> <span class="n">mutableMapOf</span><span class="p">&lt;</span><span class="n">ListId</span><span class="p">,</span> <span class="n">ListRow</span><span class="p">&gt;()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">apply</span><span class="p">(</span><span class="n">event</span><span class="p">:</span> <span class="n">EntityEvent</span><span class="p">):</span> <span class="n">Unit</span> <span class="p">=</span> <span class="k">when</span> <span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="n">ToDoListCreated</span> <span class="o">-&gt;</span> <span class="n">rows</span><span class="p">[</span><span class="n">event</span><span class="p">.</span><span class="n">id</span><span class="p">]</span> <span class="p">=</span> <span class="n">ListRow</span><span class="p">(</span><span class="n">event</span><span class="p">.</span><span class="n">id</span><span class="p">,</span> <span class="n">event</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">emptyList</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">        <span class="k">is</span> <span class="n">ItemAddedToList</span> <span class="o">-&gt;</span> <span class="n">rows</span><span class="p">.</span><span class="n">computeIfPresent</span><span class="p">(</span><span class="n">event</span><span class="p">.</span><span class="n">id</span><span class="p">)</span> <span class="p">{</span> <span class="n">_</span><span class="p">,</span> <span class="n">row</span> <span class="o">-&gt;</span>
</span></span><span class="line"><span class="cl">            <span class="n">row</span><span class="p">.</span><span class="n">copy</span><span class="p">(</span><span class="n">items</span> <span class="p">=</span> <span class="n">row</span><span class="p">.</span><span class="n">items</span> <span class="p">+</span> <span class="n">event</span><span class="p">.</span><span class="n">item</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="k">else</span> <span class="o">-&gt;</span> <span class="n">Unit</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The Kotlin was the kind you&rsquo;d want to see in a strong codebase, with extension
functions, receiver types, sealed classes, and generics all used the way they&rsquo;re
meant to be used and not just as vehicles for FP theory. The actor-based test
framework, Pesticide, was a neat pattern too: you write a test once and run it
against the domain, a local HTTP server, or a deployed instance, even if I&rsquo;m not
sure I&rsquo;d adopt the library itself over something mainstream like kotest:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Acceptance tests are defined with Pesticide using domain language and human actors,
</span></span></span><span class="line"><span class="cl"><span class="c1">// parameterized to run against an in-memory domain, local HTTP, or deployed servers:
</span></span></span><span class="line"><span class="cl"><span class="k">typealias</span> <span class="n">ZettaiDDT</span> <span class="p">=</span> <span class="n">DomainDrivenTest</span><span class="p">&lt;</span><span class="n">ZettaiActions</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">SeeATodoListDDT</span> <span class="p">:</span> <span class="n">ZettaiDDT</span><span class="p">(</span><span class="n">allActions</span><span class="p">())</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">frank</span> <span class="p">=</span> <span class="n">ToDoListOwner</span><span class="p">(</span><span class="s2">&#34;Frank&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">bob</span> <span class="p">=</span> <span class="n">ToDoListOwner</span><span class="p">(</span><span class="s2">&#34;Bob&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">shoppingListName</span> <span class="p">=</span> <span class="s2">&#34;shopping&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">shoppingItems</span> <span class="p">=</span> <span class="n">listOf</span><span class="p">(</span><span class="s2">&#34;carrots&#34;</span><span class="p">,</span> <span class="s2">&#34;apples&#34;</span><span class="p">,</span> <span class="s2">&#34;milk&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">gardenListName</span> <span class="p">=</span> <span class="s2">&#34;gardening&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">gardenItems</span> <span class="p">=</span> <span class="n">listOf</span><span class="p">(</span><span class="s2">&#34;fix fence&#34;</span><span class="p">,</span> <span class="s2">&#34;mow lawn&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nd">@DDT</span>
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">`List owners can see their lists`</span><span class="p">()</span> <span class="p">=</span> <span class="n">ddtScenario</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">setUp</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="n">frank</span><span class="p">.</span><span class="err">`</span><span class="n">starts</span> <span class="n">with</span> <span class="n">a</span> <span class="n">list</span><span class="err">`</span><span class="p">(</span><span class="n">shoppingListName</span><span class="p">,</span> <span class="n">shoppingItems</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">bob</span><span class="p">.</span><span class="err">`</span><span class="n">starts</span> <span class="n">with</span> <span class="n">a</span> <span class="n">list</span><span class="err">`</span><span class="p">(</span><span class="n">gardenListName</span><span class="p">,</span> <span class="n">gardenItems</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">}.</span><span class="n">thenPlay</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">            <span class="n">frank</span><span class="p">.</span><span class="err">`</span><span class="n">can</span> <span class="n">see</span> <span class="err">#</span><span class="n">listname</span> <span class="n">with</span> <span class="err">#</span><span class="n">itemnames</span><span class="err">`</span><span class="p">(</span><span class="n">shoppingListName</span><span class="p">,</span> <span class="n">shoppingItems</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">            <span class="n">bob</span><span class="p">.</span><span class="err">`</span><span class="n">can</span> <span class="n">see</span> <span class="err">#</span><span class="n">listname</span> <span class="n">with</span> <span class="err">#</span><span class="n">itemnames</span><span class="err">`</span><span class="p">(</span><span class="n">gardenListName</span><span class="p">,</span> <span class="n">gardenItems</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nd">@DDT</span>
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">`Only owners can see their lists`</span><span class="p">()</span> <span class="p">=</span> <span class="n">ddtScenario</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">setUp</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="n">frank</span><span class="p">.</span><span class="err">`</span><span class="n">starts</span> <span class="n">with</span> <span class="n">a</span> <span class="n">list</span><span class="err">`</span><span class="p">(</span><span class="n">shoppingListName</span><span class="p">,</span> <span class="n">shoppingItems</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">bob</span><span class="p">.</span><span class="err">`</span><span class="n">starts</span> <span class="n">with</span> <span class="n">a</span> <span class="n">list</span><span class="err">`</span><span class="p">(</span><span class="n">gardenListName</span><span class="p">,</span> <span class="n">gardenItems</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">}.</span><span class="n">thenPlay</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">            <span class="n">frank</span><span class="p">.</span><span class="err">`</span><span class="n">cannot</span> <span class="n">see</span> <span class="err">#</span><span class="n">listname</span><span class="err">`</span><span class="p">(</span><span class="n">gardenListName</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">            <span class="n">bob</span><span class="p">.</span><span class="err">`</span><span class="n">cannot</span> <span class="n">see</span> <span class="err">#</span><span class="n">listname</span><span class="err">`</span><span class="p">(</span><span class="n">shoppingListName</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The final third, especially the logging and JSON chapters, had a noticeably
higher error rate than the rest of the book. Functions like <code>storeEvents</code> got
used before they were shown, parameter counts didn&rsquo;t match, and field names had
typos. The JSON chapter has you build a hand-rolled JSON library that even the
author admits he was &ldquo;wary&rdquo; of introducing, and it&rsquo;s incomplete, since its own
reflection-based code generation &ldquo;seldom works right without manual
intervention.&rdquo; A thin adapter wrapping kotlinx.serialization in an <code>Outcome</code>
probably would have served the book&rsquo;s own goals better than building JSON
parsing from scratch. There&rsquo;s also an optional 50-page category theory appendix,
which was a mixed bag. Functors, monads, and comonads mostly confirmed what the
main text had already taught me, and Kleisli categories turned out to be <code>bind</code>
with different notation once I decoded them, but profunctors and the Yoneda
lemma were presented abstractly enough that I had to reconstruct them from the
code examples myself before they landed.</p>
<p>Looking back at it now, after a stretch in Haskell, I remember a lot more about
the DDD and TDD from this book than I do about the details of Kotlin. It was
really into TDD, with the whole app built outside-in from acceptance tests, and
I miss that now that I&rsquo;m working through 1000 pages of <em>Django 5 By Example</em>
without a single test in them. Anyway, it&rsquo;s a dense book, but it was worth the
length, and it changed how I think about combining DDD, testing, and FP instead
of treating them as separate concerns. I&rsquo;d recommend it to someone with some
Kotlin under their belt and the patience for some rough editing toward the end.</p>
]]></content:encoded></item><item><title>Head First Kotlin</title><link>https://llcawthorne.github.io/posts/head-first-kotlin/</link><pubDate>Sat, 26 Sep 2026 21:05:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/head-first-kotlin/</guid><description>&lt;p&gt;&lt;img alt="Head First Kotlin cover" loading="lazy" src="https://llcawthorne.github.io/posts/head-first-kotlin/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Better than initially assessed: Chapter 2 introduces collections, good variance
coverage (with a Pet hierarchy), covers extensions and their role in the stdlib,
two lambda/HOF chapters. Unusual ordering: generics before lambdas.
map/filter/fold deferred to lambda chapters. Coroutines appendix exists but
dated.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Head First Kotlin&lt;/em&gt; uses the usual Head First spiral approach (introduce a
concept lightly, let it sit, circle back with depth later), which meant it
deferred anything not strictly load-bearing to the appendices. Labeled breaks
and enum classes, both things I&amp;rsquo;d consider core language features, got pushed
all the way to Appendix C rather than covered in the main chapters. That
appendix is even honest about it in the title: &amp;ldquo;The Top Ten Things (We Didn&amp;rsquo;t
Cover)&amp;rdquo;: ten separate topics, including packages, visibility modifiers, sealed
classes, and object declarations, that never made it into the twelve main
chapters at all.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Head First Kotlin cover" loading="lazy" src="/posts/head-first-kotlin/images/cover.jpg"></p>
<p>Better than initially assessed: Chapter 2 introduces collections, good variance
coverage (with a Pet hierarchy), covers extensions and their role in the stdlib,
two lambda/HOF chapters. Unusual ordering: generics before lambdas.
map/filter/fold deferred to lambda chapters. Coroutines appendix exists but
dated.</p>
<p><em>Head First Kotlin</em> uses the usual Head First spiral approach (introduce a
concept lightly, let it sit, circle back with depth later), which meant it
deferred anything not strictly load-bearing to the appendices. Labeled breaks
and enum classes, both things I&rsquo;d consider core language features, got pushed
all the way to Appendix C rather than covered in the main chapters. That
appendix is even honest about it in the title: &ldquo;The Top Ten Things (We Didn&rsquo;t
Cover)&rdquo;: ten separate topics, including packages, visibility modifiers, sealed
classes, and object declarations, that never made it into the twelve main
chapters at all.</p>
<p>The early chapters lay down Kotlin&rsquo;s foundational mechanics: null safety, safe
calls, and the Elvis operator to banish <code>NullPointerException</code>s from day-to-day
code:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Chapter 8 tackles Kotlin&#39;s null safety system and nullable types:
</span></span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Duck</span><span class="p">(</span><span class="k">val</span> <span class="py">name</span><span class="p">:</span> <span class="n">String</span><span class="p">?)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">printDuckName</span><span class="p">(</span><span class="n">duck</span><span class="p">:</span> <span class="n">Duck</span><span class="p">?)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// Safe calls chain without throwing NullPointerException:
</span></span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">length</span> <span class="p">=</span> <span class="n">duck</span><span class="o">?.</span><span class="n">name</span><span class="o">?.</span><span class="n">length</span> <span class="o">?:</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">    <span class="n">println</span><span class="p">(</span><span class="s2">&#34;Duck name length: </span><span class="si">$length</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">// Executing code only when a value is guaranteed non-null:
</span></span></span><span class="line"><span class="cl">    <span class="n">duck</span><span class="o">?.</span><span class="n">name</span><span class="o">?.</span><span class="n">let</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">println</span><span class="p">(</span><span class="s2">&#34;Valid duck name: </span><span class="si">$it</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The generics chapter is surprisingly thorough. Using a concrete <code>Pet</code> hierarchy
with dogs and cats, it walks through declaration-site variance and demystifies
what <code>out</code> (covariance) and <code>in</code> (contravariance) mean in practice:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Chapter 10 uses a Pet hierarchy to teach generic variance (in/out):
</span></span></span><span class="line"><span class="cl"><span class="k">abstract</span> <span class="k">class</span> <span class="nc">Pet</span><span class="p">(</span><span class="k">val</span> <span class="py">name</span><span class="p">:</span> <span class="n">String</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Cat</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="n">String</span><span class="p">)</span> <span class="p">:</span> <span class="n">Pet</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="n">String</span><span class="p">)</span> <span class="p">:</span> <span class="n">Pet</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Covariance (out) allows Contest&lt;Cat&gt; to be passed where Contest&lt;Pet&gt; is expected:
</span></span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Contest</span><span class="p">&lt;</span><span class="k">out</span> <span class="n">T</span> <span class="p">:</span> <span class="n">Pet</span><span class="p">&gt;(</span><span class="k">val</span> <span class="py">entries</span><span class="p">:</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">getWinner</span><span class="p">():</span> <span class="n">T</span> <span class="p">=</span> <span class="n">entries</span><span class="p">.</span><span class="n">random</span><span class="p">()</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Contravariance (in) allows a Retailer&lt;Pet&gt; to supply animals to a Retailer&lt;Cat&gt;:
</span></span></span><span class="line"><span class="cl"><span class="k">interface</span> <span class="nc">Vet</span><span class="p">&lt;</span><span class="k">in</span> <span class="n">T</span> <span class="p">:</span> <span class="n">Pet</span><span class="p">&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">treat</span><span class="p">(</span><span class="n">patient</span><span class="p">:</span> <span class="n">T</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The book finishes strong with two dedicated chapters on lambdas, higher-order
functions, and standard collection combinators, illustrating trailing lambda
syntax and pipeline operations:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Chapters 11 and 12 close out with higher-order functions and collection combinators:
</span></span></span><span class="line"><span class="cl"><span class="k">data</span> <span class="k">class</span> <span class="nc">Grocery</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">name</span><span class="p">:</span> <span class="n">String</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">category</span><span class="p">:</span> <span class="n">String</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">unitPrice</span><span class="p">:</span> <span class="n">Double</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">quantity</span><span class="p">:</span> <span class="n">Int</span>
</span></span><span class="line"><span class="cl"><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">search</span><span class="p">(</span><span class="n">groceries</span><span class="p">:</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">Grocery</span><span class="p">&gt;,</span> <span class="n">criteria</span><span class="p">:</span> <span class="p">(</span><span class="n">Grocery</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Boolean</span><span class="p">):</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">Grocery</span><span class="p">&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">results</span> <span class="p">=</span> <span class="n">mutableListOf</span><span class="p">&lt;</span><span class="n">Grocery</span><span class="p">&gt;()</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="n">item</span> <span class="k">in</span> <span class="n">groceries</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">criteria</span><span class="p">(</span><span class="n">item</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="n">results</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">results</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">cart</span> <span class="p">=</span> <span class="n">listOf</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">        <span class="n">Grocery</span><span class="p">(</span><span class="s2">&#34;Tea&#34;</span><span class="p">,</span> <span class="s2">&#34;Beverage&#34;</span><span class="p">,</span> <span class="mf">4.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">        <span class="n">Grocery</span><span class="p">(</span><span class="s2">&#34;Coffee&#34;</span><span class="p">,</span> <span class="s2">&#34;Beverage&#34;</span><span class="p">,</span> <span class="mf">8.0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">        <span class="n">Grocery</span><span class="p">(</span><span class="s2">&#34;Apples&#34;</span><span class="p">,</span> <span class="s2">&#34;Produce&#34;</span><span class="p">,</span> <span class="mf">1.2</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">// Trailing lambda syntax and chaining stdlib combinators:
</span></span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">totalProduceCost</span> <span class="p">=</span> <span class="n">cart</span>
</span></span><span class="line"><span class="cl">        <span class="p">.</span><span class="n">filter</span> <span class="p">{</span> <span class="k">it</span><span class="p">.</span><span class="n">category</span> <span class="o">==</span> <span class="s2">&#34;Produce&#34;</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">.</span><span class="n">map</span> <span class="p">{</span> <span class="k">it</span><span class="p">.</span><span class="n">unitPrice</span> <span class="p">*</span> <span class="k">it</span><span class="p">.</span><span class="n">quantity</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">.</span><span class="n">fold</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span> <span class="p">{</span> <span class="n">acc</span><span class="p">,</span> <span class="n">cost</span> <span class="o">-&gt;</span> <span class="n">acc</span> <span class="p">+</span> <span class="n">cost</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>Compare that to <em>Head First Go</em>, which felt reasonably complete without needing
to punt a top-ten list to the back of the book, but that&rsquo;s not really a fair
fight. Go is a deliberately small language by design (that&rsquo;s Rob Pike&rsquo;s whole
philosophy: minimal surface area, few ways to do anything), so a Head First
treatment of it has a real shot at covering the whole language in the main
chapters. Kotlin&rsquo;s surface area is just bigger: null safety, data classes,
sealed classes, extension functions, coroutines, object
expressions/declarations, operator overloading. So a book aimed at teaching it
from scratch in a similarly-sized page count is going to hit a wall and have to
defer something. It&rsquo;s less &ldquo;Head First Kotlin did a worse job&rdquo; and more &ldquo;the two
books picked structurally different-sized languages to cover with the same
format.&rdquo;</p>
]]></content:encoded></item><item><title>Kotlin from Scratch</title><link>https://llcawthorne.github.io/posts/kotlin-from-scratch/</link><pubDate>Sat, 26 Sep 2026 21:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/kotlin-from-scratch/</guid><description>&lt;p&gt;&lt;img alt="Kotlin from Scratch cover" loading="lazy" src="https://llcawthorne.github.io/posts/kotlin-from-scratch/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Kotlin from Scratch&lt;/em&gt; is a project book, and the projects are mostly math and
computation: Euclid&amp;rsquo;s algorithm, the Sieve of Eratosthenes, Fibonacci, physics
simulations, fractals, sorting, and A* search. It was good typing practice, and
some of the math and algorithms were really interesting, but it was
disappointing as a source of good Kotlin code. The first two chapters covered
the language fundamentals in almost as much depth as all of &lt;em&gt;Head First
Kotlin&lt;/em&gt;, but that depth never came back. Nothing after chapter 2 touches
generics, sealed classes, delegation, or coroutines, extension functions never
show up, and the language features stay limited. Chapter 3 was a whole detour
into JavaFX that I didn&amp;rsquo;t ask for and won&amp;rsquo;t need for Android or Swift, though I
don&amp;rsquo;t regret typing it, since the Stage and Scene boilerplate turned into a
really cool spiral, and fighting the Gradle multi-module setup taught me more
about the build system than the book itself did.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Kotlin from Scratch cover" loading="lazy" src="/posts/kotlin-from-scratch/images/cover.jpg"></p>
<p><em>Kotlin from Scratch</em> is a project book, and the projects are mostly math and
computation: Euclid&rsquo;s algorithm, the Sieve of Eratosthenes, Fibonacci, physics
simulations, fractals, sorting, and A* search. It was good typing practice, and
some of the math and algorithms were really interesting, but it was
disappointing as a source of good Kotlin code. The first two chapters covered
the language fundamentals in almost as much depth as all of <em>Head First
Kotlin</em>, but that depth never came back. Nothing after chapter 2 touches
generics, sealed classes, delegation, or coroutines, extension functions never
show up, and the language features stay limited. Chapter 3 was a whole detour
into JavaFX that I didn&rsquo;t ask for and won&rsquo;t need for Android or Swift, though I
don&rsquo;t regret typing it, since the Stage and Scene boilerplate turned into a
really cool spiral, and fighting the Gradle multi-module setup taught me more
about the build system than the book itself did.</p>
<p>The early mathematical exercises rely heavily on traditional imperative loops
and mutable <code>var</code> declarations for classic algorithms:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// Early chapters lean heavily on mutable vars for classic mathematical algorithms:
</span></span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">gcd</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">Int</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">Int</span><span class="p">):</span> <span class="n">Int</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">var</span> <span class="py">x</span> <span class="p">=</span> <span class="n">a</span>
</span></span><span class="line"><span class="cl">    <span class="k">var</span> <span class="py">y</span> <span class="p">=</span> <span class="n">b</span>
</span></span><span class="line"><span class="cl">    <span class="k">while</span> <span class="p">(</span><span class="n">y</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">val</span> <span class="py">temp</span> <span class="p">=</span> <span class="n">y</span>
</span></span><span class="line"><span class="cl">        <span class="n">y</span> <span class="p">=</span> <span class="n">x</span> <span class="p">%</span> <span class="n">y</span>
</span></span><span class="line"><span class="cl">        <span class="n">x</span> <span class="p">=</span> <span class="n">temp</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">x</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">limit</span><span class="p">:</span> <span class="n">Int</span><span class="p">):</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">Int</span><span class="p">&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">val</span> <span class="py">isPrime</span> <span class="p">=</span> <span class="n">BooleanArray</span><span class="p">(</span><span class="n">limit</span> <span class="p">+</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span> <span class="k">true</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="n">isPrime</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="p">=</span> <span class="k">false</span>
</span></span><span class="line"><span class="cl">    <span class="n">isPrime</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="p">=</span> <span class="k">false</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">var</span> <span class="py">p</span> <span class="p">=</span> <span class="mi">2</span>
</span></span><span class="line"><span class="cl">    <span class="k">while</span> <span class="p">(</span><span class="n">p</span> <span class="p">*</span> <span class="n">p</span> <span class="o">&lt;=</span> <span class="n">limit</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">isPrime</span><span class="p">[</span><span class="n">p</span><span class="p">])</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">var</span> <span class="py">multiple</span> <span class="p">=</span> <span class="n">p</span> <span class="p">*</span> <span class="n">p</span>
</span></span><span class="line"><span class="cl">            <span class="k">while</span> <span class="p">(</span><span class="n">multiple</span> <span class="o">&lt;=</span> <span class="n">limit</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                <span class="n">isPrime</span><span class="p">[</span><span class="n">multiple</span><span class="p">]</span> <span class="p">=</span> <span class="k">false</span>
</span></span><span class="line"><span class="cl">                <span class="n">multiple</span> <span class="o">+=</span> <span class="n">p</span>
</span></span><span class="line"><span class="cl">            <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="n">p</span><span class="o">++</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">isPrime</span><span class="p">.</span><span class="n">indices</span><span class="p">.</span><span class="n">filter</span> <span class="p">{</span> <span class="n">isPrime</span><span class="p">[</span><span class="k">it</span><span class="p">]</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The author&rsquo;s code quality was the real letdown. He leans on mutable <code>var</code>s
constantly, and worse, on global mutable state. If anything, spotting all those
<code>var</code>s helped remind me to use more <code>val</code>s. The genetic algorithm chapter had
<code>tournament()</code> calls with no parameters that still returned different results
every time, because they were secretly reaching into a global population plus
some randomness, so there&rsquo;s no referential transparency and no way to reason
about a call site without reading the function body. The comments were often
pure noise too, like <code>// Run the genetic algorithm</code> sitting right above
<code>runGA()</code>. Project 16 was missing an entire function, which the errata later
confirmed wasn&rsquo;t my mistake, so I pulled that one from the GitHub companion
repo instead of fighting a broken example.</p>
<p>The <code>fold</code> and <code>map</code> chapter was a letdown in a different way. It only reached
for the classic textbook examples of summing a list, calculating a product, and
concatenating strings, and nothing that shows off what the tools are actually
for. I ended up chewing on a much better example on my own, finding all the
subsets of a set (the power set). I worked that out mostly by instinct, keeping
the subsets so far and, for each new element, adding a copy of every existing
subset with that element in it, before I ever realized <code>fold</code> was the idiomatic
way to express it. Even where the book <em>does</em> introduce a powerful construct, it
plays it safe with examples that don&rsquo;t show its range:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// The book&#39;s fold examples were basic, motivating this comparison of
</span></span></span><span class="line"><span class="cl"><span class="c1">// imperative mutable set building versus an idiomatic one-liner with fold:
</span></span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="p">&lt;</span><span class="nc">T</span><span class="p">&gt;</span> <span class="nf">powerSet</span><span class="p">(</span><span class="k">set</span><span class="p">:</span> <span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;):</span> <span class="n">Set</span><span class="p">&lt;</span><span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">var</span> <span class="py">subsetsSoFar</span><span class="p">:</span> <span class="n">MutableSet</span><span class="p">&lt;</span><span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;&gt;</span> <span class="p">=</span> <span class="n">mutableSetOf</span><span class="p">(</span><span class="n">emptySet</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="n">element</span> <span class="k">in</span> <span class="k">set</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">val</span> <span class="py">newSubsets</span><span class="p">:</span> <span class="n">MutableSet</span><span class="p">&lt;</span><span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;&gt;</span> <span class="p">=</span> <span class="n">mutableSetOf</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">        <span class="k">for</span> <span class="p">(</span><span class="n">existing</span> <span class="k">in</span> <span class="n">subsetsSoFar</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">val</span> <span class="py">combined</span><span class="p">:</span> <span class="n">MutableSet</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;</span> <span class="p">=</span> <span class="n">mutableSetOf</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">            <span class="n">combined</span><span class="p">.</span><span class="n">addAll</span><span class="p">(</span><span class="n">existing</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">combined</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">newSubsets</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">combined</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="n">subsetsSoFar</span><span class="p">.</span><span class="n">addAll</span><span class="p">(</span><span class="n">newSubsets</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">subsetsSoFar</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">fun</span> <span class="p">&lt;</span><span class="nc">T</span><span class="p">&gt;</span> <span class="nf">powerSetFold</span><span class="p">(</span><span class="k">set</span><span class="p">:</span> <span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;):</span> <span class="n">Set</span><span class="p">&lt;</span><span class="n">Set</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;&gt;</span> <span class="p">=</span>
</span></span><span class="line"><span class="cl">    <span class="k">set</span><span class="p">.</span><span class="n">fold</span><span class="p">(</span><span class="n">setOf</span><span class="p">(</span><span class="n">emptySet</span><span class="p">()))</span> <span class="p">{</span> <span class="n">subsetsSoFar</span><span class="p">,</span> <span class="n">element</span> <span class="o">-&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="n">subsetsSoFar</span> <span class="p">+</span> <span class="n">subsetsSoFar</span><span class="p">.</span><span class="n">map</span> <span class="p">{</span> <span class="k">it</span> <span class="p">+</span> <span class="n">element</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span></code></pre></div><p>One thing it did get right, which I wouldn&rsquo;t have assumed coming from Java, is
its package-naming advice to &ldquo;join multiple words or use camelCase,&rdquo; which
checks out against the official Kotlin coding conventions, since they
explicitly allow both.</p>
<p>I skipped typing the Modeling/Simulation and Fractals chapters, since they were
more JavaFX and more of the same mutable-state pattern, and just skimmed them on
GitHub instead. The sorting and searching chapter (chapter 7) had the cleanest
code in the book, with fewer <code>var</code>s, and the ones it had were properly scoped
instead of global. In-place sorting algorithms are supposed to mutate anyway, so
that&rsquo;s not really a knock.</p>
<p>The genetic algorithm (GA) chapter and the particle swarm optimization (PSO)
and ant colony chapter were the highlight. I typed three GA variants by hand (a
toy problem, a knapsack problem, and multivariate equation solving, by way of
the &ldquo;weasel program&rdquo; Shakespeare quote demo), then took the GitHub shortcut for
PSO and the traveling salesman ant simulation once I&rsquo;d internalized the pattern.
PSO actually beat the GA on the Eggholder problem: it took fewer generations,
found a solution the GA never found in multiple runs, and didn&rsquo;t get stuck in
the same local optimum the GA kept falling into:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="c1">// The closing chapters implement nature-inspired optimization algorithms,
</span></span></span><span class="line"><span class="cl"><span class="c1">// such as a genetic algorithm knapsack solver with chromosome fitness evaluation:
</span></span></span><span class="line"><span class="cl"><span class="k">data</span> <span class="k">class</span> <span class="nc">Individual</span><span class="p">(</span><span class="k">val</span> <span class="py">chromosome</span><span class="p">:</span> <span class="n">BooleanArray</span><span class="p">,</span> <span class="k">var</span> <span class="py">fitness</span><span class="p">:</span> <span class="n">Double</span> <span class="p">=</span> <span class="mf">0.0</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">GeneticAlgorithm</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">weights</span><span class="p">:</span> <span class="n">DoubleArray</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">values</span><span class="p">:</span> <span class="n">DoubleArray</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">capacity</span><span class="p">:</span> <span class="n">Double</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">popSize</span><span class="p">:</span> <span class="n">Int</span> <span class="p">=</span> <span class="mi">100</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="k">private</span> <span class="k">val</span> <span class="py">mutationRate</span><span class="p">:</span> <span class="n">Double</span> <span class="p">=</span> <span class="mf">0.01</span>
</span></span><span class="line"><span class="cl"><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">calculateFitness</span><span class="p">(</span><span class="n">ind</span><span class="p">:</span> <span class="n">Individual</span><span class="p">):</span> <span class="n">Double</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">var</span> <span class="py">totalWeight</span> <span class="p">=</span> <span class="mf">0.0</span>
</span></span><span class="line"><span class="cl">        <span class="k">var</span> <span class="py">totalValue</span> <span class="p">=</span> <span class="mf">0.0</span>
</span></span><span class="line"><span class="cl">        <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="k">in</span> <span class="n">ind</span><span class="p">.</span><span class="n">chromosome</span><span class="p">.</span><span class="n">indices</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">if</span> <span class="p">(</span><span class="n">ind</span><span class="p">.</span><span class="n">chromosome</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">                <span class="n">totalWeight</span> <span class="o">+=</span> <span class="n">weights</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">                <span class="n">totalValue</span> <span class="o">+=</span> <span class="n">values</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">            <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="k">if</span> <span class="p">(</span><span class="n">totalWeight</span> <span class="o">&lt;=</span> <span class="n">capacity</span><span class="p">)</span> <span class="n">totalValue</span> <span class="k">else</span> <span class="mf">0.0</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">fun</span> <span class="nf">tournamentSelection</span><span class="p">(</span><span class="n">population</span><span class="p">:</span> <span class="n">List</span><span class="p">&lt;</span><span class="n">Individual</span><span class="p">&gt;,</span> <span class="n">k</span><span class="p">:</span> <span class="n">Int</span> <span class="p">=</span> <span class="mi">5</span><span class="p">):</span> <span class="n">Individual</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">val</span> <span class="py">tournament</span> <span class="p">=</span> <span class="n">List</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="p">{</span> <span class="n">population</span><span class="p">.</span><span class="n">random</span><span class="p">()</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="n">tournament</span><span class="p">.</span><span class="n">maxByOrNull</span> <span class="p">{</span> <span class="k">it</span><span class="p">.</span><span class="n">fitness</span> <span class="p">}</span> <span class="o">?:</span> <span class="n">tournament</span><span class="p">.</span><span class="n">first</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>So it&rsquo;s worth reading for the algorithms and the typing reps, but not for the
Kotlin, and I wouldn&rsquo;t recommend it as a &ldquo;here&rsquo;s good idiomatic Kotlin&rdquo;
reference.</p>
]]></content:encoded></item><item><title>1177 BC</title><link>https://llcawthorne.github.io/posts/1177-bc/</link><pubDate>Fri, 25 Sep 2026 18:45:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/1177-bc/</guid><description>&lt;p&gt;&lt;img alt="1177 BC cover" loading="lazy" src="https://llcawthorne.github.io/posts/1177-bc/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;1177 BC is far less a final verdict than I would&amp;rsquo;ve preferred. Apparently, historians have discussed the Bronze Age collapse for at least 100 years, but this book mostly calls into question the traditional simple ideas and makes a case for a combination of earthquakes, revolts, and, to a much lesser extent than originally thought, the sea people invading, plus maybe some type of disruption of the trade networks, which again could be caused by the sea people or other unknown maritime raiders.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="1177 BC cover" loading="lazy" src="/posts/1177-bc/images/cover.jpg"></p>
<p>1177 BC is far less a final verdict than I would&rsquo;ve preferred. Apparently, historians have discussed the Bronze Age collapse for at least 100 years, but this book mostly calls into question the traditional simple ideas and makes a case for a combination of earthquakes, revolts, and, to a much lesser extent than originally thought, the sea people invading, plus maybe some type of disruption of the trade networks, which again could be caused by the sea people or other unknown maritime raiders.</p>
<p>It&rsquo;s also possible that the private merchant class became more important than the traditional palace-based economy, but many disagree with this opinion despite the fact it has some supporters with good arguments. The sea people may have been more merchant than invader. But that shift could&rsquo;ve happened in the chaos after the collapse, rather than being a cause of the collapse on its own.</p>
<p>The most important take home is that there are only maybe two clear references to the sea people, the strongest being from Egypt. Others are merely references to enemy ships. So much of the argument for the sea people being the sole cause of collapse is greatly overstated, especially since many of the cities that fell don&rsquo;t look like sites of combat. People have written entire books on sea people despite the lack of clear evidence. If they existed and contributed, it was probably on a smaller scale, maybe in the fall of a couple of major civilizations, possibly Egypt, but they weren&rsquo;t a clear cause of the collapse as a whole. Indeed, their artifacts may occur in many places due to them moving in after civilization collapse for other reasons. Even the clearest remains we have of the sea people are questionable. There were definitely cultural changes in artifacts post-collapse.</p>
<p>I learned a lot about how modern history has incorporated scientific methods, including DNA analysis, and it looks like migrant southern Europeans mated with Canaanites rather than invading the area. It&rsquo;s questionable what displaced the southern Europeans, but waves of earthquakes are possible judging by the remains of cities in the area.</p>
<p>There are also at least ten diseases that could&rsquo;ve ravaged the late Bronze Age civilizations, but it&rsquo;s difficult to find objective evidence and no one wrote about it if there was widespread disease. Considering there&rsquo;s no clear argument for a single cause, epidemic as a contributing cause isn&rsquo;t out of the question despite the lack of evidence. But that basically translates to the evidence being so poor that guessing is allowed.</p>
<p>There&rsquo;s more evidence than before of widespread drought due to climate change. Some letters point to famines in several of the major kingdoms, and looping back to the &ldquo;sea people,&rdquo; they could be Europeans driven south and west from famine. Apparently, historians are happy to spend their whole life arguing over drought indicated only by two textual references. Fortunately, new scientific methods have confirmed drought conclusively enough that it is now considered a major historical event. All that information has become available since the first edition of this book, and the author was quite hyped about it. It&rsquo;s awfully suspicious that climate change, which is our modern danger, also happened to be at least part of the cause of the Bronze Age collapse, but stranger coincidences have happened even if it could easily be modern historians grasping at modern problems. However, scientific pollen studies, oxygen isotope studies, stalactite growth studies, and studies of the Nile all point to extended droughts in many major kingdoms around 1250-1000 BC.</p>
<p>Honestly, it sounds like this whole book could be replaced by a sentence saying 300 years of drought did it. That&rsquo;s a bit of an oversimplification; he sticks to his guns on the idea that it was multiple factors. But the author has changed his mind enough to say drought could easily be the main driver, where in the first edition he thought drought wasn&rsquo;t well supported enough to be anything but a minor contributing factor. There&rsquo;s still an open question of whether it was climate change or volcanic activity that caused the drought. Also, the evidence of revolts in some towns could&rsquo;ve been explained by drought and famine, and it likely also contributed to European migration. So everything we talked about is still relevant. The author stands by his point that any one cause would&rsquo;ve been lucky to bring down one major civilization, much less all of them, so it is likely drought was a major contributing factor among many others, some possibly connected to the drought. The fact that the drought likely lasted 300 years is why it had a bigger impact than other smaller droughts, and the connected economy likely helped chain the failures when systems started collapsing.</p>
<p>I did learn how much faith historians put in pottery and that the siege of Troy has more historical evidence than the Hebrew Exodus.</p>
]]></content:encoded></item><item><title>Automate the Boring Stuff with Python</title><link>https://llcawthorne.github.io/posts/automate-the-boring-stuff-with-python/</link><pubDate>Sat, 19 Sep 2026 15:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/automate-the-boring-stuff-with-python/</guid><description>&lt;p&gt;&lt;img alt="Automate the Boring Stuff with Python cover" loading="lazy" src="https://llcawthorne.github.io/posts/automate-the-boring-stuff-with-python/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Sometimes it&amp;rsquo;s fun to read easy books, and this was an easy, fun book. It didn&amp;rsquo;t
go into as much depth about Python as the Python Tutorial on the Python website,
but it covered the basics, then went on a romping overview of using all sorts of
libraries to perform tasks you might need to perform. Some of the tasks were
pretty relevant, like loading an Excel file, working with JSON, or sending
yourself an email; others were cool and could be put to creative uses, like
driving a web browser with Playwright or working with a SQLite database; and
some were kind of niche topics that I&amp;rsquo;d look back up if I ever needed to deal
with them, like working with XML, OCR, or speech recognition. They were all kind
of fun to play with, so I enjoyed reading this book.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Automate the Boring Stuff with Python cover" loading="lazy" src="/posts/automate-the-boring-stuff-with-python/images/cover.jpg"></p>
<p>Sometimes it&rsquo;s fun to read easy books, and this was an easy, fun book. It didn&rsquo;t
go into as much depth about Python as the Python Tutorial on the Python website,
but it covered the basics, then went on a romping overview of using all sorts of
libraries to perform tasks you might need to perform. Some of the tasks were
pretty relevant, like loading an Excel file, working with JSON, or sending
yourself an email; others were cool and could be put to creative uses, like
driving a web browser with Playwright or working with a SQLite database; and
some were kind of niche topics that I&rsquo;d look back up if I ever needed to deal
with them, like working with XML, OCR, or speech recognition. They were all kind
of fun to play with, so I enjoyed reading this book.</p>
<p>The early chapters quickly move through language fundamentals into practical
text scanning using Python&rsquo;s <code>re</code> module and <code>pathlib</code> for file traversal:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="c1"># Chapters 9 and 10 introduce regular expressions and filesystem operations:</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">re</span>
</span></span><span class="line"><span class="cl"><span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">phone_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="sa">r</span><span class="s2">&#34;&#34;&#34;(
</span></span></span><span class="line"><span class="cl"><span class="s2">    (\d</span><span class="si">{3}</span><span class="s2">|\(\d</span><span class="si">{3}</span><span class="s2">\))?            # Area code
</span></span></span><span class="line"><span class="cl"><span class="s2">    (\s|-|\.)?                    # Separator
</span></span></span><span class="line"><span class="cl"><span class="s2">    (\d</span><span class="si">{3}</span><span class="s2">)                       # First 3 digits
</span></span></span><span class="line"><span class="cl"><span class="s2">    (\s|-|\.)                     # Separator
</span></span></span><span class="line"><span class="cl"><span class="s2">    (\d</span><span class="si">{4}</span><span class="s2">)                       # Last 4 digits
</span></span></span><span class="line"><span class="cl"><span class="s2">)&#34;&#34;&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="n">re</span><span class="o">.</span><span class="n">VERBOSE</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Scanning text files in the working directory for matching numbers:</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">Path</span><span class="o">.</span><span class="n">cwd</span><span class="p">()</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&#34;*.txt&#34;</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">content</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">read_text</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s2">&#34;utf-8&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">matches</span> <span class="o">=</span> <span class="n">phone_regex</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="n">matches</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;Found </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">matches</span><span class="p">)</span><span class="si">}</span><span class="s2"> phone number(s) in </span><span class="si">{</span><span class="n">path</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span></code></pre></div><p>From there, the book turns into a tour of practical recipes, like updating
produce prices across spreadsheet cells with <code>openpyxl</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="c1"># Chapter 14 manipulates spreadsheets using openpyxl:</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">openpyxl</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">wb</span> <span class="o">=</span> <span class="n">openpyxl</span><span class="o">.</span><span class="n">load_workbook</span><span class="p">(</span><span class="s2">&#34;produceSales.xlsx&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">sheet</span> <span class="o">=</span> <span class="n">wb</span><span class="p">[</span><span class="s2">&#34;Sheet&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Updating produce prices in place:</span>
</span></span><span class="line"><span class="cl"><span class="n">PRICE_UPDATES</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;Garlic&#34;</span><span class="p">:</span> <span class="mf">3.07</span><span class="p">,</span> <span class="s2">&#34;Celery&#34;</span><span class="p">:</span> <span class="mf">1.19</span><span class="p">,</span> <span class="s2">&#34;Lemon&#34;</span><span class="p">:</span> <span class="mf">1.27</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">row_num</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">sheet</span><span class="o">.</span><span class="n">max_row</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">produce_name</span> <span class="o">=</span> <span class="n">sheet</span><span class="o">.</span><span class="n">cell</span><span class="p">(</span><span class="n">row</span><span class="o">=</span><span class="n">row_num</span><span class="p">,</span> <span class="n">column</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">value</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="n">produce_name</span> <span class="ow">in</span> <span class="n">PRICE_UPDATES</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">        <span class="n">sheet</span><span class="o">.</span><span class="n">cell</span><span class="p">(</span><span class="n">row</span><span class="o">=</span><span class="n">row_num</span><span class="p">,</span> <span class="n">column</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">PRICE_UPDATES</span><span class="p">[</span><span class="n">produce_name</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">wb</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s2">&#34;updatedProduceSales.xlsx&#34;</span><span class="p">)</span>
</span></span></code></pre></div><p>The later chapters touch on richer automation, using Playwright to control a
headless browser, fill in form inputs, and inspect dynamic page elements:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="c1"># Later chapters automate modern web browsers using Playwright:</span>
</span></span><span class="line"><span class="cl"><span class="kn">from</span> <span class="nn">playwright.sync_api</span> <span class="kn">import</span> <span class="n">sync_playwright</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">with</span> <span class="n">sync_playwright</span><span class="p">()</span> <span class="k">as</span> <span class="n">playwright</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="n">browser</span> <span class="o">=</span> <span class="n">playwright</span><span class="o">.</span><span class="n">chromium</span><span class="o">.</span><span class="n">launch</span><span class="p">(</span><span class="n">headless</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">new_page</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://pypi.org&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># Interacting with live page elements:</span>
</span></span><span class="line"><span class="cl">    <span class="n">search_input</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">locator</span><span class="p">(</span><span class="s2">&#34;input[name=&#39;q&#39;]&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">search_input</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="s2">&#34;requests&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">search_input</span><span class="o">.</span><span class="n">press</span><span class="p">(</span><span class="s2">&#34;Enter&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">wait_for_selector</span><span class="p">(</span><span class="s2">&#34;.package-snippet&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">top_result</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">locator</span><span class="p">(</span><span class="s2">&#34;.package-snippet__name&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">first</span><span class="o">.</span><span class="n">text_content</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="s2">&#34;Top PyPI search result:&#34;</span><span class="p">,</span> <span class="n">top_result</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">browser</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></span></code></pre></div>]]></content:encoded></item><item><title>Go Language Opinions</title><link>https://llcawthorne.github.io/posts/go-language-opinions/</link><pubDate>Sat, 12 Sep 2026 18:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/go-language-opinions/</guid><description>&lt;p&gt;Go&amp;rsquo;s tooling is what stuck with me the most. gofmt is flawless, even on case
statements, no matter how hard I try to trick it, it always formats the file
correctly. Cross-compilation with GOOS/GOARCH is excellent, shipping a
single self-contained binary is genuinely nice to hand off, and the command
line tooling is great too. I like that the implementation stays transparent
instead of hiding behind framework magic, and I prefer simple structs with
methods over deep inheritance hierarchies. &lt;em&gt;Head First Go&lt;/em&gt; gave me real
confidence with the language, and &lt;em&gt;Powerful Command-Line Applications in Go&lt;/em&gt;
taught me a lot about building command-line apps, even in languages other
than Go, like how easy it is to write a markdown previewer when the standard
library gives you so much for free, and to always check out a new language&amp;rsquo;s
argument-parsing frameworks early. Even &lt;code&gt;//&lt;/code&gt; comments felt natural to me.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Go&rsquo;s tooling is what stuck with me the most. gofmt is flawless, even on case
statements, no matter how hard I try to trick it, it always formats the file
correctly. Cross-compilation with GOOS/GOARCH is excellent, shipping a
single self-contained binary is genuinely nice to hand off, and the command
line tooling is great too. I like that the implementation stays transparent
instead of hiding behind framework magic, and I prefer simple structs with
methods over deep inheritance hierarchies. <em>Head First Go</em> gave me real
confidence with the language, and <em>Powerful Command-Line Applications in Go</em>
taught me a lot about building command-line apps, even in languages other
than Go, like how easy it is to write a markdown previewer when the standard
library gives you so much for free, and to always check out a new language&rsquo;s
argument-parsing frameworks early. Even <code>//</code> comments felt natural to me.</p>
<p>Some of it is more neutral than a selling point. I appreciate Go&rsquo;s minimalism
as a deliberate design choice even though it isn&rsquo;t really my target use case.
Google&rsquo;s involvement makes me a little cautious. Binary size and startup time
don&rsquo;t matter much for what I build, and skipping a GC isn&rsquo;t a selling point
when I&rsquo;m not doing systems programming.</p>
<p>I&rsquo;m moving on from Go for now. Kotlin is more professionally applicable to
me, and it works as a better Java without leaving the JVM. Real app
development projects in Kotlin and Swift give me concrete motivation that Go
doesn&rsquo;t, and honestly my language list just needed trimming.</p>
<p>I might come back to it, though. <em>Distributed Systems in Go</em> looks like the
most transparent way to see microservice patterns without Spring hiding the
mechanics, and <em>Learn Go with Tests</em> looks good for picking up TDD patterns.
The books will still be there, and Go isn&rsquo;t going anywhere.</p>
<p>After trying ktlint in Kotlin, I&rsquo;m even more impressed with how reliable and
fast gofmt is. It&rsquo;s a benefit of working with such a simple language. ktlint
flags errors well but regularly gets stymied and unable to fix the file, so I
have to either fix it manually or ignore the error. Formatting is more
consistent in IntelliJ though, which is the main place I do Kotlin work. This
is just something that bugs me when I type in book code in Vim, and Kotlin
book code isn&rsquo;t even formatted to ktlint&rsquo;s specs either, whereas Go code
everywhere looks pretty much the same. I still have to deal with Go&rsquo;s odd
capitalization rules for function names, but at least everything else looks
reliably good.</p>
]]></content:encoded></item><item><title>Powerful Command-Line Applications in Go</title><link>https://llcawthorne.github.io/posts/powerful-command-line-applications-in-go/</link><pubDate>Fri, 28 Aug 2026 18:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/powerful-command-line-applications-in-go/</guid><description>&lt;p&gt;&lt;img alt="Powerful Command-Line Applications in Go cover" loading="lazy" src="https://llcawthorne.github.io/posts/powerful-command-line-applications-in-go/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;This was a good way to see a number of non-trivial applications in Go. It
tackled real projects like a Markdown Previewer and a Port Scanner and used
production-grade libraries like Cobra for command-line arguments and Viper for
configuration settings. The Markdown Previewer was probably good enough for me
to consider using it. Honestly, Cobra and Viper were good enough libraries
that it makes me start looking at what my options are for command-line
parsing libraries early when studying a new language now. A lot of the
examples were big to type, but that is good since it made me feel more
comfortable with the language. They were also complicated enough that I made
mistakes and got to deal with error messages from the compiler. I will say I
was disappointed multiple times that Go&amp;rsquo;s compiler points out the first error
it finds and then stops, so when you fix it you might just be greeted by
another error. It&amp;rsquo;s not like Java or Kotlin where the compiler spits out 10
errors and 5 are probably caused by the earlier errors but the other 5 need
to be corrected. The pomodoro app was actually quite usable after I got past
the fact that it wouldn&amp;rsquo;t display correctly in tmux. That was a hard
debugging session wondering what was wrong with my output from typing up the
code before I finally pinned the blame on running it in a tmux session
though, since having a tmux session is just getting so normal to me. Not only
did I learn a lot about using Go for small to intermediate-sized projects,
but I learned a lot about writing good command-line apps that I can take
with me to other languages.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Powerful Command-Line Applications in Go cover" loading="lazy" src="/posts/powerful-command-line-applications-in-go/images/cover.jpg"></p>
<p>This was a good way to see a number of non-trivial applications in Go. It
tackled real projects like a Markdown Previewer and a Port Scanner and used
production-grade libraries like Cobra for command-line arguments and Viper for
configuration settings. The Markdown Previewer was probably good enough for me
to consider using it. Honestly, Cobra and Viper were good enough libraries
that it makes me start looking at what my options are for command-line
parsing libraries early when studying a new language now. A lot of the
examples were big to type, but that is good since it made me feel more
comfortable with the language. They were also complicated enough that I made
mistakes and got to deal with error messages from the compiler. I will say I
was disappointed multiple times that Go&rsquo;s compiler points out the first error
it finds and then stops, so when you fix it you might just be greeted by
another error. It&rsquo;s not like Java or Kotlin where the compiler spits out 10
errors and 5 are probably caused by the earlier errors but the other 5 need
to be corrected. The pomodoro app was actually quite usable after I got past
the fact that it wouldn&rsquo;t display correctly in tmux. That was a hard
debugging session wondering what was wrong with my output from typing up the
code before I finally pinned the blame on running it in a tmux session
though, since having a tmux session is just getting so normal to me. Not only
did I learn a lot about using Go for small to intermediate-sized projects,
but I learned a lot about writing good command-line apps that I can take
with me to other languages.</p>
<p>The book starts with a simple word and line counter using <code>flag</code>, decoupling
I/O behind <code>io.Reader</code> so you can test it with a <code>bytes.Buffer</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapters 1 and 2 start with standard flag-based word/line counting,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// decoupling I/O using io.Reader so testing with bytes.Buffer is trivial:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">count</span><span class="p">(</span><span class="nx">r</span><span class="w"> </span><span class="nx">io</span><span class="p">.</span><span class="nx">Reader</span><span class="p">,</span><span class="w"> </span><span class="nx">countLines</span><span class="w"> </span><span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">scanner</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">bufio</span><span class="p">.</span><span class="nf">NewScanner</span><span class="p">(</span><span class="nx">r</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="p">!</span><span class="nx">countLines</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">scanner</span><span class="p">.</span><span class="nf">Split</span><span class="p">(</span><span class="nx">bufio</span><span class="p">.</span><span class="nx">ScanWords</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">wc</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="mi">0</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">for</span><span class="w"> </span><span class="nx">scanner</span><span class="p">.</span><span class="nf">Scan</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">wc</span><span class="o">++</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="nx">wc</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">lines</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">flag</span><span class="p">.</span><span class="nf">Bool</span><span class="p">(</span><span class="s">&#34;l&#34;</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;Count lines&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">flag</span><span class="p">.</span><span class="nf">Parse</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="nf">count</span><span class="p">(</span><span class="nx">os</span><span class="p">.</span><span class="nx">Stdin</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="nx">lines</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Projects like the Markdown Previewer (<code>mdp</code>) pull together file I/O, temp files,
HTML templates, and launching a browser:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapter 3 builds the Markdown previewer, converting markdown to HTML</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// and creating temporary preview files before launching a browser:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">run</span><span class="p">(</span><span class="nx">filename</span><span class="w"> </span><span class="kt">string</span><span class="p">,</span><span class="w"> </span><span class="nx">out</span><span class="w"> </span><span class="nx">io</span><span class="p">.</span><span class="nx">Writer</span><span class="p">,</span><span class="w"> </span><span class="nx">skipPreview</span><span class="w"> </span><span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="kt">error</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">input</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">os</span><span class="p">.</span><span class="nf">ReadFile</span><span class="p">(</span><span class="nx">filename</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="nx">err</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">htmlData</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nf">parseContent</span><span class="p">(</span><span class="nx">input</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">tempFile</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">os</span><span class="p">.</span><span class="nf">CreateTemp</span><span class="p">(</span><span class="s">&#34;&#34;</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;mdp*.html&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="nx">err</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">defer</span><span class="w"> </span><span class="nx">os</span><span class="p">.</span><span class="nf">Remove</span><span class="p">(</span><span class="nx">tempFile</span><span class="p">.</span><span class="nf">Name</span><span class="p">())</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nf">saveHTML</span><span class="p">(</span><span class="nx">tempFile</span><span class="p">.</span><span class="nf">Name</span><span class="p">(),</span><span class="w"> </span><span class="nx">htmlData</span><span class="p">);</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="nx">err</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">skipPreview</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="nf">preview</span><span class="p">(</span><span class="nx">tempFile</span><span class="p">.</span><span class="nf">Name</span><span class="p">())</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>By the end, the book walks through full interactive terminal applications like
the Pomodoro tool (<code>pomo</code>), backing the terminal UI with a concurrent in-memory
repository protected by <code>sync.RWMutex</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapter 9 reaches the interactive Pomodoro tool, backing the terminal UI</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// with a thread-safe in-memory repository protected by sync.RWMutex:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">type</span><span class="w"> </span><span class="nx">inMemoryRepo</span><span class="w"> </span><span class="kd">struct</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">sync</span><span class="p">.</span><span class="nx">RWMutex</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">intervals</span><span class="w"> </span><span class="p">[]</span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">Interval</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">NewInMemoryRepo</span><span class="p">()</span><span class="w"> </span><span class="o">*</span><span class="nx">inMemoryRepo</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="o">&amp;</span><span class="nx">inMemoryRepo</span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">intervals</span><span class="p">:</span><span class="w"> </span><span class="p">[]</span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">Interval</span><span class="p">{},</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="p">(</span><span class="nx">r</span><span class="w"> </span><span class="o">*</span><span class="nx">inMemoryRepo</span><span class="p">)</span><span class="w"> </span><span class="nf">Create</span><span class="p">(</span><span class="nx">i</span><span class="w"> </span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">Interval</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="kt">int64</span><span class="p">,</span><span class="w"> </span><span class="kt">error</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">r</span><span class="p">.</span><span class="nf">Lock</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">defer</span><span class="w"> </span><span class="nx">r</span><span class="p">.</span><span class="nf">Unlock</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">i</span><span class="p">.</span><span class="nx">ID</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nb">int64</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">intervals</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">r</span><span class="p">.</span><span class="nx">intervals</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nb">append</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">intervals</span><span class="p">,</span><span class="w"> </span><span class="nx">i</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="nx">i</span><span class="p">.</span><span class="nx">ID</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="p">(</span><span class="nx">r</span><span class="w"> </span><span class="o">*</span><span class="nx">inMemoryRepo</span><span class="p">)</span><span class="w"> </span><span class="nf">ByID</span><span class="p">(</span><span class="nx">id</span><span class="w"> </span><span class="kt">int64</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">Interval</span><span class="p">,</span><span class="w"> </span><span class="kt">error</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">r</span><span class="p">.</span><span class="nf">RLock</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">defer</span><span class="w"> </span><span class="nx">r</span><span class="p">.</span><span class="nf">RUnlock</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">id</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nb">int</span><span class="p">(</span><span class="nx">id</span><span class="p">)</span><span class="w"> </span><span class="p">&gt;</span><span class="w"> </span><span class="nb">len</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">intervals</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">Interval</span><span class="p">{},</span><span class="w"> </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Errorf</span><span class="p">(</span><span class="s">&#34;%w: %d&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">pomodoro</span><span class="p">.</span><span class="nx">ErrInvalidID</span><span class="p">,</span><span class="w"> </span><span class="nx">id</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="nx">r</span><span class="p">.</span><span class="nx">intervals</span><span class="p">[</span><span class="nx">id</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div>]]></content:encoded></item><item><title>Head First Go</title><link>https://llcawthorne.github.io/posts/head-first-go/</link><pubDate>Tue, 11 Aug 2026 18:00:00 -0400</pubDate><guid>https://llcawthorne.github.io/posts/head-first-go/</guid><description>&lt;p&gt;&lt;img alt="Head First Go cover" loading="lazy" src="https://llcawthorne.github.io/posts/head-first-go/images/cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Overall, it&amp;rsquo;s what I expect from a Head First book. It was a perfectly
serviceable introduction to the Go programming language. Although it&amp;rsquo;s a Head
First book, I feel like it treated me like an experienced programmer and
didn&amp;rsquo;t waste a lot of time explaining how an &lt;code&gt;if&lt;/code&gt; expression worked. Unlike
&lt;em&gt;Head First Kotlin&lt;/em&gt; which never got to a lot of things that it had to toss
into &lt;em&gt;Ten Brief Topics in the Appendix&lt;/em&gt;, it felt like it covered all the main
topics that needed to be covered to understand Go. It even includes coverage
of automated testing and a couple of chapters on web apps.&lt;/p&gt;</description><content:encoded><![CDATA[<p><img alt="Head First Go cover" loading="lazy" src="/posts/head-first-go/images/cover.jpg"></p>
<p>Overall, it&rsquo;s what I expect from a Head First book. It was a perfectly
serviceable introduction to the Go programming language. Although it&rsquo;s a Head
First book, I feel like it treated me like an experienced programmer and
didn&rsquo;t waste a lot of time explaining how an <code>if</code> expression worked. Unlike
<em>Head First Kotlin</em> which never got to a lot of things that it had to toss
into <em>Ten Brief Topics in the Appendix</em>, it felt like it covered all the main
topics that needed to be covered to understand Go. It even includes coverage
of automated testing and a couple of chapters on web apps.</p>
<p>It skips past the basics quickly and gets right into Go&rsquo;s core habits: multiple
return values and the <code>if err != nil</code> checks you end up writing everywhere:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapter 3 introduces functions, pointers, and Go&#39;s ubiquitous error handling:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">paintNeeded</span><span class="p">(</span><span class="nx">width</span><span class="w"> </span><span class="kt">float64</span><span class="p">,</span><span class="w"> </span><span class="nx">height</span><span class="w"> </span><span class="kt">float64</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="kt">float64</span><span class="p">,</span><span class="w"> </span><span class="kt">error</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">width</span><span class="w"> </span><span class="p">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Errorf</span><span class="p">(</span><span class="s">&#34;a width of %0.2f is invalid&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">width</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">height</span><span class="w"> </span><span class="p">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Errorf</span><span class="p">(</span><span class="s">&#34;a height of %0.2f is invalid&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">height</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">area</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">width</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nx">height</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">return</span><span class="w"> </span><span class="nx">area</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mf">10.0</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">amount</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nf">paintNeeded</span><span class="p">(</span><span class="mf">4.2</span><span class="p">,</span><span class="w"> </span><span class="mf">3.0</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">log</span><span class="p">.</span><span class="nf">Fatal</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Printf</span><span class="p">(</span><span class="s">&#34;%0.2f liters needed\n&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">amount</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>By the middle of the book, the focus shifts to structs, defined types, and
interfaces. Go&rsquo;s interfaces are satisfied implicitly without an <code>implements</code>
keyword, and the book spends adequate time showing how to extract concrete
values back out via type assertions:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapter 11 covers interfaces, implicit satisfaction, and type assertions:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">type</span><span class="w"> </span><span class="nx">Player</span><span class="w"> </span><span class="kd">interface</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nf">Play</span><span class="p">(</span><span class="nx">track</span><span class="w"> </span><span class="kt">string</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nf">Stop</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">type</span><span class="w"> </span><span class="nx">TapePlayer</span><span class="w"> </span><span class="kd">struct</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">Batteries</span><span class="w"> </span><span class="kt">string</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="p">(</span><span class="nx">t</span><span class="w"> </span><span class="nx">TapePlayer</span><span class="p">)</span><span class="w"> </span><span class="nf">Play</span><span class="p">(</span><span class="nx">track</span><span class="w"> </span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Playing&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">track</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="p">(</span><span class="nx">t</span><span class="w"> </span><span class="nx">TapePlayer</span><span class="p">)</span><span class="w"> </span><span class="nf">Stop</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Stopped!&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// Any type implementing Play and Stop satisfies Player automatically:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">playList</span><span class="p">(</span><span class="nx">device</span><span class="w"> </span><span class="nx">Player</span><span class="p">,</span><span class="w"> </span><span class="nx">songs</span><span class="w"> </span><span class="p">[]</span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">for</span><span class="w"> </span><span class="nx">_</span><span class="p">,</span><span class="w"> </span><span class="nx">song</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">songs</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">device</span><span class="p">.</span><span class="nf">Play</span><span class="p">(</span><span class="nx">song</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">device</span><span class="p">.</span><span class="nf">Stop</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="c1">// Type assertions safely retrieve concrete implementations:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">tape</span><span class="p">,</span><span class="w"> </span><span class="nx">ok</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">device</span><span class="p">.(</span><span class="nx">TapePlayer</span><span class="p">);</span><span class="w"> </span><span class="nx">ok</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Tape battery status:&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">tape</span><span class="p">.</span><span class="nx">Batteries</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>The final chapters put everything together into real web apps using <code>net/http</code>
handlers and <code>html/template</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="c1">// Chapters 15 and 16 wrap up by building web applications using</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// standard net/http handlers and html/template rendering:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">type</span><span class="w"> </span><span class="nx">Guestbook</span><span class="w"> </span><span class="kd">struct</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">SignatureCount</span><span class="w"> </span><span class="kt">int</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">Signatures</span><span class="w">     </span><span class="p">[]</span><span class="kt">string</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">viewHandler</span><span class="p">(</span><span class="nx">writer</span><span class="w"> </span><span class="nx">http</span><span class="p">.</span><span class="nx">ResponseWriter</span><span class="p">,</span><span class="w"> </span><span class="nx">request</span><span class="w"> </span><span class="o">*</span><span class="nx">http</span><span class="p">.</span><span class="nx">Request</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">signatures</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nf">getStrings</span><span class="p">(</span><span class="s">&#34;signatures.txt&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">http</span><span class="p">.</span><span class="nf">Error</span><span class="p">(</span><span class="nx">writer</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="p">.</span><span class="nf">Error</span><span class="p">(),</span><span class="w"> </span><span class="nx">http</span><span class="p">.</span><span class="nx">StatusInternalServerError</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">html</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">template</span><span class="p">.</span><span class="nf">ParseFiles</span><span class="p">(</span><span class="s">&#34;view.html&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">http</span><span class="p">.</span><span class="nf">Error</span><span class="p">(</span><span class="nx">writer</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="p">.</span><span class="nf">Error</span><span class="p">(),</span><span class="w"> </span><span class="nx">http</span><span class="p">.</span><span class="nx">StatusInternalServerError</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="k">return</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">guestbook</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">Guestbook</span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">SignatureCount</span><span class="p">:</span><span class="w"> </span><span class="nb">len</span><span class="p">(</span><span class="nx">signatures</span><span class="p">),</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">Signatures</span><span class="p">:</span><span class="w">     </span><span class="nx">signatures</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="nx">err</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nx">html</span><span class="p">.</span><span class="nf">Execute</span><span class="p">(</span><span class="nx">writer</span><span class="p">,</span><span class="w"> </span><span class="nx">guestbook</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">		</span><span class="nx">http</span><span class="p">.</span><span class="nf">Error</span><span class="p">(</span><span class="nx">writer</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="p">.</span><span class="nf">Error</span><span class="p">(),</span><span class="w"> </span><span class="nx">http</span><span class="p">.</span><span class="nx">StatusInternalServerError</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">	</span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div>]]></content:encoded></item><item><title>A Blog Reborn</title><link>https://llcawthorne.github.io/posts/a-blog-reborn/</link><pubDate>Tue, 04 Aug 2026 17:07:11 -0400</pubDate><guid>https://llcawthorne.github.io/posts/a-blog-reborn/</guid><description>&lt;p&gt;So, I haven&amp;rsquo;t been blogging for about ten years. To tell the truth, I spent
all day programming, so when I got off work, I spent my time reading history
or philosophy or anything else not computer related. I can see from my
previous posts that I was experimenting with video and had started reading
Agile Web Development with Rails. Well, I&amp;rsquo;m still a full stack web developer,
so I could do worse than looking back at the web framework that really started
it all. So I will read Agile Web Development with Rails 8 and get a taste of
convention before configuration. That doesn&amp;rsquo;t really fit with the new title
of the blog, but it&amp;rsquo;s still something I want to do, so I will get it done.
I was interested in functional programming and different approaches to web
development 10 years ago, and have never fully explored either, so I&amp;rsquo;m picking
up where I left off with a slightly updated approach.&lt;/p&gt;</description><content:encoded><![CDATA[<p>So, I haven&rsquo;t been blogging for about ten years. To tell the truth, I spent
all day programming, so when I got off work, I spent my time reading history
or philosophy or anything else not computer related. I can see from my
previous posts that I was experimenting with video and had started reading
Agile Web Development with Rails. Well, I&rsquo;m still a full stack web developer,
so I could do worse than looking back at the web framework that really started
it all. So I will read Agile Web Development with Rails 8 and get a taste of
convention before configuration. That doesn&rsquo;t really fit with the new title
of the blog, but it&rsquo;s still something I want to do, so I will get it done.
I was interested in functional programming and different approaches to web
development 10 years ago, and have never fully explored either, so I&rsquo;m picking
up where I left off with a slightly updated approach.</p>
<h2 id="haskell">Haskell</h2>
<p>But let&rsquo;s talk about the new title. It is &ldquo;Senior Software Engineer Learns
Functional Programming.&rdquo; One of the last things I did but never blogged about
was try to learn Haskell. I started with the venerable
<a href="https://haskellbook.com/">The Haskell Book</a>. I read a bit over half and
realized I still couldn&rsquo;t program much of anything in Haskell. This was after
spending previous effort learning functional programming. I learned some
Scala and the syntax of Clojure and felt ineffectual with both aside from
being able to use Scala as a better Java, so that&rsquo;s what led me to Haskell
to learn functional programming right. Well, I still want to do that. I didn&rsquo;t
think I wanted to really, but I spent some time reading <em>Advanced Functional
Programming with Elixir</em> and it made a perfectly good case for why Haskell is
a better programming language and featured a style that was not idiomatic
Elixir but instead very Haskell inspired, and it got me interested again. So
I&rsquo;m not going to start over with The Haskell Book and try to re-learn
programming from first principles. Instead I am going to read
<em>Haskell by Example</em> which is more hands on and dip into the explanations of
<em>The Haskell Book</em> whenever I need more theory. I&rsquo;m also about halfway
through <a href="https://learnyouahaskell.github.io/"><em>Learn You a Haskell</em></a> which
I started over vacation, since I&rsquo;m finding my intuition for working with
linked lists has degraded.</p>
<h2 id="elixir">Elixir</h2>
<p>The subtitle of the blog is &ldquo;With explorations in
Haskell, Elixir, and Clojure&rdquo;. I&rsquo;ve already read two Elixir books on the
basics of the language (reviews upcoming) and I have every intention of
spending more time with Elixir. The books I read didn&rsquo;t even touch on the cool
Actor model and OTP stuff that makes Elixir unique. It&rsquo;s not the best language
for learning to deal with immutable values since it allows you to rebind
variables, which feels a bit like cheating. Sure the data structure itself is
immutable, but you just end up pointing the same variable at the updated
copy. Haskell won&rsquo;t let you get away with that. I understand since the
variables aren&rsquo;t global and are local to the Actors working behind the scenes
it is safe even for concurrent code, but I intend to learn how to deal with
immutable data structures bound once to a name. So I will definitely spend
some time away with Haskell but eventually get back to Elixir. It overlaps
my other goal of trying web frameworks thanks to Phoenix, so my two big
projects (&ldquo;Learn Functional Programming&rdquo; and &ldquo;Try Web Frameworks&rdquo;) actually
meet.</p>
<h2 id="clojure">Clojure</h2>
<p>I have also bought the most recent edition of <em>Programming Clojure</em> and
<em>Clojure Brain Teasers</em> and plan to spend time with it again. I read
<em>Getting Clojure</em> and <em>Living Clojure</em> and <em>Clojure for the Brave and True</em>
years ago, and I felt pretty comfortable with the syntax of the languages and
all the parentheses, but I never was able to use it for much. So after I
spend some time writing code with Haskell, I&rsquo;ll spend some time with Clojure
again and see if I can do anything cool with it. I&rsquo;m a Java developer by trade,
so its position on the JVM feels quite welcome, and once I learn idiomatic
functional coding in a language where I can&rsquo;t back off and call Java code,
maybe it will be accessible to me. I&rsquo;ll probably spend a while with Haskell
and then Elixir first though. I do want to play around with Ring to try
writing my webapps with a minimalist Clojure library.</p>
<h2 id="web-frameworks">Web Frameworks</h2>
<p>Back to the web frameworks though&hellip; I was going to dive into <em>Agile Web
Development with Rails 8</em> and try Ruby. Then I will read through <em>Django 5
by Example</em>. This builds up four sizable projects which I plan to steal.
I don&rsquo;t really like any dynamic language all that much, but I do normally
prefer Python to Ruby for its usefulness with AI and its sensible stance
on one way to do things and lack of going crazy with metaprogramming. I have
every intention of stealing the Django projects to reimplement in other
frameworks to serve my own curiosity. First in Rails, then move on to the next
stop. So then I can read <em>Programming Elixir</em> and <em>Programming Phoenix
Liveview</em> to try doing a web framework. How do I plan to make time for all this?
Well, I think I can wrestle with Haskell for at most 30-60 minutes a day, so
my time beyond that can be spent toying with web frameworks which requires
less cognitive load. After Phoenix, there&rsquo;s other options. I can try writing
a typed API in Haskell with Servant or do something with Yesod. I also wouldn&rsquo;t
mind reading <em>Distributed Services in Go</em> and trying the same projects as
microservices. I happen to like Go for being so simple that you can&rsquo;t hide
anything behind the language. I&rsquo;ve recently read two books on it (reviews
forthcoming) and feel pretty comfortable with it. Aside from that, I wouldn&rsquo;t
mind trying an Angular frontend with a backend in another language, since we
actively use Angular in the new project at work. And I&rsquo;m not opposed to trying
React to just see the difference. Obviously, all JavaScript Single-Page
Applications are more the rage now than old school web frameworks like Rails,
and it fits my interests of seeing different ways to do things. I also have
been toying around with Kotlin and would love an excuse to go back, so I would
like to try Spring with Kotlin for the big enterprise way of doing a web
framework along with Ktor for a lighter weight framework in the same language.
I could code Spring in Java, but I do like not coding in Java when I&rsquo;m away
from work and find Kotlin a fun alternative. Spring and Angular are probably
the most professionally relevant interests that I&rsquo;ll be pursuing, but it&rsquo;s
obvious that I&rsquo;m not trying to maximize for utility. I do really think it
very clever that the new project at work is leaning into a modern Angular UI
with a Java backend instead of using any of the trainwreck front end projects
available on the Java platform. JSF was bad enough to make me never want to
see a Java frontend again. Anyway, that&rsquo;s as far as I&rsquo;ve thought
these two projects through, but if I make it that far with them, I&rsquo;ll have
a better idea of what I want to do next. Put together, they should keep me
busy for a while, and assuming I don&rsquo;t give up blogging for ten years or so
again, it will give me something to blog about.</p>
<h2 id="why-now">Why Now?</h2>
<p>Why do I think blogging will catch on this time? Well, what made me give up
my side projects and blogging before was primarily being burnt out on spending
all day coding at work to get off and do more of it at night. Now that my kid
is older and I&rsquo;ve got more time to focus on personal development, I figured
why not fire the blog back up so I can shout my book reviews and whatnot into
the void. Aside from that, work has us leaning a lot more on AI for writing
code these days, so it&rsquo;s as good an excuse as any to keep my own skills sharp
with some side projects. I&rsquo;ve also been rather good lately at putting my mind
to stuff and keeping it going.
I lost about 40 pounds and run 10K every day I don&rsquo;t lift weights. So maybe
I can stay focused on something intellectual too. Also, I still run over an
hour most days a week, which gives me a great opportunity to listen to a
history audiobook or fictional work, so it isn&rsquo;t like I&rsquo;m giving up my hobby
reading. I&rsquo;m just cutting into other spare time with a new project. As a busy
dad, I really get 1-2 hours of free time that I&rsquo;m not working out most days,
so it&rsquo;s easy to spend 30-60 minutes on Haskell and the remainder if there is
any on something else. Or so I think. We&rsquo;ll see if this blog rebirth lasts.
So far, I&rsquo;ve read about 8 technical books that I&rsquo;ll end up posting reviews
for, so I already have more content than I had last time before
discontinuing it, and it seems something fun to do. I&rsquo;ve already been reading
a minimum of 30 minutes a day for over a year, and often for hours, so I&rsquo;m just
going to read different stuff.</p>
<p>I didn&rsquo;t put this in the first draft, because it feels kinda silly to get
inspired by a book about a famous person, but there&rsquo;s also another thing
that motivated me to do more programming on the side. I listened to the
audiobook on Steve Jobs while I was running. Really, I don&rsquo;t care that much
about Steve Jobs and still don&rsquo;t after listening to his life story. He
definitely had vision and did good things with Apple, and I&rsquo;m writing this
on a Mac so can&rsquo;t complain about the results, but I consider him more of
a visionary businessman than a real hacker. I liked Isaacson&rsquo;s biography
of Benjamin Franklin and figured Steve Jobs would be another accessible work
by him for my runs. But you can&rsquo;t read about the founding of Apple without
encountering Woz. A true engineer that would&rsquo;ve gladly made computers and
gave them away, because he loved tinkering with circuitboards. I don&rsquo;t really
care about circuitboards either; I&rsquo;ve always been a software guy. But being
exposed to a story with that type of passion reminded me I used to be
passionate about computers.</p>
<p>I&rsquo;ve always had a bit of a love-hate relationship with Apple. I still have
Linux on my desktop PC and am a proud member of the Columbia Linux User&rsquo;s
Group despite not attending meetings all that often.
The early Apple computers were toys with no CLI and one button mice
because multiple buttons are confusing. But after OS X was reborn with BSD
under the hood and a full fledged terminal, I found that having a computer
that mostly worked with the default configuration and
actually looked pretty good made it easier for me to focus
on writing code and not spend so much time tinkering around with Linux. I
learned from the Steve Jobs book that the first Macs were expandable
because Woz thought people should be able to tinker with their own computers.
Maybe I would&rsquo;ve liked those better than the Macs at school.</p>
<p>Anyway, back to passion, I didn&rsquo;t take my computer apart and hide all the
pieces because I thought it would be faster when I put it back together
hours later. I did it because I wanted to learn how a computer was put
together (I didn&rsquo;t know I wasn&rsquo;t really a hardware guy back then; I honestly
prefer buying them off the shelf now).
I also didn&rsquo;t learn C and relational databases because I thought they would be
profitable (although database knowledge is the gift that keeps on giving).
I loved solving problems in C in the middle of the night on my hand-me-down
computer. I didn&rsquo;t found an ISP in the 90&rsquo;s to get rich quick,
I founded it to have fast Internet access and to have cool problems to
figure out. Likewise, I didn&rsquo;t make straight A&rsquo;s in school because I
expected it to help my
job prospects. No one cares about my GPA. I loved the material! It was
fascinating to learn about algorithms, operating systems, and, after
programming so long, compilers. Somewhere along the way, it just became work
like any other job. So it&rsquo;s a combination of factors: having more free time
now that my kid&rsquo;s a little older, work leaning harder on AI for the actual
code these days so I want to keep my own chops sharp on the side, a refound
passion for programming inspired by a rather unlikely source, and the fact
I&rsquo;ve been reading every day over a year anyway, so why not make it technical.
I still don&rsquo;t know functional programming beyond how to apply a good
map and filter, and I still haven&rsquo;t tried a lot of different web frameworks.
They&rsquo;re all likely to be better than the Java EE/Spring hybrid monstrosity
that I work on most of the time. Almost anything beats JSF.</p>
<p>And as an aside, this will probably be my last time trying to learn
&ldquo;functional programming&rdquo;. If I try to learn the secrets of Haskell again
and bounce off, I am just going to adopt Go as my programming language of
choice and write lots of simple procedural code with structs and <code>err</code>
checks every other line. As an old school C hacker and Perl scripter before
they bolted on OOP, it feels quite natural to write straightforward procedural
code, but I&rsquo;m trying to work outside my comfort zone even if I think the
benefits of functional programming might be overpromised.</p>
<p>But I really kinda understood the point of functional programming with
<em>Advanced Functional
Programming with Elixir</em>, and all those <code>err</code> checks in Go grated at
my nerves, so the beauty of being able to chain a bunch of calls together then
deal with errors or results at the end was quite appealing to me. Monads
aren&rsquo;t really the Elixir way though. Your average Elixir programmer would
do some simple pattern matching to catch <code>:err</code> and deal with it instead, but
<em>Advanced Functional Programming with Elixir</em> featured a Haskell inspired
functional programming library and monads. And while I wasn&rsquo;t ultimately
convinced of the utility of the Reader or Effect monads (I&rsquo;m open to learning
more about those in Haskell, and I will have to anyway if I spend time with
it), I really liked Maybe and liked Either even more. Even Java has Option,
but Either is a lot more useful. Plus parallel validations with Applicative
were kinda cool. They weren&rsquo;t a reason to re-learn programming, but I&rsquo;ll take
them along with my Either and roll with it a bit.</p>
<h2 id="conclusion">Conclusion</h2>
<p>So that&rsquo;s it. The blog is reborn. I&rsquo;ve got one project that meshes with the
title of learning functional programming. I have another of trying web
frameworks that has some limited overlap built in and picks up where the
blog left off. I transferred my old posts over and rebuilt the site in Hugo
and moved over what I could from the old Jekyll files. And I&rsquo;ve written a
very long coming back
post plus already have a stash of book reviews in my Obsidian. So I guess
I&rsquo;m back and doing this for now and we&rsquo;ll see where it goes. I may get
tired of posting updates here and just read the books, but I like having
somewhere to collect my thoughts and review what I read.</p>
]]></content:encoded></item><item><title>About</title><link>https://llcawthorne.github.io/about/</link><pubDate>Mon, 03 Aug 2026 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/about/</guid><description>&lt;img src="images/lewis-and-vader.jpg" alt="Lewis Cawthorne with Darth Vader at Disney's Hollywood Studios" style="display: block; max-width: 320px; width: 100%; margin: 0 auto; border-radius: var(--radius);" /&gt;
&lt;p&gt;I&amp;rsquo;m Lewis Cawthorne, a Senior Software Developer at EXL. All posts here are
my own opinions and are in no way reflective of my employer. Day to day I
work on the Subrosource platform: an OSGi backend, an Angular frontend,
Microsoft SQL Server, AWS, HashiCorp tooling (Vault, Consul, Nomad), and
increasingly, AI-assisted development with tools like GitHub Copilot,
Cursor, and Claude Code.&lt;/p&gt;</description><content:encoded><![CDATA[<img src="images/lewis-and-vader.jpg" alt="Lewis Cawthorne with Darth Vader at Disney's Hollywood Studios" style="display: block; max-width: 320px; width: 100%; margin: 0 auto; border-radius: var(--radius);" />
<p>I&rsquo;m Lewis Cawthorne, a Senior Software Developer at EXL. All posts here are
my own opinions and are in no way reflective of my employer. Day to day I
work on the Subrosource platform: an OSGi backend, an Angular frontend,
Microsoft SQL Server, AWS, HashiCorp tooling (Vault, Consul, Nomad), and
increasingly, AI-assisted development with tools like GitHub Copilot,
Cursor, and Claude Code.</p>
<p>This site is built with <a href="https://gohugo.io/">Hugo</a> using the
<a href="https://github.com/adityatelange/hugo-PaperMod">PaperMod</a> theme, hosted on
<a href="https://pages.github.com/">GitHub Pages</a>. Like every personal site ever
built, it is, and will probably always be, a work in progress.</p>
<p>The posts here are a mix of old and new. Some are notes from years ago that
I moved over when I rebuilt the site, kept as-is for the record.</p>
]]></content:encoded></item><item><title>Contact</title><link>https://llcawthorne.github.io/contact/</link><pubDate>Mon, 03 Aug 2026 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/contact/</guid><description>&lt;p&gt;You can get in touch with or find me at:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/llcawthorne"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/llcawthorne"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://facebook.com/llcawthorne"&gt;Facebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;My &lt;a href="https://rebellion.nerdfitness.com/topic/124542-llcawthorne%E2%80%99s-daily-battle-log/"&gt;Daily Fitness Journal&lt;/a&gt; on the Nerd Fitness Rebellion forums&lt;/li&gt;
&lt;li&gt;Or by sending an e-mail to &lt;a href="mailto:llcawthorne@gmail.com"&gt;llcawthorne@gmail.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><content:encoded><![CDATA[<p>You can get in touch with or find me at:</p>
<ul>
<li><a href="https://github.com/llcawthorne">GitHub</a></li>
<li><a href="https://www.linkedin.com/in/llcawthorne">LinkedIn</a></li>
<li><a href="https://facebook.com/llcawthorne">Facebook</a></li>
<li>My <a href="https://rebellion.nerdfitness.com/topic/124542-llcawthorne%E2%80%99s-daily-battle-log/">Daily Fitness Journal</a> on the Nerd Fitness Rebellion forums</li>
<li>Or by sending an e-mail to <a href="mailto:llcawthorne@gmail.com">llcawthorne@gmail.com</a></li>
</ul>
]]></content:encoded></item><item><title>Resume</title><link>https://llcawthorne.github.io/resume/</link><pubDate>Mon, 03 Aug 2026 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/resume/</guid><description>&lt;h1 id="lewis-cawthorne"&gt;Lewis Cawthorne&lt;/h1&gt;
&lt;p&gt;&lt;a href="mailto:llcawthorne@gmail.com"&gt;llcawthorne@gmail.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Senior Software Developer at EXL, working on the Subrosource platform.&lt;/p&gt;
&lt;h2 id="degrees"&gt;Degrees&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Masters of Engineering, Computer Science, University of South Carolina, Columbia, SC, Dec 2014&lt;/strong&gt;&lt;br&gt;
Specialization: Information Security&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;BS, Computer Science, University of South Carolina, Columbia, SC, Aug 2011&lt;/strong&gt;&lt;br&gt;
Minor: Mathematics&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AS, High Honors, Midlands Technical College, Columbia, SC, May 2009&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id="professional-employment"&gt;Professional Employment&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Senior Software Developer and Technical Lead, EXL, Jan 2015 - present&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Long-tenured technical contributor on the Subrosource platform, now over a decade with the team&lt;/li&gt;
&lt;li&gt;Platform lead for Subrosource Classic (the original Java EE / Oracle-based application) and a contributor on its ground-up replacement, built on an OSGi backend (started on Java 11, now on Java 25) with an Angular frontend, backed by Microsoft SQL Server, hosted on AWS, with infrastructure supported by HashiCorp tooling (Vault, Consul, Nomad)&lt;/li&gt;
&lt;li&gt;Maintain operation of Subrosource Classic and ensure it gets yearly security patches, in addition to new development work on its replacement, ahead of an eventual customer migration off the older platform&lt;/li&gt;
&lt;li&gt;Extensive experience with Oracle and PL/SQL; independently designed, wrote, and performance-tuned a large PL/SQL package, including deep dives into Oracle internals to resolve performance issues&lt;/li&gt;
&lt;li&gt;Using AI-assisted development tools day to day, including GitHub Copilot, Cursor, and Claude Code&lt;/li&gt;
&lt;li&gt;Took a leading role in an agile group with seven developers acting within a larger corporate organization to provide software and services to insurance domain customers&lt;/li&gt;
&lt;li&gt;Updated Subrosource Classic from Weblogic 10.3 to Weblogic 12 and from Java 1.6 to Java 1.8&lt;/li&gt;
&lt;li&gt;Maintained, extended, and helped secure the Subrosource Classic Java EE 5 application on Oracle WebLogic Application Server and Java 1.6 backed by an Oracle 11g database&lt;/li&gt;
&lt;li&gt;Performed security scans with HP Fortify software and patched found vulnerabilities&lt;/li&gt;
&lt;li&gt;Developed a web application to provide insight to support technicians debugging general data import issues with JDK 8 and Java EE 7 technologies running on Glassfish 4.1 Application Server with a Vaadin GWT-based rich user interface accessing an Oracle 11g database and custom scripts to extract text log information&lt;/li&gt;
&lt;li&gt;Researched and made recommendations on ways to ease development team growth pains by better incorporating automated unit, integration, and acceptance testing&lt;/li&gt;
&lt;li&gt;Wrote, tested, and debugged a batch process based on preexisting procedural logic to on-board a new customer by cleaning, transforming, and importing 80,000 customer claim records which were split up to over half a million relational table entries; primarily handled through the creation and integration of new awk processing scripts, some modification of a C# account registration program, and PL/SQL customizations in the database to handle customer specific account logic&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Teaching Assistant, University of South Carolina, Aug 2012 - Dec 2014&lt;/strong&gt;&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="lewis-cawthorne">Lewis Cawthorne</h1>
<p><a href="mailto:llcawthorne@gmail.com">llcawthorne@gmail.com</a></p>
<p>Senior Software Developer at EXL, working on the Subrosource platform.</p>
<h2 id="degrees">Degrees</h2>
<p><strong>Masters of Engineering, Computer Science, University of South Carolina, Columbia, SC, Dec 2014</strong><br>
Specialization: Information Security</p>
<p><strong>BS, Computer Science, University of South Carolina, Columbia, SC, Aug 2011</strong><br>
Minor: Mathematics</p>
<p><strong>AS, High Honors, Midlands Technical College, Columbia, SC, May 2009</strong></p>
<h2 id="professional-employment">Professional Employment</h2>
<p><strong>Senior Software Developer and Technical Lead, EXL, Jan 2015 - present</strong></p>
<ul>
<li>Long-tenured technical contributor on the Subrosource platform, now over a decade with the team</li>
<li>Platform lead for Subrosource Classic (the original Java EE / Oracle-based application) and a contributor on its ground-up replacement, built on an OSGi backend (started on Java 11, now on Java 25) with an Angular frontend, backed by Microsoft SQL Server, hosted on AWS, with infrastructure supported by HashiCorp tooling (Vault, Consul, Nomad)</li>
<li>Maintain operation of Subrosource Classic and ensure it gets yearly security patches, in addition to new development work on its replacement, ahead of an eventual customer migration off the older platform</li>
<li>Extensive experience with Oracle and PL/SQL; independently designed, wrote, and performance-tuned a large PL/SQL package, including deep dives into Oracle internals to resolve performance issues</li>
<li>Using AI-assisted development tools day to day, including GitHub Copilot, Cursor, and Claude Code</li>
<li>Took a leading role in an agile group with seven developers acting within a larger corporate organization to provide software and services to insurance domain customers</li>
<li>Updated Subrosource Classic from Weblogic 10.3 to Weblogic 12 and from Java 1.6 to Java 1.8</li>
<li>Maintained, extended, and helped secure the Subrosource Classic Java EE 5 application on Oracle WebLogic Application Server and Java 1.6 backed by an Oracle 11g database</li>
<li>Performed security scans with HP Fortify software and patched found vulnerabilities</li>
<li>Developed a web application to provide insight to support technicians debugging general data import issues with JDK 8 and Java EE 7 technologies running on Glassfish 4.1 Application Server with a Vaadin GWT-based rich user interface accessing an Oracle 11g database and custom scripts to extract text log information</li>
<li>Researched and made recommendations on ways to ease development team growth pains by better incorporating automated unit, integration, and acceptance testing</li>
<li>Wrote, tested, and debugged a batch process based on preexisting procedural logic to on-board a new customer by cleaning, transforming, and importing 80,000 customer claim records which were split up to over half a million relational table entries; primarily handled through the creation and integration of new awk processing scripts, some modification of a C# account registration program, and PL/SQL customizations in the database to handle customer specific account logic</li>
</ul>
<p><strong>Teaching Assistant, University of South Carolina, Aug 2012 - Dec 2014</strong></p>
<ul>
<li>Fall 2014: Lecture Instructor for CSCE 212 - Intro to Computer Architecture (Assembly)</li>
<li>Summer 2014: Lecture Instructor for CSCE 146 - Data Structures Using Java (Java)</li>
<li>Spring 2014: Lecture Instructor for CSCE 212 - Intro to Computer Architecture (Assembly)</li>
<li>Fall 2013: Lecture Instructor and Lab TA for CSCE 101 - Intro to Computing (Java)</li>
<li>Spring 2013: Lecture Instructor for CSCE 204 - Program Design and Development (Visual Basic)</li>
<li>Fall 2012: Lab TA for CSCE 145 - Algorithmic Design (Java)</li>
</ul>
<p><strong>Research Assistant, Center for Information Assurance Engineering at USC, Aug 2011 - Dec 2014</strong></p>
<ul>
<li>Quantum Complexity Theory research advised by Dr. Stephen A. Fenner</li>
<li>Analyzed algorithms which require quantum computers and how problems solvable via quantum algorithms, such as factoring, differ in structure from classical problems</li>
<li>Studied quantum entanglement effects on classic two party game theory</li>
<li>Investigated mutually unbiased bases for secure quantum key distribution</li>
<li>Expanded a C program for web based analysis and graphing of lambda closure functions including a LaTeX based formula parser</li>
</ul>
<p><strong>REU Program Coordinator, Research Experience for Undergraduates at USC, Aug 2011 - Aug 2013</strong></p>
<ul>
<li>Coordinated summer housing and activities for 10 undergraduate participants</li>
<li>Guided participants through all steps of creating and submitting an academic paper</li>
<li>Offered proofreading and implementation advice on 10 papers from 7 different subareas</li>
</ul>
<p><strong>Undergraduate Research Assistant, MLEG Lab at USC, Jun 2010 - Aug 2011</strong></p>
<ul>
<li>Created SMEE, the Sorting Motif Extraction Engine, a biomedical text analysis service using Python for Natural Language Processing and Django web framework</li>
</ul>
<p><strong>Linux System Administrator, EMR Technical Solutions, Feb 2010 - Jun 2010</strong></p>
<ul>
<li>Setup various server applications on three Linux servers</li>
<li>Managed security on servers, including detection / elimination of prior intrusion</li>
</ul>
<p><strong>Network Administrator, Wave Communications / Durocom / Volaris Online, June 1995 - Sept 2002</strong></p>
<ul>
<li>Lead the building of what quickly became a 3000-4000 customer Internet provider</li>
<li>Maintained 14 high volume servers running multiple operating systems</li>
<li>Participated in a 24-hour emergency response on call rotation</li>
<li>Supervised a team of 20-40 technical support representatives</li>
<li>Ultimately shared primary responsibility for a $10-million regional ISP with a co-administrator, which was acquired by a super-regional provider and then by Earthlink</li>
</ul>
<p><strong>Database Administrator, Doulos Productions, Apr 1992 - Nov 1996</strong></p>
<ul>
<li>Created and managed a 100,000 record relational database</li>
<li>Managed a VM386 based dumb terminal multiuser system</li>
</ul>
<h2 id="technology-applications-and-expertise">Technology Applications and Expertise</h2>
<p><strong>Current Focus:</strong> OSGi, Angular, Microsoft SQL Server, AWS, HashiCorp Vault, HashiCorp Consul, HashiCorp Nomad, AI-assisted development (GitHub Copilot, Cursor, Claude Code)</p>
<p><strong>Specialized Skills:</strong> Java EE, EJB2, EJB3, JSP, JSTL, JSF, RichFaces, JTA, JPA, Layered Architectures, Agile Development, Information Security, User Testing, Full-stack Web Development, Version Control, Web Design</p>
<p><strong>Markup/Programming:</strong> Java, Python/Django, JavaScript, JQuery, Ruby/Rails, XHTML, HTML5, CSS, CSS3, XML, XSLT, Perl, Awk, PL/SQL, Shell Scripting</p>
<p><strong>Applications:</strong> Eclipse, IntelliJ, Microsoft Office, HP Fortify Security Scanner, Google Drive, Vim, Oracle 9i-11g, Selenium, Git, Subversion, WebLogic 10.3 - 12, Glassfish 4</p>
<p><strong>OS/Environments:</strong> Mac, Linux, Unix, Ubuntu, Windows</p>
<h2 id="certifications">Certifications</h2>
<p><strong>CNSS 4011</strong>, National Training Standard for INFOSEC Professionals</p>
<h2 id="awards">Awards</h2>
<ul>
<li><strong>Presidential Graduate Fellowship</strong>, University of South Carolina, Aug 2012 - Apr 2014</li>
<li><strong>Magellan Scholarship Winner</strong>, competitive research funding, Jan 2011 - Aug 2011</li>
<li><strong>Outstanding Senior Award</strong>, University of South Carolina, Apr 2011</li>
<li><strong>IBM Master the Mainframe Competition</strong>, winner Parts 1 and 2, Dec 2010</li>
<li><strong>ΥΠE Scholarship Winner</strong>, competitive scholarship, Aug 2010</li>
</ul>
<h2 id="societies">Societies</h2>
<ul>
<li><a href="https://www.acm.org/">ACM</a>, Association for Computing Machinery</li>
<li>GCC, Gamecock Cybersecurity Club</li>
<li><a href="https://www.starscomputingcorps.org/corps">SLC</a>, STARS Leadership Corps</li>
<li>ColaLUG, Columbia Linux Users Group</li>
<li>Upsilon Pi Epsilon (ΥΠE) and Phi Theta Kappa (ΦΘK) Honor Societies</li>
</ul>
]]></content:encoded></item><item><title>O'Reilly Spring Framework Essentials</title><link>https://llcawthorne.github.io/posts/oreilly-spring-framework-essentials/</link><pubDate>Mon, 26 Jun 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/oreilly-spring-framework-essentials/</guid><description>&lt;p&gt;This time I&amp;rsquo;m working on reinforcing some of the Spring and Spring Boot
knowledge I&amp;rsquo;ve picked up from other videos, while seeing if I can learn
a couple of new tricks while at it. I&amp;rsquo;m watching
&lt;a href="https://www.safaribooksonline.com/library/view/spring-framework-essentials/9781491942680/"&gt;Spring Framework Essentials&lt;/a&gt; through my Safari Books Online membership.
It&amp;rsquo;s presented by Ken Kousen, who often hosts the Groovy Podcast. He has a
series of three Groovy videos in Safari Books Online that I wouldn&amp;rsquo;t mind
going through sometime in the future. The video series runtime is 5 hours,
14 minutes and it has a five star rating from 35 reviewers. Not bad, let&amp;rsquo;s
see what it covers.&lt;/p&gt;</description><content:encoded><![CDATA[<p>This time I&rsquo;m working on reinforcing some of the Spring and Spring Boot
knowledge I&rsquo;ve picked up from other videos, while seeing if I can learn
a couple of new tricks while at it.  I&rsquo;m watching
<a href="https://www.safaribooksonline.com/library/view/spring-framework-essentials/9781491942680/">Spring Framework Essentials</a> through my Safari Books Online membership.
It&rsquo;s presented by Ken Kousen, who often hosts the Groovy Podcast.  He has a
series of three Groovy videos in Safari Books Online that I wouldn&rsquo;t mind
going through sometime in the future.  The video series runtime is 5 hours,
14 minutes and it has a five star rating from 35 reviewers.  Not bad, let&rsquo;s
see what it covers.</p>
<p>So, these videos are going to focus on the core Spring Framework.  So we
won&rsquo;t be getting back into Spring Data or even Spring MVC in this video
series.  It says that it will talk a little about Spring Boot, since that&rsquo;s
the general way to get projects started these days.  &ldquo;One thing that you&rsquo;ll
notice about the Spring Framework, is that they never met a class or package
name too long.&rdquo;  Tell me about it.  Spring makes you appreciate autocomplete.
He uses gradle to manage projects, which is fine.  Maven or gradle are both
fine options.</p>
<p>He did a fine demonstration of basic injection in
XML, annotations, and Java config setup and quick intro to aspect
oriented programming that included an example of the <code>@Around</code> advice.  Then
he gave a quick introduction to Spring testing.  Finally someone that doesn&rsquo;t
ignore testing.  It turns out you can annotate you test class with
<code>@RunWith(SpringJUnit4ClassRunner)</code> to have Spring aware tests, and you
can add the <code>@ContextConfiguration(classes = AppConfig.class</code> so that you
have a cached ApplicationContext shared between tests in the class and the
ability to <code>@Autowire</code> any of your beans.  You can even <code>@Autowire</code> an
<code>ApplicationContext ctx</code> variable to inject a reference to your
ApplicationContext to use in tests to fetch beans you don&rsquo;t autowire.  The
fact that <code>@ContextConfiguration</code> takes a classes argument lets you have a
different configuration class for tests than the running application if
necessary.  You can also add the <code>@Transactional</code> annotation to your test
class to make all your tests occur in a transaction that gets rolled back
after test completion.  His toy app that he used to demonstrate early
principles didn&rsquo;t have any database interaction to show-off transactional
tests, but this is the part of the course that he switches from a toy app
to something a little more complicated.  He also mentions that the Spring
pet-clinic demo app makes good use of transactional tests.</p>
<p>The new application has a Service and a Repository interface.  Instead of
using Spring Data, he does all the database operations with an in-memory
and a JDBC implementation.  Everything is marked <code>@Transactional</code> at the
Service level.  He had to make a &ldquo;transactionManager&rdquo; Bean and use an
<code>@EnableTransactionManagement</code> on his Configuration class, neither of which
I recall being required when doing a Spring Boot app with <code>@Transactional</code>.
The JDBC is using the Spring JDBC Template and is a lot cleaner than straight
JDBC.  The JDBC Template does a lot of work for you.  For example, the
following one-liner works for getting a count: <code>int rowCount =  this.jdbcTemplate.queryForObject(&quot;select count(*) from t_actor&quot;), Integer.class);</code>  I like the way he looks up what he is talking about in the
online API, the same way you likely would when programming with the various
API elements.  He shows off using &ldquo;test&rdquo; and &ldquo;prod&rdquo; profiles to differentiate
between an H2 in-memory database and an Apache data connection pool backed
by MySQL.  Each repository method with the JDBC Template ends up being two
to four lines long, depending upon what he&rsquo;s try to do.  Pretty simple, but
not as simple as not defining implementation methods with Spring Data JPA.</p>
<p>Yay!  More testing.  This time we&rsquo;re testing repositories.  Just set the
annotations on the test class and annotate the test profile, then autowire
the repository and you&rsquo;re good to go.  Each test is transactional, so they
roll back changes at the end of each test.  He uses Hamcrest matchers, so
he can make assertions like <code>assertThat(accounts.size(), is(3));</code>, which
flows a bit better than standard assertEquals.  He points out that since
he is using gradle he can show the really cool gradle test report.  The
tests he ran were all quick, even with firing up and setting up the
in-memory database.  First one took half a second, but the all six of them
took less than a second total.  He succeeded in exercising all his
repository methods and making sure they worked as expected.</p>
<p>I was wrong that we weren&rsquo;t going into Spring Data.  He reimplements his
repository using Spring Data JPA for the next project.  Spring Data JPA
repositories are just interfaces.  You get queries generated for free based
upon how you name the methods in the interfaces.  You can also use the
<code>@Query</code> annotation above a method in the interface to give it a custom
query if the autogenerated language can&rsquo;t handle what you&rsquo;re after.  He defined
the JpaVendorAdapter and LocalContainerEntityManagerFactoryBean manually in
the Java Spring configuration file, which normally weren&rsquo;t require with
Spring Boot.  It&rsquo;s interesting to see how this is all done by hand, and it
isn&rsquo;t that much in total lines of configuration.  He didn&rsquo;t use the feature
of Spring Data JPA to allow repository autogeneration of methods and just
defining an interface.  Instead he defined a JpaAccountRepository that
implemented its various methods directly through an EntityManager.  He does
use <code>@PersistenceContext</code> annotation to inject his EntityManager.  Most of
the methods now are one or two lines long.  He did have to add JPA
annotations to his entity class, but most of them defaulted through good
name selection for class and fields.  Only <code>@Entity</code> on the class and <code>@Id</code>
on the primary key field actually needed to be added to the domain object.
He shows that you can use the same service with the JPA repository as was
used with the JDBC Template repository, since he designed the methods to
take the same arguments.  He uses the same tests also, which makes sense as
the interface and expected outputs are the same.</p>
<p>I forgot to mention it earlier, but this presenter uses IntelliJ for
everything.  Always nice to see!  Oh, he was just using JPA in the last
project.  The next project is where he&rsquo;s adding in Spring Data to get
the free implementations of DAO methods.  So, it turns out he uses Spring
Data for the last 12 minute segment of the presentation, and then switches
to showing the same app with Spring Boot for the last 15 minutes of the
presentation.  The app keeps getting simpler each time he introduces
more Spring features.  He actually extended JpaRepository for his
repository, where I am more accustomed to seeing CrudRepository or
PagingAndSortingRepository extended.  JpaRepository extends both.  He had
to change the method names in his service and tests to match the ones
freely given by having an interface extend on of the Spring Data interfaces,
but got to delete a lot of code that was the repository class implementation
and previous repository interface which was more complicated.  Interesting
to see that his tests run quicker now too, taking a little under 0.4 seconds.
He&rsquo;s still using an H2 in-memory database for testing and setting it up
with the same sql scripts.  He points out that all his earlier work really
was unnecessary.  The final project is to show how much of his configuration
he can get rid of also by using Spring Boot.  It&rsquo;s still interesting to
know how to do it by hand, since everything we&rsquo;ve seen is still happening
under the hood in Spring Boot.</p>
<p>So, at the end, he claims that a Spring Boot focused course is coming.  I
don&rsquo;t see it as available yet.  He had mentioned earlier this video course
would be the start of a series.  I really enjoyed Ken&rsquo;s presentation, and
would definitely watch more in this series by him.  It was a neat change
seeing Spring used for non-web apps.  I hope in the future videos he shows
off Spring MVC though, because Spring makes some nice web apps too.  He
recommends the book Spring Boot in Action at the end, but I found that book
fairly worthless.  The source code for it didn&rsquo;t match up with what was
described in the text.  Maybe now that I actually have a grasp on some of
this stuff, it would be useful and I could figure out why the sample source
code and the text don&rsquo;t match up.  Anyway, despite his poor book
recommendation at the end, I really enjoyed this video series.  It&rsquo;s worth
a watch if you&rsquo;re looking for something to view with your Safari Books Online
membership.</p>
]]></content:encoded></item><item><title>Udemy - Spring Boot Intro</title><link>https://llcawthorne.github.io/posts/udemy-spring-boot-intro/</link><pubDate>Thu, 22 Jun 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/udemy-spring-boot-intro/</guid><description>&lt;p&gt;I figured since I am a professional Java programmer that I might as well
spent some time getting familiar with some Java technologies that I don&amp;rsquo;t
get to use at work. With this in mind, I purchased Udemy&amp;rsquo;s &amp;ldquo;Spring Boot
Intro&amp;rdquo; course for $10 when they had a sale.&lt;/p&gt;
&lt;p&gt;This course moved a lot quicker than the last course I took from Udemy.
It covered basic dependency injection in Spring in probably an hour or less,
where the last class focused on dependency injection fundamentals for the
entire time. I appreciated the faster pace, as there&amp;rsquo;s a lot of stuff
to cover with Spring Boot. It handles autoconfiguring all the main projects
that make up Spring&amp;hellip; Spring MVC, Spring Rest, Spring Data, Spring Security,
etc.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I figured since I am a professional Java programmer that I might as well
spent some time getting familiar with some Java technologies that I don&rsquo;t
get to use at work.  With this in mind, I purchased Udemy&rsquo;s &ldquo;Spring Boot
Intro&rdquo; course for $10 when they had a sale.</p>
<p>This course moved a lot quicker than the last course I took from Udemy.
It covered basic dependency injection in Spring in probably an hour or less,
where the last class focused on dependency injection fundamentals for the
entire time.  I appreciated the faster pace, as there&rsquo;s a lot of stuff
to cover with Spring Boot.  It handles autoconfiguring all the main projects
that make up Spring&hellip;  Spring MVC, Spring Rest, Spring Data, Spring Security,
etc.</p>
<p>This author made it really hard to code along with him.  He did things
like restart a project with unknown initializr settings in between
videos.  He also copied and pasted a lot of code, so you couldn&rsquo;t really
type along with him.  As long as you don&rsquo;t mind pausing and typing
something in, it wasn&rsquo;t unworkable, but it got a little old.  I ended up
checking out his repo of code samples and following along with them.
He does have exercises at the end of each section, which are a good
chance to code some stuff up on your own.  He doesn&rsquo;t mention specifically
when he changes projects from the repo either, so it&rsquo;s a little hit and
miss making sure you&rsquo;re looking at the right code that he&rsquo;s working on.</p>
<p>One nice thing is this guy used IntelliJ instead of Eclipse.  He admitted
that you need the paid for version to work with Spring, but just told
people to sign up for the 30 day trial.  Fortunately, I still have my student
license, so I had all the features to play along.  It might be annoying to
people that have already done the IntelliJ trial, since it makes it harder
to follow along.  Of course, he&rsquo;s pretty hard to follow along with as it is,
so using STS or Eclipse wouldn&rsquo;t be that much worse.  Anyway, I was excited
at first that he used IntelliJ, but then he switched to Eclipse STS halfway
through the videos.  I kept following along in IntelliJ.</p>
<p>I liked the Spring Boot way of doing apps.  It felt like convention over
configuration brought to the Java world, the way it autoconfigures so much
stuff based upon what it finds loaded in your class path.  I really liked
Spring Data, which allows you to pair up standard JPA entities with
Repository interfaces that automatically generate the implementation with
queries based upon the names of the method defined in your interface.<br>
For example, if you make a method called <code>findByLastName(String lastName)</code>
in your interface, you get the query you would expect for free.  The
instructor didn&rsquo;t go into this, but it also works with QueryDSL predicates
to fill in the queries, which is pretty cool since I use QueryDSL at work. He
also showed how to do everything by hand with JDBC, but I liked the JPA
approach better.  He also showed that you can drop in mongo DB and swap
out Entity annotation for Document pretty easily in an app with very little
changes.  It was a weird choice doing JPA backed by a Microsoft SQL Server
database, and since I didn&rsquo;t feel like signing up for an Azure trial, I
just kept using H2.</p>
<p>I really liked the Dev Tools with live reload.  He showed that you have to
change a few settings in IntelliJ.  In the registry you check
compiler.automake.allow.when.app.running and in the
Preferences-&gt;Build, Execution, Deployment-&gt;Compiler you check the
Build project automatically.  Then you install a browser extension from
<a href="http://livereload.com/extensions/">http://livereload.com/extensions/</a> and it will reload automatically when
anything changes in your code. It isn&rsquo;t that much work really to save
hitting refresh all the time.  He doesn&rsquo;t use that in most of his projects,
but I kept it turned on in all the ones I did by hand.</p>
<p>I like Spring Security, but found the course&rsquo;s presentation of it to be
a little light.  It does explain how you get free security headers, some XSS
prevention, and CSRF tokens just by including Spring Security, and in his
example he works up to a custom login form backed by a database (this time
MySQL) of users, but he stores the passwords in plain text, so his app
wouldn&rsquo;t be that useful a model to look at if I ever wanted to do this for
real.</p>
<p>The REST presentation was more thorough than it needed to be.  It seems
like every talk about REST has to go over what the different status codes
mean first thing.  Why not just link out to HTTP Status Cats website.
I want to know how he gets his JSON formatted so pretty in the browser.
I&rsquo;m sure it&rsquo;s a plugin, but it isn&rsquo;t one I already have.  Oh, he finally
mentioned what it is during the REST videos.  &ldquo;JSON Viewer&rdquo; extension for
Chrome.  Nice.  Anyway, I thought REST frameworks were easy to setup when
we were doing them the hard way (RestController annotations and services),
but it turns out you can get rid of your controllers and services and
directly expose your repo through a default build REST API if you don&rsquo;t
need a lot of custom logic.  There&rsquo;s even a built in HAL Browser for
discovery and interaction with the API, if you choose to include it.
HAL Browser dependency comes from org.springframework.data and not
org.springframework.boot.  That tripped me up for a minute in the exercises.</p>
<p>For the final series of lectures, he expects you to work along with him
starting from an initial setup.  We&rsquo;ll see if this works any better&hellip;  Nope!
He still does a lot of stuff off-screen between videos.  Anyway, the final
project is a blogging website.  It uses bootstrap to look good, thymeleaf
for the templates, spring data jpa for the database interaction, and
spring security to enforce editing only by those with admin level privileges.
I still need to read the docs on thymeleaf templates to feel like I know
much about them, since he always provides the templates and doesn&rsquo;t explain
much.  They look pretty simple.  Extra attributes to HTML tags causes you
to override content that is present in the source and do other modifications.
Like <code>&lt;span sec:authentication=&quot;name&quot;&gt;Guest&lt;/span&gt;</code> will default to Guest,
but will override that value with the name of whoever is currently
authenticated.  Judging from the upcoming titles, he&rsquo;s going to throw in
some validation, which is a topic he hasn&rsquo;t covered in the previous sections.</p>
<p>I couldn&rsquo;t get his instructions for customizing validation messages to work
at all.  I got validation working pretty good with the default error
messages at least.  He claims you just need to put your custom messages
in a messages.properties file, but I did that and they didn&rsquo;t get picked up.
I assume I have to do something to get it to look in message.properties.
Everyone on stack overflow with a related problem seems to be running WARs,
so those questions don&rsquo;t seem to apply to my setup.  I&rsquo;ll dig in the
documentation later and see what&rsquo;s going on.</p>
]]></content:encoded></item><item><title>AWDWR 5.1 - 03-05 - Theory</title><link>https://llcawthorne.github.io/posts/awdwr51-03-05-theory/</link><pubDate>Mon, 05 Jun 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/awdwr51-03-05-theory/</guid><description>&lt;p&gt;Chapters 3 through 5 focus on a little bit of theory before we get to
building the tutorial application.&lt;/p&gt;
&lt;h3 id="chapter-3---the-architecture-of-rails-applications"&gt;Chapter 3 - The Architecture of Rails Applications&lt;/h3&gt;
&lt;p&gt;Chapter 3 jumps into explaining MVC.
It&amp;rsquo;s a pretty simple concept. MVC stands for Model, View, and Controller.
The &lt;em&gt;model&lt;/em&gt; is responsible for the state of the application, often the data
you store in a database. It&amp;rsquo;s also more than data; it enforces the business
rules that apply to your data. The model is both a gatekeeper and a data
store. The &lt;em&gt;view&lt;/em&gt; is responsible for generating some type of user
interface. The view&amp;rsquo;s job is done once the data is displayed.
Multiple possible views of the same data are a common case. The
&lt;em&gt;controller&lt;/em&gt; orchestrates the application. Controllers receive events from
the outside world, interact with the model, and display the appropriate
view. The book provides a simple diagram:&lt;/p&gt;</description><content:encoded><![CDATA[<p>Chapters 3 through 5 focus on a little bit of theory before we get to
building the tutorial application.</p>
<h3 id="chapter-3---the-architecture-of-rails-applications">Chapter 3 - The Architecture of Rails Applications</h3>
<p>Chapter 3 jumps into explaining MVC.
It&rsquo;s a pretty simple concept.  MVC stands for Model, View, and Controller.
The <em>model</em> is responsible for the state of the application, often the data
you store in a database.  It&rsquo;s also more than data; it enforces the business
rules that apply to your data.  The model is both a gatekeeper and a data
store.  The <em>view</em> is responsible for generating some type of user
interface.  The view&rsquo;s job is done once the data is displayed.
Multiple possible views of the same data are a common case.  The
<em>controller</em> orchestrates the application.  Controllers receive events from
the outside world, interact with the model, and display the appropriate
view.  The book provides a simple diagram:</p>
<p><img alt="MVC" loading="lazy" src="/posts/awdwr51-03-05-theory/images/mvc-diagram.png"></p>
<p>There&rsquo;s a fine introductory article on
<a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">Wikipedia</a>
if the concept is new to you.  One of the main advantages is that each
concept or action can be expressed in a single, well-known place.  Like
many modern web frameworks, Rails is designed with MVC in mind.  Rails
first sends your request to a router, which then maps it to a method of a
controller (called an <em>action</em>), and then the action looks at data in the
request to decide how to interact with the model and ultimately it prepares
information for the view, which renders the result.</p>
<p><img alt="Rails MVC" loading="lazy" src="/posts/awdwr51-03-05-theory/images/rails-mvc.png"></p>
<p>The request contains a path (<code>/line_items?product_id=2</code>) and a method
(GET, POST, PUT, PATCH, DELETE).  By default rails takes the first part of
the path, <code>line_items</code>, as the controller name and the <code>product_id</code> as the
ID of a product, which it passes to the <code>create()</code> method of a
<code>LineItemsController</code> if we assume this is a POST request.  Different types
of request are routed to different methods of the controller.</p>
<p>Rails handles a lot of the low level details of an MVC app, so you can focus
on the core application logic.  One example of this is in its ORM (object-
relational mapping) libraries which map database tables to classes.  If you
have a class called <code>Order</code>, you know it maps to a database table called
<code>orders</code>.  The <code>Order</code> object has methods to set all the data fields in the
<code>orders</code> table.  The Rails classes also wrap our database tables with
class-level methods that perform table-level operations.  For example, you
might want to look up an <code>Order</code> by ID.  Code to do so might look like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="n">order</span> <span class="o">=</span> <span class="no">Order</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">puts</span> <span class="s2">&#34;Customer </span><span class="si">#{</span><span class="n">order</span><span class="o">.</span><span class="n">customer_id</span><span class="si">}</span><span class="s2">, amount=$</span><span class="si">#{</span><span class="n">order</span><span class="o">.</span><span class="n">amount</span><span class="si">}</span><span class="s2">&#34;</span>
</span></span></code></pre></div><p>Or you could have a class level method that searches by a where clause and
returns a collection of objects:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="no">Order</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="nb">name</span><span class="p">:</span> <span class="s1">&#39;dave&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">order</span><span class="o">|</span>
</span></span><span class="line"><span class="cl">  <span class="nb">puts</span> <span class="n">order</span><span class="o">.</span><span class="n">amount</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>In addition to accessing field values, you can set values via the object
and then save it to the database:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="no">Order</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="nb">name</span><span class="p">:</span> <span class="s1">&#39;dave&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">order</span><span class="o">|</span>
</span></span><span class="line"><span class="cl">  <span class="n">order</span><span class="o">.</span><span class="n">pay_type</span> <span class="o">=</span> <span class="s2">&#34;Purchase order&#34;</span>
</span></span><span class="line"><span class="cl">  <span class="n">order</span><span class="o">.</span><span class="n">save</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>So an ORM layer maps tables to classes, rows to objects, and columns to
attributes of those objects.  Class methods are used to perform table-level
operations, and instance methods perform operations on individual rows.
<em>Active Record</em> is the ORM layer provided by Rails.  It relies on
convention over configuration and starts with sensible defaults to minimize
manual configuration by developers.</p>
<p><em>Action Pack</em> is the part of Rails that supports the views and controllers.
At its simplest, the view is a chunk of HTML code that displays some static
content, but you normally want dynamic content generated by templates.  Rails
offers templates in three flavors:</p>
<ol>
<li>Embedded Ruby (ERB), which is the most common, embeds snippets of Ruby
within an HTML document</li>
<li>ERB used to construct JavaScript fragments on the server to execute
in the browser to form the view</li>
<li>an XML builder to construct XML documents using Ruby code.</li>
</ol>
<p>The controller acts as the logical center of an application, coordinating
interaction among the user, the views, and the model.  It&rsquo;s responsible
for routing URLs to actions, it manages caching, it manages helper modules,
and it also manages sessions.  The way Rails handles most of the interaction
behind-the scenes makes controller code easy to develop and maintain.</p>
<h3 id="chapter-4---introduction-to-ruby">Chapter 4 - Introduction to Ruby</h3>
<p>All of Chapter 4 is focused on a quick review of Ruby.  I&rsquo;d recommend
a refresher at <a href="https://learnxinyminutes.com/docs/ruby/">learnxiyminutes</a>
if your Ruby is a little rusty or checkout the
<a href="http://www.zenspider.com/ruby/quickref.html">zenspider quickref</a>.<br>
The one thing those don&rsquo;t cover that is
relevant is YAML (YAML Ain&rsquo;t Markup Language).  YAML is used to define
configuration of things in Rails.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">development</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">adapter</span><span class="p">:</span><span class="w"> </span><span class="l">sqlite3</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">database</span><span class="p">:</span><span class="w"> </span><span class="l">db/development.sqlite3</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">pool</span><span class="p">:</span><span class="w"> </span><span class="m">5</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">timeout</span><span class="p">:</span><span class="w"> </span><span class="m">5000</span><span class="w">
</span></span></span></code></pre></div><p>Indentation is import in YAML, and the above snippet defines four key-value
pairs.</p>
<h3 id="chapter-5---the-depot-application">Chapter 5 - The Depot Application</h3>
<p>Chapter 5 focuses on the design of the application that is being built in
the upcoming tutorial chapters.  We&rsquo;re going to build a basic bookstore,
based upon the <a href="https://pragprog.com/">Pragmatic Bookshelf</a> website.  It
approaches the problem from a mindset of incremental development and starts
out from basic back-of-the-napkin style sketches of functionality.  It
points out that Ruby on Rails shines for this style of development, because
it doesn&rsquo;t heavily penalize changing your mind about something
mid-development.  It also points out that we&rsquo;ll be building tests as we go.
Yay!</p>
<p>To start with, we want an outline of how the application will work at a
high level.  We identify two roles: the <em>buyer</em> and the <em>seller</em>.  The
buyer browses for products, selects some to purchase, and creates an order.
The seller uses the application to maintain a list of products to sell, to
determine order awaiting shipment, and to mark orders shipped.  Here is a
first sketch of the buyer flow:</p>
<p><img alt="buyer flow" loading="lazy" src="/posts/awdwr51-03-05-theory/images/buyer-flow.png"></p>
<p>It&rsquo;s a pretty traditional and simple flow.  There&rsquo;s also the seller flow:</p>
<p><img alt="seller flow" loading="lazy" src="/posts/awdwr51-03-05-theory/images/seller-flow.png"></p>
<p>In both cases, we&rsquo;re not overspecifying things we are unsure about, like
details of the shipping method or payment methods.  We also need to think
about what the data is going to look like:</p>
<p><img alt="data" loading="lazy" src="/posts/awdwr51-03-05-theory/images/data-model.png"></p>
<p>There&rsquo;s obviously some questions left, like what goes in cart, but this is
enough to get started, and we can figure out the other details once we&rsquo;re
in a better position of knowledge later after we&rsquo;ve started.  With these
diagrams in hand to get us started and an imaginary customer to show our
progress, we&rsquo;re ready to get started on the book&rsquo;s tutorial application.</p>
]]></content:encoded></item><item><title>Misc Reading</title><link>https://llcawthorne.github.io/posts/misc-reading/</link><pubDate>Fri, 02 Jun 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/misc-reading/</guid><description>&lt;p&gt;I&amp;rsquo;m still going back to finish my Agile Web Development with Rails 5.1
series. I finished reading the main project in the book a while back
now. I just haven&amp;rsquo;t made time with the computer to create the demo
project, and I want to have it in a repo to upload and talk about
the code a little. I didn&amp;rsquo;t read the reference chapters, since
they were still incomplete. I think I&amp;rsquo;ll read Agile Web Development
with Rails 5 on Safari Books in its entirety, and that will give me a
good perspective to see what changes with the project in the Rails 5.1
version of the book. The only thing that I noticed so far that was 5.1
specific is the ActionCable Websocket stuff they throw in, so that if a price
changes on the backend it pushes the update to customers. Pretty neat
to see Websockets used for something so small, instead of big examples
of chat servers and what not like you commonly see.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;m still going back to finish my Agile Web Development with Rails 5.1
series.  I finished reading the main project in the book a while back
now. I just haven&rsquo;t made time with the computer to create the demo
project, and I want to have it in a repo to upload and talk about
the code a little.  I didn&rsquo;t read the reference chapters, since
they were still incomplete.  I think I&rsquo;ll read Agile Web Development
with Rails 5 on Safari Books in its entirety, and that will give me a
good perspective to see what changes with the project in the Rails 5.1
version of the book.  The only thing that I noticed so far that was 5.1
specific is the ActionCable Websocket stuff they throw in, so that if a price
changes on the backend it pushes the update to customers.  Pretty neat
to see Websockets used for something so small, instead of big examples
of chat servers and what not like you commonly see.</p>
<p>I&rsquo;ve read several things since finishing Agile Web Development with Rails 5.1.
One I might dedicate multiple blogposts to: &ldquo;Practical Object-Oriented Design
in Ruby&rdquo;.  It was really good, and I highlighted large sections of the book
that are worth talking about.  Some of the stuff I had seen before in places
like &ldquo;Clean Code&rdquo; and in my Software Engineering class, but it had a lot of
good direct advice on designing things properly from an object-oriented
perspective.  The examples were in Ruby, but it didn&rsquo;t linger much on
language specifics.</p>
<p>Speaking of Ruby, I&rsquo;ve been refreshing my Ruby skills after spending
time with the Agile Web Development in Rails 5.1 book and before
delving into some other Rails books (primarily Hartl&rsquo;s
<a href="https://www.railstutorial.org/">&ldquo;Ruby on Rails Tutorial: Learn Web Development with Rails&rdquo;</a>
which I read in an old version and the new rough cut of
<a href="https://www.safaribooksonline.com/library/view/the-rails-5/9780134657691/">&ldquo;The Rails 5 Way&rdquo;</a>
).  I re-read the 10th anniversary edition of
<a href="https://pragprog.com/book/ruby4/programming-ruby-1-9-2-0">the Pickaxe</a>
, since I had a hardcopy of
it on the shelf.  That link takes you to the fourth edition, rather
than the 10th anniversary edition.  It was focused on Ruby 1.9.
Then I re-read
<a href="http://poignant.guide/">Why&rsquo;s (Poignant) Guide to Ruby</a>.
It&rsquo;s a little dated, but still relevant.  And finally
for something a little more up to date, I started reading the latest
edition of <a href="http://therubyway.io">&ldquo;The Ruby Way&rdquo;</a>.</p>
<p>I like the Pickaxe best for a fast moving
introduction to the language that is worth a couple of reads, paired with
detailed chapters on various topics relating to Ruby in its setting.
Why&rsquo;s guide is classic, and gets into some neat metaprogramming topics,
although it has a lot of charmingly weird stuff in it and not so much code.
&ldquo;The Ruby Way&rdquo; is starting to feel like a bit of a slog to make it through
reading from cover to cover.  It feels like it would be a handy desk
reference, but from a reader&rsquo;s perspective, do I really want to read
how to build a GUI using five different libraries back-to-back.  It was
good for establishing a comparison of several different ways to do GUI
stuff at least.  I think I&rsquo;ll try out Shoes.  Anyway, so now I feel
like I know Ruby again, and I&rsquo;ve been using it for
<a href="http://www.codewars.com/">Code Wars</a> to get lots of practice with
toy problems.</p>
<p>Oh, I&rsquo;ve also signed up for a MOOC that teaches Software Engineering concepts
with Rails.
<a href="https://www.edx.org/course/agile-development-using-ruby-rails-uc-berkeleyx-cs169-1x-0">Agile Development Using Ruby on Rails - Basics</a>.
I signed up for the matching advanced course too.  So, if you want more Rails
material, I have some coming up to write about at least.  I&rsquo;ll write my
opinion of the MOOC after I get a chance to watch through the videos and try
the exercises.  Between the MOOC and the other Rails books I have on my
reading list, I should get a couple of nice blogposts that have some
code blocks in them.  Now that I have syntax highlighting working, might
as well use it.  There&rsquo;s also an Infinite Skills video that I have access to
through Safari Books Online that I wouldn&rsquo;t mind trying out.
<a href="https://www.safaribooksonline.com/library/view/hands-on-with-react/9781771375061/">Hands-on with React and Ruby on Rails</a>.
I don&rsquo;t have much React experience past doing the Tic-Tac Toe tutorial, but
I can probably manage it as the video doesn&rsquo;t claim you need React experience.
Anyway, I&rsquo;ll get back to reading and watching and coding stuff now, and come
back with some blogposts that include code soon.</p>
]]></content:encoded></item><item><title>Practical Vim, 2nd Edition - Second Half</title><link>https://llcawthorne.github.io/posts/practical-vim-2/</link><pubDate>Fri, 26 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/practical-vim-2/</guid><description>&lt;p&gt;So, I promised I&amp;rsquo;d mention what goodies I find in the second half of
Practical Vim, 2nd Edition. Here they are.&lt;/p&gt;
&lt;h2 id="chapter-10-copy-and-paste"&gt;Chapter 10, Copy and Paste&lt;/h2&gt;
&lt;p&gt;First, the repetition of the insert mode &lt;code&gt;&amp;lt;C-r&amp;gt;{register}&lt;/code&gt; command later
in the book was something I found useful. I think that&amp;rsquo;s a pretty handy
way to paste the contents of a register.
I never knew that &lt;code&gt;&amp;quot;+&lt;/code&gt; let&amp;rsquo;s you access the system clipboard
either. If you put the two together, you can quickly paste from the system
clipboard without leaving insert mode with &lt;code&gt;&amp;lt;C-r&amp;gt;+&lt;/code&gt;. The fact that yank
stores a copy of what it copies in the &lt;code&gt;0&lt;/code&gt; register is pretty handy too.
Nice to have an alternate way to access the last yank if I&amp;rsquo;ve clobbered it.&lt;/p&gt;</description><content:encoded><![CDATA[<p>So, I promised I&rsquo;d mention what goodies I find in the second half of
Practical Vim, 2nd Edition.  Here they are.</p>
<h2 id="chapter-10-copy-and-paste">Chapter 10, Copy and Paste</h2>
<p>First, the repetition of the insert mode <code>&lt;C-r&gt;{register}</code> command later
in the book was something I found useful.  I think that&rsquo;s a pretty handy
way to paste the contents of a register.
I never knew that <code>&quot;+</code> let&rsquo;s you access the system clipboard
either.  If you put the two together, you can quickly paste from the system
clipboard without leaving insert mode with <code>&lt;C-r&gt;+</code>.  The fact that yank
stores a copy of what it copies in the <code>0</code> register is pretty handy too.
Nice to have an alternate way to access the last yank if I&rsquo;ve clobbered it.</p>
<h2 id="chapter-11-macros">Chapter 11, Macros</h2>
<p>Most of the macros chapter was fairly new to me.  I knew the basics of how to
record and playback macros, and have used them before when in native vim and
not using an emulator.  But I&rsquo;ve never given macros intense thought or tried
to be terribly clever with them.  He goes into the idea of crafting resilient
reusable macros in some depth in the tips focused on them and covers a handful
of macro best practices.  As he puts it, &ldquo;The golden rule is this: when
recording a macro, ensure that every command is repeatable.&rdquo;</p>
<p>The author sums up macro advice with the phrase &ldquo;Normalize, Strike, Abort&rdquo;
The first question to ask when crafting a macro is, &ldquo;where am I, where
have I come
from, and where am I going.&rdquo;  Make sure the cursor is positioned so the
next command does as expected where expected.  You shouldn&rsquo;t use the
mouse when recording a macro, so make sure to take advantage of the full
range of available motion commands to maneuver to the right location to
strike.  If a motion fails while a macro is executing, Vim will abort the
rest of the macro.  This is a feature!  You don&rsquo;t want to execute your
command when you aren&rsquo;t in the right location.  Motions can act as a simple
test as to whether or not the macro should be executed.  Remember that
search is a motion too.  You can do a lot with a macro that uses the <code>n</code>
key to go to the next search item and perform an action.  Once no matches
remain, <code>n</code> will fail and the macro will stop.</p>
<p>Tip 67 points out how a simple two key macro can be useful to move and perform
the dot command multiple times.  You can&rsquo;t repeat with dot, and if you could
the number would either repeat the move multiple times or repeat the dot
multiple times in the same place, so a simple macro of a movement command
and dot is a clever trick tie a move and repeat together and replay it
multiple times.  Again, you can count on the motion failing at the end if
you choose the right motion, so you don&rsquo;t have to worry about the exact
count.  The example is as follows:</p>
<blockquote>
<p>{start}
x = &ldquo;(&quot;+a+&rdquo;,&quot;+b+&quot;,&quot;+c+&quot;,&quot;+d+&quot;,&quot;+e+&quot;)&quot;;</p>
</blockquote>
<p>And we want to change it to:</p>
<blockquote>
<p>{goal}
x = &ldquo;(&rdquo; + a + &ldquo;,&rdquo; + b + &ldquo;,&rdquo; + c + &ldquo;,&rdquo; + d + &ldquo;,&rdquo; + e + &ldquo;)&rdquo;;</p>
</blockquote>
<p>And it can be achieved with the following keystrokes:</p>
<ol>
<li><code>f+</code></li>
<li><code>s + &lt;Esc&gt;</code></li>
<li><code>qq;.q</code></li>
<li><code>22@q</code></li>
</ol>
<p>That&rsquo;s much simpler than adding the spaces around the + marks by hand.
Since the <code>f+</code> movement will fail after we are out of +&rsquo;s, it is safe
to run the macro 22 times.  The author admits to being lazy like this
often.  22 is his go to repeat number, since 2 is the same key as
@ to run the macro.  That&rsquo;s a great example of making use of &ldquo;Abort&rdquo;.</p>
<p>Appending keystrokes to macros works just like appending yanks to registers.
<code>qA</code> will append commands on the end of the macro in register a.  That&rsquo;s a
small but handy tip for getting more from macros.  The next tip covers how
to apply a macro to a series of files, either with <code>:argdo normal @a</code> or by
manually advancing with <code>:next</code> to act across the argument list.  The example
he uses is a pretty handy one of wrapping several classes in a module
declaration and adding proper indentation.  The next tip seems handy, but I
doubt it&rsquo;s general enough use for me to remember it.  It covers how to prepend
an incrementing line count to multiple lines.  The final tip of the chapter
covers the fact that you can put a macro from a register, then edit the
macro text, then yank the macro back to the register.  An interesting option
for editing macros!  One note is to be careful to use a character-wise
yank like <code>&quot;ay$&quot;</code>, or else you might get an extra <code>&lt;CR&gt;</code> at the end of
your macro.</p>
<h2 id="chapter-12---matching-patterns-and-literals">Chapter 12 - Matching Patterns and Literals</h2>
<p>First off, I learned the handy tidbit that using <code>\c</code> in a search pattern
causes it to ignore case, and <code>\C</code> to be case sensitive, regardless of
<code>ignorecase</code> settings.  You can put them anywhere in the pattern, including
just tacking them on the end.  I like the default <code>smartcase</code> where if you
include an uppercase letter it is case sensitive, otherwise not.</p>
<p>The <code>\v</code> switch anywhere in a regex makes it &ldquo;very magic&rdquo;, or more like what
you might be used to from Perl, Python, or Ruby.  It makes all characters
assume a special meaning except for &ldquo;_&rdquo;, letters, and numbers,
so you don&rsquo;t need to escape all your braces,
brackets, and parentheses.  It makes the difference between
<code>#\([0-9a-fA-F]\{6}\|[0-9a-fA-F]\{3}\)</code> and
<code>\v#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})</code> to match CSS color codes, a regex
that can be made slightly even better using the <code>\x</code> hex class as
<code>\v#(\x{6}|\x{3})</code>.  The <code>\V</code> or <code>verynomagic</code> option makes a search
only search by the literal meaning of symbols provided, even <code>.</code>, <code>*</code>,
and <code>?</code>.  Only the <code>\</code> character has special meaning in a <code>verynomagic</code>
search.  So ultimately, both the <code>\v</code> and <code>\V</code> search options are
terribly useful and worth remembering.  A good example of the <code>\V</code> option
is searching for &ldquo;a.k.a.&rdquo; with <code>/\Va.k.a.</code> instead of <code>/a\.k\.a\.</code>
I think the argument has won me over well enough to use <code>\v</code> most of
the time and <code>\V</code> on special occasions.</p>
<p>Another handy fact for regular expressions is that in <code>verymagic</code> search
mode, the <code>&lt;</code> and <code>&gt;</code> keys match word boundaries.  So a search for
<code>\v&lt;the&gt;</code> will find all the &ldquo;the&rdquo; occurrences without any &ldquo;their&rdquo; or
&ldquo;these&rdquo; being matched.  It goes on to cover some ways to handle search
field terminators in the final tip of the chapter.</p>
<h2 id="chapter-13---searching-14---substitution-15---global-commands">Chapter 13 - Searching, 14 - Substitution, 15 - Global Commands</h2>
<p>I didn&rsquo;t find anything in these two chapters particularly worthwhile, except
the fact that you can leave the search part of a substitute command blank
to use whatever the last successful search was as the pattern.  That
decouples finding the right search pattern from the overall substitute
command, and you normally want to search first anyway to make sure you
got your pattern right before making changes.   The search and replace
across a project tip was possibly useful.  Everything about the global
command was new to me and worth playing with.</p>
<h2 id="chapter-16---index-and-navigate-source-code-with-ctags">Chapter 16 - Index and Navigate Source Code with ctags</h2>
<p>This  whole chapter is about ctags and was all new to me.  It looks like an
excellent way to get the ability to jump to definitions in vim.  Apparently
I&rsquo;ve been living under a rock, since I was unaware of this feature.  This
looks like a key step into making Vim into a development environment instead
of just an editor.</p>
<h2 id="chapter-17---compile-code-and-navigate-errors-with-the-quickfix-list">Chapter 17 - Compile Code and Navigate Errors with the Quickfix List</h2>
<p>The quickfix and location lists seem handy, assuming you map navigating them
to something more convenient than typing <code>:cnext</code> and <code>:cprev</code>.  I&rsquo;ll have
to checkout the unimpaired plugin he mentions that makes the quicklist
navigable by <code>[q</code> and <code>]q</code>.  It has a number of other handy mappings, so it&rsquo;s
worth checking out instead of just putting the one set of mappings in my
vimrc.  I think I&rsquo;ll use the Tip 108 that has you make <code>:make</code> run JSLint
and populate the quickfix list with any linting errors.  I didn&rsquo;t fully
understand how to do it from the tip, but this github project looks useful:
<a href="https://github.com/bigfish/vim-nodelint">vim-nodelist</a>.</p>
<h2 id="chapter-18---search-project-wide-with-grep-vimgrep-and-others">Chapter 18 - Search Project-Wide with grep, vimgrep, and Others</h2>
<p>There&rsquo;s so many neat random things in this book.  Today I learned that there&rsquo;s
a version of grep optimized for programmers called ack.
<a href="https://beyondgrep.com/">Ack</a>.  To relate it back to vim, the book explains
how to make the vim <code>:grep</code> command use ack instead, but then tells you not
to, since there is an ack plugin for vim
<a href="https://github.com/mileszs/ack.vim">ack.vim</a>
that will use it with the <code>:ack</code> command.</p>
<h2 id="chapter-19---dial-x-for-autocompletion">Chapter 19 - Dial X for Autocompletion</h2>
<p>There&rsquo;s plugins for better autocompletion than what&rsquo;s built in.  It looks like
you can complete based off ctags with <code>&lt;C-x&gt;&lt;C-]&gt;</code> or use
<code>&lt;C-x&gt;&lt;C-i&gt;</code> to complete based off your imports in various languages.
Generic autocompletion is based off <code>&lt;C-n&gt;</code> and is probably best of the
built-ins.  You use <code>&lt;C-n&gt;</code> and <code>&lt;C-p</code> to choose next  or previous.</p>
<h2 id="chapter-20---find-and-fix-typos-with-vims-spell-checker">Chapter 20 - Find and Fix Typos with Vim&rsquo;s Spell Checker</h2>
<p>This one starts out simple, with how to use the built in spell checker.  First
think I learned is that <code>z=</code> on a misspelled word will bring up suggestions
and <code>[s</code> and <code>]s</code> let you jump between misspelled words.  I was able to try
those out successfully while writing this blog post.  <code>zg</code> adds a word to the
spell file, which worked great to add &ldquo;blog&rdquo;.  Apparently, you can fix
misspelled words without leaving Insert mode with <code>&lt;C-x&gt;s</code> to
enable autocomplete misspelled mode.  It will jump you back to the last
misspelled word and offer suggestions from the dictionary.  Pretty handy!</p>
<h2 id="summary">Summary</h2>
<p>Overall, I think I picked up more tips than I can reasonably integrate into
my workflow at once from my first reading of Practical Vim, Second Edition.
That&rsquo;s why I put a lot of them here on my blog, to remind me to try them
out.  I believe there&rsquo;s still enough that I didn&rsquo;t mention to make the book
worth another read, or at least a re-read several spots in it.  I highly
recommend it if you are already comfortable using Vim and want to pickup
tricks to take your Vim workflow to the next level.</p>
]]></content:encoded></item><item><title>Practical Vim, 2nd Edition - First Half</title><link>https://llcawthorne.github.io/posts/practical-vim-1/</link><pubDate>Mon, 22 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/practical-vim-1/</guid><description>&lt;p&gt;Practical Vim is an excellent resource for tips and trick for using vim.
It focuses on core vim features, and doesn&amp;rsquo;t spend any room talking about
plugins. Aside from a few hints to how .vimrc settings might affect certain
commands, it doesn&amp;rsquo;t spend any time telling you what to put in your .vimrc.
It does have an appendix about vimrc settings, in case you need some new ones.
The book is laid out as a series of 123 mostly standalone tips, although
they do follow a procession of least to most difficult within their
respective section. The tips are split between 20 sections. The book
doesn&amp;rsquo;t attempt to go into Vimscript. Overall, I found it a useful collection
of mostly non-obvious tips for using vim, and I feel like it has made me
more capable in using my editor of choice.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Practical Vim is an excellent resource for tips and trick for using vim.
It focuses on core vim features, and doesn&rsquo;t spend any room talking about
plugins.  Aside from a few hints to how .vimrc settings might affect certain
commands, it doesn&rsquo;t spend any time telling you what to put in your .vimrc.
It does have an appendix about vimrc settings, in case you need some new ones.
The book is laid out as a series of 123 mostly standalone tips, although
they do follow a procession of least to most difficult within their
respective section.  The tips are split between 20 sections.  The book
doesn&rsquo;t attempt to go into Vimscript.  Overall, I found it a useful collection
of mostly non-obvious tips for using vim, and I feel like it has made me
more capable in using my editor of choice.</p>
<p>The author recommends skipping around rather than reading the book from
beginning to end, however, I still found the book quite readable.  The
tips vary in difficulty from very basic (Ex: Tip 47 is &ldquo;Keep Your Fingers
on the Home Row&rdquo; and covers h, j, k, and l) to fairly advanced (Ex:
Edit the Contents of a Macro).  I really enjoy the way the author doesn&rsquo;t
repeat any content readily available in the manual.  In the electronic copy,
he links any manual references to a website with the vim manual.  For people
reading along, he provides the proper keyword to use with :h in order to
lookup the topic via vim help.  This allows him to not spend a lot of time
on prerequisite info and get directly to useful tips.</p>
<p>Some tidbits that I&rsquo;ve found useful so far are the keystrokes that he mentions
being available in Insert mode.  I never paid attention to the fact that you
can use &lt;C-w&gt; to delete back one word without leaving insert mode,
&lt;C-r&gt;{register} to quickly paste the contents of a register, and
&lt;C-v&gt;u{1234} to insert unicode character #1234, all without leaving insert
mode.  In both the previous examples, the selection in curly brackets is
replaced with just a register or just a four digit number, the curly brackets
are not typed literally.
I generally like hitting my keys one at a time while in vim, but
those are a couple of useful chords to use in insert mode.  I&rsquo;m not sure
I&rsquo;ll use the unicode one often enough to remember it, but the other two
are pretty easy to remember and of general use.  There is no tip like
&ldquo;Here are some keystrokes for Insert mode.&rdquo; but the author instead worked
providing these keystrokes into the explanation of how to do something.
The &lt;C-r&gt;{register} keystroke was provided in the &ldquo;Paste from a Register
Without Leaving Insert Mode&rdquo; tip which focused on it and &lt;C-v&gt;u{1234}
was from the &ldquo;Insert Unusual Characters by Character Code&rdquo; tip, but
the &lt;C-w&gt; keystroke was provided in the more general &ldquo;Make Corrections
Instantly from Insert Mode&rdquo; tip.</p>
<p>I learned a lot that I didn&rsquo;t know before in the section on Command-Line Mode.
As the author puts it, &ldquo;Ex commands strike far and wide.&rdquo;  I was unaware of
how the range worked with ex commands and of the variety of ex commands
available.  There are commands to delete, yank, put, copy, move, join,
normal (execute Normal mode commands on a specified or range of lines),
substitute, and global (execute and ex command where a pattern matches).
I&rsquo;ve used substitute a decent bit, but never remember knowing about the
others and how you can make them all work flexibly with a range without
having to move the cursor there first.  It&rsquo;s especially convenient that
you can use V to switch into visual line mode and select some lines, then
it will prepopulate the range of lines into your : for executing an ex
command.  You can also use % to target the whole file with a command,
which is how I&rsquo;m accustomed to working with substitute.  As an example,
<code>:%normal A;</code> will append a semicolon to every line in a file or
<code>%normal i//</code> will comment out every line in a file given a language
where <code>//</code> starts comments.  You can even write a script of ex commands
and load it into vim with <code>:source {filename}</code>.</p>
<p>I also learned that in you can use <code>:edit %:h</code> to load the working directory
of the currently active buffer as a parameter to edit, and then tab complete
it to the name of another file in the same directory.  The book recommends
you alias <code>%%</code> to <code>%:h</code> since this is so handy.  That remap made it into my
vimrc.  You can even open a file in a nonexistant directory and then use
<code>:!mkdir -p %:h</code> to create the directory so you can save the file.</p>
<p>The only obvious problem I had with some of the content is that some of it
(like the ex commands) is too vim specific to work with vim emulators.
Anymore, I spend a lot more time using IdeaVIM in IntelliJ than I clock with
real vim, but that&rsquo;s largely a personal problem.  The author doesn&rsquo;t avoid
forward references, which is only a problem if you&rsquo;re trying to read the
book through rather than skip around as recommended.  Also, the author
sometimes punts further explanation to
<a href="http://www.vimcasts.org/">VimCasts</a>.  VimCasts is an excellent resource,
and the author of this book is the man behind the site, but I like having
explanations in the book I bought rather than having to look to outside
video for them.  In his defense, he only does it for some of the more
graphical tasks like splitting windows and such.  Also, around midway
through the book when it gets to motion keys, it feels like backtracking
to such simple topics to have a Tip 47 that covers h, j, k, and l keys
and keeping your hands on home row.  This leads to a number of other
rather simplistic motion tips that are not new to anyone that&rsquo;s used
vim very long.  Fortunately these are all kept to one chapter, Chapter 8.
The fact that these complaints are all pretty nitpicky goes to show
that overall, I didn&rsquo;t find many problems with this book.</p>
<p>In general, I especially enjoy how the author explains his thinking behind
the use of
certain commands.  He&rsquo;ll sometimes show how to do something in multiple
ways that use the same number of keystrokes, and then explain why one way
better fits the general vim mindset (which often means its better for
re-use via the . command).  He does a lot of this early on in the book,
but the tips later in the book he tends to show the one way to perform
an operation.</p>
<p>I&rsquo;m only halfway through the book now, but this post is getting long
enough.  I&rsquo;ll go ahead and post what I&rsquo;ve written about the first half
of the book, and add another post later if I find some awesome tips
worth mentioning in the latter half of this book.</p>
<p><a href="http://llcawthorne.github.io/blog/2017/05/22/practical-vim-2">Second Half</a></p>
]]></content:encoded></item><item><title>Command Line Power User</title><link>https://llcawthorne.github.io/posts/command-line-power-user/</link><pubDate>Fri, 19 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/command-line-power-user/</guid><description>&lt;p&gt;Well, I promised I would review
&lt;a href="http://www.commandlinepoweruser.com/"&gt;Command Line Power User&lt;/a&gt;
the other day when I did the
&lt;a href="http://www.masteringmarkdown.com/"&gt;Mastering Markdown&lt;/a&gt; video, so here it
is. This is probably a better video series to give me an opinion of his
teaching skills, since it isn&amp;rsquo;t something I know entirely and is actually
a little over an hour of video. Each video is longer also, so it probably
won&amp;rsquo;t annoy me so much when the video player scrolls down to where I can&amp;rsquo;t
see the video after switching files.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Well, I promised I would review
<a href="http://www.commandlinepoweruser.com/">Command Line Power User</a>
the other day when I did the
<a href="http://www.masteringmarkdown.com/">Mastering Markdown</a> video, so here it
is.  This is probably a better video series to give me an opinion of his
teaching skills, since it isn&rsquo;t something I know entirely and is actually
a little over an hour of video.  Each video is longer also, so it probably
won&rsquo;t annoy me so much when the video player scrolls down to where I can&rsquo;t
see the video after switching files.</p>
<p>The first video is seven minutes of basics that are really basic.  He advised
it was skippable, and I should have taken his advice.  He recommends
installing iTerm 2 in OS X, which is what I use already on my Macbook.  He
recommends cygwin for Windows, but I tend to prefer
<a href="http://babun.github.io/">babun</a> on Windows.  I&rsquo;m watching these on the
Macbook anyway.  He recommends installing zshell and oh-my-zsh, which I
already use and enjoy.  So we&rsquo;re about to where I learn some stuff.</p>
<p>The fifth video is about colors.  It has some annoying flicking going on.
Fortunately that went away.  I was wrong about when I would learn something.
He&rsquo;s just focusing on how to edit your zshrc in video six.  Ooo, in video
seven I learned you can CMD+click links in terminal to open them in browser;
that&rsquo;s new.  Being able to use <code>take</code> to make a directory and create it at
the same time is new to me also.  Next video is covering command history,
which is a pretty standard zshell feature.  At least it&rsquo;s short.</p>
<p>Video nine is about zsh plugins.  I never remember to use my plugins often
enough, but I have a lot enabled.  I didn&rsquo;t like most of the plugins he
showed off, but it&rsquo;s useful to get people thinking about looking at the
plugins to find something they&rsquo;ll find useful.  It reminds me to lookup
commands of some of the ones I have installed.  Video ten is about <code>z</code>,
which is unrelated to zshell and completely new to me.  It&rsquo;s pretty cool.
It tracks frequently and recently used directories and lets you switch to
them via <code>z regex</code> where regex is a partial match for the directory name.
It will switch across multiple directories with the one command easily.
I see from the video that I could&rsquo;ve installed it via homebrew rather than
by hand, but it&rsquo;s already installed manually now.  It has some handy options
that are covered in the manpage.  The final tip is about <code>trash</code>, which
is like rm, but it puts what is deleted in your Trash.  I think I&rsquo;m
accustomed enough to rm not to worry about that, but those might be words
I regret someday.</p>
<p>Overall, I think there was a lot of useful stuff if you aren&rsquo;t already
familiar with zshell and oh-my-zsh.  It was a little long for the little
bit that I got out of it, but I picked up a couple of useful tips.
Overall, his teaching style is reasonable.  I didn&rsquo;t feel like falling
asleep during either of his videos, and he doesn&rsquo;t come off like he&rsquo;s
just directly reading from notes or anything.  I might try the
<a href="https://javascript30.com/">JavaScript 30 series</a> when I&rsquo;m in the mood to
code some JS, since it&rsquo;s free also.  It should be a bit more substantial.
Hopefully it doesn&rsquo;t start out as slow.</p>
]]></content:encoded></item><item><title>AWDWR 5.1 - 02 - Instant Gratification</title><link>https://llcawthorne.github.io/posts/awdwr51-02-instant-gratification/</link><pubDate>Thu, 18 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/awdwr51-02-instant-gratification/</guid><description>&lt;p&gt;First I&amp;rsquo;d like to say sorry the images are a little big. Not used to
screencaps on this retina Macbook.&lt;/p&gt;
&lt;p&gt;So, I fixed my mistake from last time. I had originally installed ruby via
homebrew, but now that I&amp;rsquo;ve read up on rbenv, it seems a lot nicer than the
old rvm, and I might want multiple versions of Ruby on my home PC. So I
uninstalled Ruby 2.4 and went with &lt;code&gt;brew install rbenv&lt;/code&gt; and then used
it to install the latest Ruby. I see why the book authors prefer it over
RVM now. It&amp;rsquo;s a lot less invasive than the old RVM.&lt;/p&gt;</description><content:encoded><![CDATA[<p>First I&rsquo;d like to say sorry the images are a little big.  Not used to
screencaps on this retina Macbook.</p>
<p>So, I fixed my mistake from last time.  I had originally installed ruby via
homebrew, but now that I&rsquo;ve read up on rbenv, it seems a lot nicer than the
old rvm, and I might want multiple versions of Ruby on my home PC.  So I
uninstalled Ruby 2.4 and went with <code>brew install rbenv</code> and then used
it to install the latest Ruby.  I see why the book authors prefer it over
RVM now.  It&rsquo;s a lot less invasive than the old RVM.</p>
<p>Anyway, on with Chapter 2, &ldquo;Instant Gratification&rdquo;.  I went ahead and
completed the code for this chapter and the exercises.  Both were fairly
trivial.  I checked it in at <a href="http://github.com/llcawthorne/demo51">demo51</a>.
If you clone that and run <code>bin/rails server</code> from the directory, you&rsquo;re
greeted by the site at http://localhost:3000/.  You get a lot for very
little with Rails.  The site you get just from running <code>rails new demo51</code>
looks like this:</p>
<p><img alt="rails welcome" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/rails.png"></p>
<p>It also looks like the default server has changed from WEBrick to Puma now.
But a page with a picture isn&rsquo;t all that impressive.  I must say that I
find it pleasant how fast the server starts.  I&rsquo;ve become used to my
Java EE servers with multiple minute startup times before you can see
changes, but not only does this server start fast, it loads changes on the
fly when in development mode, so you seldom have to restart it.  What is
also impressive is how easy it is to modify with a new route.  What is
slightly intimidating is that the rails new command actually generated
forty-six files spread across thirty-four directories.  The nice thing is
that everything is in its proper place, and hopefully by reading this book
and working with the applications a bit more we&rsquo;ll come to understand the
logic behind it.</p>
<p>The whole application in this chapter is a Hello World modified with a
timestamp to show something dynamic.  To do this, we need to generate a
new controller.  Going to the directory of our app and running
<code>bin/rails generate controller Say hello goodbye</code> will generate a
controller named Say with methods (in Rails terms, these controller
methods are called actions) hello and goodbye that will respond
to requests to <code>/say/hello</code> and <code>/say/goodbye</code>.  It puts the say controller
in <code>demo51/app/controllers/say_controller.rb</code>.  This is the controller
that contains methods for all the <code>/say/</code> routes.  Its starting code
that was generated is simply:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">SayController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span>
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">hello</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">goodbye</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>Those methods obviously don&rsquo;t do much.  Because it inherits from
<code>ApplicationController</code>, our <code>SayController</code> automatically gets all the
default controller behavior.  Even though the controller methods don&rsquo;t
have any logic, they still return a site when you navigate to the URL,
because by convention they are associated with certain views.</p>
<p><img alt="Say#hello" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/say-hello.png"></p>
<p>The route informs of the file it is currently serving
<code>app/views/say/hello.html.erb</code>, which was also automatically generated
when we created our controller with the command above.  If we edit the file
it points us to, we find what looks like a normal html file body:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erb" data-lang="erb"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Say#hello<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Find me in app/views/say/hello.html.erb<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span></code></pre></div><p>This is the view that was generated by our command.  The views for the
<code>SayController</code> we created by default are placed in the <code>app/views/say</code>
directory, and there is a view for each of the hello and goodbye methods.
The book has us change this view to instead say:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erb" data-lang="erb"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Hello from Rails!<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
</span></span></code></pre></div><p>If we refresh our browser window (without restarting the server), we see
the new output:</p>
<p><img alt="Hello from Rails" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/hello.png"></p>
<p>So far, we&rsquo;ve learned the place two things go.  Controllers go in
<code>app/controllers</code> and views go in <code>app/views</code>.  The book shows it with
the diagram:</p>
<p><img alt="directory structure" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/diagram.png"></p>
<p>The book goes on to add the time display to the page directly, then refactor
it to have the time generated by the controller and displayed in the view.
We&rsquo;ll just skip to that.  We modify say_controller.rb to generate the time:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">SayController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span>
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">hello</span>
</span></span><span class="line"><span class="cl">    <span class="vi">@time</span> <span class="o">=</span> <span class="no">Time</span><span class="o">.</span><span class="n">now</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="k">def</span> <span class="nf">goodbye</span>
</span></span><span class="line"><span class="cl">  <span class="k">end</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>and modify the view to display the variable set for it by the controller:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erb" data-lang="erb"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Hello from Rails!<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  It is now <span class="cp">&lt;%=</span> <span class="vi">@time</span> <span class="cp">%&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span></code></pre></div><p>The time is <em>data</em>, so it is supplied to the view by the controller.  The
book forewarns us we&rsquo;ll see a lot more of this once we introduce models.
It goes on to explain the step-by-step process of what the server goes
through when responding to a request, at a very high level.  We then
customize our goodbye page, but you can checkout the git repo if you want
to see that or the results of completing either of the chapter&rsquo;s two
exercises.  The one remaining item of interest it does in the app is add a
link from the Hello page to the Goodbye page and vice versa.  It does
this using built in helper methods rather than hardcoding URL&rsquo;s.  The new
hello.html.erb looks like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erb" data-lang="erb"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Hello from Rails!<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  It is now <span class="cp">&lt;%=</span> <span class="vi">@time</span> <span class="cp">%&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">  Time to say
</span></span><span class="line"><span class="cl">  <span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s2">&#34;Goodbye&#34;</span><span class="p">,</span> <span class="n">say_goodbye_path</span> <span class="cp">%&gt;</span>!
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span></code></pre></div><p>The first parameter in the call to <code>link_to()</code> is the text to be displayed
in the hyperlink, and the next parameter tells Rails to generate the link
to the goodbye action of the say controller.</p>
<p>Finally in this chapter, they display what happens when things break.  As
the authors put it &ldquo;the true test of the developer friendliness of a
framework is how it responds when things go wrong.&rdquo;  First, they ask
what would happen if we misspelled Time.now as Time.know in our controller.
Rails not only tells you the exact spot of the error, it also asks if you
meant to type &ldquo;now&rdquo; and offers an interactive debugging console:</p>
<p><img alt="rails error page" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/rails_know_error.png"></p>
<p>And before you start worrying, the web console is only shown if you&rsquo;re on the
same machine as the web server and running in development mode, so there
shouldn&rsquo;t be any chance of anyone getting into it in production unless
you specifically whitelist more ips and run the server in development mode.
Likewise, if you attempt to go to <code>http://localhost:3000/say/h3llo</code> instead
of <code>/say/hello</code>, you get:</p>
<p><img alt="rails error page" loading="lazy" src="/posts/awdwr51-02-instant-gratification/images/rails_h3llo_error.png"></p>
<p>It gives you a list of possible routes along with what controller and action
they are associated with and a helpful search box to trim it down.</p>
<p>Altogether, the app presented here is totally trivial, but in this chapter
they did manage to cover:</p>
<ul>
<li>How to create a new Rails application and how to create a new controller
in that application</li>
<li>How to create dynamic content in the controller and display it via the view</li>
<li>How to link pages together</li>
<li>How to debug problems in code or the URL</li>
</ul>
<p>Looks like the next chapter covers a bit of MVC theory, and chapter 4 is a
Rails review.  I&rsquo;ll probably comment on both in one quick post.  Then in
Chapter 5, we dig into building a bigger application.</p>
]]></content:encoded></item><item><title>Mastering Markdown</title><link>https://llcawthorne.github.io/posts/mastering-markdown/</link><pubDate>Wed, 17 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/mastering-markdown/</guid><description>&lt;p&gt;Well, for something a little different, I decided to write my opinion of a
free video course. Since I&amp;rsquo;m writing my blog in markdown, I figured why
not review it with something other than the Kramdown cheatsheet.
&lt;a href="http://wesbos.com/"&gt;Wes Bos&lt;/a&gt;
has a number of video courses, some free and some paid for. His
&lt;a href="https://masteringmarkdown.com/"&gt;Mastering Markdown&lt;/a&gt; course is one of the free
ones. It&amp;rsquo;s really only a single 23 minute video, so not much of a course, but
since he just came out with a Learn Node course and has another longer free
course of Javascript projects, I figured why not try the little course to get
a feel for his teaching style and see if I want to invest any more time
and/or money in more of
his courses later. His other free courses if you&amp;rsquo;re interested include
&lt;a href="https://commandlinepoweruser.com/"&gt;Command Line Power User&lt;/a&gt; which has some
Z shell tips that I might check out, since I&amp;rsquo;m sure I&amp;rsquo;m not making the most
of it, and &lt;a href="https://javascript30.com/"&gt;JavaScript 30&lt;/a&gt;
which is 30 days of building
30 things in vanilla JS (which promises no frameworks, no compilers, no
libraries, and no boilerplate). Unless this one is terribly, I&amp;rsquo;ll probably
sit through the command line one after this. The JavaScript 30 one I&amp;rsquo;ll
only invest time in if I like these two. Well, without further ado, here&amp;rsquo;s
my opinion of &lt;a href="https://masteringmarkdown.com/"&gt;Mastering Markdown&lt;/a&gt;.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Well, for something a little different, I decided to write my opinion of a
free video course.  Since I&rsquo;m writing my blog in markdown, I figured why
not review it with something other than the Kramdown cheatsheet.
<a href="http://wesbos.com/">Wes Bos</a>
has a number of video courses, some free and some paid for.  His
<a href="https://masteringmarkdown.com/">Mastering Markdown</a> course is one of the free
ones.  It&rsquo;s really only a single 23 minute video, so not much of a course, but
since he just came out with a Learn Node course and has another longer free
course of Javascript projects, I figured why not try the little course to get
a feel for his teaching style and see if I want to invest any more time
and/or money in more of
his courses later.  His other free courses if you&rsquo;re interested include
<a href="https://commandlinepoweruser.com/">Command Line Power User</a> which has some
Z shell tips that I might check out, since I&rsquo;m sure I&rsquo;m not making the most
of it, and <a href="https://javascript30.com/">JavaScript 30</a>
which is 30 days of building
30 things in vanilla JS (which promises no frameworks, no compilers, no
libraries, and no boilerplate).  Unless this one is terribly, I&rsquo;ll probably
sit through the command line one after this.  The JavaScript 30 one I&rsquo;ll
only invest time in if I like these two.  Well, without further ado, here&rsquo;s
my opinion of <a href="https://masteringmarkdown.com/">Mastering Markdown</a>.</p>
<p>Good to see that he isn&rsquo;t opinionated about editors.  He says use whatever
editor you&rsquo;re most comfortable with, even vim.  He uses Sublime Text though
and recommends a package for it, if you use it.  I went ahead and installed
it in my copy of Sublime Text.  It&rsquo;s called MarkdownEditing and has a lot
more features than the built in Sublime Markdown package.  I spent almost
as much time reading the Package Control Messages as the runtime of these
videos, but oh well, sometimes I open stuff up in Sublime, so I might as
well get it working alright.  I took this chance to toggle some settings
in vim-markdown while I was thinking about it.</p>
<p>It&rsquo;s a little annoying that his video player jumps down to the video list
when it advances videos.  Each one, I have to scroll back up after it
advances to see the video again.  Probably wouldn&rsquo;t be so bad on my big
monitor instead of the laptop screen.  It&rsquo;s made even more annoying by how
short the videos are. Video quality is good, and it is nice that it saves
the fact that I&rsquo;ve set the speed up to 1.25 when it switches videos.  I
learned something about footnote links that I had forgotten, and a cool
feature that lets you highlight a code block as a diff, so it wasn&rsquo;t
time wasted.  He talks a little fast anyway, so I probably wouldn&rsquo;t need
the speed increase for something that I didn&rsquo;t already know.</p>
<p>Overall, I thought the video was OK.  I&rsquo;ll try the
<a href="http://commandlinepoweruser/">Command Line Power User</a> course too and see
what I think of it.  Currently I just use zshell with oh-my-zsh and a
couple of plugins enabled, so maybe I can learn some more zshell tricks.</p>
]]></content:encoded></item><item><title>AWDWR 5.1 - 01 - Introduction</title><link>https://llcawthorne.github.io/posts/awdwr51-01-introduction/</link><pubDate>Tue, 16 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/awdwr51-01-introduction/</guid><description>&lt;p&gt;So, what do I have to blog about? I&amp;rsquo;m always trying out new stuff and reading
books, so I figure I&amp;rsquo;ll talk about that. I happen to have just gotten a
beta copy of
&lt;a href="https://pragprog.com/book/rails51/agile-web-development-with-rails-5-1"&gt;Agile Web Development with Rails 5.1&lt;/a&gt;
and since my Ruby and Rails
experience from my résumé is a little rusty, I figure I&amp;rsquo;ll
read that and blog about the experience. Starting this site using Jekyll
has made me think about Ruby lately anyway. It&amp;rsquo;s been many years since I&amp;rsquo;ve
read &amp;ldquo;Agile Web Development with Rails&amp;rdquo;, and I think it was the version that
covered Rails 1.2, so this should be a pretty new experience for me; both a
great refresher and an introduction to what is new in the Rails world these
days.&lt;/p&gt;</description><content:encoded><![CDATA[<p>So, what do I have to blog about?  I&rsquo;m always trying out new stuff and reading
books, so I figure I&rsquo;ll talk about that.  I happen to have just gotten a
beta copy of
<a href="https://pragprog.com/book/rails51/agile-web-development-with-rails-5-1">Agile Web Development with Rails 5.1</a>
and since my Ruby and Rails
experience from my résumé is a little rusty, I figure I&rsquo;ll
read that and blog about the experience.  Starting this site using Jekyll
has made me think about Ruby lately anyway.  It&rsquo;s been many years since I&rsquo;ve
read &ldquo;Agile Web Development with Rails&rdquo;, and I think it was the version that
covered Rails 1.2, so this should be a pretty new experience for me; both a
great refresher and an introduction to what is new in the Rails world these
days.</p>
<p>The obvious question is why rails when I could play with the hot new
Javascript framework.  Well, I&rsquo;ve played with React some, along with Ember,
and Angular.  I might go back to messing with them and blog about the
results later.  Right now, I&rsquo;m just in a Ruby/Rails mood.  I&rsquo;ve always liked
how the Ruby community seems to emphasize good programming practices that
carry over to any language you work in, and I recall the Agile Web Development
book being a good source of sound programming advice.  As a side note, I
understand that the book now includes information on doing a Javascript
front-end with a Rails backend, so I&rsquo;ll get in some Javascript before I&rsquo;m
through.</p>
<p>The introduction is well paced.  The parts I feel worth mentioning are
its argument that &ldquo;Rails Simply Feels Right&rdquo;, which I am inclined to agree
with.  I&rsquo;ve always thought of Rails as the cadillac of web frameworks.
There&rsquo;s a lot of ways to do the same old CRUD in other frameworks, it&rsquo;s
just rails has polish and a certain thoughtfulness of layout that makes it
all click.  It achieves a level of conciseness thanks to &ldquo;Convention over
configuration&rdquo;, adhering to the philosophy of DRY (Don&rsquo;t Repeat Yourself),
and the natural conciseness of the Ruby programming language (a trait that
I miss a lot now in my job, where my Java code tends to include a lot of
boiler plate by necessity).</p>
<p>The introduction shares a link to the guiding philosophy of
Rails, the <a href="http://rubyonrails.org/doctrine/">Rails Doctrine</a>.  It can be
argued that the Rails Doctrine is what makes Rails continue to be a strong
choice as a web framework, even though it&rsquo;s no longer the new darling on
the block, and as an aside is also one of the reasons I favor Ember of the
Javascript frameworks, since the Ember community were obviously
heavily influenced by the Ruby/Rails community.  The number one item on the
Rails Doctrine is &ldquo;Optimize for programmer happiness&rdquo;.  This is lifted
straight from Ruby, but is still something that many languages don&rsquo;t put
among the considerations, much less as a guiding principle.  I forgive them
for taking a shot at one of my other favorite language mottos, Python&rsquo;s
&ldquo;one and preferably only one way to do something&rdquo;, which I also believe has
it&rsquo;s place.  But I get their meaning that having a choice of ways to express
a solution and being able to choose among them adds a certain bit of
artistry to the craft of programming.</p>
<p>I really appreciate the 2nd principle of the Rails doctrine, &ldquo;Convention over
Configuration&rdquo;.  Right now, my primary day job is working on an app that&rsquo;s
been around for 15 years, and it seems for every problem encountered the
people came up with a way from scratch for how to handle it.  There&rsquo;s no
conventional way to do anything.  But as the author says, &ldquo;Part of the Rails’
mission is to swing its machete at the thick, and ever growing, jungle of
recurring decisions that face developers creating information systems for
the web.&rdquo;  Sane defaults make a lot of things possible with little effort,
as is shown by the demo app in the next chapter.  Just like the Principle of
Least Surprise, it begs the question of &ldquo;Sane (or least surprise) to who?&rdquo;,
but in general the framework itself is built with enough consistency that
once your steeped in its general way of doing things, they make sense as a
whole.  I endorse the idea that freedom from choice is sometimes exactly
what is needed, rather than freedom of choice to do it a different way.
&ldquo;A place for everything and everything in its place. Constraints liberate
even the most able minds.&rdquo;  This is the same type of consistency that
Python&rsquo;s motto helps provide, but with some wiggle room left for expression
in implementation.</p>
<p>I could go on analyzing tenets of the Rails Doctrine, but let&rsquo;s get back to
the book.  I will argue that I sometimes feel &ldquo;monkey patching&rdquo; is more
power than programmers need, even if it allows some cool tricks.  But I
haven&rsquo;t used it much.  It just seems a nightmare that you might end up
having to look at someone&rsquo;s legacy code down the line where they completely
misused it and nothing makes sense.  But then again, I like having sharp
knives in my kitchen too.  I just don&rsquo;t have to cook after many other chefs.
Even good programmers sometimes make questionable decisions when pushed for
time assuming the language allows certain shortcuts.  It&rsquo;s the sharp knives
offered by Ruby and Rails that sometimes make me want to stick to the easy
consistency of Python and Django, even if they require a little more
boilerplate to accomplish similar tasks.</p>
<p>I did promise to get back to the book.  It points out also that &ldquo;Rails is
Agile&rdquo;.  It&rsquo;s too easy to forget the core tenets of Agile development; they
become easily lost to a focus on the ceremonies of Agile.  The book restates
the four preferences of the Agile Manifesto:</p>
<ul>
<li>Individuals and interactions over processes and tools</li>
<li>Working software over comprehensive documentation</li>
<li>Customer collaboration over contract negotiation</li>
<li>Responding to change over following a plan</li>
</ul>
<p>As someone who works at an organization that is permanently mid-transition
between doing things waterfall and approaching them with more agility, I
like to remember the core philosophy of the Agile Manifesto and ask if the
particular procedure we&rsquo;re seeking to follow embodies those ideas.  It&rsquo;s
too easy for the core ideas to get lost in the ceremony of scrums and
sprint planning meetings and the artifacts of burndown charts.</p>
<p>Who is this book for?  It&rsquo;s aimed at application programmers who want to
build and deploy web based applications.  It&rsquo;s fine if you&rsquo;re new to Rails,
and it might be fine even if you&rsquo;re new to Ruby.  My Ruby is rusty enough
that I had to review at
<a href="https://learnxinyminutes.com/docs/ruby/">Learn X in Y Minutes</a>,
but that&rsquo;s a good sign I should
be alright.  I have a whole catalog of <a href="http://exercism.io/">Exercism</a>
problems that I worked in Ruby to review with too, in the worst case.  This
book is more about how to get things done, and doesn&rsquo;t attempt to act as
a detailed reference book.  There&rsquo;s online API references for that type of
stuff.</p>
<p>That was just the introduction!  We&rsquo;ll be a bit quicker now.  Especially
since the first chapter is all about getting setup.  It has useful
instructions for a variety of platforms, including working from a vagrant
box or using the cloud9 online IDE.  I figure that I like having a recent
version of ruby around at the command line anyway, so I followed the OS X
instructions and used homebrew (which I already had installed).  I&rsquo;m
tempted to try Cloud9 sometime, especially since a quick Google tells me
that it does have Vim keybindings.  Maybe some other time.  It looks like
in addition to rails, we need yarn and chromedriver.  I don&rsquo;t have yarn
installed yet, as I&rsquo;ve just used npm for packages, and I&rsquo;m looking forward
to using chromedriver from Ruby.  I use selenium and chromedriver at work
to do end-to-end testing of some of my applications, so I&rsquo;m used to working
with chromedriver in Java.  I needed to uninstall rvm to get the new version
of ruby on my OS X box.  It seems that rbenv is the book&rsquo;s preferred way
for managing multiple Ruby&rsquo;s these days.</p>
<p>On an unrelated note, when did OS X get the ability to remap Caps Lock to
Escape without addons?  I always used to use Seil and Karbiner, but they
quit working in the latest version of OS X.  I was about to try Karbiner
Elements, but when I checked modifier keys under Keyboard in System
Preferences, I saw that it had Caps Lock there and an Escape option.
Sorry to toss this in the middle of everything else, but it&rsquo;s really been
bugging me in Vim to not have my Caps Lock act as Escape.  Unless I stay
on a Ruby kick, the next book I review might be
<a href="https://pragprog.com/book/dnvim2/practical-vim-second-edition">Practical Vim</a>.  I
believe I saw the second edition was on
<a href="https://www.safaribooksonline.com/">Safari Books</a> the other day.
Sorry for the aside,
but I got distracted while waiting for homebrew to update all my packages.</p>
<p>Back to the book.  After covering installing in the environment of your
choice, along with some advice for when/if things go wrong, we get to
Chapter 2, &ldquo;Instant Gratification&rdquo;.  In this chapter, we&rsquo;ll make a quick
demo app to get our feet wet with Rails.  I&rsquo;ve put the demo app with
completed exercises up at <a href="http://github.com/llcawthorne/demo51">demo51</a>.
I&rsquo;ll cover Chapter 2 next blogpost, this one is already getting pretty
large.</p>
]]></content:encoded></item><item><title>Lewis Cawthorne Launches Site</title><link>https://llcawthorne.github.io/posts/first-post/</link><pubDate>Mon, 15 May 2017 00:00:00 +0000</pubDate><guid>https://llcawthorne.github.io/posts/first-post/</guid><description>&lt;p&gt;Finally got around to putting something together for my github.io site other
than what the generator spit out. I went ahead and took advantage of the fact
that they let you layout your site with &lt;a href="http://jekyllrb.com"&gt;Jekyll&lt;/a&gt; to play
with some &amp;ldquo;new to me&amp;rdquo; tech. I can write up the posts in Markdown, so maybe it
will be easy enough that I actually start blogging here.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Finally got around to putting something together for my github.io site other
than what the generator spit out.  I went ahead and took advantage of the fact
that they let you layout your site with <a href="http://jekyllrb.com">Jekyll</a> to play
with some &ldquo;new to me&rdquo; tech.  I can write up the posts in Markdown, so maybe it
will be easy enough that I actually start blogging here.</p>
]]></content:encoded></item></channel></rss>