<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<author><name>Josep Bigorra</name></author>
<title>jointhefreeworld news</title>
<description>News and Insights from the jointhefreeworld and jjba23 projects!</description>
<generator>Emacs webfeeder.el</generator>
<link>https://jointhefreeworld.org</link>
<atom:link href="https://jointhefreeworld.org/rss.xml" rel="self" type="application/rss+xml"/>
<lastBuildDate>Thu, 03 Dec 2026 19:12:49 +0100</lastBuildDate>
<item>
  <title>Sift: the Lisp formatter I kept trying to write (+lint +LSP)</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
sift is one  <a href="https://www.gnu.org/software/guile/">Guile</a> program: a formatter, a linter and a language server for Scheme, Racket, Emacs Lisp and Common Lisp. It has 95 rules, formatting is idempotent, and it runs in your editor, your terminal, CI, a container and a browser tab.
</p>

 <p>
I’ve been writing Lisp for a few years, and for most of that time my tooling was a pile of workarounds. Two editors disagreed about indentation. CI formatted the code one way and my editor another. A compiler warning was prose: no stable code, no severity, no JSON, no way to suppress it next to the line that caused it, no fix. A repository with Scheme, Emacs Lisp and Common Lisp needed three tools, three configs and three CI steps. sift is the first thing I’ve built that reads the file instead of guessing at it.
</p>

 <p>
 <i>This is the program I’ve been trying to write for years. I finally got it.</i>
</p>

 <p>
Find sift at  <a href="https://github.com/jjba23/sift">https://github.com/jjba23/sift</a>, and try it in your browser at  <a href="https://jointhefreeworld.org/sift/">https://jointhefreeworld.org/sift/</a>.
</p>

 <div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
   <img src="https://jointhefreeworld.org/ggg/dist/scheme-guile.svg" alt="Scheme Guile"></img> <img src="https://jointhefreeworld.org/ggg/dist/scheme-racket.svg" alt="Racket"></img> <img src="https://jointhefreeworld.org/ggg/dist/emacs-lisp.svg" alt="Emacs Lisp"></img> <img src="https://jointhefreeworld.org/ggg/dist/lisp-sbcl.svg" alt="Common Lisp"></img></div>

 <figure> <img src="/https/jointhefreeworld.org/static/img/sift-demo.gif" alt="sift lint, fix and format in a terminal, then the same file in Emacs" style="width: 100%;" loading="lazy"></img> <figcaption> <code>sift lint</code>,  <code>sift fix --write</code>, the formatter's diff, and the same file in Emacs with Flymake, Eglot and formatting. Recorded from a checkout.</figcaption></figure> <hr></hr> <h2>The problem  <a id="the-problem" class="anchor" href="#the-problem" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb9d5f63">
 <p>
Lisp is a tree of nested lists. The language knows it; most of the tooling around it pretends otherwise, sometimes with regex.
</p>

 <p>
Go has  <a href="https://go.dev/blog/gofmt">gofmt</a> and Rust has  <a href="https://github.com/rust-lang/rustfmt">rustfmt</a>: one program, the same answer on every machine. In the Lisp world the answer is usually “my editor does it”, “the compiler warns about it”, “we have a  <code>fmt</code> task somewhere”, or “run  <a href="https://guix.gnu.org/manual/en/html_node/Invoking-guix-style.html"> <code>guix style</code></a> on the package file”. Those are local opinions, some with a batch mode.
</p>

 <p>
That was my situation. My projects are Guix and Guile, Emacs Lisp and a little Common Lisp; Racket is the fourth dialect sift grew into. Formatting was a  <code>maak fmt</code> task running  <code>guix style</code> on every  <code>.scm</code> file and Emacs’s  <code>indent-region</code> on every  <code>.el</code> file. Linting was  <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Checkdoc.html"> <code>checkdoc</code></a>, the byte-compiler,  <a href="https://www.gnu.org/software/guile/manual/html_node/Compilation.html"> <code>guild compile -W3</code></a>,  <a href="https://guix.gnu.org/manual/en/html_node/Invoking-guix-lint.html"> <code>guix lint</code></a>,  <code>stylelint</code>, and a hand-written checker that read every  <code>.el</code> form to prove the config still loaded. Each tool was good at its slice. None of them was the thing I wanted, and they disagreed at the boundaries.
</p>
</div>
 <h2>The failed attempts  <a id="the-failed-attempts" class="anchor" href="#the-failed-attempts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgca2b440">
 <p>
I didn’t design sift in one go. I kept solving the problem with the tools I had, and each attempt taught me one piece.
</p>
</div>
 <h3>The keyboard macro  <a id="the-keyboard-macro" class="anchor" href="#the-keyboard-macro" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd9fb00d">
 <p>
Tabs to spaces, trailing whitespace gone,  <code>indent-region</code>, save, stare at the diff. Then a  <code>sed</code> script. It felt like magic for about a day, until I hit a form whose indentation depended on what the form meant. The mechanical part is easy. The structural part is the whole problem.
</p>
</div>
 <h3>Emacs in batch  <a id="emacs-in-batch" class="anchor" href="#emacs-in-batch" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9178de1">
 <p>
The obvious next step was Emacs’s own indentation engine over the whole tree. I had a file called  <code>batch-indent.el</code>:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">defun</span>  <span class="org-function-name">indent-file</span> ( <span class="org-type">&amp;optional</span> save)
   <span class="org-doc">&quot;Format the whole buffer.&quot;</span>
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max))
  (delete-trailing-whitespace)
  ( <span class="org-keyword">when</span> save
    (save-buffer)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Lisp indentation is structural, and the modes encode decades of convention, so for a while this felt like a formatter. But the answer depends on  <code>scheme-mode</code>,  <a href="https://www.nongnu.org/geiser/">Geiser</a>, the project’s  <code>indent-rules</code> and the Emacs version, so two machines could format the same file two ways and both were right according to their setup. It only indents, so it doesn’t own the printer, isn’t a fixed point, and has no lint, no exit status and no report.
</p>
</div>
 <h3>guix style  <a id="guix-style" class="anchor" href="#guix-style" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgf0b4df6">
 <p>
Next I tried the canonical tool where one existed.  <code>guix style</code> knows how a package definition should look, and it has taste. It also formats package definitions, not Scheme: not my modules, not my SXML, not my general procedures or comments. It reflows, so every new idea about line breaks turns every file into a diff. And the  <code>.el</code> files still went to Emacs, which left the repo with two formatters and a boundary where they disagreed. I kept the ambition, and the suspicion that reflowing was the enemy.
</p>
</div>
 <h3>The compiler  <a id="the-compiler" class="anchor" href="#the-compiler" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0ec3789">
 <p>
Then I tried to stop writing a linter and use the ones the language already had:  <code>checkdoc</code> and the byte-compiler for Emacs Lisp,  <code>guild compile -W3</code> for Scheme,  <code>guix lint</code> in Guix buffers, plus a small checker that read every  <code>.el</code> form and compared the module list in  <code>init.el</code> with the files on disk:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">while</span> ( <span class="org-keyword">progn</span> (forward-comment (point-max)) (not (eobp)))
  (read (current-buffer)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This taught me the most important lesson of the bunch: the language’s own reader and compiler know more than any regex. A file that doesn’t read is a finding. A docstring that doesn’t name its arguments is a convention the byte-compiler cares about.  <code>lexical-binding</code> isn’t taste; it’s a header the file needs.
</p>

 <p>
But  <code>read</code> throws away the evidence. It discards comments, keeps no positions, and can’t represent a block comment, a datum comment or a reader prefix as a node.
</p>
</div>
 <h3>The pretty-printer  <a id="the-pretty-printer" class="anchor" href="#the-pretty-printer" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org291a4a0">
 <p>
Once the tree worked, I thought the next step was a pretty-printer that decided line breaks from structure, the way  <a href="https://prettier.io/">Prettier</a> does. The output was beautiful. Then I ran it on a 300-line file and the diff touched every line.  <code>git blame</code> stopped working, and every future change would be buried under the formatter’s opinions. I reverted the file and never wrote that pretty-printer again. That’s where the no-reflow rule comes from.
</p>
</div>
 <h3>read plus a scanner  <a id="read-plus-a-scanner" class="anchor" href="#read-plus-a-scanner" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgfceefd6">
 <p>
Before I wrote the reader, I tried to build the linter on Guile’s  <code>read</code> plus a line scanner:  <code>read</code> gave me forms, the scanner gave me lines, and a table mapped one to the other. Comments fell through the table. A comment inside a form, a  <code>#;</code> datum comment, a string with a semicolon in it: the two representations disagreed and I couldn’t tell which one was right. I gave up and wrote the reader. One representation has to win, and it has to carry positions.
</p>
</div>
 <h3>The pre-commit hook  <a id="the-pre-commit-hook" class="anchor" href="#the-pre-commit-hook" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org2e72d89">
 <p>
I wired  <code>guix style</code> and  <code>emacs --batch</code> into a pre-commit hook. It was fast and useful, and it caught tabs and trailing whitespace before they landed, but it only caught what those tools caught, it couldn’t fix anything, and every repository had its own copy. The pipeline shape was right. The tool behind it was missing.
</p>
</div>
 <h3>One tool per dialect  <a id="one-tool-per-dialect" class="anchor" href="#one-tool-per-dialect" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3930485">
 <p>
The obvious next move was one tool per dialect: Racket’s formatter for Racket,  <code>guix style</code> for Scheme, Emacs for Elisp, something else for Common Lisp. It worked, in the sense that each dialect got a tool. It gave me four tools, four configs, four CI steps and four styles that disagreed at the boundaries.
</p>
</div>
 <h2>What it is  <a id="what-it-is" class="anchor" href="#what-it-is" aria-label="Link to this section">#</a></h2> <h3>One executable  <a id="one-executable" class="anchor" href="#one-executable" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org105d918">
 <div class="jfw-code"> <pre>sift format [OPTIONS] [FILE...]      <span class="org-comment-delimiter"># </span> <span class="org-comment">print the formatted file
</span>sift lint [OPTIONS] [FILE...]        <span class="org-comment-delimiter"># </span> <span class="org-comment">report findings
</span>sift check [OPTIONS] [FILE...]       <span class="org-comment-delimiter"># </span> <span class="org-comment">print the patch, exit 1 if any
</span>sift fix [OPTIONS] [FILE...]         <span class="org-comment-delimiter"># </span> <span class="org-comment">lint --fix
</span>sift ci [OPTIONS] [FILE-OR-DIR...]   <span class="org-comment-delimiter"># </span> <span class="org-comment">format check + lint, never writes
</span>sift lsp                             <span class="org-comment-delimiter"># </span> <span class="org-comment">a language server on stdin/stdout
</span>sift doctor                          <span class="org-comment-delimiter"># </span> <span class="org-comment">what ran, what it read, what it decided
</span>sift list-checkers [--dialect D]     <span class="org-comment-delimiter"># </span> <span class="org-comment">the catalogue as a table
</span>sift explain RULE                    <span class="org-comment-delimiter"># </span> <span class="org-comment">one rule's reasoning
</span>sift config show|explain|trust ...   <span class="org-comment-delimiter"># </span> <span class="org-comment">the settings, and which layer won
</span>sift install-hooks [--force]         <span class="org-comment-delimiter"># </span> <span class="org-comment">a pre-commit hook that runs `ci'</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Status 0 is clean, 1 is findings, 2 is a usage error or a file that can’t be read.
</p>

 <p>
The dialect is explicit ( <code>--dialect</code>), then the extension, then the shebang, then a marker in the first 200 lines:  <code>#lang</code> is Racket,  <code>defpackage</code> is Common Lisp,  <code>define-module</code> is Scheme,  <code>lexical-binding</code> is Emacs Lisp. If none answers, it says so. It never guesses.
</p>

 <div class="jfw-code"> <pre>$ cat square.scm
(define (square x)
(* x x))

$ sift check square.scm
--- square.scm
+++ square.scm
@@ -1,2 +1,2 @@
 (define (square x)
 <span class="org-function-name">-</span>(* x x))
+  (* x x))
$ echo $ <span class="org-variable-name">?</span>
1</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <code>check</code> prints the patch and exits 1. It never modifies your files.  <code>sift format --write square.scm</code> makes the change, and the next  <code>sift check</code> exits 0.
</p>

 <p>
When the environment and the tool disagree, ask the tool:
</p>

 <div class="jfw-code"> <pre>$ sift doctor
sift 1.41.2
  guile       3.0.11
  library     /home/joe/Hacking/sift/src
  rules       95
  dialects    scheme, racket, elisp, cl

Compilers
  scheme available
  elisp available
  cl not found

Configuration
  project  /home/joe/project/sift.yaml

Settings that are not the default
  brackets: square    <span class="org-comment-delimiter"># </span> <span class="org-comment">/home/joe/project/sift.yaml
</span>  severity: warning    <span class="org-comment-delimiter"># </span> <span class="org-comment">/home/joe/project/sift.yaml</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>The formatter  <a id="the-formatter" class="anchor" href="#the-formatter" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgc7dce5b">
 <p>
Every node carries its source location. Comments, blank lines, datum comments and reader prefixes are nodes, not trivia. A file with one broken form still gets a tree, because a linter that says nothing about a file it couldn’t parse fails exactly when it’s needed.
</p>

 <p>
The reader knows each dialect’s read syntax rather than a compromise:  <code>#\a</code> is a character in Scheme, Racket and Common Lisp and  <code>?a</code> in Emacs Lisp;  <code>#:key</code> is an uninterned symbol and  <code>:key</code> a keyword;  <code>#| ... |#</code> nests;  <code>#;</code> comments out the next datum;  <code>#lang</code> opens a Racket module; a square bracket is a vector in Emacs Lisp and a clause delimiter in Scheme. sift doesn’t average the two.
</p>

 <p>
The formatter does six things: normalise line endings, normalise spacing, place closing delimiters, compute indentation, optionally align inline comments, and preserve blank lines up to the style’s limits. Everything else comes out as written, including line breaks, strings, escapes and comments. Run it twice and you get the same bytes; the suite formats every fixture and then formats the result to check.
</p>

 <p>
Indentation is three rules. A form whose first element is a symbol is looked up in the dialect’s table; a data list or vector aligns under its first element; anything else lines its arguments up under the first argument. That’s the whole algorithm. The tables exist for the forms where structure alone isn’t enough.
</p>

 <p>
Two styles.  <code>community</code> keeps closing delimiters trailing,  <code>dangling</code> puts each on its own line. Scheme writes  <code>cond</code> clauses with square brackets, as Guile and Guix do, and  <code>--brackets=parens</code> or  <code>--brackets=preserve</code> changes that; Emacs Lisp and Common Lisp keep what they were given. The  <code>clause-brackets</code> rule ( <code>SIFT036</code>) reports a file that hasn’t been formatted yet, and its fix swaps the two characters.
</p>

 <p>
It refuses to reflow a long line (the  <code>line-length</code> rule warns instead), invent a missing parenthesis, rewrite an expression, or format inside a  <code>#;</code> datum comment, a  <code>#.</code> form or a  <code>#&lt;...&gt;</code> object.  <code>sift fix</code> doesn’t reformat, because a fix that moved whitespace would touch every line of the patch it was meant to make readable.
</p>
</div>
 <h3>The linter  <a id="the-linter" class="anchor" href="#the-linter" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9462fe2">
 <p>
A rule is a record: name, code, description, dialects, default severity, procedure and example. The driver reads the file once, runs the rules the dialect applies to, folds in what the reader reported, honours suppression comments, and sorts the findings by file, line, column and rule. There are 95 rules, each with a stable code ( <code>SIFT001</code> through  <code>SIFT095</code>), assigned by hand and never reused.  <code>sift explain RULE</code> reads the reasoning out of the program, and  <a href="https://github.com/jjba23/sift/blob/trunk/doc/rules.org"> <code>doc/rules.org</code></a> is generated from the records.
</p>

 <p>
The catalogue, condensed:
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Where</th>
 <th scope="col" class="org-left">What it checks</th>
</tr></thead> <tbody> <tr> <td class="org-left">all four</td>
 <td class="org-left">whitespace, line length, delimiters, empty bodies,  <code>progn</code>, blank lines, comment levels, single-letter names, the  <code>if</code> /  <code>when</code> /  <code>unless</code> family, keyword arguments, complexity</td>
</tr> <tr> <td class="org-left">Scheme and Racket</td>
 <td class="org-left">internal defines,  <code>letrec</code>, quasiquote, clause brackets, docstrings, eta and beta reduction,  <code>let</code> simplification</td>
</tr> <tr> <td class="org-left">Emacs Lisp</td>
 <td class="org-left">docstrings,  <code>lexical-binding</code>,  <code>interactive</code>,  <code>provide</code>,  <code>declare</code>,  <code>require-cl</code>,  <code>save-excursion-set-buffer</code></td>
</tr> <tr> <td class="org-left">Common Lisp</td>
 <td class="org-left">package prefixes, double colons, dangling parentheses, LOOP style,  <code>identity</code>,  <code>ecase-otherwise</code>,  <code>mixed-lambda-list</code></td>
</tr> <tr> <td class="org-left">Guix</td>
 <td class="org-left">gexps,  <code>#$output</code>,  <code>with-imported-modules</code>, phase names,  <code>sha256</code>, package synopses,  <code>inputs</code></td>
</tr> <tr> <td class="org-left">SXML</td>
 <td class="org-left">attribute lists, children, empty elements</td>
</tr></tbody></table> <p>
 <code>sift explain if-without-else</code> prints that record: the code, the name, the description, the dialects, the severity, a failing example and the expected fix. A diagnostic and a documentation page are the same data, which is the part I like most.
</p>

 <p>
A rule may carry a fix, which is one range.  <code>sift lint --fix</code> applies fixes from the highest offset down, then lints once to show what’s left; there’s no loop. If a fix introduced a parse error the file didn’t have, every fix of that run is discarded and the original findings are reported. A file the reader couldn’t finish is refused, because a fix around a missing parenthesis would be a guess.  <code>--force</code> is for a caller who knows better.
</p>

 <p>
Some rules have no fix on purpose.  <code>unmatched-parens</code> won’t guess where a  <code>)</code> belongs.  <code>wrap-in-let</code> won’t invent a binding name. The naming rules won’t rename anything.  <code>blank-line-in-body</code> won’t delete a line. Deciding how to split or name code is your work.
</p>

 <p>
Suppression is a comment, not a config list:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;; </span> <span class="org-comment">sift:disable-next-line keyword-arguments
</span>(make-window a b c d e f g)

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">sift:disable wrap-in-let
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">f</span> x)
  ...)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">sift:enable wrap-in-let</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <code>disable-next-line</code> covers the next line,  <code>disable</code> covers to the end of the top-level form, and  <code>enable</code> ends it. An exception list in a config file is a list no review reaches. This one is in the diff.
</p>

 <p>
Fixing isn’t filtered by severity.  <code>severity: warning</code> says what fails a build, not what’s worth repairing on request.
</p>
</div>
 <h3>Configuration  <a id="configuration" class="anchor" href="#configuration" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5dcdb80">
 <p>
 <code>format</code> prints,  <code>--write</code> writes,  <code>check</code> answers with a patch and a status,  <code>lint</code> reports,  <code>lint --fix</code> fixes, and  <code>ci</code> asks both questions without touching the tree. A job that edits the tree it’s judging is a job whose verdict means nothing.
</p>

 <p>
The same findings come out as the compile-style line  <code>file:line:column: severity: [rule] sentence</code>, JSON,  <a href="https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html">SARIF</a>, GitHub annotations, or  <code>null</code>.  <code>--watch</code> re-runs when a file the run read changes.  <code>SIFT_JOBS</code> is the only setting that controls parallelism.
</p>

 <p>
Settings are  <code>sift.yaml</code>, or a  <code>sift.scm</code> the project has trusted. They’re layered: defaults, system, user, project, command line. Discovery stops at the repository root. YAML is data and can’t execute anything; Scheme is code and must be trusted explicitly, with  <code>--config</code>,  <code>SIFT_TRUST_CONFIG=1</code> or  <code>sift config trust sift.scm</code>. An unknown key is refused with a position, and  <code>sift config show --verbose</code> names the layer that won.
</p>

 <div class="jfw-code"> <pre>line-length: 90
brackets: square
severity: warning
checkers: [trailing-whitespace, docstring-missing]
stdlib: true</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The formatter has few knobs on purpose: a formatter with a hundred options has no opinion. The tuning lives in the linter, where you choose which of the 95 rules run, what their thresholds are, and which severity fails a build. The language server reads the same files, so  <code>sift.yaml</code> is the single place where editor behaviour is written down: inlay hints, hover, completion, stdlib, downloads, compiler diagnostics, import organization.
</p>
</div>
 <h3>The language server  <a id="the-language-server" class="anchor" href="#the-language-server" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org72f4f55">
 <p>
 <code>sift lsp</code> speaks LSP over standard input and output, so the editor and the pipeline get the same findings, fixes and formatting.
</p>

 <p>
It answers diagnostics, quickfixes, fix-all, the extract and inline refactors, import organization, formatting, hover, definition, references, highlights, symbols, completion, inlay hints, rename and signature help; a file rename keeps a Scheme module or an Emacs Lisp  <code>provide</code> in step.
</p>

 <p>
It refuses the type hierarchies, semantic tokens, code lenses, folding, range formatting, format-on-type, pull diagnostics and workspace folder changes. sift models no types, expands no macro, and has no opinion about what to fold. “Method not found” is more useful than a plausible lie.
</p>

 <p>
The project is read in a thread from  <code>initialize</code> on. Two thousand files arrive in batches of sixty-four, so the first answer comes after the first batch and each later batch replaces the snapshot whole. A jump has 100 ms, a reference search 200 ms, and  <code>sift/indexStatus</code> says how far the reading has got.
</p>

 <p>
The standard library is indexed from source: Guile’s modules, Emacs’s  <code>load-path</code> and package trees,  <a href="https://asdf.common-lisp.dev/">ASDF</a> and  <a href="https://www.sbcl.org/">SBCL</a> sources, Racket’s  <code>collects</code> and  <code>pkgs</code>, and what each implementation says about itself.  <code>car</code> is compiled into libguile and no file says where, so the implementation is asked once to write down every name it documents, as source. A jump to  <code>car</code> lands in code that reads like the file it’s in. Writing that felt a little illegal, and it’s the LSP work I’m proudest of.
</p>

 <p>
The server can ask the dialect’s compiler for a second opinion on open or save:  <code>guild</code>,  <code>emacs</code>,  <code>sbcl</code>, whichever is installed. A missing compiler is simply not asked, and  <code>compiler-diagnostics: false</code> turns it off.
</p>
</div>
 <h3>The editing loop  <a id="the-editing-loop" class="anchor" href="#the-editing-loop" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orga75eda1">
 <p>
My Emacs configuration ( <a href="https://github.com/jjba23/heks-emacs">heks-emacs</a>) puts a  <a href="https://www.nongnu.org/geiser/">Geiser</a> REPL in the middle of Scheme development.  <code>C-c g r</code> starts or switches to the project’s REPL: a  <code>guix repl</code> in a package buffer, a plain  <code>guile</code> one elsewhere, one per project.  <code>C-c g e</code> evaluates the definition at point,  <code>C-c g b</code> loads the file,  <code>C-c g k</code> interrupts,  <code>C-c g d</code> opens the debugger.
</p>

 <p>
sift runs in the same buffer, at the same time, without asking the REPL for anything.  <code>sift-flymake</code> runs  <code>sift lint --stdin --format=json</code> on the buffer’s own text, saved or not, and turns findings into  <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Flymake.html">Flymake</a> diagnostics with the rule’s code and name. The drift backend marks the lines  <code>sift format</code> would rewrite.  <code>C-c g H</code> explains the rule at point,  <code>C-c g a</code> applies its fix,  <code>C-c g A</code> applies every fix,  <code>C-c g f</code> formats. Nothing is written; every step is one  <code>undo</code> away.
</p>

 <p>
The REPL and the linter answer different questions. The REPL knows what the program does when it runs: the loaded state, the values, the stack, the debugger. sift knows what the file says and what a pipeline will say about it, which is how it can tell you that a  <code>cond</code> clause after  <code>else</code> can never run, that an import is unused, or that a line isn’t formatted the way  <code>sift ci</code> will require. A REPL can’t tell you your file is unformatted, and a formatter can’t tell you what an expression returned. So sift is asked first, because it needs nothing but itself;  <code>guild compile</code> and  <code>guix lint</code> are the second opinion on save; Geiser is the third, for what only a running image knows.
</p>

 <p>
The loop I do a hundred times a day: start the REPL, write a one-armed  <code>if</code>, watch  <code>SIFT012</code> appear on a dirty buffer, read the rule, apply the fix, evaluate the definition, format, reload. No save and no build in the middle.
</p>
</div>
 <h3>Editors, CI and the browser  <a id="editors-ci-and-the-browser" class="anchor" href="#editors-ci-and-the-browser" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org6f297de">
 <p>
The clients are thin wrappers over the program:
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Editor</th>
 <th scope="col" class="org-left">What to use</th>
</tr></thead> <tbody> <tr> <td class="org-left">Emacs</td>
 <td class="org-left"> <code>emacs/sift.el</code>: Flymake and Eglot</td>
</tr> <tr> <td class="org-left"> <a href="https://neovim.io/">Neovim</a></td>
 <td class="org-left"> <code>editors/vim/neovim.lua</code>: a  <code>vim.lsp.start</code> setup</td>
</tr> <tr> <td class="org-left"> <a href="https://www.vim.org/">Vim</a></td>
 <td class="org-left"> <code>editors/vim/</code>:  <code>:SiftLint</code>,  <code>:SiftFormat</code>,  <code>:SiftFix</code>,  <code>:SiftExplain</code></td>
</tr> <tr> <td class="org-left"> <a href="https://code.visualstudio.com/">VS Code</a></td>
 <td class="org-left"> <code>editors/vscode/</code>: no build step, no dependencies</td>
</tr> <tr> <td class="org-left"> <a href="https://helix-editor.com/">Helix</a></td>
 <td class="org-left">format on save through  <code>sift format --stdin</code></td>
</tr> <tr> <td class="org-left">the browser</td>
 <td class="org-left"> <code>web/</code>: sift compiled to  <a href="https://webassembly.org/">WebAssembly</a></td>
</tr></tbody></table> <p>
In a pipeline, one command asks both questions:
</p>

 <div class="jfw-code"> <pre>sift ci src/ tests/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
It exits 1 if either check finds something, 2 if a file can’t be read or parsed, and it never writes. There’s a reusable  <a href="https://github.com/features/actions">GitHub workflow</a>:
</p>

 <div class="jfw-code"> <pre>name: sift
on: [push, pull_request]
jobs:
  sift:
    uses: jjba23/sift/.github/workflows/sift.yml@v1.41.2</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
It annotates the diff and uploads SARIF to code scanning, so an unfixed finding becomes an alert instead of a line in a log. There’s also a composite action, a pre-commit hook, a  <a href="https://pre-commit.com/"> <code>pre-commit</code></a> declaration, a  <a href="https://dprint.dev/">dprint</a> process plugin, and a  <a href="https://www.docker.com/">Docker</a> image.
</p>

 <p>
The browser build sounds like a stunt and isn’t.  <code>web/</code> is formatting and linting compiled to WebAssembly with  <a href="https://spritely.institute/hoot/">Guile Hoot</a>, with an editor page around it. The same reader, formatter and 95 rules are in the tab; the two rules that need a project report nothing, and no input leaves the tab. The whole contract is one procedure of one string to one string:
</p>

 <div class="jfw-code"> <pre>(web-request  <span class="org-string">&quot;{\&quot;op\&quot;:\&quot;lint\&quot;,\&quot;source\&quot;:\&quot;(if a b)\&quot;}&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;{\&quot;ok\&quot;:true,\&quot;result\&quot;:{\&quot;warnings\&quot;:[…],\&quot;counts\&quot;:{…}}}&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The module is 3.4 MB. A screenful formats in 17 ms and lints in 56 ms; 1.2 kB is 52 ms and 145 ms; 6 kB is 780 ms and 1.2 s. The first two rows never reach the 300 ms debounce. The number isn’t the interesting part. The source of truth stayed put: the tab runs the same modules  <code>bin/sift</code> runs, four Guile libraries have stand-ins in  <code>web/compat</code>,  <a href="https://srfi.schemers.org/srfi-13/">SRFI-13</a> is thirteen procedures with a test that compares the browser’s answers to Guile’s byte for byte, and eight tests hold the dependency one way.
</p>

 <p>
The page is live at  <a href="https://jointhefreeworld.org/sift/">https://jointhefreeworld.org/sift/</a>: an editor with the dialect, style and severity as controls, findings linked to the source, an outline, completion, inlay hints and a rules browser.
</p>

 <figure> <img src="/https/jointhefreeworld.org/static/img/sift-web.png" alt="The sift editor in a browser tab" style="width: 100%;" loading="lazy"></img> <figcaption>The browser build at jointhefreeworld.org/sift. The same reader, formatter and rules, compiled with Guile Hoot.</figcaption></figure></div>
 <h3>What a run costs  <a id="what-a-run-costs" class="anchor" href="#what-a-run-costs" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org13023d0">
 <p>
On my machine:
</p>

 <pre class="example" id="orgfa2c9d1">
lint the tree (28 files, 14896 lines)       337ms, 160.7 MiB allocated
check the tree (28 files): format           253ms,  59.0 MiB allocated
lint (lsp.scm, every checker)               171ms,  19.2 MiB allocated
read the tree (28 files)                    143ms,  44.7 MiB allocated
</pre>

 <p>
Both numbers matter: a pass that conses per node makes every other pass slower, and the allocation count shows it even when the clock looks good. Three questions dominated the cost of a lint, each originally answered by walking something a second time: whether a node is code or data, what a form is called, and where the lines begin. Computing each once took a lint of the repository from twenty-five seconds to under one, and the allocation from a gigabyte and a half to a hundred and forty megabytes.
</p>

 <p>
The suite I ran while writing this: 119 suites, 1160 tests, 2624 assertions, about a minute. The reader is tested dialect by dialect, the formatter on a golden corpus plus an idempotence pass, each rule with a passing case, a failing case and a re-lint after its fix, the CLI as a subprocess, the language server over the wire. The project formats itself, so  <code>maak self-check</code> is a real gate.
</p>
</div>
 <h2>The style  <a id="the-style" class="anchor" href="#the-style" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org751e0d4">
 <p>
The style is the common practice of the four communities, written down in  <a href="https://github.com/jjba23/sift/blob/trunk/doc/style.org"> <code>doc/style.org</code></a>:  <a href="http://mumble.net/~campbell/scheme/style.txt">Riastradh</a>,  <a href="https://google.github.io/styleguide/lispguide.xml">Google’s Common Lisp guide</a>,  <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html">the Emacs Lisp manual’s docstring tips</a>,  <a href="https://small.r7rs.org/">R7RS</a>, and the conventions of Guile and Guix.
</p>

 <p>
The short version: two columns for every body; arguments align under the first; one blank line between top-level forms, never inserted where there was none; closing delimiters trail unless a project says  <code>dangling</code>; square brackets for Scheme clauses as a setting, not a law; keywords line up; your macros get your indent rules, because no formatter knows what your macro means; no reflowing, since a line break records where you judged the form to end; a reader prefix glues to its datum; a comment stays on its line.
</p>

 <p>
sift declines some Riastradh rules: a 72 or 80 column limit (the default is 96, or 80 for Emacs Lisp), pages and form feeds (they rewrite every line number below the break), 21-line top-level forms, and  <code>with-</code> versus  <code>call-with-</code> prefixes, which needs to know whether an argument is called.
</p>

 <p>
What it won’t do is the other half of the style. It doesn’t rename, reorder or inline a procedure on its own, and it doesn’t introduce a delimiter. It never guesses a dialect. A fix it can’t verify is discarded, not applied with a warning. Lint reports, fix is opt-in, and CI never writes. Suppression belongs next to the code, and codes never move, because a code is what an editor and a bug report quote. Few knobs: a formatter with a hundred options has no opinion. Refuse what you can’t answer. The browser is a compile of the same modules and the editors are thin wrappers, so there’s no second implementation. MIT, because a formatter in other people’s pipelines can’t carry a licensing question.
</p>

 <p>
It doesn’t expand macros, type-check or know your conventions. It reports and you decide. Where it can be wrong, the rule says so:  <code>wrap-in-let</code> is a suggestion,  <code>keyword-arguments</code> counts, thresholds are settings. The LSP has two limits: references are matched by name within one dialect, and the project is read in the background, so a jump answers from what’s been read. Range formatting, format-on-type, fold ranges, macro-introduced names, pull diagnostics and a  <code>--since REV</code> mode are in scope and not built yet.
</p>
</div>
 <h2>Compared to the neighbours  <a id="compared-to-the-neighbours" class="anchor" href="#compared-to-the-neighbours" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org81191dd">
 <p>
Clojure is the one Lisp community that has this.  <a href="https://github.com/weavejester/cljfmt">cljfmt</a> formats and  <a href="https://github.com/clj-kondo/clj-kondo">clj-kondo</a> lints, both good, and both Clojure-only. Outside it, Scheme has  <code>scheme-mode</code>,  <code>guild compile -W3</code> and  <code>guix style</code>, and none of them is a general formatter, a project linter or an LSP. Emacs Lisp has  <code>checkdoc</code> and the byte-compiler, but a compiler warning is prose: no stable code, JSON, SARIF, CLI or fix. Common Lisp has  <a href="https://slime.common-lisp.dev/">SLIME</a> and  <a href="https://github.com/joaotavora/sly">SLY</a>, which are an environment, not a program a pipeline runs. Racket has its own tools, and a repo with Scheme and Elisp still needs the others.
</p>

 <p>
The canonical formatters are the other reference point. rustfmt and gofmt are one language, one style and no linting; their authority comes from being canonical, while sift has to write the style down.  <a href="https://clang.llvm.org/docs/ClangFormat.html">clang-format</a> makes configuration its product, which is the opposite bet.  <a href="https://prettier.io/">Prettier</a> is the closest in philosophy, but it reflows and doesn’t preserve every comment and blank line.
</p>

 <p>
The neighbours do three things I want to steal: a checkable macro configuration from clj-kondo, answers from real analysis from SLIME and SLY, and the authority of a canonical tool from rustfmt and gofmt.
</p>

 <p>
Inside Guix and Guile the gap is habits:  <code>assoc-ref %outputs</code>, a  <code>#$output</code> that makes a file, a  <code>use-modules</code> inside a gexp that  <code>with-imported-modules</code> doesn’t mark, an unquoted phase name, a  <code>sha256</code> that isn’t  <code>(base32 &quot;...&quot;)</code>, a synopsis that opens with an article,  <code>inputs</code> written as a labelled alist. Those are rules with codes and fixes now.
</p>
</div>
 <h2>Under the hood  <a id="under-the-hood" class="anchor" href="#under-the-hood" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org143db9b">
 <p>
 <code>src/sift/</code> is one module per job:
</p>

 <pre class="example" id="org65a290b">
records.scm       locations, findings, rule records, codes, AST nodes
reader.scm        the permissive, location-preserving reader
format.scm        the pipeline, indentation tables, renderer
checkers/         one module per family of rules
lint.scm          run, suppress, filter, sort, fix, re-lint
render.scm        human, JSON, GitHub, null, SARIF
config.scm        discovery, merging, provenance, trust
lsp.scm           diagnostics, actions, formatting, hover, navigation
cli.scm           args-fold, dispatch, exit codes
</pre>

 <p>
 <code>records</code> is the vocabulary;  <code>reader</code> and  <code>format</code> use it; the checkers use  <code>records</code> and  <code>check/base</code>;  <code>lint</code> assembles them;  <code>render</code> prints;  <code>lsp</code> speaks the protocol;  <code>cli</code> wires it up. Nothing in  <code>format</code> or a checker knows about ports or exit codes.
</p>

 <p>
The implementation is Guile 3.0 and the standard library. No C dependency, no build step. The launcher is a small  <a href="https://en.wikipedia.org/wiki/POSIX">POSIX</a> shell script that finds its own symlink chain, puts  <code>src/</code> on the load path and hands the arguments to  <code>(sift cli)</code>.
</p>

 <p>
Install with  <code>guix install sift</code> from the  <a href="https://github.com/jjba23/guix-jointhefreeworld">guix-jointhefreeworld</a> channel,  <code>nix run</code> from the  <a href="https://nixos.org/">Nix</a> flake,  <a href="https://brew.sh/">Homebrew</a> from the tap, a container image, or a checkout and  <code>./bin/sift version</code>. The Emacs package is one file with no dependencies beyond Emacs 28.1.
</p>
</div>
 <h2>Come help  <a id="come-help" class="anchor" href="#come-help" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org109ecd6">
 <p>
The list of Lisp dialects that deserve a better reader is long.
</p>

 <ul class="org-ul"> <li> <b>A bug report.</b> Give the input, the output you expected, and  <code>sift version</code> with the first section of  <code>sift doctor</code>. A file sift refuses to parse is a bug even when the file is broken; the message must say where.</li>
 <li> <b>A rule.</b> One record and one test file. The catalogue, docs and editor integrations follow.</li>
 <li> <b>A dialect detail.</b> An escape, a comment in an odd place, a body that indents by something other than two.</li>
 <li> <b>An editor integration.</b> Neovim, Vim and VS Code each have a directory and a test; a fourth editor is one directory more.</li>
 <li> <b>A sentence in the docs.</b> A sentence that causes hesitation is a defect.</li>
</ul> <p>
To start: read  <a href="https://github.com/jjba23/sift/blob/trunk/doc/style.org"> <code>doc/style.org</code></a>, run  <code>maak test</code>, add the rule or fix with its test under  <code>tests/checkers/</code>, then run  <code>maak self-check</code>,  <code>maak check</code> and  <code>maak fixture-check</code>. Send a pull request, or a patch with  <code>git format-patch</code> and  <code>git send-email</code>.
</p>

 <p>
The  <a href="https://github.com/jjba23/sift/blob/trunk/AI_POLICY.md">AI policy</a> is short: agents may explore, plan, branch, run the build and tests, commit, push, open and merge pull requests, and cut releases. A human is the author of record and must be able to explain and debug every line. TDD is required, and the tool and what it did are disclosed. A rule written with an agent is as welcome as one without; the review concerns the code.
</p>
</div>
 <h2>What’s next  <a id="whatrsquos-next" class="anchor" href="#whatrsquos-next" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgef5facb">
 <ul class="org-ul"> <li> <b>Range formatting and format-on-type.</b> The formatter indents from column zero, so a fragment lands at the margin. The hard part is an origin column that still produces, for the range it touched, the bytes a whole-buffer run would.</li>
 <li> <b>A  <code>--since REV</code> mode.</b> Lint the lines a diff touched, not the whole tree, so a large codebase can adopt a linter without a mass reformat.</li>
 <li> <b>Resolution across files.</b> Follow  <code>define-module</code>,  <code>#:use-module</code>,  <code>defpackage</code> and  <code>provide</code> far enough that a reference is a binding, not a name. Then a project-wide rename is correct in every file.</li>
 <li> <b>A declared-macro table.</b> A project declares what its macros bind, so references and rename can see the names a macro introduces.</li>
 <li> <b>The style as a specification.</b> The rules and the corpus are already there; the next step is a document a second implementation can be checked against.</li>
 <li> <b>A fifth dialect.</b> Racket was the fourth and cost a table, a dozen rules re-argued and a corpus of its own. Each one after that is more evidence that the reader, formatter and rule records are the general part.</li>
</ul> <p>
None of this is a promise with a date. If one of them sounds like your afternoon, open an issue and I’ll help you land it.
</p>
</div>
 <h2>Closing  <a id="closing" class="anchor" href="#closing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgef2e545">
 <p>
The failed attempts taught me that a Lisp file is a tree, that a community can agree on a style and a program can enforce it, and that the language’s own reader and compiler know more than any regex. The detours taught me the rest: never reflow, let one representation win, put the conventions in a program, ship one executable.
</p>

 <p>
What none of them had was the premise: read the file as a datum with positions and print it back. Once that was true, formatting became a fixed point, a fix became a range, a finding became data, and the editor and the pipeline got the same answer. The seeds weren’t wasted either. They were the reader, the style and the rules, waiting for the thing that would hold them together. The name is the bet: a source file mixes the program with the layout; sift separates them, checks the program, and puts the layout back.
</p>

 <p>
If you have a Lisp dialect that deserves a better reader, a rule your project keeps repeating in review, or an editor that should have the server, come and plant one.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Emacs finally folds to my liking</span></a>
 <span></span>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/">The FREE stack - My Tech Radar</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/index.html</guid>
  <pubDate>Thu, 03 Dec 2026 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Emacs finally folds to my liking</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
I’ve been slowly turning  <a href="https://codeberg.org/jjba23/heks-emacs">my Emacs config</a> into something I actually  <i>enjoy</i> using, not just something that works, and folding was the last place where that wasn’t true.
</p>

 <p>
Every mode had its own idea of what folding is:  <code>treesit-fold</code> in Tree-sitter modes, Hideshow in the Lisp-ish ones, Outline in everything that resembles text, Org with its own invisible text that no one else’s commands can undo.
</p>

 <p>
So every buffer had different keys, a different look, and worst of all  different  <i>performance</i> characteristics. Folding a big file sometimes felt like holding my breath.
</p>

 <p>
I’m running Emacs 32.0.50 from  <code>master</code> (built from source, as one does), and it’s finally one system.
</p>


 <div id="orgabe112f" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/heks/screen-2026-10-23-16-17-32.png"></img></p>
</div>
 <h2>kirigami is the piece I didn’t know I needed  <a id="kirigami-is-the-piece-i-didnrsquot-know-i-needed" class="anchor" href="#kirigami-is-the-piece-i-didnrsquot-know-i-needed" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org163b27f">
 <p>
 <a href="https://github.com/jamescherti/kirigami.el">kirigami</a> doesn’t fold anything itself. It  <i>dispatches</i>: it keeps a list of folding engines, checks which one is actually active in the buffer, and forwards to it. Tree-sitter, Hideshow, Outline, Org, Vdiff — all behind one interface.
</p>

 <p>
So on top of it I put one set of keys, the same in a Kotlin buffer, YAML, a Scheme or ELisp buffer and an Org file:
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Key</th>
 <th scope="col" class="org-left">Does</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>C-c v c</code></td>
 <td class="org-left">close this fold</td>
</tr> <tr> <td class="org-left"> <code>C-c v C</code></td>
 <td class="org-left">close every fold</td>
</tr> <tr> <td class="org-left"> <code>C-c v o</code></td>
 <td class="org-left">open this fold</td>
</tr> <tr> <td class="org-left"> <code>C-c v O</code></td>
 <td class="org-left">open this fold and everything under it</td>
</tr> <tr> <td class="org-left"> <code>C-c v r</code></td>
 <td class="org-left">reveal everything</td>
</tr> <tr> <td class="org-left"> <code>C-c v t</code></td>
 <td class="org-left">toggle the fold at point</td>
</tr></tbody></table> <p>
That sounds small. It is not small. The number of times a day I used to think “wait, what does TAB do in this mode again” is now zero, and the muscle memory transfers across an entire polyglot config.
</p>

 <p>
One wrinkle worth mentioning: kirigami answers with the  <i>first</i> engine in its list whose mode is on, and  <code>outline-minor-mode</code> is on in nearly every buffer I have. In the buffers where I deliberately turned on Hideshow — Scheme, for instance — that choice has to win, otherwise  <code>C-c v c</code> folds “headings” a Scheme file doesn’t have. So I reorder  <code>kirigami-fold-list</code> to put Hideshow first instead of rewriting it; engines kirigami adds later still get used wherever Hideshow is off.
</p>
</div>
 <h2>Tree-sitter folding, with guides that are actually lines  <a id="tree-sitter-folding-with-guides-that-are-actually-lines" class="anchor" href="#tree-sitter-folding-with-guides-that-are-actually-lines" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgdf95d4b">
 <p>
Most of my programming buffers are  <code>*-ts-mode</code>, so  <code>treesit-fold</code> does the work there — bash, C, C++, CMake, CSS, Dockerfile, Elixir, Go, HTML, Java, JS/TS/TSX, JSON, Kotlin, Lua, Nix, PHP, Python, Ruby, Rust, Scala, TOML, YAML. Line counts are shown inline, which I find genuinely useful when deciding whether to open a fold.
</p>

 <p>
The indicators took the most fiddling.  <code>treesit-fold-indicators</code> draws a block’s guide with a bitmap 23 rows tall, centered in the line beside it. A line in my config is 29 pixels — the font’s 23 plus six of  <code>line-spacing</code> — so every row of the guide was a 23-pixel dash with three pixels of nothing above and below it. A folded block looked like a  <i>dotted</i> line running down the fringe. Not subtle, just wrong.
</p>

 <p>
There’s no setting for that, so I replaced the bitmaps: a single-row bitmap that  <code>define-fringe-bitmap</code> repeats down however tall the line is (no spacing can introduce a gap), plus a  <code>+=/</code>-= box and an end-elbow cut to the exact height of a line, so the guide runs from the marker into the row below and turns toward the text where the block ends. It’s an advice on the function that builds the string for each line. It looks like a bracket now, not a perforation.
</p>

 <p>
And the colour: the indicators inherited  <code>shadow</code>, which most themes make as bright as a comment. Fine for one marker on one line, wrong for a marker on  <i>every</i> line of a block — the grey became a rule drawn through the code. They’re now  <code>shadow</code> blended 50% toward the theme’s background, recomputed on every theme and scale change, so it fades correctly on light themes too and no theme needs a special entry.
</p>
</div>
 <h2>Hideshow earns its keep  <a id="hideshow-earns-its-keep" class="anchor" href="#hideshow-earns-its-keep" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgef40e99">
 <p>
Not everything has a grammar, and I’m not going to pretend otherwise:
</p>

 <ul class="org-ul"> <li> <b>Scheme</b> — my Emacs build has no Scheme grammar, so Scheme buffers use Hideshow with  <code>hs-block-start-regexp</code> set to  <code>&quot;^(&quot;</code> and  <code>hs-forward-sexp-function</code> set to  <code>forward-sexp</code>. A Scheme file is a sequence of top-level forms, so each definition is a fold, and collapsing the one you’re inside works from anywhere within it. That’s the behaviour I wanted from the start and Hideshow doesn’t guess it by default.</li>
 <li> <b>Emacs Lisp</b> — the  <code>prog-mode</code> fallback, same keys.</li>
 <li> <b>XML</b> — folds from start tag to end tag using  <code>nxml-scan-element-forward</code>, skipping  <code>&lt;?xml ?&gt;</code>, comments, DOCTYPE and self-closing elements.</li>
 <li> <b>YAML</b> (the non-Tree-sitter mode) — indentation-based blocks with a small  <code>forward-sexp</code> of my own that walks to the end of the indented block.</li>
</ul> <p>
Hideshow’s own fringe indicators ( <code>hs-show-indicators</code> +  <code>hs-indicator-type 'fringe</code>) are on in all of these, so it doesn’t feel like a downgrade from the Tree-sitter buffers.
</p>

 <p>
The rule I enforce per buffer is  <b>exactly one set of indicators</b>: Tree-sitter buffers get  <code>treesit-fold</code> and Hideshow is turned off; Hideshow buffers get Hideshow and Outline’s clickable buttons are turned off so the two don’t double up; outline-only buffers (Markdown, diff) keep the buttons. Nobody ends up with two markers per block.
</p>
</div>
 <h2>Org, which needed its own everything  <a id="org-which-needed-its-own-everything" class="anchor" href="#org-which-needed-its-own-everything" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org30fde3f">
 <p>
Org folds with text properties, not overlays, so neither Tree-sitter nor Hideshow nor Outline’s buttons can draw a marker for it. So I wrote its own indicators: a fringe triangle pointing down for an open heading, right for a folded one, clickable with  <code>mouse-1</code> to toggle exactly like  <code>TAB</code>. Folding itself is untouched —  <code>TAB</code>,  <code>S-TAB</code> and the  <code>C-c v</code> keys all still work.
</p>

 <p>
The performance part is where the real win is. A naive “redraw indicators after every command” implementation is a disaster in a large file, because it re-searches the buffer and rebuilds every overlay on every pause. Mine is driven by the text instead:
</p>

 <ul class="org-ul"> <li>if  <code>buffer-chars-modified-tick</code> didn’t change, only the indicators that are  <b>on screen</b> are redrawn — off-screen headings can wait until they’re scrolled to;</li>
 <li>if it changed and the change was recorded, only the  <b>dirty region</b> is rebuilt;</li>
 <li>if it changed with no recorded change, only then is the whole buffer rebuilt.</li>
</ul> <p>
Folding changes text properties rather than characters, so folding alone takes the cheap path. Fold state is read back from Org on each redraw rather than remembered, so external folding can never leave a stale marker.
</p>

 <p>
Two config choices matter just as much:  <code>org-fold-core-style</code> is  <code>text-properties</code> (so a visibility cycle doesn’t re-parse the file),  <code>org-element-use-cache</code> is on, and Org starts with  <code>showeverything</code> — which is both what I want (a note is read, not consulted) and the cheaper state, because it skips the visibility passes that walk every heading on open. I also removed a  <code>org-restart-font-lock</code> that was re-fontifying the whole buffer a second time on open; JIT-lock handles what’s on screen.
</p>
</div>
 <h2>It feels smooth, and that’s the whole point  <a id="it-feels-smooth-and-thatrsquos-the-whole-point" class="anchor" href="#it-feels-smooth-and-thatrsquos-the-whole-point" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org31e5cf4">
 <p>
The end result is that folding is  <i>boring</i> now.  <code>C-c v c</code> in Kotlin, Scheme, Elisp, Org, XML, YAML, Markdown. Guides that look like brackets. Indicators quiet enough to ignore until you need them. No pause on a 3000-line Org file. No two competing markers.
</p>

 <p>
It honestly changes how much I collapse and expand while reading code. I used to avoid folding because it felt fiddly; now it’s free and mouse friendly.
</p>

 <p>
If you want to read the actual code: it’s in  <a href="https://codeberg.org/jjba23/heks-emacs/src/branch/trunk/src/modules/dev-folding.el">dev-folding.el</a> for the engines and indicators, the  <code>heks/fold-*</code> wrappers in  <code>heks-emacs.el</code> for the keys, and the Org indicators live in  <code>org.el</code>. Everything is GPL-3.0, and it’s tested:  <code>maak verify</code> asserts a fold actually covers a whole definition and that the documented keys are bound, and  <code>maak keys</code> fails on a key that does two jobs or names a command that doesn’t exist.
</p>

 <p>
Happy to answer questions about any of it, especially if you’ve fought the  <code>treesit-fold-indicators</code> bitmaps yourself, because that one cost me an evening and I’d love to know if there’s a cleaner way.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/">YAML Schemas in Emacs with Eglot</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/index.html</guid>
  <pubDate>Sat, 24 Oct 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
OrgWebAlchemy is a Guile library that parses Org mode with a Parsing Expression Grammar and renders it to HTML, Markdown, or SXML. I wrote  <a href="https://jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">an earlier article</a> about why a PEG is the right tool for Org: the grammar describes the language, the parser builds a tree, the renderers turn that tree into output.
</p>

 <p>
This is the follow-up, and it turned into a harder question than I expected: how do you make a parser fast without making it wrong? I didn’t want something that’s quick on my test files and quietly behaves differently on yours.
</p>

 <p>
So: the features I added, how I measured them, what the profiler said, the two rounds of fixes, and how I checked the language didn’t change. Every number below comes with a way to reproduce it, because a number you can’t check is advertising, not evidence.
</p>

 <p>
 <b>TLDR; Here is the whole article in five sentences</b>:
</p>

 <ul class="org-ul"> <li>Parsing a 58 KB Org document now takes 5.1 ms, where it used to take 32.2 ms, a factor of 6.4.</li>
 <li>The same parse now allocates 3.9 MB, where it used to allocate 30.3 MB, 7.8 times less garbage.</li>
 <li>A document consisting of one 80 KB line went from 8.2 seconds to 0.37 milliseconds, because the old path was quadratic in the length of a line and the new one is linear.</li>
 <li>The library gained a Markdown renderer, figures, named elements, cross-references, a proper table reader and mixed nested lists, and it says plainly what it still doesn’t do.</li>
 <li>None of this was guessed: there are 155 test definitions and 281 assertions, an equivalence run compared the new parser with the previous one on about 70,000 inputs, and a test sweeps about 390,000 positions to check the scanner’s stop set.</li>
</ul> <img alt="One Org document, rendered by both renderers. " src="https://codeberg.org/jjba23/orgwebalchemy/media/branch/trunk/assets/orgwebalchemy-demo.gif"></img> <h2>Free software, and why this is a library  <a id="free-software-and-why-this-is-a-library" class="anchor" href="#free-software-and-why-this-is-a-library" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge9fbd65">
 <p>
OrgWebAlchemy is free software under the GNU Lesser General Public License, version 3 or later, with this documentation under the GNU Free Documentation License. Run it, study it, change it, ship your changed versions.
</p>

 <p>
It could have been a service instead: you send your Org file to a server you don’t control, and get HTML back. That can be convenient, and it can even be gratis, but it leaves you helpless in the ways that matter. You can’t study it, can’t fix it, and can’t keep using it when the operator loses interest or changes the terms. A library goes into your program, on your machine, under your control.
</p>

 <p>
The LGPL is a compromise, and I’ll name it as one. The GPL would keep every program that uses this code free too, and that’s the stronger guarantee for users. For libraries the GNU Project has long accepted a weaker license so that more programs can use them, including some that aren’t free, and I’ve followed that tradition. Use it in a free program and you’re helping the community; use it in a nonfree one and I’d rather you made that program free.
</p>

 <p>
There’s a second reason it’s a library. Org mode is a language, and a language is worth as much as the number of programs that can read it. A parser only Emacs can use is a parser for one program. One that any Guile program can call is a parser for a text editor, a static site generator, a wiki, a notebook, a mail archiver, a package’s docs build, or something nobody has written yet. I don’t know what you’ll build with it, and that’s the point.
</p>

 <p>
And a word on what it isn’t: it’s not Emacs and doesn’t try to be. Emacs is where Org lives, where it gets edited, and where its export machinery started. OrgWebAlchemy doesn’t replace that, it just lets other Scheme programs read the same files. When it disagrees with Emacs about some corner of the syntax, Emacs is right and this is a bug.
</p>
</div>
 <h2>What the program is now  <a id="what-the-program-is-now" class="anchor" href="#what-the-program-is-now" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org16b70e9">
 <p>
OrgWebAlchemy is still three small modules. What changed is how much of the language each one covers.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Module</th>
 <th scope="col" class="org-left">Lines</th>
 <th scope="col" class="org-left">What it owns</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>(orgwebalchemy peg)</code></td>
 <td class="org-left">1,700</td>
 <td class="org-left">the grammar, the AST, the run scanners, link classification, name resolution</td>
</tr> <tr> <td class="org-left"> <code>(orgwebalchemy html)</code></td>
 <td class="org-left">720</td>
 <td class="org-left">rendering to HTML and SXML, and every CSS class parameter</td>
</tr> <tr> <td class="org-left"> <code>(orgwebalchemy markdown)</code></td>
 <td class="org-left">430</td>
 <td class="org-left">rendering the same AST to Markdown</td>
</tr> <tr> <td class="org-left">Test suite</td>
 <td class="org-left">1,670</td>
 <td class="org-left">155 test definitions and 281 assertions, many of them table-driven</td>
</tr></tbody></table> <p>
The API is still small enough to hold in your head.
</p>

 <div class="jfw-code"> <pre>(use-modules (orgwebalchemy html)
             (orgwebalchemy markdown)
             (orgwebalchemy peg))

(org-&gt;html  <span class="org-string">&quot;This is ~test~ code.&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;This is &lt;code&gt;test&lt;/code&gt; code.&quot;
</span>
(org-&gt;markdown  <span class="org-string">&quot;This is ~test~ code.&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;This is `test` code.&quot;
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">parse once, render as often as you like
</span>( <span class="org-keyword">define</span>  <span class="org-function-name">ast</span> (org-&gt;ast  <span class="org-string">&quot;* Hello\nA *bold* line.\n&quot;</span>))
(org-ast-&gt;html ast)
(org-ast-&gt;markdown ast)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The rest of this article is about what happens between those calls.
</p>
</div>
 <h2>Teaching the parser more of Org  <a id="teaching-the-parser-more-of-org" class="anchor" href="#teaching-the-parser-more-of-org" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org583fc40">
 <p>
“Supporting Org” hides a lot of work, because Org isn’t a markup language with a tidy grammar. It’s a pile of conventions accumulated over years of a GNU Emacs major mode, some of them deliberately informal, and each one has to be considered on its own terms. Every feature below started as a sentence in the Org manual, became a grammar pattern, then became a test.
</p>
</div>
 <h3>Links: decide once, in the parser  <a id="links-decide-once-in-the-parser" class="anchor" href="#links-decide-once-in-the-parser" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5736540">
 <p>
An Org link’s target says what kind of link it is. A target starting with  <code>https://</code> is external.  <code>file:photo.png</code> is a file, and so is a bare  <code>notes.org</code>.  <code>#custom-id</code> points inside the document,  <code>*Heading</code> at a heading, and a  <code>::search</code> suffix says where inside the target you land.
</p>

 <p>
The old code let each renderer read the target and decide for itself, which is exactly how two back ends drift apart. HTML grows a special case for image extensions, Markdown grows a slightly different one, and after a year of small repairs the same document means two things depending on which function you call. A user who notices won’t know which one is right, and will be right not to trust either.
</p>

 <p>
So classification moved into the parser, where it happens once.
</p>

 <div class="jfw-code"> <pre>(org-link-parts  <span class="org-string">&quot;https://example.org/a&quot;</span>)    <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (https . &quot;//example.org/a&quot;)
</span>(org-link-parts  <span class="org-string">&quot;file:photo.png&quot;</span>)           <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (file . &quot;photo.png&quot;)
</span>(org-link-parts  <span class="org-string">&quot;notes.org&quot;</span>)                <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (file . &quot;notes.org&quot;)
</span>(org-link-parts  <span class="org-string">&quot;#custom-id&quot;</span>)               <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (internal . &quot;custom-id&quot;)
</span>(org-link-parts  <span class="org-string">&quot;*My Section&quot;</span>)              <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (heading . &quot;My Section&quot;)
</span>(org-link-parts  <span class="org-string">&quot;notes.org::*Heading&quot;</span>)      <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; (file . &quot;notes.org&quot;)
</span>(org-link-search  <span class="org-string">&quot;notes.org::*Heading&quot;</span>)     <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;*Heading&quot;
</span>(org-image-link?  <span class="org-string">&quot;photo.jpeg?raw=1&quot;</span>)        <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; #t</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Both renderers then ask the same questions and follow the same answer.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Org</th>
 <th scope="col" class="org-left">HTML</th>
 <th scope="col" class="org-left">Markdown</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>[[file:photo.png][a photo]]</code></td>
 <td class="org-left"> <code>&lt;img src=&quot;photo.png&quot; alt=&quot;a photo&quot; /&gt;</code></td>
 <td class="org-left"> <code>![a photo](photo.png)</code></td>
</tr> <tr> <td class="org-left"> <code>[[images/diagram.svg]]</code></td>
 <td class="org-left"> <code>&lt;img src=&quot;images/diagram.svg&quot; alt=&quot;...&quot; /&gt;</code></td>
 <td class="org-left"> <code>![images/diagram.svg](images/diagram.svg)</code></td>
</tr> <tr> <td class="org-left"> <code>[[file:notes.org][notes]]</code></td>
 <td class="org-left"> <code>&lt;a href=&quot;notes.org&quot;&gt;notes&lt;/a&gt;</code></td>
 <td class="org-left"> <code>[notes](notes.org)</code></td>
</tr> <tr> <td class="org-left"> <code>[[#custom-id][there]]</code></td>
 <td class="org-left"> <code>&lt;a href=&quot;#custom-id&quot;&gt;there&lt;/a&gt;</code></td>
 <td class="org-left"> <code>[there](#custom-id)</code></td>
</tr> <tr> <td class="org-left"> <code>[[*My Section][up]]</code></td>
 <td class="org-left"> <code>&lt;a href=&quot;#my-section&quot;&gt;up&lt;/a&gt;</code></td>
 <td class="org-left"> <code>[up](#my-section)</code></td>
</tr> <tr> <td class="org-left"> <code>[[https://gnu.org][GNU]]</code></td>
 <td class="org-left"> <code>&lt;a href=&quot;https://gnu.org&quot;&gt;GNU&lt;/a&gt;</code></td>
 <td class="org-left"> <code>[GNU](https://gnu.org)</code></td>
</tr></tbody></table> <p>
Two details deserve a sentence each. The  <code>::search</code> suffix is set aside before the path is used as a file name, so  <code>file:notes.org::*Heading</code> doesn’t produce a broken file name. And  <code>C:/tmp/x.txt</code> isn’t mistaken for a link with a scheme named  <code>c</code>, because a real scheme is lower case. Small stuff, but it’s the kind of small stuff that decides whether a program is pleasant to use on somebody else’s computer.
</p>
</div>
 <h3>Figures  <a id="figures" class="anchor" href="#figures" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org65a7d9a">
 <p>
Org gives the element after a  <code>#+CAPTION:</code> or  <code>#+NAME:</code> keyword a caption and a name. When that element is a link to an image, the three things are one object: a figure. The parser folds them together, so renderers get a single node instead of three neighbors they have to guess about.
</p>

 <div class="jfw-code"> <pre>(org-&gt;html  <span class="org-string">&quot;#+NAME: fig:arch\n#+CAPTION: The architecture\n[[file:diagram.png][a diagram]]\n&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;&lt;figure id=\&quot;fig:arch\&quot;&gt;&lt;img src=\&quot;diagram.png\&quot; alt=\&quot;a diagram\&quot; /&gt;&lt;figcaption&gt;The architecture&lt;/figcaption&gt;&lt;/figure&gt;&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The name the figure carries is the identifier that a  <code>[[fig:arch]]</code> link resolves to, so the cross-reference can’t break. Both facts come from one place, and one place can’t disagree with itself.
</p>

 <div class="jfw-code"> <pre>(org-&gt;html  <span class="org-string">&quot;#+NAME: fig:arch\n#+CAPTION: The arch\n[[file:a.png]]\n\nSee [[fig:arch]].\n&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;&lt;figure id=\&quot;fig:arch\&quot;&gt;...&lt;/figure&gt;&lt;p&gt;See &lt;a href=\&quot;#fig:arch\&quot;&gt;fig:arch&lt;/a&gt;.&lt;/p&gt;&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Markdown has no  <code>figure</code> element, so it gets the image, the caption as an emphasised line, and an explicit anchor for the cross-reference. What counts as a figure is deliberately narrow: the keywords must sit immediately before a paragraph holding exactly one image link and nothing else. Everything else stays a keyword line. Inventing a caption for an element this parser doesn’t caption is worse than saying nothing, because the reader would never learn that something got silently dropped.
</p>
</div>
 <h3>Named elements  <a id="named-elements" class="anchor" href="#named-elements" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orge6f915a">
 <p>
A figure is the image case of a more general rule. A  <code>#+NAME:</code> line names the element after it, and anything that renders as something a link can land on can be named: a table, a source block, a quote, a list, a separator, a paragraph.
</p>

 <div class="jfw-code"> <pre>(org-&gt;html  <span class="org-string">&quot;#+NAME: tbl:users\n| Users | 1024 |\n\nSee [[tbl:users]].\n&quot;</span>)
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=&gt; &quot;&lt;table id=\&quot;tbl:users\&quot;&gt;...&lt;/table&gt;&lt;p&gt;See &lt;a href=\&quot;#tbl:users\&quot;&gt;tbl:users&lt;/a&gt;.&lt;/p&gt;&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
HTML puts the identifier on the element itself. Markdown has nothing to hang it on, so it emits an anchor in front, same as for a figure. A bare target that matches the name of an element in the same document resolves as a cross-reference, which is why  <code>[[tbl:users]]</code> and  <code>[[notes]]</code> work. A target that already says what it is — a scheme, a  <code>file:</code> prefix, a leading  <code>#</code> or  <code>*</code>, or a  <code>::search</code> suffix — keeps the meaning it wrote.
</p>

 <p>
One asymmetry, documented rather than hidden: a  <code>#+CAPTION:</code> in front of a named table isn’t folded into it, because captions on tables aren’t rendered yet. The line stays an ordinary keyword line where the writer put it.
</p>
</div>
 <h3>Tables, read by their bars  <a id="tables-read-by-their-bars" class="anchor" href="#tables-read-by-their-bars" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org89cad25">
 <p>
Tables looked finished until I looked at the edges. What should  <code>|</code> on a line of its own be? What is  <code>| a ||</code>? What happens to a row that ends the input with no newline?
</p>

 <p>
The old pattern counted separators and made one cell for each, which meant a row with no cells could raise an error, and a row that ended the input got a phantom empty cell from the newline it didn’t have. The rewrite reads a row the way Org does: by the bars that separate the cells, where a bar closes a row when nothing but the end of the line follows it. That one rule answers all three questions.
</p>

 <ul class="org-ul"> <li>A line that is only its closing bar ( <code>|</code> on its own) is a row of  <b>one empty cell</b>, not a row with no cells.</li>
 <li> <code>| a ||</code> is a row of  <b>two cells</b>, the second of them empty, rather than a paragraph.</li>
 <li>A row that ends the input keeps exactly the cells that were written.</li>
</ul> <p>
An empty cell also keeps its column, because an empty value is now the empty string instead of the bare tag symbol that an empty  <code>(* ...)</code> match leaves behind. The difference sounds academic until it is your table.
</p>
</div>
 <h3>Lists that mix and nest  <a id="lists-that-mix-and-nest" class="anchor" href="#lists-that-mix-and-nest" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9baa3a6">
 <p>
Org lets a list change its bullet type part-way through, and it lets a nested list use a different kind from its parent. So the grammar stopped having three separate list productions and grew one.
</p>

 <div class="jfw-code"> <pre>(define-peg-pattern org-list all
                    (+ ( <span class="org-keyword">or</span> desc-item unordered-item ordered-item)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The renderers group consecutive items of the same kind into the proper element, which is what makes  <code>- outer</code> with  <code>1. nested</code> inside it come out as an unordered list containing an ordered one. Checkboxes, description items and arbitrary nesting depth follow from the same rule.
</p>
</div>
 <h3>The rest of the surface  <a id="the-rest-of-the-surface" class="anchor" href="#the-rest-of-the-surface" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5bb42fd">
 <p>
Between those features and the earlier work, the supported set is now: headings with TODO keywords, priorities and tags; paragraphs; unordered, ordered and description lists in any mixture and at any depth; checkboxes; tables with empty cells; source, example, quote, verse, center, export and comment blocks; keywords and in-buffer settings; comments; fixed-width lines; separators; footnotes, whether references, definitions or inline; bold, italic, underline, strikethrough, code, verbatim, superscript, subscript, escaped markup and forced line breaks; links with and without descriptions, bare URLs, images, figures, named elements and heading anchors.
</p>

 <p>
That’s most of what people actually write. Not all of Org, and the manual has a section listing the gaps instead of hiding them, because a library that lies about its coverage just wastes everyone’s time.
</p>
</div>
 <h2>Measuring the work  <a id="measuring-the-work" class="anchor" href="#measuring-the-work" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc8809e3">
 <p>
Before optimizing anything I wanted a benchmark that could tell me whether a change helped, and that couldn’t be fooled by the change itself.
</p>

 <p>
The benchmarks live in  <code>test/veritas/benchmark/scope.scm</code>. They use the same  <a href="https://codeberg.org/jjba23/veritas">Veritas</a> framework as the unit suite, selected by test type so they never slow down  <code>maak test</code>.
</p>

 <div class="jfw-code"> <pre> <span class="org-variable-name">VERITAS_TEST_TYPE</span>=benchmark  <span class="org-sh-escaped-newline">\</span>
guix shell -m manifest.scm -- guile -L ./src -L ./test  <span class="org-sh-escaped-newline">\</span>
  -c  <span class="org-string">'((@ (veritas runner) run-tests))'</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The suite measures five workloads and prints three tables — wall clock, allocation, and the collapse pass — formatted as Markdown, ready to paste into the manual. That last part matters: a number you have to retype by hand quietly stops being true.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Workload</th>
 <th scope="col" class="org-left">What it exercises</th>
</tr></thead> <tbody> <tr> <td class="org-left">Parse the feature fixture</td>
 <td class="org-left">every construct the parser knows, in 1.8 KB</td>
</tr> <tr> <td class="org-left">Parse README.org</td>
 <td class="org-left">a real 58 KB document with prose, tables and code blocks</td>
</tr> <tr> <td class="org-left">Render the feature fixture to HTML</td>
 <td class="org-left">parsing plus the HTML renderer</td>
</tr> <tr> <td class="org-left">Render the feature fixture to Markdown</td>
 <td class="org-left">parsing plus the Markdown renderer</td>
</tr> <tr> <td class="org-left">Parse a 50-clause inline paragraph</td>
 <td class="org-left">the inline grammar, under maximum pressure</td>
</tr></tbody></table></div>
 <h3>Five runs, keep the fastest  <a id="five-runs-keep-the-fastest" class="anchor" href="#five-runs-keep-the-fastest" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgaab1886">
 <p>
One wall clock reading on a laptop isn’t a measurement, it’s a rumor. The suite runs each workload five times and reports the fastest, on the theory that the other four got interrupted by a browser, a compiler, or the collector arriving at a bad moment.
</p>

 <p>
It’s not statistically pure and I won’t pretend it is. It’s a lower bound on the cost of the work, measured on a machine that’s also doing other things. Allocation is the stable half and stays within a few percent; wall clock moves 10–20% between sessions. Repeat it and get a different number and you’ve found the noise, not an error. Be suspicious of anyone who reports wall clock figures without it.
</p>
</div>
 <h3>Allocation, not only time  <a id="allocation-not-only-time" class="anchor" href="#allocation-not-only-time" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org817f005">
 <p>
Guile’s collector is good enough that you can write a parser allocating a megabyte per kilobyte of input and still call it fast, right up until it’s in a server serving several documents at once. So the suite measures the heap too. The heap is collected before each workload, and what’s reported is  <code>heap-total-allocated</code>: everything the workload asked for, including garbage it dropped immediately. That’s allocation pressure, the thing that triggers collections, not the memory a result keeps.
</p>

 <p>
The last column is Guile’s  <code>gc-time-taken</code>, which is collector  <b>processor</b> time. Guile sums its marker threads, so one full collection of a big heap can be reported as several times its wall clock cost on a many-core machine. Read it as how much collector work a workload causes, not as a share of the clock. Same note is in the benchmark’s docstring, because an easy-to-misread number will get misread.
</p>
</div>
 <h3>Fragments and the collapse pass  <a id="fragments-and-the-collapse-pass" class="anchor" href="#fragments-and-the-collapse-pass" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgfd1bf91">
 <p>
The last measurement in the suite is the one that eventually explained everything: how many string  <b>fragments</b> a parse hands to the pass that merges them, and how long the merging takes.
</p>

 <p>
Take a pattern written as  <code>(* (and (not-followed-by eol) peg-any))</code>, meaning “consume characters until the newline”. The compiled pattern produces one parse object and one string fragment per character. A line of  <code>n</code> characters costs  <code>n</code> one-character substrings,  <code>n</code> list cells, and a merge over all of them. On a document of short lines nobody notices; on a 45 KB line it’s the whole program.
</p>

 <p>
The fragment table made that visible with no profiling at all.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-right"></col> <col class="org-right"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Document</th>
 <th scope="col" class="org-right">Fragments handed to the collapse pass</th>
 <th scope="col" class="org-right">Collapse (ms)</th>
</tr></thead> <tbody> <tr> <td class="org-left">Feature fixture (1.8 KB)</td>
 <td class="org-right">82</td>
 <td class="org-right">0.04</td>
</tr> <tr> <td class="org-left">README.org (58 KB)</td>
 <td class="org-right">1,264</td>
 <td class="org-right">0.39</td>
</tr> <tr> <td class="org-left">Plain prose (32 KB)</td>
 <td class="org-right">400</td>
 <td class="org-right">0.22</td>
</tr> <tr> <td class="org-left">One 45 KB line</td>
 <td class="org-right">1</td>
 <td class="org-right">0.005</td>
</tr></tbody></table> <p>
The last row is the interesting one. Forty-five kilobytes of text arrive as a single fragment, because a run scanner took them in one substring instead of forty-five thousand. The README, 58 KB of input, arrives as about 1,300 fragments — roughly one per line of prose instead of one per character.
</p>
</div>
 <h2>What the profile said  <a id="what-the-profile-said" class="anchor" href="#what-the-profile-said" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org92185c8">
 <p>
Veritas profiles every benchmark with Guile’s  <code>statprof</code>, and that’s what turned a vague feeling that big files were slow into a statement about one procedure.
</p>

 <p>
I fed the old parser a document made of one 40 KB line and looked at the profile.
</p>

 <pre class="example" id="orgc68e91b">
%     cumulative   self              procedure
 97.55      1.77      1.77  list?
  0.61    115.98      0.01  ice-9/boot-9.scm:220:5:map1
  0.61      0.03      0.01  orgwebalchemy/peg.scm:339:0
  0.61      0.01      0.01  reverse
  0.00  23786.61      0.00  ice-9/peg/simplify-tree.scm:48:0:string-group
  0.00      3.56      0.00  ice-9/peg/simplify-tree.scm:65:0:string-collapse
</pre>

 <p>
97.5% of the time is inside  <code>list?</code>. Not the grammar, not the renderers, not any of my own code: one predicate, called by Guile’s own tree simplifier.
</p>

 <p>
My hypothesis was that the PEG engine was slow. The truth was a helper in  <code>(ice-9 peg simplify-tree)</code> asking  <code>(list? lst)</code> of the rest of the list at every level of its recursion, which walks the list quadratically.
</p>

 <p>
Here is the relevant part of  <code>string-group</code>.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">string-group</span> lst)
  ( <span class="org-keyword">if</span> (not (list? lst))        <span class="org-comment-delimiter">;; </span> <span class="org-comment">&lt;- O(length) at every level
</span>      lst
      ( <span class="org-keyword">if</span> (null? lst)
          '()
          ( <span class="org-keyword">let</span> ((next (string-group (cdr lst))))    <span class="org-comment-delimiter">;; </span> <span class="org-comment">non-tail recursion
</span>            ...))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
For a run of  <code>n</code> fragments that’s about  <code>n²/2</code> list steps. A line of 40,000 characters means 800 million of them, which is exactly the 1.77 seconds in the profile. Doubling the line quadruples the bill, and the measurements agree: 20 KB took about 420 ms, 40 KB about 1,760 ms.
</p>

 <p>
So there were two problems and only one was mine. My grammar produced one fragment per character, handing the quadratic pass an enormous run to chew on. And the collapse pass was quadratic in the length of a run, so even a modest run cost more than it should. Fix only the first and a slow path waits for anyone who writes a long line; fix only the second and you still allocate megabytes for nothing. Both had to go.
</p>
</div>
 <h2>The two rounds of repair  <a id="the-two-rounds-of-repair" class="anchor" href="#the-two-rounds-of-repair" aria-label="Link to this section">#</a></h2> <h3>First round: fast paths in the grammar  <a id="first-round-fast-paths-in-the-grammar" class="anchor" href="#first-round-fast-paths-in-the-grammar" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org1e3edda">
 <p>
The first round was micro-optimization of the grammar. It helped, though not where I expected.
</p>

 <p>
The scheme alternation used to be fifteen whole-string comparisons.
</p>

 <div class="jfw-code"> <pre>(define-peg-pattern url-scheme all
                    ( <span class="org-keyword">or</span>  <span class="org-string">&quot;http://&quot;</span>  <span class="org-string">&quot;https://&quot;</span>  <span class="org-string">&quot;ftp://&quot;</span>  <span class="org-string">&quot;ftps://&quot;</span>
                         <span class="org-string">&quot;file://&quot;</span>  <span class="org-string">&quot;ssh://&quot;</span>  <span class="org-string">&quot;sftp://&quot;</span>  <span class="org-string">&quot;ws://&quot;</span>  <span class="org-string">&quot;wss://&quot;</span>
                         <span class="org-string">&quot;git://&quot;</span>  <span class="org-string">&quot;gopher://&quot;</span>  <span class="org-string">&quot;tel:&quot;</span>  <span class="org-string">&quot;mailto:&quot;</span>
                         <span class="org-string">&quot;irc://&quot;</span>  <span class="org-string">&quot;ircs://&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Grouping the alternatives by first character means a position that can’t begin a scheme fails after one comparison instead of fifteen.
</p>

 <div class="jfw-code"> <pre>(define-peg-pattern url-scheme all
                    ( <span class="org-keyword">or</span> ( <span class="org-keyword">and</span>  <span class="org-string">&quot;h&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;ttps://&quot;</span>  <span class="org-string">&quot;ttp://&quot;</span>))
                        ( <span class="org-keyword">and</span>  <span class="org-string">&quot;f&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;tps://&quot;</span>  <span class="org-string">&quot;tp://&quot;</span>  <span class="org-string">&quot;ile://&quot;</span>))
                        ( <span class="org-keyword">and</span>  <span class="org-string">&quot;s&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;sh://&quot;</span>  <span class="org-string">&quot;ftp://&quot;</span>))
                        ( <span class="org-keyword">and</span>  <span class="org-string">&quot;w&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;ss://&quot;</span>  <span class="org-string">&quot;s://&quot;</span>))
                        ( <span class="org-keyword">and</span>  <span class="org-string">&quot;g&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;opher://&quot;</span>  <span class="org-string">&quot;it://&quot;</span>))
                         <span class="org-string">&quot;tel:&quot;</span>
                         <span class="org-string">&quot;mailto:&quot;</span>
                        ( <span class="org-keyword">and</span>  <span class="org-string">&quot;i&quot;</span> ( <span class="org-keyword">or</span>  <span class="org-string">&quot;rcs://&quot;</span>  <span class="org-string">&quot;rc://&quot;</span>))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The alternation of inline constructs was badly ordered too. It tried the multi-character constructs, footnotes, links and the scheme scan before the single-character markers, so a line full of  <code>*bold*</code> and  <code>/italic/</code> paid for the expensive branches first. Putting the one-character markers first and the link and URL machinery last costs nothing.
</p>

 <div class="jfw-code"> <pre>(define-peg-pattern inline-special body
                    ( <span class="org-keyword">or</span> inline-bold inline-italic inline-code inline-verbatim
                        inline-underline inline-strike
                        inline-superscript inline-subscript
                        inline-line-break inline-escape
                        inline-footnote-inline inline-footnote-def inline-footnote-ref
                        inline-link-with-desc inline-link-no-desc
                        inline-raw-url))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I also added a hand-written class for plain characters, so ordinary text gets taken with a few range tests instead of a  <code>not-followed-by</code> check against the whole inline grammar at every position.
</p>

 <p>
The result: the inline benchmark doubled, the document benchmarks improved by about a third, and  <b>the single-line case didn’t move at all</b>. That last bit was the useful part, because it said the remaining cost wasn’t in the grammar.
</p>
</div>
 <h3>Second round: run scanners  <a id="second-round-run-scanners" class="anchor" href="#second-round-run-scanners" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org30191ef">
 <p>
A compiled PEG pattern in Guile is just a procedure of  <code>(string length position)</code> returning  <code>(end . body)</code> or  <code>#f</code>. Nothing stops you writing that procedure by hand and naming it in the grammar like any other pattern. That’s the whole idea of the run scanners: find the end of the run in one C-level scan with  <code>string-index</code> and return a single substring.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">run-end</span> str len pos stop-chars stop?)
   <span class="org-doc">&quot;Return the end of the run from POS that stops at the first character
of STOP-CHARS at which STOP? holds, or at LEN.&quot;</span>
  ( <span class="org-keyword">let</span>  <span class="org-function-name">loop</span> ((i pos))
    ( <span class="org-keyword">let</span> ((candidate ( <span class="org-keyword">or</span> (string-index str stop-chars i len) len)))
      ( <span class="org-keyword">if</span> ( <span class="org-keyword">or</span> (&gt;= candidate len) (stop? str len candidate))
          candidate
          (loop (1+ candidate))))))

( <span class="org-keyword">define</span> ( <span class="org-function-name">text-run</span> str len pos stop-chars stop?)
  ( <span class="org-keyword">let</span> ((end (run-end str len pos stop-chars stop?)))
    (list end (substring str pos end))))

( <span class="org-keyword">define</span> ( <span class="org-function-name">line-text-scanner</span> str len pos)
   <span class="org-doc">&quot;Consume the rest of the line as one string.&quot;</span>
  (text-run str len pos nl-chars always-stop))

(define-peg-pattern line-content all line-text-scanner)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
There are thirteen such scanners now, one for each construct whose body is “text up to a delimiter”: a line, a table cell, a link target, a link description, a footnote body, a keyword value, the body of a source block, a description key, the body of a raw URL.
</p>

 <p>
The delicate part is the  <code>stop?</code> predicate. For a line, every newline really does end the run. For inline text, an asterisk ends the run only if  <code>inline-special</code> really matches there; otherwise it’s an asterisk in the middle of a sentence. So the scanner stops at every candidate, asks the grammar whether something begins there, and if not, continues past that character. Still one  <code>string-index</code> call per candidate, and there’s at most one candidate per markup character in a line.
</p>

 <p>
Thirteen scanners would be a maintenance problem if each had its own idea of where text ends, so the character sets live in one place, each with a comment saying who stops there.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span>  <span class="org-function-name">nl-chars</span> (char-set #\newline #\return))
( <span class="org-keyword">define</span>  <span class="org-function-name">table-stop-chars</span> (char-set #\| #\newline #\return))
( <span class="org-keyword">define</span>  <span class="org-function-name">inline-stop-chars</span>
   <span class="org-comment-delimiter">;; </span> <span class="org-comment">every character that can begin an inline construct: the markup markers,
</span>   <span class="org-comment-delimiter">;; </span> <span class="org-comment">the letters a raw URL scheme can start with, and the newline
</span>  (char-set #\* #\/ #\~ #\= #\_ #\+ #\^ #\\ #\[
            #\h #\f #\s #\w #\g #\t #\m #\i #\r
            #\newline #\return))
( <span class="org-keyword">define</span>  <span class="org-function-name">link-stop-chars</span> (char-set #\] #\newline #\return))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Second round, second part: a linear collapse pass  <a id="second-round-second-part-a-linear-collapse-pass" class="anchor" href="#second-round-second-part-a-linear-collapse-pass" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orge4198f5">
 <p>
The other half was dropping the quadratic  <code>string-collapse</code>. The library now has its own  <code>collapse-tree</code>, keeping the exact contract of Guile’s procedure: children collapsed before their parent, a maximal run of adjacent strings concatenated, a list of strings not joining the run around it, a one-element result unwrapped. The difference is that grouping happens in one pass with one  <code>reverse</code>.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">string-group-linear</span> lst)
  ( <span class="org-keyword">let</span>  <span class="org-function-name">loop</span> ((nodes lst) (run '()) (out '()))
    ( <span class="org-keyword">cond</span>
      ((null? nodes)
       (reverse ( <span class="org-keyword">if</span> (null? run) out (cons (reverse run) out))))
      ((string? (car nodes))
       (loop (cdr nodes) (cons (car nodes) run) out))
      ( <span class="org-keyword">else</span>
       (loop (cdr nodes) '()
             ( <span class="org-keyword">if</span> (null? run)
                 (cons (car nodes) out)
                 (cons (car nodes) (cons (reverse run) out))))))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Same contract, not merely a similar one, so it produces identical trees. That’s what let me prove the rewrite safe instead of hoping it was. On its own it’s about 530× faster at 32,000 fragments.
</p>
</div>
 <h2>The measurements  <a id="the-measurements" class="anchor" href="#the-measurements" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2878bfe">
 <p>
Everything below was measured in the project’s Guix shell with Guile 3.0.9, on the Ryzen 5 7640U laptop I write on, with a browser open. Five runs per workload, fastest reported. Three columns: before any optimization, after the grammar fast paths, and now.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Workload</th>
 <th scope="col" class="org-left">Before (µs)</th>
 <th scope="col" class="org-left">Fast paths (µs)</th>
 <th scope="col" class="org-left">Now (µs)</th>
 <th scope="col" class="org-left">Total speed-up</th>
</tr></thead> <tbody> <tr> <td class="org-left">Parse the feature fixture (1.8 KB)</td>
 <td class="org-left">790</td>
 <td class="org-left">590</td>
 <td class="org-left">320</td>
 <td class="org-left">2.5×</td>
</tr> <tr> <td class="org-left">Parse README.org (58 KB)</td>
 <td class="org-left">32,200</td>
 <td class="org-left">23,600</td>
 <td class="org-left">5,070</td>
 <td class="org-left">6.4×</td>
</tr> <tr> <td class="org-left">Render the fixture to HTML</td>
 <td class="org-left">3,480</td>
 <td class="org-left">2,360</td>
 <td class="org-left">1,840</td>
 <td class="org-left">1.9×</td>
</tr> <tr> <td class="org-left">Render the fixture to Markdown</td>
 <td class="org-left">3,090</td>
 <td class="org-left">2,250</td>
 <td class="org-left">1,690</td>
 <td class="org-left">1.8×</td>
</tr> <tr> <td class="org-left">Parse a 50-clause inline paragraph</td>
 <td class="org-left">6,010</td>
 <td class="org-left">3,070</td>
 <td class="org-left">2,270</td>
 <td class="org-left">2.7×</td>
</tr></tbody></table> <p>
The allocation table tells the same story from the other side.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Workload</th>
 <th scope="col" class="org-left">Before (KiB/op)</th>
 <th scope="col" class="org-left">Fast paths (KiB/op)</th>
 <th scope="col" class="org-left">Now (KiB/op)</th>
</tr></thead> <tbody> <tr> <td class="org-left">Parse the feature fixture</td>
 <td class="org-left">900</td>
 <td class="org-left">620</td>
 <td class="org-left">230</td>
</tr> <tr> <td class="org-left">Parse README.org</td>
 <td class="org-left">30,300</td>
 <td class="org-left">19,700</td>
 <td class="org-left">3,890</td>
</tr> <tr> <td class="org-left">Render the fixture to HTML</td>
 <td class="org-left">3,310</td>
 <td class="org-left">2,200</td>
 <td class="org-left">1,360</td>
</tr> <tr> <td class="org-left">Render the fixture to Markdown</td>
 <td class="org-left">3,140</td>
 <td class="org-left">2,160</td>
 <td class="org-left">1,360</td>
</tr> <tr> <td class="org-left">Parse the 50-clause inline paragraph</td>
 <td class="org-left">5,660</td>
 <td class="org-left">2,740</td>
 <td class="org-left">1,690</td>
</tr></tbody></table> <p>
Parsing the 58 KB README now allocates about 68 bytes per input byte, where it used to allocate roughly 530. That’s the difference between a parse that reliably triggers a collection of its own and one that often doesn’t.
</p>
</div>
 <h3>One long line: from eight seconds to a third of a millisecond  <a id="one-long-line-from-eight-seconds-to-a-third-of-a-millisecond" class="anchor" href="#one-long-line-from-eight-seconds-to-a-third-of-a-millisecond" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org6cdc789">
 <p>
The clearest way to see the quadratic is to hold everything else constant and grow a single line. Here’s a document whose entire content is one line of plain prose.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-right"></col> <col class="org-right"></col> <col class="org-right"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Line length</th>
 <th scope="col" class="org-right">Before (ms)</th>
 <th scope="col" class="org-right">Fast paths (ms)</th>
 <th scope="col" class="org-right">Now (ms)</th>
</tr></thead> <tbody> <tr> <td class="org-left">5 KB</td>
 <td class="org-right">26.4</td>
 <td class="org-right">26.3</td>
 <td class="org-right">0.07</td>
</tr> <tr> <td class="org-left">10 KB</td>
 <td class="org-right">109</td>
 <td class="org-right">105</td>
 <td class="org-right">0.08</td>
</tr> <tr> <td class="org-left">20 KB</td>
 <td class="org-right">423</td>
 <td class="org-right">408</td>
 <td class="org-right">0.12</td>
</tr> <tr> <td class="org-left">40 KB</td>
 <td class="org-right">1,760</td>
 <td class="org-right">1,630</td>
 <td class="org-right">0.22</td>
</tr> <tr> <td class="org-left">80 KB</td>
 <td class="org-right">8,180</td>
 <td class="org-right">7,110</td>
 <td class="org-right">0.37</td>
</tr></tbody></table> <p>
Read the first two columns: each doubling of the line multiplies the time by four. That’s a quadratic curve, and the grammar fast paths barely dented it, because per-character fragments and a quadratic merge are exactly what grammar fast paths don’t touch. Now the third column: each doubling roughly doubles the time, because  <code>string-index</code> runs at memory speed and there’s one fragment per line instead of one per character.
</p>

 <p>
At 80 KB that’s a factor of about 22,000. That’s the extreme end of the curve, though. The realistic headline is the 6.4× on the README, where the time is spread over a whole document instead of concentrated in one pathological line.
</p>
</div>
 <h3>The collapse pass on its own  <a id="the-collapse-pass-on-its-own" class="anchor" href="#the-collapse-pass-on-its-own" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgaf48d7c">
 <p>
To separate the two effects I benchmarked Guile’s  <code>string-collapse</code> against the library’s  <code>collapse-tree</code> on plain lists of string fragments, with no parser and no renderers involved.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-right"></col> <col class="org-right"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Fragments</th>
 <th scope="col" class="org-right"> <code>string-collapse</code> (ms)</th>
 <th scope="col" class="org-right"> <code>collapse-tree</code> (ms)</th>
</tr></thead> <tbody> <tr> <td class="org-left">2,000</td>
 <td class="org-right">3.8</td>
 <td class="org-right">0.09</td>
</tr> <tr> <td class="org-left">4,000</td>
 <td class="org-right">15.4</td>
 <td class="org-right">0.17</td>
</tr> <tr> <td class="org-left">8,000</td>
 <td class="org-right">58.6</td>
 <td class="org-right">0.37</td>
</tr> <tr> <td class="org-left">16,000</td>
 <td class="org-right">241</td>
 <td class="org-right">0.72</td>
</tr> <tr> <td class="org-left">32,000</td>
 <td class="org-right">1,000</td>
 <td class="org-right">1.9</td>
</tr></tbody></table> <p>
Four times per doubling on the left, two on the right. That’s the whole profile in one table.
</p>
</div>
 <h3>What the profile looks like now  <a id="what-the-profile-looks-like-now" class="anchor" href="#what-the-profile-looks-like-now" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3d4e248">
 <p>
The point of a rewrite is that the profile stops pointing at one thing. Parsing the README two hundred times now gives this.
</p>

 <pre class="example" id="org7da9688">
%     cumulative   self              procedure
 26.32      0.75      0.75  %after-gc-thunk
  8.27      0.41      0.24  string-append
  6.02      0.17      0.17  string=
  4.51      0.24      0.13  orgwebalchemy/peg.scm:99:0
  4.51      0.15      0.13  reverse
  3.76      0.15      0.11  string-group-linear
  3.01      1.43      0.09  orgwebalchemy/peg.scm:375:0
  2.26      1.86      0.06  collapse-tree
</pre>

 <p>
The biggest entry now is the collector itself, about a quarter of the time. Then the string work that building a tree implies, then the collapse pass at a few percent, then a long tail of small pattern procedures. No more 97%. Further gains have to come from allocating less, not from finding another bottleneck.
</p>
</div>
 <h2>Why you can believe the measurements  <a id="why-you-can-believe-the-measurements" class="anchor" href="#why-you-can-believe-the-measurements" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org09c8403">
 <p>
Speed is easy to claim and easy to fake, because you can make any parser faster by making it wrong. Since the work touched the scanners that decide where text ends, I needed a way to show the language hadn’t changed.
</p>
</div>
 <h3>Equivalence with the previous parser  <a id="equivalence-with-the-previous-parser" class="anchor" href="#equivalence-with-the-previous-parser" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org496bdf1">
 <p>
The test suites can’t express “the parser still does what it did before”, because they encode what it ought to do. So there’s a separate check that loads the old parser and the new one into one process — the old one under renamed modules pulled out with  <code>git show REV:src/orgwebalchemy/peg.scm</code> and its neighbors — and compares six results for every input: the document tree, the inline tree, and the HTML and Markdown each renderer writes.
</p>

 <p>
The scanner rewrite was checked this way on about 70,000 inputs. Those included every pair of interesting characters (printable ASCII, tab, newline, carriage return, the other control characters and two multi-byte characters) as documents, as inline text, and inside a link, a footnote and a description list; the README; the test fixtures; hand-written edge cases such as markup at every position, tables with empty cells and lines without a newline; and about 6,000 randomly generated documents.
</p>

 <p>
The empty-value change was checked again on about 38,000 of those inputs. It reported about 230 differences, every one of them a change I’d made on purpose. More interesting: it found no input that raised an error on the new side, where the old code raised on 21 of them, each a table row with no cells in it. That’s how a bug fix should show up — as a difference you can name and explain.
</p>

 <p>
The table change was checked on about 38,000 inputs and found 16 that parse differently. All 16 were table lines whose last bar is followed by nothing but the end of the line, which is exactly what changed.
</p>
</div>
 <h3>The stop set  <a id="the-stop-set" class="anchor" href="#the-stop-set" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org72f8620">
 <p>
A run scanner may leap over a character only if it’s sure that character can’t begin a construct. Get that set wrong by one character and the scanner silently swallows the beginning of a link or a footnote, and no equivalence test against the previous parser would catch it, because the previous parser had no scanners at all.
</p>

 <p>
So  <code>inline-stop-chars</code> is checked against the grammar itself: at every position where  <code>inline-special</code> really matches, the character that begins it must be in the set. Sweeping about 390,000 positions of the README, the fixtures, every pair of bytes and some random markup found about 6,000 constructs and no gap.
</p>
</div>
 <h3>Three deliberate differences  <a id="three-deliberate-differences" class="anchor" href="#three-deliberate-differences" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org6b2d033">
 <p>
Three differences came out of these runs, all now pinned down by tests.
</p>

 <ol class="org-ol"> <li>A run of two or more  <code>#+CAPTION:</code> or  <code>#+NAME:</code> lines before an element that isn’t a figure used to come out of the folding step in reverse order. It now keeps document order, which is what the docs always claimed and what a reader expects of anything called a sequence.</li>
 <li>The text of something empty is now the empty string, instead of the bare tag symbol an empty match leaves behind. This is what keeps an empty cell in its column, keeps a source block without a language rendering as a source block, and keeps an empty keyword, comment, fixed-width line, footnote or block in the document instead of letting it vanish.</li>
 <li>A table row is read by its bars, as described above.</li>
</ol> <p>
Everything else produces identical output, and the naming feature is an addition to the language, so it’s covered by tests rather than equivalence.
</p>
</div>
 <h3>A trap when adding tests  <a id="a-trap-when-adding-tests" class="anchor" href="#a-trap-when-adding-tests" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org181a2ff">
 <p>
One trap is worth recording, because I lost an afternoon to it. Veritas collects a test’s assertions by filtering the body for procedures, so assertions wrapped in a  <code>let</code>, a  <code>when</code> or a  <code>parameterize</code> are silently reduced to the last one. Keep every assertion at the top level of the test body, and call a helper when you need a parameterization. The tests for the class parameters show the pattern.
</p>
</div>
 <h2>What is still expensive  <a id="what-is-still-expensive" class="anchor" href="#what-is-still-expensive" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1c5c1fc">
 <p>
Honesty is part of the design, so here’s what these numbers don’t say.
</p>

 <ul class="org-ul"> <li> <b>Inline parsing is the most expensive stage per byte.</b> A 50-clause paragraph of inline markup, 4.1 KB, takes 2.3 ms, about 1.8 MB per second, against 11 MB per second for a whole document of prose. Some of that is inherent in a grammar where every position has to try the alternatives. Still, it’s the number I’d attack next.</li>
 <li> <b>Allocation is still dominated by the tree.</b> About 68 bytes of allocation per input byte, and a quarter of the parse is the collector. A cheaper node representation, or flattening parts of the tree while parsing, would buy real time.</li>
 <li> <b>There’s no incremental path.</b> A changed document is parsed from the beginning. For an editor or a live preview, that’s the feature that would matter most, and the one I most want to write.</li>
 <li> <b>The benchmarks measure this implementation on its own.</b> They don’t compare it with other Org implementations, and they don’t measure the incremental case. Both would be welcome additions.</li>
</ul></div>
 <h2>What Org has that this library does not  <a id="what-org-has-that-this-library-does-not" class="anchor" href="#what-org-has-that-this-library-does-not" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcdf4d3f">
 <p>
The manual has a “Current limitations” section so this article doesn’t have to pretend. The known gaps:
</p>

 <ul class="org-ul"> <li> <b>Captions on non-figures.</b> A  <code>#+CAPTION:</code> before a table, a source block or a block quote is still an ordinary keyword line, because those captions aren’t rendered yet. Figures are the exception, and they’re done.</li>
 <li> <b>Bare superscripts and subscripts.</b> Only the braced forms,  <code>x^{2}</code> and  <code>H_{2}O</code>, are recognized. Bare forms like  <code>x^2</code> are not, deliberately, since they can’t always be told apart from ordinary text.</li>
 <li> <b>Babel, the agenda, the export dispatcher.</b> OrgWebAlchemy is a library, not an Emacs package. It parses Org; it doesn’t execute code blocks and doesn’t hook into Org’s export machinery.</li>
 <li> <b>The long tail.</b> Org has years of conventions in it:  <code>#+ATTR_HTML</code>,  <code>#+RESULTS</code>, column width cookies, archived subtrees, custom TODO sequences read from the document, and more. Each one needs a decision about whether to parse it, render it or leave it as text, and this library would rather leave it as text than guess.</li>
</ul> <p>
If one of these gets in your way, that’s exactly the kind of report worth sending, ideally with the smallest Org snippet that shows the problem.
</p>
</div>
 <h2>Distribution  <a id="distribution" class="anchor" href="#distribution" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbb3fedb">
 <p>
A library nobody can install is a library nobody uses, so packaging caught up too.
</p>

 <ul class="org-ul"> <li> <b>Guix.</b> A self-contained package recipe is in the manual, pinned at version 1.2.1 with its hash, and the project is on its way into Guix itself as  <code>guile-orgwebalchemy</code>.</li>
 <li> <b>Nix.</b> A  <code>flake.nix</code> and a  <code>default.nix</code> build the working tree with the same derivation as the nixpkgs package, so a change that breaks one breaks the other for the same reason. They cover x86_64 and aarch64, on GNU/Linux and on Darwin.</li>
 <li> <b>Continuous integration.</b> Pushes to  <code>trunk</code> trigger a Woodpecker pipeline that submits the  <code>maak-test</code> and  <code>maak-deploy</code> tasks to  <a href="https://byggsteg.jointhefreeworld.org">Byggsteg</a>, my own CI system, itself written in Scheme.</li>
 <li> <b>Documentation.</b> The manual is the library’s README, and the API reference is generated from the docstrings in the source with  <code>guile-documenta</code>:  <a href="https://jointhefreeworld.org/api-docs/orgwebalchemy/index.html">the OrgWebAlchemy API documentation</a>.</li>
</ul></div>
 <h2>Reproduce the measurements  <a id="reproduce-the-measurements" class="anchor" href="#reproduce-the-measurements" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3870358">
 <p>
Every number here comes from the repository and from commands the manual documents. If you want to check my work:
</p>

 <div class="jfw-code"> <pre>git clone https://codeberg.org/jjba23/orgwebalchemy.git
 <span class="org-builtin">cd</span> orgwebalchemy

 <span class="org-comment-delimiter"># </span> <span class="org-comment">the unit suite
</span>guix shell -m manifest.scm -- guile -L ./src -L ./test  <span class="org-sh-escaped-newline">\</span>
  -c  <span class="org-string">'((@ (veritas runner) run-tests))'</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">the benchmarks (they print the tables above)
</span> <span class="org-variable-name">VERITAS_TEST_TYPE</span>=benchmark  <span class="org-sh-escaped-newline">\</span>
guix shell -m manifest.scm -- guile -L ./src -L ./test  <span class="org-sh-escaped-newline">\</span>
  -c  <span class="org-string">'((@ (veritas runner) run-tests))'</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Run them yourself. If your numbers differ a lot from mine, I’d like to know — a parser that’s fast on one laptop and slow on another has a wrong assumption hidden in it.
</p>
</div>
 <h2>What I take from this  <a id="what-i-take-from-this" class="anchor" href="#what-i-take-from-this" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3af6da0">
 <p>
The lesson I keep relearning here is that correctness and speed aren’t two phases of the work. Writing the scanners forced me to state exactly which characters can begin a construct, and that list is now a specification a test sweeps about 390,000 positions. The equivalence harness that showed the rewrite was safe is also the reason I dared attempt it.
</p>

 <p>
Which brings me to the larger point, the reason I care about parsing Org at all. Org mode is one of the good ideas of our time: plain text people can read and write without special software, meaning that survives the programs, grown inside a free editor where its users could extend it. Every program that can read Org makes the format a bit more useful, and a format more programs can read is one people can trust with years of their writing.
</p>

 <p>
This library is a small contribution to that. It lets a Scheme program read what you wrote in Org, render it as HTML a browser can show without running anyone else’s code, or as Markdown other tools understand — under a free license, on your machine, with source you can read. The web has no shortage of ways to take a document away from its author. I’d like to add one more way to give it back.
</p>
</div>
 <h2>Links  <a id="links" class="anchor" href="#links" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc609f62">
 <ul class="org-ul"> <li>Source code:  <a href="https://codeberg.org/jjba23/orgwebalchemy">https://codeberg.org/jjba23/orgwebalchemy</a></li>
 <li>Manual, which is the README:  <a href="https://codeberg.org/jjba23/orgwebalchemy/src/branch/trunk/README.org">https://codeberg.org/jjba23/orgwebalchemy/src/branch/trunk/README.org</a></li>
 <li>API documentation:  <a href="https://jointhefreeworld.org/api-docs/orgwebalchemy/index.html">https://jointhefreeworld.org/api-docs/orgwebalchemy/index.html</a></li>
 <li>Issue tracker:  <a href="https://codeberg.org/jjba23/orgwebalchemy/issues">https://codeberg.org/jjba23/orgwebalchemy/issues</a></li>
 <li>The earlier article on the PEG approach:  <a href="https://jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML</a></li>
 <li>Veritas, the test framework:  <a href="https://codeberg.org/jjba23/veritas">https://codeberg.org/jjba23/veritas</a></li>
 <li>Programs that use it:  <a href="https://codeberg.org/jjba23/lucidplan">LucidPlan</a> and  <a href="https://codeberg.org/jjba23/wikimusic">WikiMusic</a></li>
</ul> <p>
If you build something with OrgWebAlchemy, send a link — it’s always good to see where the library travels. And if this is worth supporting, you can  <a href="https://bmc.link/jjbigorra">buy me a cup of coffee ☕</a> so I can keep at it.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Where hexagonal architecture shines, and what to reach for instead</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Emacs finally folds to my liking</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/">The FREE stack - My Tech Radar</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/index.html</guid>
  <pubDate>Sat, 24 Oct 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Where hexagonal architecture shines, and what to reach for instead</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Ports and adapters, also called  <i>hexagonal architecture</i>, is the pattern I reach for when a system has rules worth protecting, and the pattern I refuse when it has none. This article is the map between those two cases.
</p>

 <p>
If you have read  <a href="/https/jointhefreeworld.org/blog/articles/development/hexagon-of-doom/index.html">Hexagon of Doom</a>, you know the other half of the argument: on a small service with a thin domain, the hexagon is pure indirection, and the indirection costs more than the boundary buys. On the tech radar, ports and adapters now sits in  <b>Adopt</b>, with exactly that qualification in its note: the boundary earns its keep wherever the domain is the complicated part.
</p>

 <p>
Both statements are true at once, and the whole skill is telling which one describes the code in front of you. Read “hexagonal” as a shortening of “hex-a-GO-nal”, and “ports and adapters” as plain English: the domain declares what it needs, and the outside world supplies it.
</p>
 <h2>The one thing the pattern actually requires  <a id="the-one-thing-the-pattern-actually-requires" class="anchor" href="#the-one-thing-the-pattern-actually-requires" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1a19955">
 <p>
A  <b>port</b> is an interface, owned by the domain, written in the domain’s own words. A  <b>adapter</b> is the code outside the domain that satisfies it: a database, an HTTP client, a clock, a message queue, a filesystem. That is the entire pattern. Folders, layers and names like  <code>infrastructure/ports/out/</code> are decoration on top of one rule:
</p>

 <blockquote>
 <p>
The domain must not depend on the world. The world depends on the domain.
</p>
</blockquote>

 <p>
Everything the pattern buys follows from that rule, and nothing else does. The tests you gain are free of I/O because the domain never asked for I/O; the swap you gain is cheap because a swap is one function call in one place; the framework upgrade that does not touch your rules is quiet for the same reason.
</p>

 <p>
The deeper benefit, and the one people forget to mention, is  <b>thinking</b>: a port is a sentence about what the domain needs. Writing that sentence out loud is often worth more than the code underneath it, because it forces you to notice that a “payment service” was really a price lookup plus a ledger entry.
</p>
</div>
 <h2>Four questions that decide it  <a id="four-questions-that-decide-it" class="anchor" href="#four-questions-that-decide-it" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7f06cb3">
 <p>
Before you draw a hexagon, answer these. They are the same questions I use on the radar, and they are honest about the answer “no”.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Question</th>
 <th scope="col" class="org-left">If the answer is yes</th>
 <th scope="col" class="org-left">If the answer is no</th>
</tr></thead> <tbody> <tr> <td class="org-left">Is the domain the complicated part?</td>
 <td class="org-left">the boundary protects something worth it</td>
 <td class="org-left">you are protecting an empty room</td>
</tr> <tr> <td class="org-left">Will there be more than one adapter, for real?</td>
 <td class="org-left">the seam pays on the second adapter</td>
 <td class="org-left">you built a seam for one implementation</td>
</tr> <tr> <td class="org-left">Must the rules run without I/O?</td>
 <td class="org-left">the port is the only way to test them</td>
 <td class="org-left">the test will hit the database anyway</td>
</tr> <tr> <td class="org-left">Will the domain outlive this framework?</td>
 <td class="org-left">the boundary is the insurance, and cheap</td>
 <td class="org-left">the framework is the system, and you know it</td>
</tr></tbody></table> <p>
The last one is the question I care about most, and the one that is hardest to answer honestly on a Monday morning. A rule about how invoices are priced will outlive any framework you name. A controller that validates a form will not.
</p>
</div>
 <h2>Kotlin and Spring: the pattern as the framework intended  <a id="kotlin-and-spring-the-pattern-as-the-framework-intended" class="anchor" href="#kotlin-and-spring-the-pattern-as-the-framework-intended" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org18c2933">
 <p>
Kotlin is a lovely language for ports, because an interface with one method is a sentence, and Spring already does dependency injection well. The port is an interface; the domain service takes one as a constructor parameter; the adapter wears the annotation.
</p>

 <div class="jfw-code"> <pre> <span class="org-keyword">typealias</span>  <span class="org-type">Sku</span> =  <span class="org-type">String</span>
 <span class="org-keyword">typealias</span>  <span class="org-type">Cents</span> =  <span class="org-type">Int</span>

 <span class="org-keyword">data</span>  <span class="org-keyword">class</span>  <span class="org-type">Line</span>( <span class="org-keyword">val</span>  <span class="org-variable-name">sku</span>:  <span class="org-type">Sku</span>,  <span class="org-keyword">val</span>  <span class="org-variable-name">quantity</span>:  <span class="org-type">Int</span>)

 <span class="org-comment-delimiter">// </span> <span class="org-comment">The port: the domain's own interface, in the domain's own words.
</span> <span class="org-keyword">interface</span>  <span class="org-type">Catalogue</span> {
     <span class="org-keyword">fun</span>  <span class="org-function-name">priceOf</span>(sku:  <span class="org-type">Sku</span>):  <span class="org-type">Cents</span>
}

 <span class="org-comment-delimiter">// </span> <span class="org-comment">The rule, in the only place it is allowed to live.
</span> <span class="org-keyword">class</span>  <span class="org-type">QuoteService</span>( <span class="org-keyword">private</span>  <span class="org-keyword">val</span>  <span class="org-variable-name">catalogue</span>:  <span class="org-type">Catalogue</span>) {
     <span class="org-keyword">fun</span>  <span class="org-function-name">total</span>(lines:  <span class="org-type">List&lt;Line&gt;</span>):  <span class="org-type">Cents</span> =
        lines.sumOf { line -&gt; catalogue.priceOf(line.sku) * line.quantity }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The adapter is the only Spring-aware part, and it should be the only part that imports the framework at all:
</p>

 <div class="jfw-code"> <pre>@ <span class="org-type">Repository</span>
 <span class="org-keyword">class</span>  <span class="org-type">JdbcCatalogue</span>( <span class="org-keyword">private</span>  <span class="org-keyword">val</span>  <span class="org-variable-name">jdbc</span>:  <span class="org-type">JdbcTemplate</span>) :  <span class="org-type">Catalogue</span> {
     <span class="org-keyword">override</span>  <span class="org-keyword">fun</span>  <span class="org-function-name">priceOf</span>(sku:  <span class="org-type">Sku</span>):  <span class="org-type">Cents</span> =
        jdbc.queryForObject(
             <span class="org-string">&quot;select price from product where sku = ?&quot;</span>,  <span class="org-type">Int</span>:: <span class="org-keyword">class</span>.java, sku,
        ) ?: error( <span class="org-string">&quot;unknown sku: </span> <span class="org-variable-name">$sku</span> <span class="org-string">&quot;</span>)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Two things are worth saying about this. First, Kotlin’s own tools are enough to express the port: an interface, a class, a function type. Where the port has exactly one method, a function type is often better than an interface, because a lambda is the cheapest adapter in the world.
</p>

 <p>
Second, and this is the  <b>tell</b> I look for in a review: if an annotation from the framework appears inside the domain, there is no hexagon, whatever the folder names say. A  <code>@Transactional</code> on a domain method, a  <code>@Entity</code> on an aggregate, a  <code>@Component</code> on a service that holds a rule: each one welds the domain to Spring, and the boundary you paid for is gone. Spring’s convenience is not the same thing as an architecture.
</p>
</div>
 <h3>Where Spring’s own DI is already enough  <a id="where-springrsquos-own-di-is-already-enough" class="anchor" href="#where-springrsquos-own-di-is-already-enough" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd6dccb7">
 <p>
Spring wires your objects, and that is genuinely most of what a small application needs. If the “domain” is a controller calling two repositories and assembling a response, ports add a second indirection on top of the container, and the container was already the seam. That is the Hexagon of Doom case, in Kotlin, and it is more common than anyone admits.
</p>
</div>
 <h2>Guile Scheme: the same shape with none of the ceremony  <a id="guile-scheme-the-same-shape-with-none-of-the-ceremony" class="anchor" href="#guile-scheme-the-same-shape-with-none-of-the-ceremony" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga0e4228">
 <p>
In Scheme you do not need a container to invert a dependency. A port is a record of procedures, the composition root is a function, and the wiring happens in one place that a human being can read in ten seconds. Here is the same shop domain, with the module boundary carrying the architecture:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">The domain, and the port it declares.  Nothing here knows that a
</span> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">database, a web server or a clock exists.
</span>( <span class="org-keyword">define-module</span> ( <span class="org-type">shop</span> domain pricing)
   <span class="org-builtin">#:declarative?</span> #t
   <span class="org-builtin">#:use-module</span> (srfi srfi-1)
   <span class="org-builtin">#:use-module</span> (srfi srfi-9)
   <span class="org-builtin">#:export</span> (make-catalogue catalogue? catalogue-price quote-total))

 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">A catalogue is not a class: it is a record holding one procedure,
</span> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">from a SKU to a price in cents.  This is the port.
</span>( <span class="org-keyword">define-record-type</span>  <span class="org-type">&lt;catalogue&gt;</span>
  (make-catalogue price-of) catalogue?
  (price-of catalogue-price-of))

( <span class="org-keyword">define</span> ( <span class="org-function-name">catalogue-price</span> catalogue sku)
  ((catalogue-price-of catalogue) sku))

 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">The rule of the domain, in the only place it is allowed to live.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">quote-total</span> catalogue lines)
   <span class="org-doc">&quot;Return the total in cents of LINES, a list of (SKU . QUANTITY).&quot;</span>
  (fold ( <span class="org-keyword">lambda</span> (line total)
          (+ total (* (catalogue-price catalogue (car line)) (cdr line))))
        0
        lines))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
An adapter is a function that returns one of those records, and it is impossible to tell a clever adapter from a boring one:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">shop</span> adapters catalogue)
   <span class="org-builtin">#:declarative?</span> #t
   <span class="org-builtin">#:use-module</span> (shop domain pricing)
   <span class="org-builtin">#:export</span> (fixed-catalogue alist-catalogue))

 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">For tests and for the REPL: prices known in advance.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">fixed-catalogue</span> prices)
  (make-catalogue ( <span class="org-keyword">lambda</span> (sku)
                    ( <span class="org-keyword">or</span> (assoc-ref prices sku)
                        (error  <span class="org-string">&quot;unknown sku&quot;</span> sku)))))

 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">For development: a price list held in memory.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">alist-catalogue</span> rows)
  (make-catalogue ( <span class="org-keyword">lambda</span> (sku)
                    ( <span class="org-keyword">or</span> (assoc-ref rows sku)
                        (error  <span class="org-string">&quot;unknown sku&quot;</span> sku)))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The composition root names the adapter, and it is the only place that does:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">main</span>)
  ( <span class="org-keyword">let</span> ((catalogue (alist-catalogue '(( <span class="org-string">&quot;tea&quot;</span> . 650) ( <span class="org-string">&quot;pot&quot;</span> . 2400)))))
    (format #t  <span class="org-string">&quot;total: ~a cents~%&quot;</span>
            (quote-total catalogue '(( <span class="org-string">&quot;tea&quot;</span> . 2) ( <span class="org-string">&quot;pot&quot;</span> . 1))))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Running it shows the arithmetic, and nothing else:
</p>

 <pre class="example" id="org2863ba2">
total: 3700 cents
</pre>

 <p>
And the test needs no mocking framework, because a catalogue that returns fixed prices  <b>is</b> a catalogue:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">test-quote-total</span>)
  ( <span class="org-keyword">let</span> ((catalogue (fixed-catalogue '(( <span class="org-string">&quot;tea&quot;</span> . 100) ( <span class="org-string">&quot;pot&quot;</span> . 500)))))
    ( <span class="org-keyword">unless</span> (= 700 (quote-total catalogue '(( <span class="org-string">&quot;tea&quot;</span> . 2) ( <span class="org-string">&quot;pot&quot;</span> . 1))))
      (error  <span class="org-string">&quot;quote-total is wrong&quot;</span>)))
  (display  <span class="org-string">&quot;quote-total: ok\n&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <pre class="example" id="org6441f37">
quote-total: ok
</pre>

 <p>
This is why I keep coming back to Lisp for this pattern. The indirection tax that makes the hexagon expensive in Java-shaped code does not exist here: a port is data, an adapter is a closure, and the REPL lets you replace the adapter while the system runs and ask the domain what it thinks. LucidPlan and Byggsteg both put the data layer behind exactly this kind of seam, and I  <a href="/https/jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/index.html">wrote about the repository eDSL</a> that makes the SQLite adapter one  <code>define-repo-method</code> long.
</p>

 <p>
The one discipline Lisp demands is the discipline no compiler will give you: nothing stops you from calling  <code>sqlite3</code> inside the domain module. The protection is your module header, and a reviewer who reads it.
</p>
</div>
 <h2>Haskell: the port is a value, and the types keep the promise  <a id="haskell-the-port-is-a-value-and-the-types-keep-the-promise" class="anchor" href="#haskell-the-port-is-a-value-and-the-types-keep-the-promise" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd5d8669">
 <p>
Haskell gives you the same record-of-functions port, except the compiler now checks the sentence you wrote:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">type</span>  <span class="org-haskell-type">Sku</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-type">String</span>
 <span class="org-haskell-keyword">type</span>  <span class="org-haskell-type">Cents</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-type">Integer</span>

 <span class="org-comment-delimiter">-- </span> <span class="org-comment">The port: a record of functions.  Nothing about a database here.
</span> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">Catalogue</span> m  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Catalogue</span> { priceOf  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Sku</span>  <span class="org-haskell-operator">-&gt;</span> m  <span class="org-haskell-type">Cents</span> }

 <span class="org-comment-delimiter">-- </span> <span class="org-comment">The rule, and the only place it is allowed to live.
</span> <span class="org-haskell-definition">quoteTotal</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Monad</span> m  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Catalogue</span> m  <span class="org-haskell-operator">-&gt;</span> [( <span class="org-haskell-type">Sku</span>,  <span class="org-haskell-type">Int</span>)]  <span class="org-haskell-operator">-&gt;</span> m  <span class="org-haskell-type">Cents</span>
 <span class="org-haskell-definition">quoteTotal</span> catalogue lines  <span class="org-haskell-operator">=</span>
  sum  <span class="org-haskell-operator">&lt;$&gt;</span> traverse ( <span class="org-haskell-operator">\</span>(sku, qty)  <span class="org-haskell-operator">-&gt;</span> ( <span class="org-haskell-operator">*</span> qty)  <span class="org-haskell-operator">&lt;$&gt;</span> priceOf catalogue sku) lines</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now look at the type of  <code>quoteTotal</code>. It says the function needs a catalogue and a monad, and it says nothing about a database handle, a connection pool or a logger, because it does not have one. In a language where effects are visible in the type, that is not a comment about your intent: it is a fact about the program.
</p>

 <p>
The usual alternative is a type class ( <code>class Catalogue m where priceOf :: Sku -&gt; m Cents</code>), which reads even better at the call site and is how a lot of production Haskell is written. It has one trap worth naming: a type class with a single instance for the whole program quietly says “everything in this monad may talk to the database”, and blessing all of  <code>IO</code> is not the same as handing one component the capability it needs. When I want the boundary to be real, I pass the record.
</p>
</div>
 <h2>Domain-driven design is the part that actually pays  <a id="domain-driven-design-is-the-part-that-actually-pays" class="anchor" href="#domain-driven-design-is-the-part-that-actually-pays" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6c52552">
 <p>
If you remember one thing from this article, remember this: the abstraction that pays for itself is almost never the architecture, it is the  <b>model</b>. Ubiquitous language, aggregates with real invariants, a repository that behaves like a collection of domain objects, domain events where the business already speaks in events. Do that well and the ports fall out almost as a side effect, because a good model has an obvious boundary.
</p>

 <p>
The Repository pattern deserves its own paragraph here, because it is my favourite and the most misused. A repository is not a DAO with a nicer name. It exists so that the domain can say “give me the aggregate with this identity, save this aggregate, forget it” and stay ignorant of SQL, of tables and of the shape of rows. The scheme repository eDSL I linked above does precisely this: one record per repository, one procedure per operation, and the concrete implementation living in a module the domain never imports.
</p>

 <p>
The failure mode is DDD vocabulary without DDD discipline: folders named  <code>domain/</code>, entities that are bags of setters, an “aggregate” with no invariant, a “value object” that is a  <code>String</code>. That is ceremony, and ceremony is what makes people write articles called Hexagon of Doom. If your model is anemic, no boundary will save it: anemic models are exactly the case where the hexagon has nothing to protect and the indirection is pure cost.
</p>
</div>
 <h2>The tiny microservice: here, KISS wins  <a id="the-tiny-microservice-here-kiss-wins" class="anchor" href="#the-tiny-microservice-here-kiss-wins" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf694c86">
 <p>
A service that receives a request, validates it, calls two other services and writes one row does not have a domain. It has a  <b>flow</b>. Drawing a hexagon around a flow costs you four files per change, a debugging session that crosses three layers, and an onboarding document nobody reads. I have written that code, and I have deleted it again.
</p>

 <p>
The signs that you are in this case, all at once:
</p>

 <ul class="org-ul"> <li>the rules fit in one function, and that function is under twenty lines;</li>
 <li>there is exactly one adapter per port, and there will be exactly one for the foreseeable future;</li>
 <li>the tests are about wiring, not about behaviour;</li>
 <li>a change to a business rule touches the port, the adapter and the wiring before it touches the rule.</li>
</ul> <p>
When you see that, collapse the layers. Keep the naming good, keep the validation at the edge where the untrusted data is, and give the domain to the framework’s own mechanisms. The whole point of KISS is not to be lazy; it is to spend your complexity budget on the part of the system that is genuinely hard.
</p>
</div>
 <h2>MVC still wins where the application is a conversation about pages  <a id="mvc-still-wins-where-the-application-is-a-conversation-about-pages" class="anchor" href="#mvc-still-wins-where-the-application-is-a-conversation-about-pages" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org098f927">
 <p>
Now the part I find myself defending most often, because MVC has become unfashionable while quietly remaining the best fit for a large class of programs: content sites, admin tools, internal CRUD applications, anything where the user’s interaction is “ask for a page, get a page”.
</p>

 <p>
MVC and hexagonal are not rivals. Look at MVC honestly and you find the same dependency arrows: the controller is an adapter for the transport, the view is an adapter for presentation, and the model is the domain. The difference is the  <b>cut</b>: MVC slices the system by the request lifecycle, which is exactly the axis along which a page-serving application is understood.
</p>

 <p>
My favourite implementation of that cut is  <a href="https://artanis.dev/">GNU Artanis</a> with SXML and the repository pattern, and this is the stack I reach for by default:
</p>

 <ul class="org-ul"> <li> <b>The route is the controller.</b> Artanis hands the handler a request context, and the handler asks the repository for the model it needs.</li>
 <li> <b>The view is data.</b> SXML is a list, so a page is a value. Artanis renders either a template file or an S-expression through the same  <code>tpl-&gt;html</code>, which means a view can be a function, a fragment or a file, and there is no template language to learn beyond parentheses.</li>
 <li> <b>The repository is the door to the database.</b> The SQLite implementation stays in its own module, behind the same eDSL as the rest of my projects.</li>
</ul> <p>
A route in that shape is short enough to read out loud:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;; </span> <span class="org-comment">The route is the controller.  tpl-&gt;html takes either a template file
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">or an S-expression, and here the view is a value.
</span>(get  <span class="org-string">&quot;/jobs/:id&quot;</span>
  ( <span class="org-keyword">lambda</span> (rc)
    ( <span class="org-keyword">let</span> ((job (job-repo-find rc (params rc  <span class="org-string">&quot;id&quot;</span>))))
      (tpl-&gt;html `(section (@ (class  <span class="org-string">&quot;job&quot;</span>))
                           (h1 ,(job-ref job))
                           (pre ,(job-command job)))))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Rendering is the same primitive Guile ships, which is why I can show you the output instead of promising it:
</p>

 <div class="jfw-code"> <pre>(use-modules (sxml simple))
(sxml-&gt;xml `(section (@ (class  <span class="org-string">&quot;order&quot;</span>))
                     (h2  <span class="org-string">&quot;order-1&quot;</span>)
                     (p  <span class="org-string">&quot;total: &quot;</span> ,total  <span class="org-string">&quot; cents&quot;</span>)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <pre class="example" id="org01e2b43">
&lt;section class=&quot;order&quot;&gt;&lt;h2&gt;order-1&lt;/h2&gt;&lt;p&gt;total: 1300 cents&lt;/p&gt;&lt;/section&gt;
</pre>

 <p>
Why this still beats a browser application with a client-side framework for such a site:
</p>

 <ul class="org-ul"> <li> <b>One source of truth for state.</b> There is no client-side copy of the model to synchronize, so there is no class of bug where the two copies disagree.</li>
 <li> <b>The browser does what it is good at.</b> Links, forms, back button, bookmarks, printing and a page that works when the JavaScript does not arrive.</li>
 <li> <b>The whole stack is one language and one process.</b> A stack trace goes from the route to the SQL without crossing a serialization boundary, and the same repository code serves the views and the jobs.</li>
 <li> <b>HTML is data.</b> SXML means the view can be composed, tested and refactored like any other function, without a template engine that cannot be debugged.</li>
</ul> <p>
MVC fails when the interaction becomes a  <b>conversation about state</b> rather than a request for a page: a drag-and-drop editor, a live dashboard, a collaborative document. There the client is the application, and pretending otherwise is how you end up with a page reload per keystroke. Know which of the two you are building, and pick accordingly: that is the whole decision.
</p>
</div>
 <h2>CQRS, when it is interesting  <a id="cqrs-when-it-is-interesting" class="anchor" href="#cqrs-when-it-is-interesting" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org59dbe1d">
 <p>
Command Query Responsibility Segregation, pronounced in full whenever you have to justify it, is the idea that writing and reading are different jobs, and that the write side should record  <b>facts</b> while the read side derives whatever shape the reader wants.
</p>

 <p>
I like to show it in its smallest honest form, with no framework at all:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">The write side records facts.  It does not maintain a table, and it
</span> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">does not know what anybody will read.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">record-order-placed</span> log order total)
   <span class="org-doc">&quot;Return LOG with one more fact: ORDER was placed for TOTAL cents.&quot;</span>
  (cons `(order-placed ,order ,total) log))

( <span class="org-keyword">define</span> ( <span class="org-function-name">record-order-refunded</span> log order amount)
   <span class="org-doc">&quot;Return LOG with one more fact: AMOUNT cents were refunded on ORDER.&quot;</span>
  (cons `(order-refunded ,order ,amount) log))

 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">The read side is a fold over the facts.  It holds no state of its
</span> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">own, so it can be thrown away and rebuilt whenever you ask.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">order-summary</span> log)
  (fold ( <span class="org-keyword">lambda</span> (event summary)
          ( <span class="org-keyword">cond</span>
           (( <span class="org-keyword">and</span> (pair? event) (eq? 'order-placed (car event)))
            (put-summary summary (cadr event) (caddr event)))
           (( <span class="org-keyword">and</span> (pair? event) (eq? 'order-refunded (car event)))
            (put-summary summary (cadr event) (- (caddr event))))
           ( <span class="org-keyword">else</span> summary)))
        '()
        (reverse log)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Three facts in, one derived summary out:
</p>

 <pre class="example" id="orge2ebe09">
facts in the log: 3
read model: ((order-2 . 3700) (order-1 . 500))
</pre>

 <p>
That is CQRS in twenty lines: the write side appends facts, the read side folds them. The interesting part is not the code, it is the  <b>freedom</b>: a new question about orders is a new fold over the same facts, without touching the write model or migrating anything.
</p>

 <p>
CQRS earns its keep when at least one of these is true:
</p>

 <ul class="org-ul"> <li>the read side needs several shapes of the same data, and each shape would otherwise be a query with six joins;</li>
 <li>reads and writes have different load profiles, so they want to scale apart;</li>
 <li>the history matters as much as the current state, for audit, for replay, or for the business itself;</li>
 <li>the same facts feed more than one consumer: a screen, a report, a search index, an email digest.</li>
</ul> <p>
It becomes a bill you cannot pay when there is one read shape, one table and one transaction, because now you own two models and the eventual consistency between them, and the only thing you bought is typing. The tell is a projection that exists to reproduce a  <code>SELECT</code> you could have written in an afternoon.
</p>
</div>
 <h3>The two gotchas  <a id="the-two-gotchas" class="anchor" href="#the-two-gotchas" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org7a25e89">
 <p>
Two failures I have seen more than once, so you can recognize them earlier than I did:
</p>

 <ul class="org-ul"> <li> <b>Two models, one transaction, no story.</b> CQRS is not free consistency. If your projection must be updated in the same transaction as the write, you have not separated anything; you have renamed it.</li>
 <li> <b>Events as a data dump.</b> A fact should be written in the language of the business: “order placed”, “refund issued”. An event that carries a whole table row is a change log wearing a domain’s clothes, and it will break the first time you refactor the schema.</li>
</ul></div>
 <h2>Choosing, in one table  <a id="choosing-in-one-table" class="anchor" href="#choosing-in-one-table" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9226626">
 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Situation</th>
 <th scope="col" class="org-left">Reach for</th>
 <th scope="col" class="org-left">Because</th>
</tr></thead> <tbody> <tr> <td class="org-left">Rules are the hard part, several adapters are real</td>
 <td class="org-left">ports and adapters</td>
 <td class="org-left">the boundary protects the expensive part</td>
</tr> <tr> <td class="org-left">A flow: validate, call two services, write a row</td>
 <td class="org-left">the framework, plainly</td>
 <td class="org-left">there is no domain to protect</td>
</tr> <tr> <td class="org-left">Pages asked for by a user, database behind them</td>
 <td class="org-left">MVC, a repository, server-rendered views</td>
 <td class="org-left">the request lifecycle is the natural cut</td>
</tr> <tr> <td class="org-left">Several read shapes over the same facts</td>
 <td class="org-left">CQRS, with a projection</td>
 <td class="org-left">each question becomes a fold, not a migration</td>
</tr> <tr> <td class="org-left">A model you cannot explain to a colleague</td>
 <td class="org-left">domain-driven design, before any architecture</td>
 <td class="org-left">the model is the abstraction that pays</td>
</tr> <tr> <td class="org-left">A framework you might leave in two years</td>
 <td class="org-left">a port at that seam, and only there</td>
 <td class="org-left">insurance is cheap when it is bought in one place</td>
</tr></tbody></table> <p>
The rows are not exclusive. My own projects use MVC at the edge, repositories for the data layer, ports where a real second implementation exists, and a fold wherever history is more useful than state. The radar entry and this table say the same thing, and they will keep saying it: match the pattern to the complexity you actually have, and be honest about which part of your system is complicated.
</p>

 <p>
If you take one habit away from all of this, take  <a href="/https/jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/index.html">the repository as a seam</a> and the question “what would I have to change to satisfy this port a second time?”. If the answer is “one file”, you have an architecture. If the answer is “everything”, you have a folder structure.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/">The FREE stack - My Tech Radar</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/index.html</guid>
  <pubDate>Tue, 13 Oct 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Hi everyone. In this blog post I want to take you in an adventure of parsing Org mode with Parsing Expression Grammars (PEG) in Guile Scheme  <code>(ice-9 peg)</code> and converting to HTML (via SXML): OrgWebAlchemy.
</p>

 <p>
I wanted to share something with you all that I’ve been working on for a while. It all started with some naive regular expressions to parse Org mode content, but I pretty quickly realized I needed something smarter than that to get to where I want to. It’s taken a while but I am finally more knowledgeable of what Parsing Expression Grammars can do, thanks to GNU’s great  <code>(ice-9 peg)</code> module and tutorials.
</p>

 <p>
I thought it might be interesting to people here who enjoy Lisp, Scheme, parsing, Org mode, or the general idea of meta-meta-meta-programming as I like to call it. Disclosure, AI has helped me get a grip of PEG and debug some things, but development of OrgWebAlchemy is “my own spaghetti” and the unit tests and manual verification (and lots of pretty printing the AST) has guided me towards quite a nice implementation (if I may say so myself).
</p>

 <p>
 <b>Project’s source code</b> @ Codeberg:  <a href="https://codeberg.org/jjba23/orgwebalchemy">https://codeberg.org/jjba23/orgwebalchemy</a>
</p>

 <p>
OrgWebAlchemy is a Guile Scheme library for parsing Org-mode documents into an AST and rendering them to HTML. My main use-case is to export Org to HTML without needing Emacs, and to integrate this feature into some projects of mine, allowing me to write Org mode and have it pretty rendered.
</p>

 <p>
The basic idea is pretty simple:
</p>

 <div class="jfw-code"> <pre>(use-modules (orgwebalchemy html))

(org-&gt;html  <span class="org-string">&quot;This is ~test~ code.&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
becomes something like:
</p>

 <div class="jfw-code"> <pre>This is &lt; <span class="org-function-name">code</span>&gt;test&lt;/ <span class="org-function-name">code</span>&gt; code.</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
But the interesting part is what happens in between.
</p>

 <blockquote>
 <p>
Org document
</p>
 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <tbody> <tr></tr></tbody></table> <p>
        v
Parsing Expression
    Grammar
</p>
 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <tbody> <tr></tr></tbody></table> <p>
  v
AST
</p>
 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <tbody> <tr></tr></tbody></table> <p>
     v
SXML -&gt; HTML
</p>
</blockquote>

 <p>
See here an example showing how OrgWebAlchemy enables the LucidPlan project to render pretty Org mode to HTML
</p>


 <div id="org3685b84" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/orgwebalchemy/screen-2026-09-24-11-21-12.png"></img></p>
</div>


 <div id="orgeca428a" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/orgwebalchemy/screen-2026-09-24-11-21-23.png"></img></p>
</div>

 <hr></hr> <h2>More resources  <a id="more-resources" class="anchor" href="#more-resources" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1328f42">
 <ul class="org-ul"> <li>See wikipedia page on PEG:  <a href="https://en.wikipedia.org/wiki/Parsing_expression_grammar">https://en.wikipedia.org/wiki/Parsing_expression_grammar</a></li>
 <li>See the tutorial by GNU/for Emacs Lisp (is also a good learning source):  <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-Expression-Grammars.html">https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-Expression-Grammars.html</a></li>
 <li>See the tutorial by GNU/for Guile:  <a href="https://doc.guix.gnu.org/guile/3.0.9/en/html_node/PEG-Parsing.html">https://doc.guix.gnu.org/guile/3.0.9/en/html_node/PEG-Parsing.html</a></li>
</ul> <hr></hr></div>
 <h2>PEG vs. a mountain of regexes?  <a id="peg-vs-a-mountain-of-regexes" class="anchor" href="#peg-vs-a-mountain-of-regexes" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd16ca97">
 <p>
Org-mode looks simple until you actually try to parse it. Headings are easy. A paragraph is easy. A list is easy (wait actually no, this has made me sweat).
</p>

 <p>
And then suddenly you have:
</p>

 <ul class="org-ul"> <li>nested lists</li>
 <li>ordered, unordered and description lists</li>
 <li>different indentation levels</li>
 <li>inline markup</li>
 <li>links containing descriptions</li>
 <li>source blocks</li>
 <li>example blocks</li>
 <li>quote blocks</li>
 <li>tables</li>
 <li>escaping</li>
 <li>constructs which must stop consuming input at exactly the right place</li>
</ul> <p>
At this point, the usual approach of adding another regular expression starts to become somewhat… adventurous. :-)
</p>

 <p>
You end up with things like:
</p>

 <blockquote>
 <p>
match this,
unless that follows it,
except inside this block,
unless it is a description,
but don’t consume the newline,
unless the previous line was a list item…
</p>
</blockquote>

 <p>
That is not really describing a language anymore. It is describing the history of your parser’s bugs.
</p>

 <p>
So OrgWebAlchemy uses Parsing Expression Grammars (PEGs) through Guile’s excellent  <code>(ice-9 peg)</code> module. e.g.
</p>

 <div class="jfw-code"> <pre>(define-peg-pattern element body
  ( <span class="org-keyword">or</span> empty-line
      heading
      separator
      table
      src-block
      quote-block
      example-block
      export-html-block
      description-list
      unordered-list
      ordered-list
      paragraph))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This is rather nice because the grammar itself starts looking like documentation for the language.
</p>

 <p>
And Guile lets us express PEGs directly as S-expressions (alternatively you can also use the more traditional syntax if you don’t like it), which makes the Lisper in me very happy.
</p>

 <p>
One thing I particularly like about this approach is that we have loose coupling and the detail of generating SXML and then rendering HTML is a “presentation concern”. this opens possibilities to later exporting to Markdown or other formats.
</p>

 <p>
For example:
</p>

 <pre class="example" id="orgd1995ea">
- name :: Josep
- project :: orgwebalchemy
- language :: Scheme
</pre>

 <p>
can become an AST along the lines of:
</p>

 <div class="jfw-code"> <pre>(description-list
 (unordered-item
  (desc-key  <span class="org-string">&quot;name&quot;</span>)
  (line-content  <span class="org-string">&quot;Josep&quot;</span>))
 ...)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I’m still busy with the exact representation and getting it all right. But as of now v1.0 has some stability :-) I would really love feedback on the project from the great smart people that hang out around here.
</p>

 <hr></hr> <p>
Of course Org mode is a huge piece of (great) software, so I am far from supporting all features, but some core important constructs are there:
</p>

 <ul class="org-ul"> <li>Headings (lines starting by n *)</li>
 <li>Paragraphs (any “non-special” text)</li>
 <li>Unordered, Ordered and Description lists (with any level of nesting)</li>
 <li>Italic, Bold, Inline Code</li>
 <li>Links with and without description (with nested parsing)</li>
 <li>Horizontal separators (---–—) five or more dashes</li>
 <li>Tables</li>
 <li> <code>#+begin_src</code></li>
 <li> <code>#+begin_example</code></li>
 <li> <code>#+begin_quote</code> (with nested parsing)</li>
 <li> <code>#+begin_export html</code> : Org syntax is parsed by your PEG grammar, but raw HTML export blocks bypass the Org inline parser and are emitted as trusted literal output.</li>
</ul> <hr></hr></div>
 <h2>YAY recursive lists  <a id="yay-recursive-lists" class="anchor" href="#yay-recursive-lists" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org87905b7">
 <p>
One of the fun parts has been getting nested Org lists right.
</p>

 <p>
Something like:
</p>

 <pre class="example" id="org6996677">
- Item 1
  - Item 1.1
  - Item 1.2
- Item 2
</pre>

 <p>
should become a quasi-tree
</p>

 <p>
The parser initially produces the flat sequence of list items, and the AST processing phase turns indentation into nested structure.
</p>

 <p>
The HTML renderer can then naturally produce:
</p>

 <div class="jfw-code"> <pre>&lt; <span class="org-function-name">ul</span>&gt;
  &lt; <span class="org-function-name">li</span>&gt;
    Item 1
    &lt; <span class="org-function-name">ul</span>&gt;
      &lt; <span class="org-function-name">li</span>&gt;Item 1.1&lt;/ <span class="org-function-name">li</span>&gt;
      &lt; <span class="org-function-name">li</span>&gt;Item 1.2&lt;/ <span class="org-function-name">li</span>&gt;
    &lt;/ <span class="org-function-name">ul</span>&gt;
  &lt;/ <span class="org-function-name">li</span>&gt;
  &lt; <span class="org-function-name">li</span>&gt;Item 2&lt;/ <span class="org-function-name">li</span>&gt;
&lt;/ <span class="org-function-name">ul</span>&gt;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I do still have a small issue here, and that is about the mixing of different list types in nested way. Hopefully it’s a subtle bug to fix.
</p>

 <p>
The HTML side uses SXML, because if we’re already writing Lisp, we might as well represent our HTML as Lisp data too. :-) that really helps a lot and makes building the markup tree so much nicer
</p>

 <p>
I’ve taken care to allow full customization to the output HTML (via Guile parameters) so that the renderer isn’t hard-coded to one particular website’s idea of what HTML ought to look like.Most of them are plain list of classes, but per-heading-level customization is a bit more flexible:
</p>

 <div class="jfw-code"> <pre>(heading-classes
 ( <span class="org-keyword">lambda</span> (level)
   ( <span class="org-keyword">case</span> level
     ((1) '( <span class="org-string">&quot;text-4xl&quot;</span>  <span class="org-string">&quot;font-bold&quot;</span>))
     ((2) '( <span class="org-string">&quot;text-2xl&quot;</span>  <span class="org-string">&quot;font-semibold&quot;</span>))
     ( <span class="org-keyword">else</span> '( <span class="org-string">&quot;text-base&quot;</span>)))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Why am I making this?  <a id="why-am-i-making-this" class="anchor" href="#why-am-i-making-this" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org26f51fb">
 <p>
Partly because I wanted it, I like a challenge, and it’s super fun to work with parsing, ASTs and the lot… I could just use Emacs to do this job as there is no better implementation of Org.
</p>

 <p>
The way it’s coming together though, I like the idea of having a small, hackable, free-software Org parser written in Lisp that other people can extend and customize (perhaps add more renderers, or Org features).
</p>
</div>
 <h2>Free software  <a id="free-software" class="anchor" href="#free-software" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4c1ad30">
 <p>
OrgWebAlchemy is licensed under the GNU LGPL v3 or later.
</p>

 <p>
The project is intended to soon be packaged for GNU Guix as  <code>guile-orgwebalchemy</code>.
</p>

 <p>
There is also a test suite in the repository which is already proving to be a good safety net and showcase of what the parser can do.
</p>


 <div id="org946e8e4" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/orgwebalchemy/screen-2026-09-24-10-52-55.png"></img></p>
</div>

 <hr></hr></div>
 <h2>Closing thoughts  <a id="closing-thoughts" class="anchor" href="#closing-thoughts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org064bf49">
 <p>
I’d be really happy to hear your thoughts, especially about the grammar, AST design, parser architecture, or interesting Org constructs that I have not handled yet.
</p>

 <p>
Happy hacking! ✨
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Quest for the eternal Dock - lambdock</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Where hexagonal architecture shines, and what to reach for instead</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/maak/">Maak: The power of Lisp that powers your trusty command runner and the enlightenments</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/index.html</guid>
  <pubDate>Fri, 25 Sep 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Quest for the eternal Dock - lambdock</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>lambdock: quest for the eternal dock  <a id="lambdock-quest-for-the-eternal-dock" class="anchor" href="#lambdock-quest-for-the-eternal-dock" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org864fffa">
 <p>
This is the story of  <code>lambdock</code>:  <a href="https://codeberg.org/jjba23/lambdock">https://codeberg.org/jjba23/lambdock</a>
</p>

 <p>
 <code>lambdock</code> is a modern, hyper-hackable, Wayland-native desktop dock application (C and Guile Scheme + GTK4) w/ REPL.
</p>

 <blockquote>
 <p>
As a heavy computer user, spending most of my day enjoying digital life, and as an eye-candy enjoyer and workflow optimization afficionado, I have long dreamt of the ultimate desktop dock.
</p>

 <p>
Here’s the story behind  <code>lambdock</code> , the Wayland-native beast with infinite hackability, fluid physics animcations, instant responsiveness, and free as in freedom .
</p>

 <p>
But to get here, I will first take you through the mindset, the graveyard of failed prototypes, the uphill battles and the ultimate conquest of GTK4 C runtime, and embedding of a living, breathing, interactive Lisp heart.
</p>
</blockquote>
</div>
 <h2>Quest for the eternal Dock  <a id="quest-for-the-eternal-dock" class="anchor" href="#quest-for-the-eternal-dock" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5d628cb">
 <p>
For years, desktop GNU/Linux users moving to Wayland faced a recurring tragedy: the loss of iconic, deeply hackable docks like Cairo-Dock and Plank. That being said, anno 2026, those (and other) projects have made great efforts to become Wayland-compatible, so that’s great. While bar engines like Waybar and EWW excel at status displays, a true application dock that can rival those heavyweights (and macOS too) requires a unique blend of layout  positioning, dynamic window tracking, auto-hiding, and fluid hover physics for animations.
</p>

 <p>
 <code>lambdock</code>’s  is a story of resilience in many ways, as I cannot even remember how many attempts I made at building a dock (in different ways). Little did I know how many paradigms, ideas and PoCs would collapse before my vision became tangible reality.
</p>

 <img alt="lambdock showcase" src="https://jointhefreeworld.org/static-assets/lambdock/gif_2026-08-07_22-32-33.gif"></img> <img alt="lambdock showcase whitesur icons" src="https://jointhefreeworld.org/static-assets/lambdock/gif_2026-09-07_23-32-42.gif"></img> <hr></hr> <ul class="org-ul"> <li> <b>Wayland Native</b>: Built on GTK4 and  <code>gtk4-layer-shell</code> for smooth edge anchoring, cubic-eased slide animations, and compositor integration.</li>
 <li> <b>Dynamic Window Tracking</b>: Uses  <code>zwlr_foreign_toplevel_manager_v1</code> to display active app indicators, window titles, and popover HUDs for focusing or closing instances.</li>
 <li> <b>Multi-Monitor Flexibility</b>: Span docks across all connected screens ( <code>#:monitor 'all</code>) or lock them to specific output connectors (e.g.,  <code>&quot;DP-1&quot;</code>).</li>
 <li> <b>Smooth Auto-Hide</b>: Keeps the dock out of your way with configurable reveal thresholds and fluid sliding animations.</li>
 <li> <b>Declarative Lisp Configurations</b> 🔮: Harness the power of GNU Guile Scheme for declarative dock setups, custom app launchers, separators, and options. Multiple config files and multiple docks are supported.</li>
 <li> <b>Smart and Safe Hot-Reloading</b>: Automatic file watcher ( <code>GFileMonitor</code>) and REPL hook ( <code>reload-dock!</code>) safely re-evaluate Scheme settings and GTK CSS without blocking the UI thread.</li>
 <li> <b>Live Interactive Socket REPL</b>: Query state or alter dock parameters live over a Unix domain socket ( <code>/tmp/lambdock-repl.sock</code>) via Emacs/Geiser,  <code>socat</code>, or  <code>ncat</code>.</li>
 <li> <b>Theme Engine</b>: Extensible with CSS, and ships with built-in themes, while supporting user extensions and overrides via  <code>~/.config/lambdock/styles.css</code>.</li>
 <li> <b>Flexible Icon Resolution</b>: Best-effort fallback pipeline resolving GTK theme icons, absolute paths, system pixmaps, and symbolic variants.</li>
 <li> <b>Async Command Launching</b>: Spawns binaries, scripts, and Flatpaks asynchronously using GLib process spawning without freezing the UI.</li>
 <li> <b>App Noise Filtering</b>: Flexible exclusion lists ( <code>#:exclude-apps</code>) to prevent background utilities or specific application IDs from creating unwanted launchers.</li>
 <li> <b>Reproducible Builds</b>: Fully hermetic development environment and builds powered by GNU Guile, Meson, and GNU Guix.</li>
 <li> <b>Native fluid fish-eye</b> magnification effect on hover (a la macOS) which is opt-in since some users might want less animations.</li>
 <li> <b>Dock Scrolling</b>: Seamless mouse wheel scrolling over dock items when the bar exceeds available display dimensions.</li>
</ul> <hr></hr> <p>
On the 30th of July 2026, I had a revelation and set out to build  <b>lambdock</b>: a Wayland-native desktop dock that wouldn’t just replicate the macOS or Cairo-Dock experience, but would transcend it with full runtime inspectability, hackability, and Lisp enlightenment.
</p>

 <p>
I find GTK to be the very best UI toolkit for GNU/Linux and other platforms, anno 2026. So for me that choice was pretty clear, even if I also toyed with Qt and others, but GTK always came  on top. After the wreckage of many PoCs and while reading some HackerNews in bed, a thought crossed my mind, and suddenly,  <b>absolute clarity</b>!
</p>

 <p>
Why not use idiomatic modern GTK4, in the language that it’s written in. Oh wait, that language, C, has  <code>libguile.h</code>, a great library inter-operability with Lisp (GNU Guile Scheme), allowing bi-directional bindings and communication. Why not go down this rabbit hole, which might at the same time teach me more about my favourite language (GNU Guile) and allow me a frictionless setup with GTK and native super performance.
</p>

 <img src="https://jointhefreeworld.org/static-assets/lambdock/Agnus_Dei_red_flag.svg" width="380" alt="Agnus Dei"></img> <blockquote>
 <p>
I therefore designed lambdock in my mind, in bed, much inspired by Emacs. A powerful, small C core that powers the program, rendering, graphics and low level details, and an embedded GNU Guile Scheme engine that at runtime is the heart and brain of the whole thing. This architecture uniquely delivers interactive socket REPL control, Lisp metaprogramming macros, dynamic multi-dock spawning, native Wayland foreign-toplevel window tracking, and frame-clock-driven hover animations.
</p>
</blockquote>
</div>
 <h2>Graveyard of Prototypes  <a id="graveyard-of-prototypes" class="anchor" href="#graveyard-of-prototypes" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge41fb74">
 <p>
The journey to  <code>lambdock</code> was paved with ambitious Proofs of Concept (PoCs) that ultimately died. I cycled through several languages, approaches, frameworks, and architecture experiments, chasing the dream of rapid development without sacrificing low-level display server control.
</p>

 <p>
The quest initially aimed for a pure, 100% Lisp architecture using Guile GI and other existing Guile GTK bindings. However, this vision collapsed under sparse documentation and inscrutable binding layers. Bridging GTK’s imperative, object-oriented state with functional Scheme patterns created constant architectural friction, and a small community meant every binding edge-case became a dead end and a long dive in the rabbit hole.
</p>

 <p>
Trying Python + GTK3/4 offered rapid prototyping and a massive library ecosystem, but crashed into severe real-time performance limits. Single-threaded bottlenecks and Global Interpreter Lock (GIL) stutters ruined fluid slide-out animations unless backed by custom C code. That also triggered me to think, might as well just write this whole thing in C. Coupled with a heavy memory footprint and fragile IPC mechanisms, the runtime proved too heavy and unpredictable for a low-latency desktop dock.
</p>

 <p>
Attempts with Rust, GTK bindings, and custom compositor IPC promised memory safety and fearless concurrency, yet introduced severe verbosity and binding friction. Mismatches between Rust’s async event loops and GTK4’s main thread created structural problems, the borrow checker was a real PITA when working with GTK and the dynamic features I wanted to support, while the lack of  reflection completely shut the door on (easily) embedding a live, interactive Lisp REPL.
</p>

 <p>
I made a final attempt by using JavaScript/Node and Layer Shell targeted familiar web-style styling and asynchronous I/O. However, this suffered from bloated resource consumption, poor integration with low-level Wayland protocols, and no clear pathway for Lisp extensibility, and thus it quickly gained its place in the graveyard of abandoned prototypes.
</p>
</div>
 <h2>Iron Skeleton, Lisp Soul  <a id="iron-skeleton-lisp-soul" class="anchor" href="#iron-skeleton-lisp-soul" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org31d14ee">
 <ul class="org-ul"> <li> <b>C + GTK4 + gtk4-layer-shell</b> is the undisputed champion of native Wayland surface control. C provides raw speed, zero-cost GLib integration, memory layout efficiency, flawless Wayland scanner protocol generation and the best GTK documentation you can get.</li>
 <li> <b>GNU Guile Scheme ( <code>libguile</code>)</b> is the ultimate runtime mind. Instead of configuring the dock with static, dead JSON or TOML files, embedding Lisp (Guile Scheme) via  <code>libguile.h</code> gives the dock a living Lisp heart and turns it into an infinitely extensible program.</li>
</ul> <div class="jfw-code"> <pre> <span class="org-comment-delimiter">/* </span> <span class="org-comment">The moment C boots the Lisp engine in main.c</span> <span class="org-comment-delimiter"> */</span>
 <span class="org-type">int</span>  <span class="org-function-name">main</span>( <span class="org-type">int</span>  <span class="org-variable-name">argc</span>,  <span class="org-type">char</span> ** <span class="org-variable-name">argv</span>) {
 <span class="org-preprocessor">#ifdef</span> DEFAULT_GSK_RENDERER
  g_setenv( <span class="org-string">&quot;GSK_RENDERER&quot;</span>, DEFAULT_GSK_RENDERER, FALSE);
 <span class="org-preprocessor">#endif</span>
   <span class="org-comment-delimiter">/* </span> <span class="org-comment">Boot the GNU Guile Scheme engine and surrender control to inner_main</span> <span class="org-comment-delimiter"> */</span>
  scm_boot_guile(argc, argv, inner_main,  <span class="org-constant">NULL</span>);
   <span class="org-keyword">return</span> 0;
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
By hosting  <code>libguile</code> directly inside C’s GTK4 main loop,  <code>lambdock</code> achieves what I consider the holy grail, much like GNU Emacs does:  <b>infinite extensibility, uncompromising native performance for rendering and animation, and metaprogramming superpowers of Lisp for user configuration and live REPL inspection.</b>
</p>

 <hr></hr></div>
 <h2>Etymology  <a id="etymology" class="anchor" href="#etymology" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga5c3fea">
 <p>
The name  <i>lambdock</i> is a play on words combining:
</p>

 <ul class="org-ul"> <li> <b>Ship Docks</b> ⚓ where containers and applications dock safely.</li>
 <li> <code>lambda λ</code> expressions from functional programming &amp; Lisp enlightenment.</li>
 <li> <b>Lambs</b> 🐑 (gentle, fluffy, lightweight, and clean).</li>
 <li> <b>Docks</b> as desktop UI components (e.g., Plank, Cairo-Dock, macOS Dock).</li>
</ul> <p>
 <code>lambdock</code> adopts as  its project logo the   <a href="https://en.wikipedia.org/wiki/Agnus_Dei">Agnus Dei</a>: The Lamb of God carrying a cross and a red flag
</p>

 <p>
You could say using this dock  <i>es casi una experiencia religiosa como la de  <a href="https://www.youtube.com/watch?v=3DV57Y4tEAM&amp;t=3s">Enrique Iglesias</a></i>
</p>

 <hr></hr></div>
 <h2>Multi-Config &amp; Multi-Dock Instance  <a id="multi-config-amp-multi-dock-instance" class="anchor" href="#multi-config-amp-multi-dock-instance" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge9fe7b3">
 <p>
 <code>lambdock</code> features built-in multi-dock orchestration. Rather than being limited to a single dock bar, you can run multiple independent docks simultaneously across different screen edges or monitors.
</p>

 <ul class="org-ul"> <li> <b>Automatic Directory Monitoring</b>:  <code>lambdock</code> watches  <code>~/.config/lambdock/</code> for files matching  <code>settings.scm</code> or  <code>settings-*.scm</code> (e.g.,  <code>settings-left.scm</code>,  <code>settings-bottom.scm</code>).</li>
</ul> <p>
Each configuration file defines its own isolated  <code>LambdockState</code>, position ( <code>dock-position</code>), theme ( <code>dock-theme</code>), monitor targets ( <code>dock-monitor</code>), and item launcher layout ( <code>dock-items</code>).
</p>
 <ul class="org-ul"> <li> <b>Dynamic Spawning</b>: Creating a new  <code>settings-2.scm</code> file instantly spawns a new dock bar on screen.</li>
 <li> <b>Dynamic Hot-Reloading</b>: Editing any  <code>settings-*.scm</code> file hot-reloads that specific dock instance without flickering or restarting other running instances.</li>
 <li> <b>Dynamic Destruction</b>: Deleting a  <code>settings-*.scm</code> file safely tears down and destroys its corresponding dock window, removing Wayland handles and GTK widgets without crashing the application.</li>
</ul> <hr></hr></div>
 <h2>What systems does lambdock support?  <a id="what-systems-does-lambdock-support" class="anchor" href="#what-systems-does-lambdock-support" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgaf23177">
 <p>
 <code>lambdock</code> is a GNU/Linux first utility.
</p>

 <p>
The tool uses  <code>gtk4-layer-shell</code> to render to the screen and positioning and for dock behavior.
</p>

 <p>
That means it works well in Wayland compositors that support the   <code>wlr-layer-shell-unstable-v1</code> protocol, including:
</p>

 <ul class="org-ul"> <li>KDE Plasma (Wayland session)</li>
 <li>Smithay-based compositors: Niri, COSMIC Desktop</li>
 <li>wlroots-based compositors: Sway, Hyprland, River, Wayfire</li>
 <li>Mir-based compositors</li>
</ul> <p>
Note: GNOME (Mutter) currently not supported due to not implementing the protocol
</p>

 <hr></hr></div>
 <h2>How the Bi-Directional Engine Works  <a id="how-the-bi-directional-engine-works" class="anchor" href="#how-the-bi-directional-engine-works" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb27e008">
 <p>
 <code>lambdock</code> is not merely configured by Scheme. It has an embedded, extensible Lisp engine and runtime environment which complements a high-performance C applciation core and graphics engine. Execution flows bi-directionally between C and Guile.
</p>

 <p>
The entry point of the binary ( <code>main.c</code>) boots the Guile interpreter using  <code>scm_boot_guile</code>. The C runtime acts as the host and invokes Scheme procedures to manage state and extract settings.
</p>

 <p>
Scheme is not restricted to passive data declarations, as it can trigger actions inside the running C engine.
</p>

 <p>
lambdock provides a beautiful Lisp DSL for defining your dock, based on items and presets
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Scheme Constructor / Procedure</th>
 <th scope="col" class="org-left">Return Type</th>
 <th scope="col" class="org-left">Description</th>
 <th scope="col" class="org-left">Keyword Arguments</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>(app-item ...)</code></td>
 <td class="org-left">Record</td>
 <td class="org-left">Custom application launcher definition</td>
 <td class="org-left"> <code>#:name</code>,  <code>#:exec</code>,  <code>#:icon</code></td>
</tr> <tr> <td class="org-left"> <code>(dynamic-item ...)</code></td>
 <td class="org-left">Record</td>
 <td class="org-left">Dynamic polling widget displaying dynamic textual data</td>
 <td class="org-left"> <code>#:name</code>,  <code>#:icon</code>,  <code>#:exec</code>,  <code>#:poll-fn</code>,  <code>#:interval-ms</code>,  <code>#:hover-animate?</code></td>
</tr> <tr> <td class="org-left"> <code>(preset-launcher 'symbol)</code></td>
 <td class="org-left">Record</td>
 <td class="org-left">Standard launcher resolved from internal preset list</td>
 <td class="org-left">Symbol (e.g.  <code>'emacs</code>,  <code>'alacritty</code>)</td>
</tr> <tr> <td class="org-left"> <code>(preset-launchers-for 'a 'b)</code></td>
 <td class="org-left">List</td>
 <td class="org-left">Batch helper returning a list of preset launchers</td>
 <td class="org-left">Variadic list of symbols</td>
</tr> <tr> <td class="org-left"> <code>(separator-item)</code></td>
 <td class="org-left">Record</td>
 <td class="org-left">Layout divider line</td>
 <td class="org-left">None</td>
</tr> <tr> <td class="org-left"> <code>(preset-icon 'symbol)</code></td>
 <td class="org-left">String</td>
 <td class="org-left">Resolves default icon name string for a given preset</td>
 <td class="org-left">Symbol</td>
</tr></tbody></table> <p>
The magic of  <code>lambdock</code> lies in the seamless bi-directional bridge between the C graphics core and the GNU Guile Scheme engine. See an example config file:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;; </span> <span class="org-comment">Modern, declarative Lisp configuration in ~/.config/lambdock/settings.scm
</span>( <span class="org-keyword">define</span>  <span class="org-function-name">dock-auto-hide?</span> #t)
( <span class="org-keyword">define</span>  <span class="org-function-name">dock-position</span> 'bottom)
( <span class="org-keyword">define</span>  <span class="org-function-name">dock-icon-size</span> 48)
( <span class="org-keyword">define</span>  <span class="org-function-name">dock-theme</span> 'vanilla)
( <span class="org-keyword">define</span>  <span class="org-function-name">dock-monitor</span> 'all)

( <span class="org-keyword">define</span>  <span class="org-function-name">dock-items</span>
  (append
   (preset-launchers-for 'alacritty 'google-chrome 'spotify-flatpak 'nautilus)
   (list (separator-item))
   (preset-launchers-for 'emacs 'intellij 'bruno-flatpak)
   (list (separator-item))
   (preset-launchers-for 'ram 'cpu 'cpu-temp 'battery)))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">=== you can evaluate any Lisp code here too ===
</span>
(use-modules (ice-9 popen)
             (ice-9 rdelim)
             (srfi srfi-19)
             (srfi srfi-1))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Helper to run a shell command and return its output as a clean string
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">sh-output</span> cmd)
  ( <span class="org-keyword">let*</span> ((port (open-input-pipe cmd))
         (output (read-line port)))
    (close-pipe port)
    ( <span class="org-keyword">if</span> (eof-object? output)  <span class="org-string">&quot;&quot;</span> output)))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Enable auto-hide only on a specific hostname (e.g., laptop setup)
</span>( <span class="org-keyword">define</span>  <span class="org-function-name">dock-auto-hide?</span>
  (string=? (string-trim-both (sh-output  <span class="org-string">&quot;hostname&quot;</span>))  <span class="org-string">&quot;thinkpad&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Read Eval Print Loop (REPL)  <a id="read-eval-print-loop-repl" class="anchor" href="#read-eval-print-loop-repl" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7581754">
 <p>
For purposes of development, experimentation and live hackability,  <code>lambdock</code> features an embedded GNU Guile Scheme runtime. You can enable a background Unix domain socket REPL to query or dynamically alter the running dock’s state in real time.
</p>

 <p>
Through Guile’s  <code>(system repl server)</code>,  <code>lambdock</code> can spawn Unix domain sockets (one per dock instance) for example at  <code>/tmp/lambdock-repl.sock</code>. You can plug directly into a running dock process via Emacs (Geiser),  <code>socat</code>, or  <code>ncat</code>.
</p>

 <p>
Because GTK4 requires all UI modifications to happen on the main thread while the REPL listens on a background thread,  <code>lambdock</code> uses GLib’s  <code>g_idle_add</code> to dispatch Scheme-triggered UI updates safely:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">/* </span> <span class="org-comment">Thread-safe C callback triggered from Guile REPL evaluation</span> <span class="org-comment-delimiter"> */</span>
 <span class="org-keyword">static</span>  <span class="org-type">gboolean</span>  <span class="org-function-name">on_manual_reload_idle</span>( <span class="org-type">gpointer</span>  <span class="org-variable-name">user_data</span>) {
  ( <span class="org-type">void</span>)user_data;
  LOG_C_INFO( <span class="org-string">&quot;Main&quot;</span>,  <span class="org-string">&quot;Redrawing UI from in-memory Guile state...&quot;</span>);
  redraw_active_docks();
   <span class="org-keyword">return</span> G_SOURCE_REMOVE;
}

 <span class="org-keyword">static</span>  <span class="org-type">SCM</span>  <span class="org-function-name">scm_reload_dock</span>( <span class="org-type">void</span>) {
  g_idle_add(on_manual_reload_idle,  <span class="org-constant">NULL</span>);
   <span class="org-keyword">return</span> SCM_UNSPECIFIED;
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can edit a theme, change icon dimensions, or redefine launchers in Emacs, issue a   <code>(reload-dock!)</code>, and watch your dock transform live, without restarting or dropping a single frame!
</p>

 <p>
In your  <code>~/.config/lambdock/settings.scm</code> file, set  <code>#:enable-repl?</code> to  <code>#t</code>. You can optionally customize the socket path using  <code>#:repl-socket-path</code> (defaults to  <code>/tmp/lambdock-repl.sock</code>):
</p>

 <div class="jfw-code"> <pre>(configure-dock!
  <span class="org-builtin">#:position</span> 'bottom
  <span class="org-builtin">#:items</span> (list ...)
  <span class="org-comment-delimiter">;; </span> <span class="org-comment">.... other settings
</span>  <span class="org-builtin">#:enable-repl?</span> #t
  <span class="org-builtin">#:repl-socket-path</span>  <span class="org-string">&quot;/tmp/lambdock-repl.sock&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can then inspect or modify the dock state, and when desired also reload the dock (with  <code>reload-dock!</code>).
</p>

 <p>
Once connected, you can evaluate Scheme expressions against the running  <code>lambdock</code> instance, possibilities are endless, e.g.
</p>

 <pre class="example" id="org31e39d3">
scheme@(guile-user)&gt; (use-modules (lambdock core))
scheme@(guile-user)&gt; (get-dock-theme) ;; -&gt; 'vanilla
scheme@(guile-user)&gt; (set-dock-theme! 'nature)
scheme@(guile-user)&gt; (reload-dock!)
</pre>

 <p>
If you use Emacs with Geiser:
</p>

 <ol class="org-ol"> <li>Run  <code>M-x geiser-connect-local</code>.</li>
 <li>Select  <code>guile</code> as the Scheme implementation.</li>
 <li>Enter the socket path:  <code>/tmp/lambdock-repl.sock</code>.</li>
</ol> <p>
See here Emacs + Geiser GIF
</p>
 <img alt="lambdock showcase" src="https://jointhefreeworld.org/static-assets/lambdock/gif_2026-08-06_13-13-17.gif"></img> <p>
You can connect directly from your terminal using different tooling, like  <code>nc</code>,  <code>ncat</code>,   <code>socat</code> wrapped with  <code>rlwrap</code> , and others:
</p>

 <div class="jfw-code"> <pre>socat - UNIX-CONNECT:/tmp/lambdock-repl.sock
ncat -U /tmp/lambdock-repl.sock
nc -U /tmp/lambdock-repl.sock
rlwrap socat - UNIX-CONNECT:/tmp/lambdock-repl.sock</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <hr></hr></div>
 <h2>Victory: Upstream in Guix, Nix, OCI and Beyond!  <a id="victory-upstream-in-guix-nix-oci-and-beyond" class="anchor" href="#victory-upstream-in-guix-nix-oci-and-beyond" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org912b9ab">
 <p>
What began as a chaotic experiment in a local directory has officially arrived on the global stage.
</p>

 <p>
 <code>lambdock</code> is upstreamed and natively packaged in GNU Guix. You can run or install it in a single hermetic command:
</p>

 <div class="jfw-code"> <pre>guix time-machine --channels=channels.scm -- shell -f guix.scm -- lambdock</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Fully upstreamed into Nixpkgs (today) and available as a Flake too:
</p>

 <div class="jfw-code"> <pre>nix --extra-experimental-features  <span class="org-string">'nix-command flakes'</span> run .#</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <code>lambdock</code> binaries and native packages are marching across the GNU/Linux ecosystem:
</p>

 <ul class="org-ul"> <li> <b>openSUSE / RPM</b>: Packaged on OBS with native  <code>lambdock.spec</code>.</li>
 <li> <b>Debian / Ubuntu</b>: Full  <code>debian/</code> rules and unsigned  <code>.deb</code> build pipeline.</li>
 <li> <b>Arch Linux</b>: Ready-to-build  <code>PKGBUILD</code> in  <code>packaging/arch</code>.</li>
 <li> <b>Containers</b>: Lightweight OCI images on DockerHub for Podman/Docker.</li>
</ul> <hr></hr></div>
 <h2>What does one learn after the Odyssey  <a id="what-does-one-learn-after-the-odyssey" class="anchor" href="#what-does-one-learn-after-the-odyssey" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge97f4f4">
 <ul class="org-ul"> <li> <b>Don’t fight the platform</b>: If you are building a Wayland utility on GNU/Linux, consider embracing C and GTK4/Layer-Shell directly. The clarity, speed, and reliability are unmatched. Even if you might have to shoot yourself in the foot a couple times with memory management ☺️</li>
 <li> <b>Lisp remains THE supreme extension engine</b>: Embedding  <code>libguile</code> transformed a simple UI bar into an extensible and programmable canvas where users can run shell pipelines, system queries, and dynamic macros right inside their config files.</li>
 <li> <b>Don’t surrender to “good enough”</b>: The failed PoCs were not wasted time, they were but the crucible that forged the ultimate architecture.</li>
</ul> <p>
Long live Free Software, long live Lisp, and happy docking! 🐑⚓λ
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Emacs Eglot for Scala and Kotlin (JVM)</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/">Building Conky with Wayland Support on GNU Guix</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/index.html</guid>
  <pubDate>Sat, 29 Aug 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Emacs Eglot for Scala and Kotlin (JVM)</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
When Emacs 29 made  <code>eglot</code> the built-in, default Language Server Protocol (LSP) client, many of us rejoiced.
</p>

 <p>
It is lightweight, fast, adheres strictly to Emacs philosophy, and doesn’t try to reinvent the wheel.
</p>

 <p>
However, being minimal means that when an LSP server steps out of line or acts quirky,  <code>eglot</code> doesn’t provide a million customizable toggles to fix it out-of-the-box. Instead, it expects you to leverage the power of Emacs Lisp.
</p>

 <p>
In this post, I will dissect my production-ready  <code>eglot</code> setup (part of my  <code>heks-emacs</code> configuration) which I use in my day-to-day work, with Scala and Kotlin (and some Java).
</p>

 <p>
For reference, find my  full Eglot config here:  <a href="https://codeberg.org/jjba23/heks-emacs/src/branch/trunk/src/modules/eglot.el">https://codeberg.org/jjba23/heks-emacs/src/branch/trunk/src/modules/eglot.el</a>
</p>

 <p>
We will walk through basic language setups, specialized workspace configuration handling, and dive deep into some advanced JSON-RPC and advice-based workarounds for  <b>Scala (Metals)</b> and  <b>Kotlin</b> that make development truly seamless from Emacs and liberate you from IntelliJ ☺️.
</p>

 <p>
It’s not perfect, but it’s pretty darn close to perfection if you ask me, and the developer experience and speed that it enables is just wild. Thank you Emacs, thank you GNU, thank you Eglot! 🐂
</p>

 <hr></hr> <p>
Before looking at the code, let’s talk about why we are doing this. For years, the conventional wisdom stated that if you write JVM languages, especially Scala or Kotlin, you must use  <a href="https://www.jetbrains.com/idea/">IntelliJ IDEA</a>. The narrative claimed that these languages are too complex for a standard text editor.
</p>

 <p>
But what do you actually get with IntelliJ? A massive, monolithic Java application that frequently hogs 8GB+ of RAM, locks up your system while “indexing pre-built binaries,” and forces you into a closed proprietary ecosystem.
</p>

 <p>
Emacs turns this paradigm on its head through three core strengths:
</p>

 <ul class="org-ul"> <li>The Unix Philosophy of LSP: Instead of a single IDE trying to compile, index, and render your code simultaneously, Emacs splits these duties.  <a href="https://www.gnu.org/software/emacs/manual/html_node/eglot/">Eglot</a> acts as a lean, protocol-first transport layer that talks to dedicated language servers via JSON-RPC.</li>
 <li>Infinite Hackability: If IntelliJ has a bug in how it auto-completes Kotlin code, you are stuck waiting for JetBrains to issue a patch. In Emacs, you can write a 10-line Lisp advice function to intercept the network payload and patch the bug live in your editor buffer.</li>
 <li>Unified Interface: You use the same text-manipulation utilities, text-jumping tools ( <code>xref</code>), and completion frameworks ( <code>corfu</code>,  <code>company</code>, etc.) whether you are adjusting a Nix expression, editing a Markdown file, or refactoring a massive Scala service.</li>
</ul> <hr></hr> <h2>Hooks, Keybindings, and Initial Configurations  <a id="hooks-keybindings-and-initial-configurations" class="anchor" href="#hooks-keybindings-and-initial-configurations" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9b6b15f">
 <p>
Let’s start with how  <code>eglot</code> is initialized. I use Elpaca and  <code>use-package</code> to manage the configuration, ensuring it doesn’t download an external package since it is built-in ( <code>:ensure nil</code>). Then I add some hooks to automatically start the language server for certain modes.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> eglot
   <span class="org-builtin">:ensure</span> nil
   <span class="org-builtin">:hook</span> ((scala-ts-mode . eglot-ensure)
         (sh-mode . eglot-ensure)
         (markdown-mode . eglot-ensure)
         (markdown-ts-mode . eglot-ensure)
         (nix-ts-mode . eglot-ensure)
         (html-mode . eglot-ensure)
         (css-mode . eglot-ensure)
         (css-ts-mode . eglot-ensure)
         (html-ts-mode . eglot-ensure)
         (js-mode . eglot-ensure)
         (js-ts-mode . eglot-ensure)
         (kotlin-ts-mode . eglot-ensure)
         (yaml-mode . eglot-ensure)
         (yaml-ts-mode . eglot-ensure)
          <span class="org-comment-delimiter">;; </span> <span class="org-comment">formatting
</span>         (before-save . eglot-format-buffer))
   <span class="org-comment-delimiter">;; </span> <span class="org-comment">..................
</span>   <span class="org-comment-delimiter">;; </span> <span class="org-comment">more config
</span>  )</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <ul class="org-ul"> <li> <b>Eglot-Ensure Everywhere:</b> I hook  <code>eglot-ensure</code> into almost every programming mode I use, adapting both classic modes and modern Tree-sitter ( <code>*-ts-mode</code>) alternatives.</li>
 <li> <b>Auto-Formatting:</b> Adding  <code>eglot-format-buffer</code> to  <code>before-save</code> guarantees code style compliance automatically every time a file hits the disk.</li>
</ul> <p>
My keybindings are nested under the  <code>C-c i</code> prefix, keeping them memorable and consistent across languages. The mnemonic keyword is “IDE” .
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">:bind</span> (( <span class="org-string">&quot;C-c i i&quot;</span> . eglot-find-implementation)
       ( <span class="org-string">&quot;C-c i e&quot;</span> . eglot)
       ( <span class="org-string">&quot;C-c i k&quot;</span> . eglot-shutdown-all)
       ( <span class="org-string">&quot;C-c i r&quot;</span> . eglot-rename)
       ( <span class="org-string">&quot;C-c i x&quot;</span> . eglot-reconnect)
       ( <span class="org-string">&quot;C-c i a&quot;</span> . eglot-code-actions)
       ( <span class="org-string">&quot;C-c i m&quot;</span> . eglot-menu)
       ( <span class="org-string">&quot;C-c i f&quot;</span> . eglot-format-buffer)
       ( <span class="org-string">&quot;C-c i h&quot;</span> . eglot-inlay-hints-mode))
 <span class="org-builtin">:init</span>
( <span class="org-keyword">setq</span> eglot-autoshutdown t
      eglot-confirm-server-edits nil
      eglot-report-progress t
      eglot-extend-to-xref t
      eglot-sync-connect 1
      eglot-connect-timeout 60
      eglot-autoreconnect t)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then with these  <code>:init</code> settings:
</p>

 <ul class="org-ul"> <li> <code>eglot-autoshutdown</code> cleans up language server processes as soon as the last buffer managed by them is killed.</li>
 <li> <code>eglot-extend-to-xref</code> allows Emacs’ cross-referencing commands to smoothly transition into external library files outside your workspace directory.</li>
</ul> <hr></hr></div>
 <h2>Fine-Tuning Server Definitions and Workspaces  <a id="fine-tuning-server-definitions-and-workspaces" class="anchor" href="#fine-tuning-server-definitions-and-workspaces" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc669dc2">
 <p>
Under the  <code>:config</code> block, we begin optimizing specific language servers. For instance, removing default configurations before re-adding custom entries prevents collisions.
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">:config</span>
( <span class="org-keyword">setopt</span> eglot-code-action-indications nil)  <span class="org-comment-delimiter">;; </span> <span class="org-comment">Cleans up Emacs 31 visual noise
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Clean slate for Scala and Kotlin
</span>( <span class="org-keyword">setq</span> eglot-server-programs (assq-delete-all 'scala-mode eglot-server-programs))
( <span class="org-keyword">setq</span> eglot-server-programs (assq-delete-all 'scala-ts-mode eglot-server-programs))
( <span class="org-keyword">setq</span> eglot-server-programs (assoc-delete-all 'scala-ts-mode eglot-server-programs))

(add-to-list 'eglot-server-programs `(scala-ts-mode . ( <span class="org-string">&quot;metals&quot;</span>
                                                        <span class="org-string">&quot;-Xmx4G&quot;</span>
                                                        <span class="org-string">&quot;-XX:+UseZGC&quot;</span>
                                                        <span class="org-string">&quot;-Dmetals.http=true&quot;</span>
                                                        <span class="org-builtin">:initializationOptions</span> ( <span class="org-builtin">:isHttpEnabled</span> t))))

( <span class="org-keyword">setq</span> eglot-server-programs (assoc-delete-all 'kotlin-ts-mode eglot-server-programs))
(add-to-list 'eglot-server-programs '(kotlin-ts-mode . ( <span class="org-string">&quot;intellij-server&quot;</span>  <span class="org-string">&quot;--stdio&quot;</span>)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Why these changes?</b>
</p>

 <ul class="org-ul"> <li> <b>Scala (Metals):</b> I pass specific JVM tuning flags directly to Metals (allocating a comfortable 4GB heap and utilizing the Z Garbage Collector for minimal latency). Also, enabling Metals HTTP communication via initialization options lets us hook into specialized UI features if needed.</li>
 <li> <b>Kotlin:</b> I swap out standard options for the IntelliJ-backed Kotlin Language Server ( <code>intellij-server --stdio</code>).</li>
</ul></div>
 <h2>Global Workspace Configurations  <a id="global-workspace-configurations" class="anchor" href="#global-workspace-configurations" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf45c501">
 <p>
 <code>eglot-workspace-configuration</code> lets you pass customized variables downstream to your language servers. This section of my configuration acts like a universal  <code>settings.json</code>:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">setq-default</span> eglot-workspace-configuration
              '(
                 <span class="org-builtin">:metals</span> (  <span class="org-builtin">:autoImportBuild</span>  <span class="org-string">&quot;all&quot;</span>
                           <span class="org-builtin">:isHttpEnabled</span> t
                           <span class="org-builtin">:superMethodLensesEnabled</span> t
                           <span class="org-builtin">:showInferredType</span> t
                           <span class="org-builtin">:enableSemanticHighlighting</span> t
                           <span class="org-builtin">:inlayHints</span> (  <span class="org-builtin">:inferredTypes</span> ( <span class="org-builtin">:enable</span> t )
                                         <span class="org-builtin">:implicitArguments</span> ( <span class="org-builtin">:enable</span> nil)
                                         <span class="org-builtin">:implicitConversions</span> ( <span class="org-builtin">:enable</span> nil )
                                         <span class="org-builtin">:typeParameters</span> ( <span class="org-builtin">:enable</span> t )
                                         <span class="org-builtin">:hintsInPatternMatch</span> ( <span class="org-builtin">:enable</span> nil ))
                           <span class="org-builtin">:bloopJvmProperties</span> [ <span class="org-string">&quot;-Xmx4G&quot;</span>])
                 <span class="org-builtin">:haskell</span> ( <span class="org-builtin">:formattingProvider</span>  <span class="org-string">&quot;ormolu&quot;</span>)
                 <span class="org-builtin">:typescript</span> ( <span class="org-builtin">:format</span> ( <span class="org-builtin">:baseIndentSize</span> 0
                                                       <span class="org-builtin">:convertTabsToSpaces</span> t
                                                       <span class="org-builtin">:indentSize</span> 2
                                                       <span class="org-builtin">:semicolons</span>  <span class="org-string">&quot;remove&quot;</span>
                                                       <span class="org-builtin">:tabSize</span> 2))
                 <span class="org-builtin">:javascript</span> ( <span class="org-builtin">:format</span> ( <span class="org-builtin">:baseIndentSize</span> 0
                                                       <span class="org-builtin">:convertTabsToSpaces</span> t
                                                       <span class="org-builtin">:indentSize</span> 2
                                                       <span class="org-builtin">:semicolons</span>  <span class="org-string">&quot;remove&quot;</span>
                                                       <span class="org-builtin">:tabSize</span> 2))
                 <span class="org-builtin">:rust-analyzer</span> ( <span class="org-builtin">:check</span> ( <span class="org-builtin">:command</span>  <span class="org-string">&quot;clippy&quot;</span>)
                                        <span class="org-builtin">:cargo</span> ( <span class="org-builtin">:sysroot</span>  <span class="org-string">&quot;discover&quot;</span>
                                                         <span class="org-builtin">:features</span>  <span class="org-string">&quot;all&quot;</span>
                                                         <span class="org-builtin">:buildScripts</span> ( <span class="org-builtin">:enable</span> t))
                                        <span class="org-builtin">:diagnostics</span> ( <span class="org-builtin">:disabled</span> [ <span class="org-string">&quot;macro-error&quot;</span>])
                                        <span class="org-builtin">:procMacro</span> ( <span class="org-builtin">:enable</span> t))

                 <span class="org-builtin">:yaml</span> (  <span class="org-builtin">:format</span> ( <span class="org-builtin">:enable</span> t)
                         <span class="org-builtin">:validate</span> t
                         <span class="org-builtin">:hover</span> t
                         <span class="org-builtin">:completion</span> t
                         <span class="org-builtin">:schemas</span> (
                                  https://codeberg.org/jjba23/pop-test/raw/branch/trunk/resources/json-schema/pop-test.json [ <span class="org-string">&quot;golden-test.yaml&quot;</span>  <span class="org-string">&quot;golden-test.yml&quot;</span>  <span class="org-string">&quot;pop-test.yaml&quot;</span>  <span class="org-string">&quot;pop-test.yml&quot;</span>]
                                  https://raw.githubusercontent.com/Vandebron/gh-mpyl/refs/heads/main/src/mpyl/schema/project.schema.yml [ <span class="org-string">&quot;project.yml&quot;</span>]
                                  https://json.schemastore.org/yamllint.json [ <span class="org-string">&quot;/*.yml&quot;</span>])
                         <span class="org-builtin">:schemaStore</span> ( <span class="org-builtin">:enable</span> t))
                 <span class="org-builtin">:nil</span> ( <span class="org-builtin">:formatting</span> ( <span class="org-builtin">:command</span> [ <span class="org-string">&quot;nixfmt&quot;</span>]))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Notable Configurations here:
</p>

 <ul class="org-ul"> <li> <b>Metals:</b> Granular inlay hints are activated specifically for inferred types and type parameters while muting implicit conversions to keep buffers readable. (more options here:  <a href="https://scalameta.org/metals/docs/editors/user-configuration/">https://scalameta.org/metals/docs/editors/user-configuration/</a>)</li>
 <li> <b>YAML Schema Mapping:</b> Maps distinct internet-hosted JSON schemas straight to patterns of YAML files automatically.</li>
</ul> <hr></hr></div>
 <h2>Deep Dive: The Workarounds  <a id="deep-dive-the-workarounds" class="anchor" href="#deep-dive-the-workarounds" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org01ef484">
 <p>
This is where things get interesting. Sometimes servers violate standard LSP expectations, requiring custom Emacs Lisp logic to bridge the gap.
</p>
</div>
 <h3>Fixing Eldoc Overload  <a id="fixing-eldoc-overload" class="anchor" href="#fixing-eldoc-overload" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org496f496">
 <p>
By default,  <code>eldoc</code> can easily get flooded by different feedback mechanisms. This block prioritizes structural code diagnostics over generic hover data:
</p>

 <div class="jfw-code"> <pre>(add-hook 'eglot-managed-mode-hook
          ( <span class="org-keyword">lambda</span> ()
             <span class="org-comment-delimiter">;; </span> <span class="org-comment">Show flymake diagnostics first.
</span>            ( <span class="org-keyword">setq</span> eldoc-documentation-functions
                  (cons #'flymake-eldoc-function
                        (remove #'flymake-eldoc-function eldoc-documentation-functions)))
             <span class="org-comment-delimiter">;; </span> <span class="org-comment">Show all eldoc feedback.
</span>            ( <span class="org-keyword">setq</span> eldoc-documentation-strategy #'eldoc-documentation-compose)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Kotlin Source Navigation (Jar URI Translation)  <a id="kotlin-source-navigation-jar-uri-translation" class="anchor" href="#kotlin-source-navigation-jar-uri-translation" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org007509d">
 <p>
When traversing into a dependency library using Kotlin, the server returns file references formatted as  <code>jar:///path/to/library.jar!/File.kt</code>. Emacs can’t resolve this scheme directly out of the box, throwing errors when you try to jump to definition.
</p>

 <p>
By wrapping Eglot’s URI translators with advice, we can map this custom scheme into something Emacs understands (especially alongside companion extensions like  <code>jarchive</code>):
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">defun</span>  <span class="org-function-name">heks/eglot-uri-to-path-kotlin</span> (orig-fn uri  <span class="org-type">&amp;rest</span> args)
  ( <span class="org-keyword">if</span> ( <span class="org-keyword">and</span> (stringp uri) (string-prefix-p  <span class="org-string">&quot;jar:///&quot;</span> uri))
      (apply orig-fn (replace-regexp-in-string  <span class="org-string">&quot;^jar:///&quot;</span>  <span class="org-string">&quot;jar:file:///&quot;</span> uri) args)
    (apply orig-fn uri args)))

( <span class="org-keyword">defun</span>  <span class="org-function-name">heks/eglot-path-to-uri-kotlin</span> (orig-fn path  <span class="org-type">&amp;rest</span> args)
  ( <span class="org-keyword">if</span> ( <span class="org-keyword">and</span> (stringp path) (string-prefix-p  <span class="org-string">&quot;jar:file:///&quot;</span> path))
      (replace-regexp-in-string  <span class="org-string">&quot;^jar:file:///&quot;</span>  <span class="org-string">&quot;jar:///&quot;</span> path)
    (apply orig-fn path args)))

( <span class="org-keyword">if</span> (fboundp 'eglot-uri-to-path)
    ( <span class="org-keyword">progn</span>
      (advice-add 'eglot-uri-to-path  <span class="org-builtin">:around</span> #'heks/eglot-uri-to-path-kotlin)
      (advice-add 'eglot-path-to-uri  <span class="org-builtin">:around</span> #'heks/eglot-path-to-uri-kotlin))
  ( <span class="org-keyword">progn</span>
    (advice-add 'eglot--uri-to-path  <span class="org-builtin">:around</span> #'heks/eglot-uri-to-path-kotlin)
    (advice-add 'eglot--path-to-uri  <span class="org-builtin">:around</span> #'heks/eglot-path-to-uri-kotlin)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Intercepting the Kotlin Empty  <code>newText</code> Auto-Completion Bug  <a id="intercepting-the-kotlin-empty-codenewtextcode-auto-completion-bug" class="anchor" href="#intercepting-the-kotlin-empty-codenewtextcode-auto-completion-bug" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9859801">
 <p>
A notorious issue in certain Kotlin LSP releases occurs during auto-completion. The server reports matching candidates, but mistakenly attaches a  <code>textEdit</code> field containing an empty string ( <code>newText: &quot;&quot;</code>). This causes Eglot to wipe out the word you are completing entirely.
</p>

 <p>
To solve this, I intercept the incoming JSON-RPC response payloads, both synchronous and asynchronous. If a Kotlin completion candidate returns an empty string edit, we strip the `textEdit` attribute completely, forcing Eglot to fall back gracefully to standard prefix matching.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">defun</span>  <span class="org-function-name">my-jsonrpc-request-kotlin-fix</span> (orig-fn connection method params  <span class="org-type">&amp;rest</span> args)
   <span class="org-doc">&quot;Fix kotlin-lsp empty newText bug by removing textEdit to trigger Eglot fallback.&quot;</span>
  ( <span class="org-keyword">let</span> ((result (apply orig-fn connection method params args)))
    ( <span class="org-keyword">when</span> ( <span class="org-keyword">and</span> (eq method  <span class="org-builtin">:textDocument/completion</span>)
               (derived-mode-p 'kotlin-mode 'kotlin-ts-mode)
               result)
      ( <span class="org-keyword">let</span> ((items ( <span class="org-keyword">if</span> (vectorp result) result (plist-get result  <span class="org-builtin">:items</span>))))
        (seq-do ( <span class="org-keyword">lambda</span> (item)
                  ( <span class="org-keyword">let</span> ((text-edit (plist-get item  <span class="org-builtin">:textEdit</span>)))
                     <span class="org-comment-delimiter">;; </span> <span class="org-comment">If the server sent an empty newText, strip textEdit completely
</span>                     <span class="org-comment-delimiter">;; </span> <span class="org-comment">so Eglot falls back to replacing the actual prefix.
</span>                    ( <span class="org-keyword">when</span> ( <span class="org-keyword">and</span> text-edit (equal (plist-get text-edit  <span class="org-builtin">:newText</span>)  <span class="org-string">&quot;&quot;</span>))
                      (plist-put item  <span class="org-builtin">:textEdit</span> nil))))
                items)))
    result))

( <span class="org-keyword">defun</span>  <span class="org-function-name">my-jsonrpc-async-request-kotlin-fix</span> (orig-fn connection method params  <span class="org-type">&amp;rest</span> args)
   <span class="org-doc">&quot;Fix kotlin-lsp empty newText bug in asynchronous Eglot requests.&quot;</span>
  ( <span class="org-keyword">if</span> ( <span class="org-keyword">and</span> (eq method  <span class="org-builtin">:textDocument/completion</span>)
           (derived-mode-p 'kotlin-mode 'kotlin-ts-mode))
      ( <span class="org-keyword">let*</span> ((orig-success (plist-get args  <span class="org-builtin">:success-fn</span>))
             (new-success ( <span class="org-keyword">lambda</span> (result)
                            ( <span class="org-keyword">let</span> ((items ( <span class="org-keyword">if</span> (vectorp result) result (plist-get result  <span class="org-builtin">:items</span>))))
                              (seq-do ( <span class="org-keyword">lambda</span> (item)
                                        ( <span class="org-keyword">let</span> ((text-edit (plist-get item  <span class="org-builtin">:textEdit</span>)))
                                          ( <span class="org-keyword">when</span> ( <span class="org-keyword">and</span> text-edit (equal (plist-get text-edit  <span class="org-builtin">:newText</span>)  <span class="org-string">&quot;&quot;</span>))
                                            (plist-put item  <span class="org-builtin">:textEdit</span> nil))))
                                      items))
                            (funcall orig-success result)))
             (new-args (plist-put (copy-sequence args)  <span class="org-builtin">:success-fn</span> new-success)))
        (apply orig-fn connection method params new-args))
    (apply orig-fn connection method params args)))

(advice-add 'jsonrpc-request  <span class="org-builtin">:around</span> #'my-jsonrpc-request-kotlin-fix)
(advice-add 'jsonrpc-async-request  <span class="org-builtin">:around</span> #'my-jsonrpc-async-request-kotlin-fix)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Silencing Metals Semantic Refresh Flickering  <a id="silencing-metals-semantic-refresh-flickering" class="anchor" href="#silencing-metals-semantic-refresh-flickering" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgdf46953">
 <p>
Scala Metals aggressively forces full buffer semantic token refreshes. In large projects, this results in visual layout flickering and unnecessary CPU strain. Disabling this also can solve some startup issues for Metals.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">defun</span>  <span class="org-function-name">my/eglot-disable-metals-semantic-refresh</span> (orig-fn server)
  ( <span class="org-keyword">let*</span> ((caps (funcall orig-fn server))
         (workspace (plist-get caps  <span class="org-builtin">:workspace</span>))
         (tokens (plist-get workspace  <span class="org-builtin">:semanticTokens</span>)))
    ( <span class="org-keyword">when</span> tokens
      (plist-put tokens  <span class="org-builtin">:refreshSupport</span>  <span class="org-builtin">:json-false</span>))
    caps))

(advice-add 'eglot-client-capabilities  <span class="org-builtin">:around</span> #'my/eglot-disable-metals-semantic-refresh)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Companion Packages: Java and Compressed Archives  <a id="companion-packages-java-and-compressed-archives" class="anchor" href="#companion-packages-java-and-compressed-archives" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2e0872f">
 <p>
To complete the setup, I load complementary minor modes outside of Eglot’s core file, ensuring smooth operations for Java and deep navigation for packed jars:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> eglot-java
   <span class="org-builtin">:ensure</span> t
   <span class="org-builtin">:after</span> (eglot)
   <span class="org-builtin">:hook</span> ((java-mode . eglot-java-mode)
         (java-ts-mode . eglot-java-mode)))

( <span class="org-keyword">use-package</span> jarchive
   <span class="org-builtin">:ensure</span> t
   <span class="org-builtin">:config</span>
  (jarchive-mode))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <ul class="org-ul"> <li> <code>eglot-java</code>: Provisions proper workspace configurations specifically for Eclipse JDT LS seamlessly.</li>
 <li> <code>jarchive</code>: Works harmoniously alongside the Kotlin JAR-URI translation hack, opening zipped up source containers into regular, viewable Emacs buffers.</li>
</ul></div>
 <h2>The way I like it on reproducibility  <a id="the-way-i-like-it-on-reproducibility" class="anchor" href="#the-way-i-like-it-on-reproducibility" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org70a0873">
 <p>
I generally don’t use the “global” system wide JDK installation, but I use isolated development reproducible shells with Nix flakes.
</p>

 <p>
I’ll eventually probably move to using Guix, but for now package availability isn’t quite there for JVM world so Nix it is.
</p>

 <p>
This way you can easily work on the same machine with many environments and projects (e.g. different Java versions) and no need for SDKMan or version managers, but clean isolated per-project reproducible builds.
</p>

 <p>
So I create a  <code>flake.nix</code> and add it to Git.
</p>

 <p>
Kotlin development flake (TODO intellij-server via Nix):
</p>
 <div class="jfw-code"> <pre>{
  inputs = {
    nixpkgs.url = &quot;github:NixOS/nixpkgs/nixos-unstable&quot;;
    systems.url = &quot;github:nix-systems/default&quot;;
  };
  outputs = { systems, nixpkgs, ... }:
    let
      eachSystem = f:
        nixpkgs.lib.genAttrs (import systems)
        (system: f nixpkgs.legacyPackages.${system});
    in {
      devShells = eachSystem (pkgs: {
        default = pkgs.mkShell {
          buildInputs = with pkgs; [
            ktfmt
            ktlint
            kotlin
            jdk25
            nil
            just
            yaml-language-server
          ];
        };
      });
    };
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Scala development flake.
</p>
 <div class="jfw-code"> <pre>{
  inputs = {
    nixpkgs.url = &quot;github:NixOS/nixpkgs/nixos-unstable&quot;;
    systems.url = &quot;github:nix-systems/default&quot;;
  };
  outputs = { systems, nixpkgs, ... }:
    let
      eachSystem = f:
        nixpkgs.lib.genAttrs (import systems)
        (system: f nixpkgs.legacyPackages.${system});
    in {
      devShells = eachSystem (pkgs: {
        default = pkgs.mkShell {
          buildInputs = with pkgs; [
            scala_2_13
            jdk25
            metals
            sbt
            scalafmt
            scalafix
            scala-cli
            yaml-language-server
            coursier
          ];
        };
      });
    };
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then I load the flake with  <a href="https://direnv.net/">direnv</a> so I create a  <code>.envrc</code> file .
</p>
 <div class="jfw-code"> <pre>use flake</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This way and inside Emacs I can use  <a href="https://github.com/wbolster/emacs-direnv">emacs-direnv</a> to dynamically switch contexts inside Emacs LSPs and have even multiple running.
</p>

 <p>
I also plug direnv into my Bash shell configurations and thus complete the development environment.
</p>
</div>
 <h2>Conclusion  <a id="conclusion" class="anchor" href="#conclusion" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbf4a4e4">
 <p>
Eglot’s minimal, built-in design doesn’t mean you have to settle for sub-par language server behavior. After all, you are using Emacs, so the power is infinite!
</p>

 <p>
By intercepting communication at the JSON-RPC level via  <code>advice-add</code>, you can tailor client-server behaviors exactly to your liking.
</p>

 <p>
Happy hacking! ✨
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/maak/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Maak: The power of Lisp that powers your trusty command runner and the enlightenments</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Quest for the eternal Dock - lambdock</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/">YAML Schemas in Emacs with Eglot</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/index.html</guid>
  <pubDate>Tue, 21 Jul 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Maak: The power of Lisp that powers your trusty command runner and the enlightenments</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>The infinitely extensible command runner, control plane and project automator à la Make (Guile Scheme - Lisp)</i>
</p>

 <p>
Find the project at  <a href="https://codeberg.org/jjba23/maak">https://codeberg.org/jjba23/maak</a>
</p>

 <p>
Most build tools invent their own limited domain-specific language.  Maak embraces the powerful  <b>λ Lisp</b>.
</p>

 <p>
This also means your code is solid, reliable and robust for the next 50 years at least.
</p>

 <p>
If you like my work, please support me by  <a href="https://bmc.link/jjbigorra">buying me a cup of coffee ☕</a> so I can continue with a lot of motivation.
</p>

 <div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
   <img src="https://jointhefreeworld.org/ggg/dist/scheme-guile.svg" alt="Scheme Guile"></img> <img src="https://jointhefreeworld.org/ggg/dist/gnu-guix.svg" alt="GNU Guix"></img> <img src="https://jointhefreeworld.org/ggg/dist/maak.svg" alt="Maak"></img> <img src="https://jointhefreeworld.org/ggg/dist/license-gpl3+.svg" alt="GPLv3+"></img> <img src="https://jointhefreeworld.org/ggg/dist/license-fdl13+.svg" alt="FDLv1.3+"></img> <img src="https://jointhefreeworld.org/ggg/dist/jointhefreeworld-org.svg" alt="Join The Free World"></img></div>

 <hr></hr> <h2>Core features  <a id="core-features" class="anchor" href="#core-features" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org52bc81d">
 <p>
Instead of learning a limited DSL, you can leverage your existing Lisp skills to define tasks, manage data, and automate your workflows with ease. Define functions, manipulate lists, use conditional, create macros—the entire language is at your disposal.
</p>

 <p>
You can also easily call external shell commands and integrate with your existing scripts and tools.
</p>

 <p>
All you will need to do to use Maak is to write a file (by default  <code>./maak.scm</code>) where you define your Maak file module and import Maak library:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">maak</span>)
   <span class="org-builtin">#:declarative?</span> #t
   <span class="org-builtin">#:use-module</span> (maak maak))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Defining tasks  <a id="defining-tasks" class="anchor" href="#defining-tasks" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge5d8fe0">
 <p>
Any function (with or without arguments) you define in this file becomes a runnable task.
</p>
</div>
 <h3>Task Export &amp; Visibility Rule  <a id="task-export-amp-visibility-rule" class="anchor" href="#task-export-amp-visibility-rule" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org528c1f2">
 <ul class="org-ul"> <li> <b>Open Fallback (No Exports)</b>: If you do not write an  <code>#:export</code> directive in your module (or leave it empty), Maak is completely “open season”: all procedures in the file are treated as runnable tasks.</li>
 <li> <b>Strict Lock (With Exports)</b>: If you define anything in your  <code>#:export</code> directive (e.g.,  <code>#:export (quick-math)</code>), then only the explicitly exported procedures will be treated as tasks. Any other functions become private helper procedures and are completely hidden from the CLI and  <code>--list</code> command.</li>
</ul> <p>
If no task is passed via command-line, Maak will run the  <code>default</code> task.
</p>

 <p>
Tasks can:
</p>
 <ul class="org-ul"> <li>Run shell commands with the  <code>$</code> helper.</li>
 <li>Print logs with  <code>log-info</code>.</li>
 <li>Call other Maak tasks.</li>
 <li>Use any Guile Scheme function you define (or import from a library).</li>
 <li>Some syntactic sugar for working with Guix dev shells and time-machine, e.g.   <code>manifest-shell</code> and  <code>program-shell</code> as well as  <code>time-machine-manifest-shell</code> and more</li>
</ul> <p>
⚠️ Beware not to use names for tasks that conflict with names of built-in Scheme functions as this can cause some problems. For example, avoid calling something  <code>format</code> or  <code>display</code>, choose something else instead.
</p>

 <p>
You can extend Maak by defining new tasks — just like writing functions in Scheme.
</p>

 <p>
Here’s an example:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">hello</span>)
   <span class="org-doc">&quot;Say hello from Maak!&quot;</span>
  (display  <span class="org-string">&quot;Hello from Maak!&quot;</span>)
  (display (format #f  <span class="org-string">&quot;~a + ~a = ~a&quot;</span> 3 4 (+ 3 4))))

( <span class="org-keyword">define</span> ( <span class="org-function-name">quick-math</span> x-arg y-arg)
   <span class="org-comment-delimiter">;; </span> <span class="org-comment">beware task args come always as strings due to CLI parse
</span>  ( <span class="org-keyword">let*</span> ((x (string-&gt;number x-arg))
         (y (string-&gt;number y-arg)))
    (format #t  <span class="org-string">&quot;~a + ~a = ~a&quot;</span> x y
            (+ x y))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can now run it:
</p>

 <div class="jfw-code"> <pre>maak hello
maak quick-math 23 42</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can also run multiple tasks easily (sequentially) via a comma-separated list :
</p>

 <div class="jfw-code"> <pre>maak fmt,compile,test</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Often it’s just cleaner to do it directly in Lisp (Scheme code ) in your Maakfile (where it’s also trivial to add concurrent computations)
</p>

 <p>
More advanced examples here and below:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;; </span> <span class="org-comment">Format Scheme source code files according to the Guix style guide.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">fmt</span>)
  (log-info  <span class="org-string">&quot;Format Scheme files using Guix Style&quot;</span>)
  ($ '( <span class="org-string">&quot;find . -maxdepth 8 -name '*.scm'&quot;</span>
        <span class="org-string">&quot;-type f -exec guix style -f {} \\;&quot;</span>)
      <span class="org-builtin">#:verbose?</span> #t))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Display program help screen.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">help</span>)
  ($ '( <span class="org-string">&quot;guix shell -f guix.scm -- maak --help&quot;</span>)))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">By default (no task given) run help.
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">default</span>)
  ($ '( <span class="org-string">&quot;maak --list&quot;</span>))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Do some quick math
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">arithmetics</span>)
  (fmt)  <span class="org-comment-delimiter">;; </span> <span class="org-comment">call another task first
</span>  ( <span class="org-keyword">let*</span> ((entries '(1 3 5 7 9))
         (arithmetics ( <span class="org-keyword">lambda</span>(x) (* x x 3)))
         (some-data ( <span class="org-keyword">map</span> arithmetics entries)))
    (log-info  <span class="org-string">&quot;Running default task&quot;</span>)
    (log-info  <span class="org-string">&quot;Performed some fun arithmetics:\nResult: ~a&quot;</span> some-data)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr> <div id="org7ae8aeb" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/maak/new-maak-small.png"></img></p>
</div>

 <p>
The project logo of maak was generated by the ChatGPT Dall-E LLM when fed this very document
</p>

 <hr></hr></div>
 <h2>Command Line Interface Options  <a id="command-line-interface-options" class="anchor" href="#command-line-interface-options" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4812bc2">
 <p>
Maak provides standard CLI options to manage your execution pipeline:
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Short Flag</th>
 <th scope="col" class="org-left">Long Flag</th>
 <th scope="col" class="org-left">Argument</th>
 <th scope="col" class="org-left">Description</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>-f</code></td>
 <td class="org-left"> <code>--file</code></td>
 <td class="org-left"> <code>FILE</code></td>
 <td class="org-left">Specify the path to the Maak file (defaults to  <code>./maak.scm</code>).</td>
</tr> <tr> <td class="org-left"> <code>-h</code></td>
 <td class="org-left"> <code>--help</code></td>
 <td class="org-left">None</td>
 <td class="org-left">Display the help screen and exit.</td>
</tr> <tr> <td class="org-left"> <code>-l</code></td>
 <td class="org-left"> <code>--list</code></td>
 <td class="org-left">None</td>
 <td class="org-left">List all available tasks in the currently loaded Maak file.</td>
</tr> <tr> <td class="org-left"> <code>-n</code></td>
 <td class="org-left"> <code>--dry-run</code></td>
 <td class="org-left">None</td>
 <td class="org-left">Dry-run mode. Print shell commands instead of executing them.</td>
</tr> <tr> <td class="org-left"> <code>-q</code></td>
 <td class="org-left"> <code>--quiet</code></td>
 <td class="org-left">None</td>
 <td class="org-left">Quiet mode. Suppress standard logging, banners, and header outputs.</td>
</tr></tbody></table> <p>
To pass arguments directly to a task, it’s recommended to separate options from tasks with a double-dash ( <code>--</code>):
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">Run clean and build in dry-run mode, quietly
</span>maak -n -q -- clean,build

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Run a custom task with arguments
</span>maak -f ./my-tasks.scm -- deploy production</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <hr></hr></div>
 <h2>Examples of maak files  <a id="examples-of-maak-files" class="anchor" href="#examples-of-maak-files" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcc285d6">
 <p>
Find below a list of some projects using maak for their automation. Reminder:  <code>maak.scm</code> is the default name of a maak file, but you can choose to use a different one.
</p>

 <ul class="org-ul"> <li> <a href="https://codeberg.org/jjba23/heks-linux">Heks GNU/Linux</a> - The witches’ GNU/Linux: modular, flexible, reproducible, powered by Lisp and Fedora / Debian + GNOME / Niri</li>
 <li> <a href="https://codeberg.org/jjba23/lucidplan">LucidPlan</a> - Project management (CMS) for everyone - free and open</li>
 <li> <a href="https://codeberg.org/jjba23/veritas">Veritas</a> - Unit, Integration and Black Box testing framework powered by Lisp (Guile Scheme)</li>
 <li> <a href="https://codeberg.org/jjba23/mutastructura">Mutastructura</a> -  Relational Schema and Database Migrations powered by Lisp (Guile Scheme)</li>
 <li> <a href="https://codeberg.org/jjba23/ggg">GGG (Guile Glyph Generator)</a> - Create SVG images, handy useful glyphs, org/markdown badges.</li>
 <li> <a href="https://codeberg.org/jjba23/hygguile">Hygguile</a> - UI framework for cozy and professional user-interfaces for everyone with the power of Scheme.</li>
 <li> <a href="https://codeberg.org/jjba23/sss">SSS (Supreme Sexp System)</a> - SSS is a Lisp machine adventure, where the hacking culture is celebrated. This custom GNU + Linux setup enhances customization to infinity, encourages the hacking spirit.</li>
</ul> <hr></hr></div>
 <h2>Why write Maak ?  <a id="why-write-maak-" class="anchor" href="#why-write-maak-" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9f44fa2">
 <p>
Have you ever found Makefile to be repetitive, lacking expressiveness and having a weird, limited syntax and unexpected arcane behavior?
</p>

 <p>
No fear,  <b>Maak</b> is here. With the full power of Lisp directly in your command runner/control plane,  easily define functions, data, lists, loop through them, macros, etc. Maak replaces the arcane syntax of Make with the power and elegance of a full-featured functional programming language: GNU Guile Scheme λ.
</p>

 <p>
Maak replaces Make’s runes and mystery with the power and clarity of GNU Guile Scheme λ.
</p>
</div>
 <h2>The Problems with Make  <a id="the-problems-with-make" class="anchor" href="#the-problems-with-make" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org52836b0">
 <p>
Many developers find GNU Make and related tooling to be at times frustrating and not intuitive, despite being so powerful.
</p>

 <p>
Makefile often contains  <i>repetitive</i> code, particularly when dealing with similar targets or file types. You might have to write a separate rule for every single output file, even if the process is exactly the same. The limited syntax makes it difficult to abstract this logic into reusable functions or macros, leading to a lot of copy-pasting.
</p>

 <p>
Make’s syntax is a Domain-Specific Language (DSL), not a general-purpose programming language. While it’s powerful for its intended purpose of managing dependencies, it’s  <i>terrible for anything else</i>.
</p>

 <p>
Defining variables, using conditionals, or looping over a list of items can be surprisingly clunky and often requires arcane, non-standard constructs.
</p>

 <p>
Make has many “gotchas” that can trip up even experienced users.
</p>
</div>
 <h2>How Maak Innovates  <a id="how-maak-innovates" class="anchor" href="#how-maak-innovates" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3d305fc">
 <p>
Maak positions itself as a modern infinitely extensible task runner, using the functional programming language  GNU Guile Scheme (a dialect of Lisp). No need for .PHONY recipes here.
</p>

 <p>
Maak gives you the power of Scheme. You’re not restricted to a limited, weird syntax. This means you can easily define functions to avoid repetition, create complex data structures (like lists and maps), and use control flow statements (like loops and conditionals) to write much cleaner and more expressive scripts.
</p>

 <p>
Instead of having to learn a new, limited language, you can leverage your existing Lisp knowledge to define tasks, manage data, and automate your workflows. This leads to code that is much easier to read, write, and maintain. For example, you can write a simple loop to process all your source files instead of writing a separate rule for each one.
</p>

 <p>
Maak is designed to be your central control plane. While Make is primarily focused on building software from source, Maak is a general-purpose command runner. This means you can use it for tasks like running tests, deploying applications, or managing your development environment. It’s meant to be a more flexible and powerful alternative for all your project’s automation needs.
</p>

 <hr></hr></div>
 <h2>Parameterize: customize the running of tasks and commands  <a id="parameterize-customize-the-running-of-tasks-and-commands" class="anchor" href="#parameterize-customize-the-running-of-tasks-and-commands" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd7f023a">
 <p>
Dry-run and quietness can be defined globally using the command-line options ( <code>-n</code> /  <code>-q</code>), but they are also easily controlled and overridden in lexical scope via Lisp (Scheme) parameters.
</p>

 <p>
This gives you a highly precise control mechanism when testing. For example, you can write a test task that dynamically runs destructive file manipulations safely in a localized dry-run scope, without requiring the user to pass a CLI flag.
</p>

 <p>
Dry-runs for example are  good for testing.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">fmt</span>)
   <span class="org-doc">&quot;Format Scheme source code files according to the Guix style guide.&quot;</span>
  (syscall  <span class="org-string">&quot;ls&quot;</span>)  <span class="org-comment-delimiter">;; </span> <span class="org-comment">this will run
</span>   <span class="org-comment-delimiter">;; </span> <span class="org-comment">this will not
</span>  ( <span class="org-keyword">parameterize</span> ((dry-run? #t)
                 (quiet? #f))
    (delete-file-recursively  <span class="org-string">&quot;tmp&quot;</span>)
    ($ '( <span class="org-string">&quot;find . -maxdepth 8 -name '*.scm'&quot;</span>
          <span class="org-string">&quot;-type f -exec guix style -f {} \\;&quot;</span>)
        <span class="org-builtin">#:verbose?</span> #t)))
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">it will print instead or unning
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">[DRY-RUN]: rm -rfv tmp
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">[DRY-RUN]: find . -maxdepth 8 -name '*.scm' -type f -exec guix style -f {} \;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Help  <a id="help" class="anchor" href="#help" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf3946bd">
 <p>
The project’s automation is done using Maak itself, check the  <code>maak.scm</code> file.
</p>

 <p>
Also, find the technical Guile Scheme API documentation of Maak here:
</p>

 <p>
 <a href="https://jointhefreeworld.org/api-docs/maak/index.html">https://jointhefreeworld.org/api-docs/maak/index.html</a>
</p>

 <p>
You can see the program’s help by invoking ggg with the  <code>--help</code> argument or looking at  <code>resources/help.txt</code>.
</p>

 <hr></hr></div>
 <h2>Installing  <a id="installing" class="anchor" href="#installing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga26778c">
 <p>
maak is officially distributed via:
</p>
 <ul class="org-ul"> <li>Guix package manager</li>
 <li>Podman/Docker images</li>
</ul> <p>
 <i>That being said, feel free to use it as you wish, within the terms of the GNU General Public License v3 or newer.</i>
</p>
</div>
 <h3>On Guix  <a id="on-guix" class="anchor" href="#on-guix" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org1ee118d">
 <p>
Maak is Guix-first and caters to Guix as first-class citizen in favor of other package managers or build systems. Maak targets exclusively systems that can run Guile Scheme (and optionally Guix). Check the  <code>maak.scm</code>, the  <code>guix.scm</code> and  <code>manifest.scm</code> for more details.
</p>

 <p>
Requirements:
</p>
 <ul class="org-ul"> <li> <b>Guix</b>: The Guix package manager will ensure a reproducible working software, and will manage all needed dependencies for you.</li>
 <li> <b>Guile Scheme:</b>  This entire program is written using the official GNU extension language, Guile Scheme.</li>
</ul> <p>
If you just want to quickly install it to your profile:
</p>

 <div class="jfw-code"> <pre>guix package --install-from-file=./guix.scm</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
For example, to enter an environment shell with maak temporarily you can use:
</p>
 <div class="jfw-code"> <pre>guix time-machine --channels=channels.scm -- shell -f guix.scm</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can also chain commands to it:
</p>

 <div class="jfw-code"> <pre>guix time-machine --channels=channels.scm --  <span class="org-sh-escaped-newline">\</span>
     shell -f guix.scm --  <span class="org-sh-escaped-newline">\</span>
     maak --help</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can also run a dev shell (with manifest)
</p>
 <div class="jfw-code"> <pre>guix time-machine --channels=channels.scm --  <span class="org-sh-escaped-newline">\</span>
     shell -m manifest.scm -- guile -L ./src -c  <span class="org-sh-escaped-newline">\</span>
      <span class="org-string">'((@(maak main) main))'</span> --list</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Maak is available in upstream Guix as  <code>maak</code> in the module  <code>(gnu packages build-tools)</code>
</p>
</div>
 <h3>On Podman/Docker  <a id="on-podmandocker" class="anchor" href="#on-podmandocker" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgddcdc5e">
 <p>
Maak is also available as a Docker container, from DockerHub (also compatible with Podman).
</p>

 <p>
 <a href="https://hub.docker.com/repository/docker/jjba23/maak/general">https://hub.docker.com/repository/docker/jjba23/maak/general</a>
</p>

 <p>
You can also build images of maak yourself, using  <code>guix pack</code>. See the  <code>maak.scm</code> file for more.
To load these tarball images, you can do  <code>podman load &lt; my.tar.gz</code>
</p>

 <p>
Then you can run Maak from the container, and bind your local filesystem to give access, for example:
</p>

 <div class="jfw-code"> <pre>docker container run -v /home/joe:/home/joe  <span class="org-sh-escaped-newline">\</span>
    docker.io/jjba23/maak:latest  <span class="org-sh-escaped-newline">\</span>
    maak -f /home/joe/hacking/maak/maak.scm --list</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Shell completions: Bash, ZSH, Fish  <a id="shell-completions-bash-zsh-fish" class="anchor" href="#shell-completions-bash-zsh-fish" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org83f9591">
 <p>
Maak offers a simple but powerful shell completion. When you are in a directory with  <code>maak.scm</code> files, you can type  <code>maak</code> followed by space, then hit TAB and you will see the names of maak tasks appear. This is done by reading the current file and extracting task names from it with some awk magic.
</p>

 <p>
See the scripts at  <code>./scripts</code> . You should “source” these script if you want these completions to be available for you.
</p>

 <p>
You might find these variables useful (for your  <code>.bashrc</code>,  <code>.zshrc</code>  or  <code>fish</code> config) specially if you run Guix, but feel free to download and load the scripts from  <code>./scripts</code> at your will in your shell.
</p>

 <p>
For ZSH and fish shell, scripts are also provided, and should be loaded in similar fashion. See  <code>./scripts</code>
</p>

 <p>
ZSH users will want to add the Maak completion script to  <code>$FPATH</code>. Fish users will want to look at  <code>$fish_complete_path</code>.
</p>

 <p>
Bash example:
</p>

 <div class="jfw-code"> <pre> <span class="org-variable-name">maak_bin_install_dir</span>=$( <span class="org-sh-quoted-exec">which maak</span>)
 <span class="org-variable-name">maak_install_dir</span>=$( <span class="org-sh-quoted-exec">realpath &quot;${maak_bin_install_dir}&quot;</span>)
 <span class="org-variable-name">maak_bin</span>=$( <span class="org-sh-quoted-exec">dirname &quot;${maak_install_dir}&quot;</span>)
 <span class="org-variable-name">maak_store</span>=$( <span class="org-sh-quoted-exec">dirname &quot;${maak_bin}&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/usr/bin/</span> <span class="org-keyword">env</span> <span class="org-comment"> bash
</span> <span class="org-variable-name">maak_completions</span>= <span class="org-string">&quot;${maak_store}/share/scripts/maak-completion.bash&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Load Maak auto-completions
</span> <span class="org-keyword">if</span> [[ -f  <span class="org-string">&quot;${maak_completions}&quot;</span> ]];  <span class="org-keyword">then</span>
   <span class="org-builtin">source</span>  <span class="org-string">&quot;${maak_completions}&quot;</span> || true
 <span class="org-keyword">fi</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <hr></hr></div>
 <h2>Maak integrations  <a id="maak-integrations" class="anchor" href="#maak-integrations" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7d3f9ed">
 <p>
Creating a connection to Maak from your favourite programmable environment should be simple.
</p>

 <p>
You can see an Emacs integration here:  <a href="https://codeberg.org/jjba23/maak.el">maak.el</a>
</p>


 <div id="orgdd2f2d4" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/maak/maak-in-emacs.png"></img></p>
</div>

 <hr></hr></div>
 <h2>Licensing  <a id="licensing" class="anchor" href="#licensing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3c80ffe">
 <p>
Maak and all of its source code are free software, licensed under the GNU General Public License v3 (or newer at your convenience).
</p>

 <p>
 <a href="https://www.gnu.org/licenses/gpl-3.0.html">https://www.gnu.org/licenses/gpl-3.0.html</a>
</p>

 <p>
The documentation and examples, including this document, which are provided with Maak, are all licensed under the GNU Free Documentation License v1.3 (or newer at your convenience).
</p>

 <p>
 <a href="https://www.gnu.org/licenses/fdl-1.3.html">https://www.gnu.org/licenses/fdl-1.3.html</a>
</p>

 <hr></hr></div>
 <h2>REPL: Interactive workflow, developer power  <a id="repl-interactive-workflow-developer-power" class="anchor" href="#repl-interactive-workflow-developer-power" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4d3baa6">
 <p>
A REPL (Read-Eval-Print Loop) is an interactive environment, which can be used connected to your console, running application, language compiler and more, which gives you superpowers as an engineer 🦸🏼.
</p>

 <p>
Lisp dialects, more specifically Guile Scheme, have great support for this. I personally of course like to do this with  <a href="https://guix.gnu.org/">Guix</a>,  <a href="https://www.gnu.org/software/emacs/">Emacs</a>, ( <a href="https://git.sr.ht/~abcdw/emacs-arei">Arei/Ares</a> +  <a href="https://github.com/vspinu/sesman">sesman</a>) you can get an ultimate extensible powerful editor experience, miles ahead of traditional IDEs 🐂 .
</p>

 <p>
It fundamentally changes the development workflow by eliminating the slow  <i>edit, save, compile, run</i> cycle. Instead of writing a whole program and then running it to see what happens, you get a fast, conversational workflow. What does this mean for in practice?
</p>

 <ul class="org-ul"> <li> <b>Incremental Development:</b> Write, test, inspect, evaluate one function or even one line at a time. Get immediate feedback without running the entire app.</li>
 <li> <b>Powerful Debugging:</b> Forget adding  <code>print</code> statements and restarting. You can pause, inspect objects, change values, and even redefine a broken function on the fly to test a fix in any environment (yes even in production, while running).</li>
 <li> <b>Fast Prototyping &amp; Learning:</b> Instantly experiment with a new library or API. Just load it and start calling functions to see how they work, which is much faster than only reading documentation.</li>
</ul> <p>
When integrated into your code editor, you can execute any piece of code (a line, a selection, or a file) with a keyboard shortcut and see the result instantly, creating a seamless and powerful development experience.
</p>

 <hr></hr></div>
 <h2>AI Policy  <a id="ai-policy" class="anchor" href="#ai-policy" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org07c5f4e">
 <p>
This project adheres to the  <a href="https://jointhefreeworld.org/ai-policy/">jointhefreeworld AI (Artificial Intelligence) policy</a>.
</p>

 <p>
Our core principle is simple:  <b>AI should assist human creativity and problem-solving, never replace human reasoning.</b>
</p>

 <p>
While tools like Large Language Models (LLMs) and interactive chatbots can be beneficial for reviewing, refactoring small functions, or acting as a sounding board, they should be used with moderation.
</p>

 <p>
We require a human in the loop for all contributions.
</p>



 <hr></hr></div>
 <h2>Code of conduct  <a id="code-of-conduct" class="anchor" href="#code-of-conduct" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgff5a59e">
 <p>
This project adheres to the jointhefreeworld code of conduct. Find it here:
</p>

 <p>
 <a href="https://jointhefreeworld.org/code-of-conduct/">https://jointhefreeworld.org/code-of-conduct/</a>
</p>

 <p>
In summary, we foster an inclusive, respectful, and cooperative environment for all contributors and users of this free software project. Inspired by the ideals of the GNU Project, we strive to uphold freedom, equality, and community as guiding principles. We believe that collaboration in a community of mutual respect is essential to creating excellent free software.
</p>

 <hr></hr></div>
 <h2>Maak Project  <a id="maak-project" class="anchor" href="#maak-project" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org8811b05">
 <p>
Contributing to free software is a uniquely beautiful act because it embodies principles of generosity, collaboration, and empowerment.
</p>

 <p>
We welcome everyone to feel invited to the Maak Project, and encourage active contribution in all forms, to improve it and/or suggest improvements, brainstorm with me, make it more modular/flexible, etc, feel free to contact me &lt;jjbigorra@gmail.com&gt; to chat, discuss or report feedback.
</p>

 <p>
Find here the Backlog and Kanban boards for Maak:  <a href="https://lucidplan.jointhefreeworld.org/tickets/maak">https://lucidplan.jointhefreeworld.org/tickets/maak</a>
</p>

 <p>
Maak embodies the spirit of GNU: simplicity, freedom, and curiosity.
It’s both a tool and a playground for learning Lisp-based automation.
</p>

 <p>
As you grow comfortable, extend Maak — define your own DSLs, orchestrate builds, or automate your projects in elegant Scheme.
</p>

 <p>
Happy hacking! ✨
</p>

 <hr></hr></div>
 <h2>The Philosophy of Maak  <a id="the-philosophy-of-maak" class="anchor" href="#the-philosophy-of-maak" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge593ab2">
 <p>
Maak was designed with a few simple but powerful ideas in mind — ideas rooted in the GNU tradition and Lisp philosophy.
</p>
</div>
 <h3>Lisp as the Language of Tasks  <a id="lisp-as-the-language-of-tasks" class="anchor" href="#lisp-as-the-language-of-tasks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9019978">
 <p>
Every build rule, every script, is a first-class Scheme function.
This means your automation scripts are  <b>composable</b>,  <b>readable</b>, and  <b>hackable</b>.
</p>
</div>
 <h3>Purity and Reproducibility  <a id="purity-and-reproducibility" class="anchor" href="#purity-and-reproducibility" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgbffed2d">
 <p>
Maak believes in pure, deterministic environments, that’s why it integrates so well with GNU Guix 🐂.
</p>
</div>
 <h3>Small Is Beautiful  <a id="small-is-beautiful" class="anchor" href="#small-is-beautiful" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org20ded81">
 <p>
No YAML, HOCON, INI or configs, no hidden logic, no magic — just clean Scheme code.
</p>

 <p>
Every part of Maak can be read, understood, and extended within a good afternoon of hacking ☕.
</p>
</div>
 <h3>Free as in Freedom  <a id="free-as-in-freedom" class="anchor" href="#free-as-in-freedom" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd3a62e7">
 <p>
It’s free software under the GNU GPL, built to encourage curiosity, learning, and contribution.
</p>

 <p>
You own your build logic, you can read it, change it, and share it freely.
</p>

 <hr></hr></div>
 <h2>Hacking on Maak  <a id="hacking-on-maak" class="anchor" href="#hacking-on-maak" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org30d8900">
 <p>
In systems where  <code>maak</code> is already installed, a good way to compile from source and test all program functionalities is a pure shell:
</p>

 <div class="jfw-code"> <pre>guix shell --pure -f guix.scm  <span class="org-sh-escaped-newline">\</span>
     bash coreutils util-linux-with-udev guile --  <span class="org-sh-escaped-newline">\</span>
     maak --list

 <span class="org-comment-delimiter"># </span> <span class="org-comment">run project tests
</span>guix time-machine --channels=channels.scm --  <span class="org-sh-escaped-newline">\</span>
     shell -f guix.scm --pure --  <span class="org-sh-escaped-newline">\</span>
     maak test</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Hacking Freedom: Compiling GNU Emacs from Source</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Emacs Eglot for Scala and Kotlin (JVM)</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/maak/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/maak/index.html</guid>
  <pubDate>Wed, 15 Jul 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Hacking Freedom: Compiling GNU Emacs from Source</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
By compiling GNU Emacs directly from the upstream Savannah repositories, you unlock the absolute bleeding edge of the extensible, self-documenting operating system disguised as a text editor.
</p>

 <p>
True autonomy over your computing environment sometimes involves building your own tools and customizing many programs.
</p>

 <p>
We start by cloning the live development branch straight from the GNU project’s forge.
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">maker sure to have Git
</span>sudo apt update
sudo apt upgrade

sudo apt install git

 <span class="org-builtin">cd</span> ~/Fork  <span class="org-comment-delimiter"># </span> <span class="org-comment">or wherever
</span>git clone https://git.savannah.gnu.org/git/emacs.git emacs-build
 <span class="org-builtin">cd</span> emacs-build</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
 <h2>Dependencies  <a id="dependencies" class="anchor" href="#dependencies" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2a7234e">
 <p>
Depending on the compilation options we choose, we need some build and compile time dependencies. Before we can shape the metal, we need the furnace. For example in Debian we need things like:
</p>

 <div class="jfw-code"> <pre>sudo apt update
sudo apt install build-essential autoconf imagemagick libmagickwand-dev libgtk-3-dev librsvg2-dev libsqlite3-dev libgccjit0 libgccjit-15-dev libgnutls28-dev libtree-sitter-dev</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <div class="note" id="org1b3e451">
 <p>
Pro-tip: If you want a quick shortcut to grab standard development headers for graphics and window management libraries, you can run  <code>sudo apt-get build-dep emacs</code> before moving to the next step.
</p>

</div>
</div>
 <h2>Autogen  <a id="autogen" class="anchor" href="#autogen" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9cac869">
 <p>
Run the autogen.sh the first time
This script will generate the configuration scaffold. You only really need to do this once (and I always forget about it for this very reason). Simply do this on the command line:
</p>

 <p>
 <code>./autogen.sh</code>
It checks that you have all you need to get started and prints output like this:
</p>

 <pre class="example" id="orgf92de28">
Checking whether you have the necessary tools...
(Read INSTALL.REPO for more details on building Emacs)
Checking for autoconf (need at least version 2.65) ... ok
Your system has the required tools.
Building aclocal.m4 ...
Running 'autoreconf -fi -I m4' ...
Building 'aclocal.m4' in exec ...
Running 'autoreconf -fi' in exec ...
Configuring local git repository...
'.git/config' -&gt; '.git/config.~1~'
git config transfer.fsckObjects 'true'
git config diff.cpp.xfuncname '!^[ 	]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])
^((::[[:space:]]*)?[A-Za-z_][A-Za-z_0-9]*[[:space:]]*\(.*)$
^((#define[[:space:]]|DEFUN).*)$'
git config diff.elisp.xfuncname '^\([^[:space:]]*def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
git config diff.m4.xfuncname '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
git config diff.make.xfuncname '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
git config diff.shell.xfuncname '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
git config diff.texinfo.xfuncname '^@node[[:space:]]+([^,[:space:]][^,]+)'
Installing git hooks...
'build-aux/git-hooks/commit-msg' -&gt; '.git/hooks/commit-msg'
'build-aux/git-hooks/pre-commit' -&gt; '.git/hooks/pre-commit'
'build-aux/git-hooks/prepare-commit-msg' -&gt; '.git/hooks/prepare-commit-msg'
'build-aux/git-hooks/post-commit' -&gt; '.git/hooks/post-commit'
'build-aux/git-hooks/pre-push' -&gt; '.git/hooks/pre-push'
'build-aux/git-hooks/commit-msg-files.awk' -&gt; '.git/hooks/commit-msg-files.awk'
'.git/hooks/applypatch-msg.sample' -&gt; '.git/hooks/applypatch-msg'
'.git/hooks/pre-applypatch.sample' -&gt; '.git/hooks/pre-applypatch'
</pre>

 <p>
You can now run  <code>./configure</code>
Do not be intimidated by it. Focus on the final line instead, which directs you to the configure directive.
</p>
</div>
 <h2>Configuration Flags  <a id="configuration-flags" class="anchor" href="#configuration-flags" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org00b9bc3">
 <p>
This is where you sculpt Emacs to your exact workflow. True hackers audit their build environment—you can inspect every configuration option available by running  <code>./configure --help</code>.
</p>

 <p>
For a modern, highly optimized, Wayland-native hacker workstation, these choices are optimal:
</p>

 <div class="jfw-code"> <pre>./configure --with-native-compilation=aot  <span class="org-sh-escaped-newline">\</span>
            --with-tree-sitter  <span class="org-sh-escaped-newline">\</span>
            --with-pgtk  <span class="org-sh-escaped-newline">\</span>
            --with-dbus  <span class="org-sh-escaped-newline">\</span>
            --with-imagemagick  <span class="org-sh-escaped-newline">\</span>
            --with-mailutils</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Why these flags matter:  <a id="why-these-flags-matter" class="anchor" href="#why-these-flags-matter" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb046970">
 <dl class="org-dl"> <dt> <code>--with-native-compilation=aot</code></dt> <dd>Compiles Emacs Lisp directly into native machine code Ahead-Of-Time. Maximum performance, zero lag.</dd>
 <dt> <code>--with-tree-sitter</code></dt> <dd>Swaps out old regex parsing for high-performance, incremental AST parsing. Better structural navigation and syntax awareness.</dd>
 <dt> <code>--with-pgtk</code></dt> <dd>Pure GTK. Critical if you are running a modern Wayland compositor and want to bypass the legacy Xwayland translation layer completely.</dd>
</dl></div>
 <h2>Compile and Install  <a id="compile-and-install" class="anchor" href="#compile-and-install" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org84e59d0">
 <p>
First, ensure you are starting from a completely pristine state. If you are rebuilding an older tree or updating a previous commit, wipe away old compilation artifacts:
</p>

 <div class="jfw-code"> <pre>make clean</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now, unleash the compiler. Instead of hardcoding an arbitrary job number, let’s query your machine to leverage every single parallel thread your processor has to offer:
</p>

 <div class="jfw-code"> <pre>make -j$( <span class="org-sh-quoted-exec">nproc</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Once the compilation wraps up successfully, verify your creation in-place before deploying it system-wide:
</p>

 <div class="jfw-code"> <pre>./src/emacs --version</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You should be greeted by that glorious declaration of software liberty:
</p>

 <pre class="example" id="org2cb3bf5">
GNU Emacs 31.0.50
Copyright (C) 2026 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
</pre>

 <p>
If everything looks pristine, purge any pre-packaged, stale distro binaries and inject your custom-built system into the local environment:
</p>

 <div class="jfw-code"> <pre>sudo apt remove emacs emacs-pgtk
rm -rf ~/.emacs.d
sudo make install</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Do a final check to confirm your shell path resolves directly to your new build:
</p>

 <div class="jfw-code"> <pre>which emacs
emacs --version</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>How to Roll Back  <a id="how-to-roll-back" class="anchor" href="#how-to-roll-back" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd9cb0ec">
 <p>
A good hacker respects filesystem layout and modularity.  <b>Do not delete this build directory.</b> Keeping this folder intact ensures you retain the local blueprint of your installation. If you ever want to upgrade to a newer upstream commit or cleanly purge this build from your system, simply navigate back here and run:
</p>

 <div class="jfw-code"> <pre>sudo make uninstall</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Your operating environment remains clean, untainted, and completely under your control. Welcome to the bleeding edge. Happy hacking! 🚀
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">jointhefreeworld - A Style Guide for Documentation</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/maak/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Maak: The power of Lisp that powers your trusty command runner and the enlightenments</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/">YAML Schemas in Emacs with Eglot</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/index.html</guid>
  <pubDate>Wed, 01 Jul 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>jointhefreeworld - A Style Guide for Documentation</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <div id="table-of-contents" role="doc-toc">
 <h2>Table of Contents</h2>
 <div id="text-table-of-contents" role="doc-toc">
 <ul> <li> <a href="#orgf187e09">Basic points of style</a></li>
 <li> <a href="#orga4db93b">More points of style</a></li>
 <li> <a href="#orgc001746">Ordering your text</a></li>
 <li> <a href="#orga67041c">Code examples</a></li>
 <li> <a href="#orgca42198">Metaphors</a></li>
 <li> <a href="#orgc34dcf4">English usage</a></li>
</ul></div>
</div>
 <blockquote>
 <p>
Based largely on comments by Ron Hale-Evans, Robert J. Chassell, and Richard M. Stallman.
</p>
</blockquote>

 <p>
This guide collects the habits that make technical writing clear and useful. It applies to manuals, tutorials, READMEs, and blog posts alike.
</p>
 <h2>Basic points of style  <a id="basic-points-of-style" class="anchor" href="#basic-points-of-style" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf187e09">
 <ul class="org-ul"> <li> <b>Show, don’t just tell.</b> Use plenty of examples, but avoid being overly redundant.</li>
 <li>Move slowly. Do not impose too much of a cognitive load at once on the reader.</li>
 <li>Explain things in detail if you are writing a tutorial for a novice. Since one tends to under-explain anyway, pretend you are writing for an intelligent person who is entirely unfamiliar with the technology you are explaining.</li>
 <li>Don’t say too little. If you cannot include enough information on a topic to do more than tantalize a novice, omit it entirely.</li>
 <li>Do not assume the reader has specific knowledge of mathematics or computer science when it is possible they don’t. You may have to explain what an integer is or what a byte is, at least at the level of a tutorial.</li>
 <li>Explain your value judgments. For example, if you say a code snippet is or is not “useful”, explain  <b>why</b>. Value judgments can only be formed by people with knowledge of the relevant subject; if the reader already possessed that baseline knowledge, they probably wouldn’t need your documentation.</li>
 <li>If necessary, repeat yourself—especially if the information is vital and might be missed the first time. Also, if your reader is unlikely to remember a minor point that is nevertheless important to understand a major one, it is acceptable to restate it.</li>
 <li>Design your text for a blind person; this is a good structural discipline. Documents, especially web pages, turn out much better. When you want to know how a document will sound, run it through a text-to-speech function (Emacs can do this for you via  <code>M-x emacspeak</code> or similar speech facilities).</li>
 <li>Diagrams are sometimes helpful. Similarly, tables and lists of categories (variable types, types of operators, etc.) can help the reader digest a large amount of information without a lot of superfluous connective text.</li>
 <li>Anticipate problems the reader might encounter—“gotchas” that you might have experienced yourself—and explicitly point them out.</li>
</ul></div>
 <h2>More points of style  <a id="more-points-of-style" class="anchor" href="#more-points-of-style" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga4db93b">
 <ul class="org-ul"> <li> <b>Explain conventions.</b> Software programming and usage often rely on conventions that are not obvious to newcomers. For example, a  <code>0</code> return code in a C program signifies “zero errors”. Always explain structural conventions such as this.</li>
 <li>Always tell people how to pronounce code when you introduce new terms. For example, if you are explaining pointers, tell the reader that  <code>*my_ptr</code> can be pronounced “the contents of the memory location  <code>my_ptr</code>”. This teaches those who vocalize text internally to pronounce code correctly, rather than inventing an idiosyncratic method that could hinder their collaboration.</li>
 <li>Qualify your statements. Don’t simply say, for example, “Parameters must have their types declared.” Must  <b>all</b> parameters have their types declared? If so, say so; if not, state precisely which parameters require it and which do not, providing clear examples.</li>
</ul></div>
 <h2>Ordering your text  <a id="ordering-your-text" class="anchor" href="#ordering-your-text" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc001746">
 <ul class="org-ul"> <li>Write about the most important things in a section first. Give critical concepts their own subsections. Don’t make the mistake of writing, “Blah, blah, and blah. Oh, and by the way, this next part is really important…”</li>
 <li>Put important warning notes to the reader in dedicated subsections. This visually signals their importance.</li>
 <li>People tend to remember best the things they encounter first and last in a sequence.</li>
 <li>Order the information in your nodes sequentially from simple to complex.</li>
 <li>Don’t use complex terminology without defining it, at least in a brief, preliminary way. Never use terms in the process of defining themselves.</li>
 <li>Make your assumptions clear before you rely on them. For example, if you assume that the reader knows basic trigonometry, state this constraint before launching into an example involving it. Provide pointers to where the reader can learn about the missing prerequisite.</li>
 <li>Recursion and nested data structures are notoriously difficult. Your text can easily get out of control. Be extra careful to phrase your explanations cleanly so the reader does not end up in a conceptual tangle.</li>
 <li>If your chapter is titled “About foo and bar”, do not discuss your topics in the reverse order of “bar” and “foo”. Be parallel and consistent throughout the section. Plan your text carefully in advance.</li>
 <li>If you have two tables or lists of information that discuss the same items, combine them. Don’t force the reader to flip back and forth to correlate data in their head.</li>
 <li>Don’t combine different topics in the same paragraph or node. If you want to start a new topic, start a new paragraph or a new node.</li>
 <li>After making an important point, end the paragraph and let the reader absorb that information. Don’t clutter the paragraph with trailing details; save those details for later.</li>
 <li>When explaining a feature of a program, awaken the reader’s interest by first outlining the specific problem the feature solves. Write text that motivates the reader to keep turning pages.</li>
</ul></div>
 <h2>Code examples  <a id="code-examples" class="anchor" href="#code-examples" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga67041c">
 <ul class="org-ul"> <li>Give sample output for code examples wherever possible.</li>
 <li>Don’t waste the reader’s time with frivolous, overly abstract examples that have no real-world utility.</li>
 <li>When you discuss a function, do not include parentheses in its name unless you are explicitly illustrating a function call. For example, write  <code>cos</code> rather than  <code>cos()</code>.</li>
 <li>In a source code block, snuggle the code up to the block markup tags. Do not insert empty lines between the lines containing formatting commands (like `#+begin_src`) and the lines containing the actual code.</li>
 <li> <b>Always test your code.</b> Verify your code examples by compiling and running them immediately before finalizing your text. This applies even to one-liners.</li>
 <li>Double-check your mathematical examples as well as your code. Catching a basic error will cause your reader to rapidly lose confidence in your technical accuracy.</li>
 <li>Use the present “timeless” tense when describing what code does. Example: “The  <code>foo</code> function takes an integer variable  <code>bar</code> and multiplies it by 5.”</li>
 <li>Don’t use examples that will become dated. You don’t know how long your text will circulate. For example, instead of binding a year variable to a fixed hardcoded string like  <code>2026</code>, use relative time offsets or abstract but realistic epoch markers.</li>
 <li>Use concrete rather than abstract variable names. Concrete names reduce cognitive strain. For example, a variable called  <code>cost_of_lunch</code> is inherently clearer than  <code>foo</code>. However, do not make names so hyper-specific that the overarching structural lesson is lost.</li>
 <li>Satisfy the reader’s curiosity about whether alternative coding paths are possible, but make your ultimate architectural recommendations crystal clear.</li>
</ul></div>
 <h2>Metaphors  <a id="metaphors" class="anchor" href="#metaphors" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgca42198">
 <ul class="org-ul"> <li>Develop your metaphors explicitly. For example, if you say local variables are “invisible” outside their functions, explain that this usage stems from a structural metaphor where functions act like buildings and local variables are like people unable to look from one sealed building into another.</li>
 <li>Technical jargon often carries metaphorical underpinnings. For example, pointers “point to” memory addresses. Unpack these roots when introducing jargon.</li>
 <li>Explain where your metaphors break down. For example, when explaining pointers in C, note that while a real-world finger can point to anything (animal, vegetable, or mineral), a typed pointer can only point to a strictly defined type of variable (e.g., only to integers, or only to floats).</li>
 <li>Use a metaphor consistently; do not mix them. If you state that local variables are “invisible” outside their functions, do not later say they are “nonexistent” without providing clear transitional text explaining why you are shifting perspective.</li>
 <li>Avoid hyper-localized idioms and implicit metaphors wherever possible; they make translation into other languages exceptionally difficult.</li>
</ul></div>
 <h2>English usage  <a id="english-usage" class="anchor" href="#english-usage" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc34dcf4">
 <p>
Consult established references on English style, such as the classic  <i>The Elements of Style</i> by Strunk and White.
</p>

 <ul class="org-ul"> <li>Don’t mention non-free software by name unless it is absolutely unavoidable to explain interoperability.</li>
 <li>Refer to GNU more and Unix less. Always write “GNU/Linux”, never just “Linux”, unless you are specifically referring strictly to the isolated Linux kernel.</li>
 <li>Use the word “illegal” only for matters of state law and government policy. For violations of the syntax or semantic rules of programming languages, use “invalid” or “ill-formed”.</li>
 <li>Always address the reader directly as “you”. Example: “If you want to display the diagram, press the  <code>RET</code> key.”</li>
 <li>Use “must”, “should”, “may”, and “can” precisely. Do not conflate rigid technical requirements with optional user choices.</li>
 <li>Examples are “shown”, not “given”. Only useful, fully functional standalone programs qualify as free gifts to the world.</li>
 <li>“Kinds of” and “types of” are strictly followed by a singular noun. It is not “types of variables”, but “types of variable”.</li>
 <li>Place zero text between the phrase “as follows” and the data or text that is meant to follow it.</li>
 <li>Maintain a strict visual and textual boundary separating plain English prose from code blocks or raw syntax.</li>
 <li>Humans frequently misprocess double negatives. Phrase your text cleanly so that a reader cannot accidentally miss a critical “not”. Never repeat negative constraints in a manner that visually mimics positive assertions.</li>
 <li>Most programmers (with the proud exception of Lisp hackers) dislike dense parentheses in prose. Use them as sparingly as possible in body text and tables.</li>
 <li>Use language precisely. For example, in languages like C, a “declaration” is fundamentally distinct from a “definition”. Many technical terms sound alike and share adjacent conceptual space, but you must cleanly distinguish them for your readers. Do not merely state that two terms differ; explain the precise boundary where they part ways.</li>
 <li>Similarly, distinguish separate contextual usages of the same jargon word. For example: differentiate clearly between “the value of a variable” versus “passing an argument by value”.</li>
</ul></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/scriba-structured-logging-library-in-lisp/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Scriba v0.3.3 - Structured Logging in Lisp</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Hacking Freedom: Compiling GNU Emacs from Source</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/">Mètsàtron's astral analysis of Joe's being</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/">Brief aan mijzelf</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/index.html</guid>
  <pubDate>Sun, 21 Jun 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Scriba v0.3.3 - Structured Logging in Lisp</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>A structured logging framework for Guile Scheme</i>
</p>

 <blockquote>
 <p>
     “Scriba is a structured logging library for GNU Guile that prioritizes
flexibility and observability.  It provides modular log routing, formatting,
and filtering, allowing developers to generate human-readable console logs
during development and machine-readable JSON logs for production environments.
Key features include an auto-logger configured via environment variables,
dynamically scoped log contexts using Scheme parameters, ahead-of-time log
level filtering, and minimal runtime overhead achieved through memoization
and compile-time macros.”
</p>
</blockquote>

 <p>
Find the source code here:  <a href="https://codeberg.org/jjba23/scriba">https://codeberg.org/jjba23/scriba</a>
</p>

 <p>
A Lisp structured logging library with flexibility, performance and configuration in mind, powered by Guile Scheme.
</p>


 <div id="org79bb5be" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/scriba/screen-2026-06-02-20-11-36.png"></img></p>
</div>

 <p>
If you like my work, please support me by  <a href="https://bmc.link/jjbigorra">buying me a cup of coffee ☕</a> so I can continue with a lot of motivation.
</p>

 <div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
   <img src="https://jointhefreeworld.org/ggg/dist/scheme-guile.svg" alt="Scheme Guile"></img> <img src="https://jointhefreeworld.org/ggg/dist/gnu-guix.svg" alt="GNU Guix"></img> <img src="https://jointhefreeworld.org/ggg/dist/license-lgpl3+.svg" alt="LGPLv3+"></img> <img src="https://jointhefreeworld.org/ggg/dist/license-fdl13+.svg" alt="FDLv1.3+"></img> <img src="https://jointhefreeworld.org/ggg/dist/jointhefreeworld-org.svg" alt="Join The Free World"></img></div>

 <hr></hr> <h2>Why Scriba?  <a id="why-scriba" class="anchor" href="#why-scriba" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6dd1dce">
 <p>
A primary advantage of Scriba over standard  <code>display</code>,  <code>write</code>, or  <code>println</code> procedures is fine-grained control over log routing, formatting and filtering, with the addition of structured context in logs.
</p>

 <p>
By separating formatting, severity levels, and output destinations, Scriba offers modularity that makes extending the library or writing your own custom loggers trivial.
</p>

 <p>
Scriba is built around the core abstraction of a  <b>logger</b>. It achieves high performance by memoizing computations and leveraging compile-time macro expansions.
</p>

 <p>
Find the complete, technical Guile Scheme   <a href="https://jointhefreeworld.org/api-docs/scriba/index.html">API documentation here</a>
</p>

 <p>
Available loggers:  <code>console</code> ,  <code>color-console</code>,  <code>syslog</code> and  <code>json</code>
</p>


 <hr></hr></div>
 <h2>Observability and Structured Logging  <a id="observability-and-structured-logging" class="anchor" href="#observability-and-structured-logging" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga063dae">
 <p>
In modern software development, simply writing  <code>(display &quot;\nError happened&quot;)</code> is no longer enough. As applications grow in complexity, understanding their internal state in production (observability) becomes critical.
</p>

 <p>
In practice, we see that traditional unstructured logs are nice and easy for humans to read, but notoriously difficult for machines to parse, search, and alert on.
</p>

 <p>
That’s why structured logging is important. In that mindset, we treat logs not as strings of text, but as structured data (typically JSON).
</p>

 <p>
By attaching key-value pairs (context) to your logs, you allow log aggregators (think Grafana Loki, Elasticsearch, or Datadog) to instantly filter and visualize system behavior.
</p>

 <p>
This also makes your life easier when debugging or trying to gain insights into your system.
</p>

 <p>
Scriba gives you the tooling and provides and expressive logger API that can produce beautiful, human-readable logs in development, and robust, machine-readable structured logs in production, without changing a single line of your application code.
</p>

 <p>
Log level is optional in Scriba, as log context can also provide log control.
</p>


 <hr></hr></div>
 <h2>Quickstart  <a id="quickstart" class="anchor" href="#quickstart" aria-label="Link to this section">#</a></h2> <h3>Example logging formats  <a id="example-logging-formats" class="anchor" href="#example-logging-formats" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org13e277b">
 <p>
Example console logging:
</p>
 <pre class="example" id="orgba2dc38">
[INFO] [2026-05-24 11:23:06 CEST] Hello Scriba, 2 + 2 = 4!
[INFO] [2026-05-24 11:23:06 CEST] [sample-1=value-1] Some log with context
[2026-06-03 11:56:35 CEST] [#hello #world] Yes! Log with tags! [planet=earth]
</pre>

 <p>
Example JSON logging:
</p>
 <pre class="example" id="org92c785b">
{&quot;level&quot;:&quot;INFO&quot;,&quot;time&quot;:&quot;2026-05-24 11:23:06 CEST&quot;,&quot;message&quot;:&quot;Some log with context&quot;,&quot;sample-2&quot;:&quot;value-2&quot;}
{&quot;level&quot;:&quot;WARNING&quot;,&quot;time&quot;:&quot;2026-05-24 11:23:06 CEST&quot;,&quot;message&quot;:&quot;some kind of warning&quot;}
{&quot;tags&quot;:[&quot;performance&quot;],&quot;time&quot;:&quot;2026-06-03 11:56:35 CEST&quot;,&quot;host&quot;:&quot;joe-vdb-thinkpad&quot;,&quot;message&quot;:&quot;Slept 0 seconds&quot;}
</pre>

 <p>
Example syslog logging (RFC 5424):
</p>
 <pre class="example" id="orgc7f3604">
&lt;14&gt;2 2026-05-29T10:56:49+0200 joe-vdb-thinkpad 37222 - Hello Scriba!
&lt;14&gt;2 2026-05-29T10:56:49+0200 joe-vdb-thinkpad 37222 - [sample-1=&quot;value-1&quot;] Some log with context
&lt;12&gt;2 2026-05-29T10:56:49+0200 joe-vdb-thinkpad 37222 - some kind of warning
&lt;14&gt;2 2026-06-03T11:59:18+0200 joe-vdb-thinkpad 80672 - Not gonna sleep! [#performance #benchmark]
</pre>
</div>
 <h3>The Auto-Configured Logger  <a id="the-auto-configured-logger" class="anchor" href="#the-auto-configured-logger" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5b9353e">
 <p>
While you can instantiate specific loggers manually, the simplest way to get started is with the  <b>auto-logger</b>. It reads environment variables (and, in the future, Scheme configuration files) to automatically determine at runtime which logger to use and how to configure it.
</p>

 <p>
This is especially useful for maintaining different logging behaviors between development and production environments. A common use-case is to use a pretty and colorful console logger in local development, and structured JSON logging in production, for logs to be parsed and aggregated by tools like Loki.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">my-module</span>)
   <span class="org-builtin">#:use-module</span> (scriba auto)
   <span class="org-builtin">#:use-module</span> (scriba scriba))

( <span class="org-keyword">let*</span> ((s (scriba-auto-logger)))
  (log-info s  <span class="org-string">&quot;Hello Scriba!&quot;</span>)
  (with-log-context `((key-1 . value-1))
                    (log-info s  <span class="org-string">&quot;Message with context&quot;</span>)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
 <b>Note:</b> Logger creation is memoized. Subsequent calls to create the same logger (even elsewhere in your codebase) are instant because the result is only computed once.
</p>
</div>
 <h4>Environment Configuration  <a id="environment-configuration" class="anchor" href="#environment-configuration" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-orga7defcd">
 <p>
The auto-logger checks for  <code>SCRIBA_</code> prefixed environment variables.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Scriba Env Var</th>
 <th scope="col" class="org-left">Description</th>
 <th scope="col" class="org-left">Default</th>
</tr></thead> <tbody> <tr> <td class="org-left"> <code>SCRIBA_LOGGER</code></td>
 <td class="org-left">The logger backend to use ( <code>console</code> ,  <code>color-console</code>,  <code>syslog</code> or  <code>json</code>).</td>
 <td class="org-left"> <code>console</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_LOG_LEVEL</code></td>
 <td class="org-left">Minimum severity level (e.g.,  <code>debug</code>,  <code>info</code>,  <code>error</code>).</td>
 <td class="org-left"> <code>info</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_JSON_PRETTY</code></td>
 <td class="org-left">Set to  <code>true</code> or  <code>1</code> to pretty-print JSON logs.</td>
 <td class="org-left"> <code>#f</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_WITH_TIMESTAMP</code></td>
 <td class="org-left">Set to  <code>true</code> or  <code>1</code> to include timestamps.</td>
 <td class="org-left"> <code>#t</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_TIMESTAMP_FORMAT</code></td>
 <td class="org-left">The  <code>strftime</code> format string (e.g.,  <code>&quot;%F %T %z&quot;</code>).</td>
 <td class="org-left"> <code>&quot;%F %T %Z&quot;</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_OUT_PORT</code></td>
 <td class="org-left">The output port to be used (e.g.  <code>stdout</code> or  <code>stderr</code> or TODO  <code>file</code>)</td>
 <td class="org-left"> <code>(current-output-port)</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_FLUSH_PORT</code></td>
 <td class="org-left">Set to  <code>true</code> or  <code>1</code> to force port flushing every log action</td>
 <td class="org-left"> <code>#t</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_LOG_LAYOUT</code></td>
 <td class="org-left">Comma-separated list of log fields</td>
 <td class="org-left"> <code>'(level tags time name message context)</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_TAG_FILTER</code></td>
 <td class="org-left">Comma-separated list of tags to filter on (only log if matching)</td>
 <td class="org-left"> <code>'()</code></td>
</tr> <tr> <td class="org-left"> <code>SCRIBA_CONTEXT_FILTER</code></td>
 <td class="org-left">Comma-separated list of semi-colon separated key value pairs</td>
 <td class="org-left"> <code>'()</code></td>
</tr></tbody></table> <p>
Because in its implementation, the  <code>get-env-*</code> functions act as defaults for the  <code>#:key</code> arguments in  <code>%make-scriba-auto-logger</code>, you can easily override the environment programmatically:  <code>(scriba-auto-logger #:level 'trace)</code>.
</p>


 <hr></hr></div>
 <h2>Core Concepts  <a id="core-concepts" class="anchor" href="#core-concepts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd83d770">
 <p>
Each logger supports a shared set of options, albeit possibly with different defaults. Check the implementation of each logger for more accurate details.
</p>
</div>
 <h3>Specific Loggers  <a id="specific-loggers" class="anchor" href="#specific-loggers" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgea90ac1">
 <p>
Loggers are (optionally named) entities responsible for emitting logs. They act as the primary interface between your application and Scriba. If you prefer to have more control and bypass the auto-logger, you can instantiate specific loggers directly.
</p>

 <p>
See  <a href="file:src/scriba/">file:src/scriba/</a> for more details.
</p>

 <p>
All logger implementations share the same fundamental traits and supported functions. Some properties, and default values are specific to certain loggers.
</p>

 <p>
See also the project’s unit tests for more complex configurations:  <a href="file:test/veritas/unit/log-spec.scm">file:test/veritas/unit/log-spec.scm</a> and  <a href="file:test/veritas/unit/auto-log-spec.scm">file:test/veritas/unit/auto-log-spec.scm</a>
</p>
</div>
 <h4>Console Logger  <a id="console-logger" class="anchor" href="#console-logger" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org7478b0a">
 <div class="jfw-code"> <pre>(use-module (scriba scriba)
            (scriba console))

( <span class="org-keyword">let*</span> ((s (scriba-console-logger  <span class="org-builtin">#:name</span> 'console-logger
                                  <span class="org-builtin">#:level</span> 'info)))
  (log-info s  <span class="org-string">&quot;1 + 1 = ~a&quot;</span> (+ 1 1))
  (log-message s  <span class="org-string">&quot;This message will always be logged (no level)&quot;</span>)
  (log-error s  <span class="org-string">&quot;A critical error occurred&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h4>Color Console Logger  <a id="color-console-logger" class="anchor" href="#color-console-logger" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org779066b">
 <div class="jfw-code"> <pre>(use-module (scriba scriba)
            (scriba color-console))

( <span class="org-keyword">let*</span> ((s (scriba-color-console-logger  <span class="org-builtin">#:level</span> 'info)))
  (log-info s  <span class="org-string">&quot;1 + 1 = ~a&quot;</span> (+ 1 1))
  (log-message s  <span class="org-string">&quot;This message will always be logged (no level)&quot;</span>)
  (log-error s  <span class="org-string">&quot;A critical error occurred&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h4>JSON Logger  <a id="json-logger" class="anchor" href="#json-logger" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org8670f8b">
 <div class="jfw-code"> <pre>(use-module (scriba scriba)
            (scriba json))

( <span class="org-keyword">let*</span> ((s (scriba-json-logger  <span class="org-builtin">#:name</span> 'json-logger
                               <span class="org-builtin">#:level</span> 'info
                               <span class="org-builtin">#:pretty?</span> #f)))
  (log-warning s  <span class="org-string">&quot;Something suspicious happened&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h4>Syslog Logger  <a id="syslog-logger" class="anchor" href="#syslog-logger" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org36a5522">
 <div class="jfw-code"> <pre>(use-module (scriba scriba)
            (scriba syslog))

( <span class="org-keyword">let*</span> ((s (scriba-syslog-logger  <span class="org-builtin">#:level</span> 'info)))
  (log-info s  <span class="org-string">&quot;2 + 2 = ~a&quot;</span> (+ 2 2))
  (log-warning s  <span class="org-string">&quot;Something suspicious happened&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <hr></hr></div>
 <h3>Log Levels  <a id="log-levels" class="anchor" href="#log-levels" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org13cab3c">
 <p>
For Scriba, log level is an opt-in concept. Not every system benefits from the same kind of log filtering. Other approaches like tag-based or property-based logging are powerful as well.
</p>

 <p>
So you can e.g.  <code>log-info</code> or you can just do  <code>log-message</code> if you always want to log.
</p>

 <p>
In the core inner workings of Scriba, we consider log level  <code>#t</code> to mean always log, and  <code>#f</code> to never log.
</p>

 <p>
A logging action is executed only if its designated level is higher than or equal to the effective level of the configured logger.
</p>

 <blockquote>
 <p>
A log action of level L issued to a logger having an effective level Q, is enabled if L ≥ Q.
</p>
</blockquote>

 <p>
The standard hierarchy is:
 <code>trace</code> &lt;  <code>debug</code> &lt;  <code>info</code> &lt;  <code>success</code> &lt;  <code>warning</code> &lt;  <code>error</code> &lt;  <code>critical</code>
</p>


 <hr></hr></div>
 <h3>Log Context  <a id="log-context" class="anchor" href="#log-context" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd2c7443">
 <p>
For better observability, it is often useful to attach dynamic metadata to your log lines. Scriba handles this seamlessly via contexts:
</p>

 <div class="jfw-code"> <pre>(with-log-context '((request-id .  <span class="org-string">&quot;req-1234&quot;</span>) (user .  <span class="org-string">&quot;alice&quot;</span>))
  (log-info logger  <span class="org-string">&quot;Fetching database records...&quot;</span>)
   <span class="org-comment-delimiter">;; </span> <span class="org-comment">Any deeper function calls that log will automatically include this context!
</span>  (do-some-work a b c))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can construct your own logger and filter based on context,  with  <code>#:context-filter</code> constructor argument, that accepts an alist (the context). Filtering is lenient (can compare symbols, numbers and strings loosely).
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((s (scriba-console-logger  <span class="org-builtin">#:name</span> 'console-logger
                               <span class="org-builtin">#:level</span> 'info
                               <span class="org-comment-delimiter">;; </span> <span class="org-comment">filter on context
</span>                               <span class="org-builtin">#:context-filter</span> `((some-key .  <span class="org-string">&quot;some-value&quot;</span>)))))
  (with-log-context `((some-key .  <span class="org-string">&quot;some-value&quot;</span>))
                 (log-info s  <span class="org-string">&quot;2 + 2 = ~a&quot;</span> (+ 2 2))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <hr></hr></div>
 <h3>Log Routing  <a id="log-routing" class="anchor" href="#log-routing" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgafc2e90">
 <p>
In general, the most common use-case for programs is to emit log lines to the standard output (stdout). From there you can capture the output and redirect as needed.
</p>

 <p>
Some applications and users may require more advanced functionality like logging to files, sockets, or network destinations.
</p>

 <p>
Scriba offers an easily configurable interface to log destination, thanks to Scheme’s fantastic input/output port system.
</p>

 <p>
By default:
</p>
 <div class="jfw-code"> <pre>(scriba-console-logger  <span class="org-builtin">#:out-port</span> (current-output-port))  <span class="org-comment-delimiter">;; </span> <span class="org-comment">stdout generally</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Logging to a file (TODO how to auto-rolling log files?):
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((file-port (open-output-file  <span class="org-string">&quot;test.log&quot;</span>))
       (s (scriba-console-logger  <span class="org-builtin">#:out-port</span> file-port)))
  (log-info s  <span class="org-string">&quot;Hello Scriba!&quot;</span>)
  (close-output-port file-port))  <span class="org-comment-delimiter">;; </span> <span class="org-comment">don't forget to close file ports!</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Logging to a string port (in-memory) can be useful to capture logs and test that your program logs as expected:
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((string-port (open-output-string))
      (s (scriba-console-logger  <span class="org-builtin">#:out-port</span> string-port)))
  (log-info s  <span class="org-string">&quot;Hello Scriba!&quot;</span>)
  ( <span class="org-keyword">let*</span> ((result (get-output-string string-port)))
    (equal? result  <span class="org-string">&quot;\n[INFO] Hello Scriba!&quot;</span>)))  <span class="org-comment-delimiter">; </span> <span class="org-comment">#t</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h3>Log Format  <a id="log-format" class="anchor" href="#log-format" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org1aac444">
 <p>
You can easily customize the log format and disable certain fields via  <code>#:layout</code>
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((s (scriba-console-logger  <span class="org-builtin">#:name</span> 'console-logger
                               <span class="org-builtin">#:level</span> 'info
                               <span class="org-builtin">#:layout</span> '(level tags time host name context message))))
  (log-info s  <span class="org-string">&quot;2 + 2 = ~a&quot;</span> (+ 2 2)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h3>Log Tags and tag-based logging  <a id="log-tags-and-tag-based-logging" class="anchor" href="#log-tags-and-tag-based-logging" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org8a4677c">
 <p>
a.k.a. property-based logging
</p>

 <p>
You can also choose to use log tags to filter upon, and even go for a tag-based / property-based logging approach where your don’t even need log level. Such as every log can have context, every log can also have tags.
</p>

 <div class="jfw-code"> <pre>[#performance #db] [2026-06-02 21:19:24 CEST] Slept 0 seconds
[2026-06-02 21:21:40 CEST] [INFO] [#hello #world] Yes! [planet=earth]</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can construct your own logger and filter based on tags,  with  <code>#:tag-filter</code> constructor argument, that accepts a list of symbols (the tags) . Filtering is lenient (can compare symbols, numbers and strings loosely).
</p>

 <p>
Tags can be added (and nested) just like context, with  <code>with-log-tags</code> macro.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((s (scriba-console-logger  <span class="org-builtin">#:name</span> 'console-logger
                               <span class="org-builtin">#:level</span> 'info
                               <span class="org-comment-delimiter">;; </span> <span class="org-comment">filter on tags
</span>                               <span class="org-builtin">#:tag-filter</span> '(benchmark db performance))))
  (with-log-tags '(benchmark db performance)
                 (log-info s  <span class="org-string">&quot;2 + 2 = ~a&quot;</span> (+ 2 2))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>My Excuses &amp; Good Logging from Day One  <a id="my-excuses-amp-good-logging-from-day-one" class="anchor" href="#my-excuses-amp-good-logging-from-day-one" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org37f4e5d">
 <p>
I’m sure you’ve felt this, when starting a new project, setting up a  <i>proper</i> logging framework feels like an unnecessary chore.
</p>

 <p>
We reach for  <code>(display &quot;\ngot here&quot;)</code> or  <code>format</code> because it is frictionless.
</p>

 <p>
But as the codebase grows, those scattered print statements become a noisy, unsearchable liability.
</p>

 <p>
With Scriba, you have less excuses to procrastinate:
</p>

 <ul class="org-ul"> <li> <b>“It is too much boilerplate to set up.”</b>
With the  <code>scriba-auto-logger</code>, it takes exactly two lines of code to get a fully functioning, formatted logger. No complex configuration files or initialization rituals required.</li>

 <li> <b>“Structured JSON is terrible to read during local development.”</b>
You do not have to look at JSON while developing. Scriba’s auto-logger separates your code from your deployment environment. You can get beautiful, human-readable, even colorful console logs on your machine, and robust, machine-parsable JSON logs in production—just by changing the  <code>SCRIBA_LOGGER</code> environment variable.</li>

 <li> <b>“I don’t want to pass metadata through 20 function layers.”</b>
Scriba’s  <code>with-log-context</code> dynamically scopes your data. You can attach a  <code>request-id</code> or  <code>user-id</code> at the top level of your application, and every log statement nested deep within your call stack will automatically include it thanks to Scheme’s parameters and  <code>parameterize</code>.</li>

 <li> <b>“A logging library will slow down my high-performance prototype.”</b>
Thanks to the attention put into performance, Scriba’s overhead is minimal (and worth it). When a log level is disabled (e.g., debug logs in a production environment), the internal I/O and string formatting operations are entirely bypassed.</li>
</ul> <p>
Start with Scriba on day one ✨
</p>

 <hr></hr></div>
 <h2>Performance Under the Hood  <a id="performance-under-the-hood" class="anchor" href="#performance-under-the-hood" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7d74058">
 <p>
Logging is a global cross-cutting concern, and it should never become the bottleneck in your application’s execution.
</p>

 <p>
Scriba achieves high throughput by front-loading as much computation as possible, using the macro system, and leveraging Guile’s native optimizations.
</p>
</div>
 <h3>Constructor Memoization  <a id="constructor-memoization" class="anchor" href="#constructor-memoization" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3805ad1">
 <p>
Creating and configuring loggers can involve reading environments, parsing strings, and allocating records.
</p>

 <p>
Scriba exposes a  <code>memoize-logger</code> macro that wraps logger factories with a hash-table cache. If you request a logger with the exact same configuration parameters anywhere in your codebase, Scriba instantly returns the cached instance instead of rebuilding it.
</p>
</div>
 <h3>Ahead-of-Time Level Filtering  <a id="ahead-of-time-level-filtering" class="anchor" href="#ahead-of-time-level-filtering" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org8bca9fd">
 <p>
Instead of checking the log severity level on every single  <code>log-*</code> invocation, Scriba evaluates the hierarchy exactly once when the logger is instantiated.
-Scriba permanently binds that logger’s irrelevant functions to a lightning-fast no-op function when below the level threshold.
</p>
 <ul class="org-ul"> <li>This means calling a disabled log level entirely bypasses string formatting, port flushing, and I/O routing ✨.</li>
</ul></div>
 <h3>Compile-Time Macros  <a id="compile-time-macros" class="anchor" href="#compile-time-macros" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgf81f0a3">
 <p>
A great deal of effort is taken to keep runtime overhead strictly minimal, and Scriba avoids doing much dynamic dispatch or runtime reflection.
</p>

 <p>
Some boilerplate operations, such as generating keyword-based record constructors ( <code>define-record-with-kw</code>) and generating the domain logging functions ( <code>define-logger-method</code>), are handled by Scheme macros that expand natively at compile-time.
</p>
</div>
 <h3>Efficient Context Management  <a id="efficient-context-management" class="anchor" href="#efficient-context-management" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd046071">
 <p>
Attaching metadata via  <code>with-log-context</code>   and  <code>with-log-tags</code> does not mutate global state or require expensive thread-locking or mutexes or anything like that.
</p>

 <p>
It relies on Guile’s native  <code>parameterize</code>, which securely and efficiently handles dynamically scoped, thread-local variables.
</p>

 <p>
Log tags can be filtered on at runtime, so you can log exclusively lines that contain a tag, also not even needing log levels and allowing more fine-grained control.
</p>

 <hr></hr> <div id="org0ddcbd7" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/scriba/scriba_small.png"></img></p>
</div>

 <hr></hr></div>
 <h2>Runtime Dependencies  <a id="runtime-dependencies" class="anchor" href="#runtime-dependencies" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge622d3b">
 <p>
Scriba has minimal dependencies, requiring only GNU Guile Scheme and a small set of standard libraries. See  <code>manifest.scm</code> for full details.
</p>

 <p>
Guile libraries used:
</p>

 <ul class="org-ul"> <li>Guile JSON v4</li>
</ul> <p>
Testing:
</p>
 <ul class="org-ul"> <li> <a href="https://codeberg.org/jjba23/veritas">Veritas test framework</a>  for Guile Scheme</li>
</ul> <hr></hr></div>
 <h2>Licensing  <a id="licensing" class="anchor" href="#licensing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgff8ce1e">
 <p>
scriba and all of its source code are free software, licensed under the GNU Lesser General Public License v3 (or newer at your convenience).
</p>

 <p>
 <a href="https://www.gnu.org/licenses/lgpl-3.0.html">https://www.gnu.org/licenses/lgpl-3.0.html</a>
</p>

 <p>
The documentation and examples, including this document, which are provided with scriba, are all licensed under the GNU Free Documentation License v1.3 (or newer at your convenience).
</p>

 <p>
 <a href="https://www.gnu.org/licenses/fdl-1.3.html">https://www.gnu.org/licenses/fdl-1.3.html</a>
</p>

 <hr></hr></div>
 <h2>Installing  <a id="installing" class="anchor" href="#installing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6aebfc2">
 <p>
scriba is packaged via the Guix package manager officially, as  <code>guile-scriba</code>. It is recommended you use Guix to work on your Guile Scheme projects, and install scriba with it (in your manifest.scm for example). See also the  <code>guix.scm</code>
</p>

 <p>
Alternatively, you can modify the package definition to your willing, or install it manually by downloading the source code files and adding them directly to your  <code>GUILE_LOAD_PATH</code> or even better, use a Guix shell  <code>manifest.scm</code> and add the package with something like this:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-public</span>  <span class="org-function-name">guile-scriba</span>
  (package
    (name  <span class="org-string">&quot;guile-scriba&quot;</span>)
    (version  <span class="org-string">&quot;x.x.x&quot;</span>)
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url  <span class="org-string">&quot;https://codeberg.org/jjba23/scriba.git&quot;</span>)
             (commit (string-append  <span class="org-string">&quot;v&quot;</span> version))))
       (file-name (git-file-name name version))
       (sha256
        (base32  <span class="org-string">&quot;&lt;dependent on version&gt;&quot;</span>))))
    (build-system guile-build-system)
    (arguments
     (list
       <span class="org-builtin">#:source-directory</span>  <span class="org-string">&quot;src&quot;</span>))
    (propagated-inputs (list guile-json-4))
    (inputs (list guile-3.0))
    (synopsis  <span class="org-string">&quot;Structured logging framework for Guile Scheme&quot;</span>)
    (description
      <span class="org-string">&quot;Scriba is a structured logging library for GNU Guile that prioritizes
flexibility and observability.  It provides modular log routing, formatting,
and filtering, allowing developers to generate human-readable console logs
during development and machine-readable JSON logs for production environments.
Key features include an auto-logger configured via environment variables,
dynamically scoped log contexts using Scheme parameters, ahead-of-time log
level filtering, and minimal runtime overhead achieved through memoization
and compile-time macros.&quot;</span>)
    (home-page  <span class="org-string">&quot;https://codeberg.org/jjba23/scriba&quot;</span>)
    (license license:lgpl3+)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>AI Policy  <a id="ai-policy" class="anchor" href="#ai-policy" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org78c6732">
 <p>
This project adheres to the  <a href="https://jointhefreeworld.org/ai-policy/">jointhefreeworld AI (Artificial Intelligence) policy</a>.
</p>

 <p>
Our core principle is simple:  <b>AI should assist human creativity and problem-solving, never replace human reasoning.</b>
</p>

 <p>
While tools like Large Language Models (LLMs) and interactive chatbots can be beneficial for reviewing, refactoring small functions, or acting as a sounding board, they should be used with moderation.
</p>

 <p>
We require a human in the loop for all contributions.
</p>

 <hr></hr></div>
 <h2>Code of conduct  <a id="code-of-conduct" class="anchor" href="#code-of-conduct" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcd32643">
 <p>
This project adheres to the jointhefreeworld code of conduct. Find it here:
</p>

 <p>
 <a href="https://jointhefreeworld.org/code-of-conduct/">https://jointhefreeworld.org/code-of-conduct/</a>
</p>

 <p>
In summary, we foster an inclusive, respectful, and cooperative environment for all contributors and users of this free software project. Inspired by the ideals of the GNU Project, we strive to uphold freedom, equality, and community as guiding principles. We believe that collaboration in a community of mutual respect is essential to creating excellent free software.
</p>

 <hr></hr></div>
 <h2>Scriba Project  <a id="scriba-project" class="anchor" href="#scriba-project" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7bdae67">
 <p>
Contributing to free software is a uniquely beautiful act because it embodies principles of generosity, collaboration, and empowerment.
</p>

 <p>
We welcome everyone to feel invited to the scriba Project, and encourage active contribution in all forms, to improve it and/or suggest improvements, brainstorm with me, make it more modular/flexible, etc, feel free to contact me &lt;jjbigorra@gmail.com&gt; to chat, discuss or report feedback.
</p>

 <p>
Find here the Backlog and Kanban boards for scriba:  <a href="https://lucidplan.jointhefreeworld.org/tickets/scriba">https://lucidplan.jointhefreeworld.org/tickets/scriba</a>
</p>

 <hr></hr></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Manifesto for Agile Software Development</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">jointhefreeworld - A Style Guide for Documentation</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/scriba-structured-logging-library-in-lisp/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/scriba-structured-logging-library-in-lisp/index.html</guid>
  <pubDate>Thu, 04 Jun 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Manifesto for Agile Software Development</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
We are uncovering better ways of developing software by doing it and helping others do it. Find  <a href="https://agilemanifesto.org/">the original manifesto here</a>.
</p>


 <p>
Through this work we have come to value:
</p>

 <blockquote>
 <p>
 <b>Individuals and interactions</b> beat processes and tools
</p>

 <p>
 <b>Working software</b> beats comprehensive documentation
</p>

 <p>
 <b>Customer collaboration</b> beats contract negotiation
</p>

 <p>
 <b>Responding to change</b> beats following a plan
</p>
</blockquote>

 <p>
That is, while there is value in the items on the right, we value the items on the left more.
</p>

 <hr></hr> <h2>Principles behind the Agile Manifesto  <a id="principles-behind-the-agile-manifesto" class="anchor" href="#principles-behind-the-agile-manifesto" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5b0490f">
 <p>
We follow these principles:
</p>

 <p>
Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.
</p>

 <p>
Welcome changing requirements, even late in development. Agile processes harness change for the customer’s competitive advantage.
</p>

 <p>
Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.
</p>

 <p>
Business people and developers must work together daily throughout the project.
</p>

 <p>
Build projects around motivated individuals. Give them the environment and support they need, and trust them to get the job done.
</p>

 <p>
The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.
</p>

 <p>
Working software is the primary measure of progress.
</p>

 <p>
Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
</p>

 <p>
Continuous attention to technical excellence and good design enhances agility.
</p>

 <p>
Simplicity–the art of maximizing the amount of work not done–is essential.
</p>

 <p>
The best architectures, requirements, and designs emerge from self-organizing teams.
</p>

 <p>
At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Why I Still Reach for Scheme and Lisp Instead of Haskell</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/scriba-structured-logging-library-in-lisp/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Scriba v0.3.3 - Structured Logging in Lisp</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/">Most Technical Problems are People Problems</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/agile-manifesto/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/agile-manifesto/index.html</guid>
  <pubDate>Tue, 02 Jun 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Why I Still Reach for Scheme and Lisp Instead of Haskell</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
There is a persistent tension in software engineering between the beautiful, mathematically pure ideal of a program, and the messy, pragmatic reality of just getting things done. Over my career, I’ve explored the depths of both extremes in an attempt to find my personal sweet spot for hacking.
</p>

 <p>
Before you sharpen your keyboards and start a flame war over the title, let me point out that I haven’t written this post to talk bad about  <a href="https://www.haskell.org/">Haskell</a>, or any other tool for that matter. In fact, I love Haskell. I taught myself, banged my head against the wall over the course of three years, and built several real-world projects with it (some even became a bit lucrative).
</p>

 <p>
Between my time in the web development world, the  <a href="https://go.dev/">Go</a> world, the JVM world with  <a href="https://www.java.com/">Java</a>,  <a href="https://www.scala-lang.org/">Scala</a> and  <a href="https://kotlinlang.org/">Kotlin</a>, and my long history hacking in  <a href="https://lisp-lang.org/">Lisp</a> ( <a href="https://www.gnu.org/software/emacs/">Emacs</a>,  <a href="https://common-lisp.net/">Common</a>,  <a href="https://schemers.org/">Scheme</a>), I have come to deeply appreciate functional programming.
</p>

 <hr></hr> <h2>Enlightening as it can be  <a id="enlightening-as-it-can-be" class="anchor" href="#enlightening-as-it-can-be" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7926e12">
 <p>
Haskell has what likely is the most amazing, enlightening and complex type system to work with (as do more  <a href="https://en.wikipedia.org/wiki/ML_(programming_language)">ML languages</a>).
</p>

 <p>
It is also the undisputed king of introducing mathematical ideas and concepts to programming, and popularizing them. Haskell circles are frequented by PhDs, computer science researchers,  <a href="https://en.wikipedia.org/wiki/Category_theory">category theorists</a> and all kinds of smart people (don’t underestimate other communities, like Schemers though).
</p>

 <p>
Some of the amazing innovations of Haskell or that it has helped popularize, which blew my mind several times:
</p>
 <ul class="org-ul"> <li> <a href="https://en.wikipedia.org/wiki/Algebraic_data_type">algebraic data types</a></li>
 <li> <a href="https://en.wikipedia.org/wiki/Pattern_matching">pattern matching</a></li>
 <li> <a href="https://en.wikipedia.org/wiki/Functor">functors</a>,  <a href="https://en.wikipedia.org/wiki/Monad_(functional_programming)">monads</a></li>
 <li> <a href="https://en.wikipedia.org/wiki/Monoid">monoids</a>,  <a href="https://en.wikipedia.org/wiki/Semigroup">semigroups</a></li>
 <li>effectful computation modelled as monads</li>
 <li>purely functional domain-specific languages (DSLs)</li>
 <li>etc.</li>
</ul> <p>
All these kind of things often feel bolted-on or missing entirely in other languages!
</p>

 <p>
For all its brilliance, Haskell resists most of the attempts people make to just  <b>hack</b> and write useful code  <i>quickly</i>.
</p>

 <p>
Specially people new to functional programming (or god forbid new to monads and functors! A monad is just a monoid in the category of endofunctors, what’s the problem?)
</p>

 <hr></hr></div>
 <h2>When pragmatism enables actual productivity  <a id="when-pragmatism-enables-actual-productivity" class="anchor" href="#when-pragmatism-enables-actual-productivity" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3ebb931">
 <p>
Scheme (and Lisp in general) might lack Haskell’s innovations and purity, favoring a minimalistic flexibility instead, but it mixes practicality with functional beauty in a way that makes it a functional language for human beings.
</p>

 <p>
Actually, in my opinion, Scheme (and Lisp) allows you to express complex systems and problem domains in more simple terms than any other language can.
</p>

 <p>
Take a recent adventure of mine, for example. I was spinning up a prototype for a bookmark management tool, just one of many projects I’ve come up with over the years.
</p>

 <p>
I started in Haskell as I thought the beauty of data modelling and pure side-effect-free reasoning would work well: it’s also fast, elegant, and once you’ve used modules like  <a href="https://hackage.haskell.org/package/parsec">Parsec</a>,  <a href="https://docs.servant.dev/">Servant</a>, and  <a href="https://hackage.haskell.org/package/optparse-applicative">optparse-applicative</a>, it’s tough to imagine writing certain things, like a parser, without it.
</p>

 <p>
One of the steps in the proof-of-concept was transforming some data models to XML and output them to a file.
</p>

 <p>
If I were doing this in Kotlin or Java, it would be trivial: drop a dependency into Gradle, wire up  <a href="https://github.com/FasterXML/jackson">Jackson</a> or a standard DOM parser, and ten minutes later the data is in memory and ready to manipulate.
</p>

 <p>
After a frustrating hour with my Haskell project, and even after years of experience with the language, I was still wrestling with the dependencies, and later with monadic API, and I ended up giving up on the whole thing after I noticed I even forgot what I was doing in the first place.
</p>

 <p>
This has often been my friction point with Haskell. It is beautiful, but it fights you when you just want to get your hands dirty and prototype, without a  <i>big design upfront</i> even though  <a href="https://en.wikipedia.org/wiki/Type-driven_development">type-driven development</a> can also be nice and work well in some cases.
</p>

 <p>
Scheme ( <a href="https://www.gnu.org/software/guile/">GNU Guile</a> for me) doesn’t have Haskell’s brutally efficient compiler, although it is quite speedy thanks to the C foundation. What it has is the terseness, power, and more importantly,  <b>it makes the actual act of hacking a joy</b>.
</p>

 <p>
As elegant as Haskell’s purely functional foundation is, it can really complicate simple, crucial, impure tasks like writing to files or talking over a network.
</p>

 <p>
Monads are Haskell’s answer to this, but they often feel like a heavy abstraction tax; they allow you to write useful software, but they rarely make it intuitive or fast to prototype.
</p>

 <p>
These kind of heavy-handed abstractions are in my opinion really beautiful, but not justifiable for most projects. Please do ask yourself, do I really need a functional effect system, is it worth the complexity and cognitive load? Do I really need the pure/impure computation strictness enforced at compile time? Remember that later, just adding a simple  <code>print</code> somewhere is not going to work without refactor (welcome to the  <code>IO</code> monad).
</p>

 <p>
As a long-time Lisper, for me this is a massive barrier to usability. In many ways, you can only fix what you can observe.
</p>

 <p>
Scheme happily sacrifices academic purity so you can slap a  <code>(write ...)</code> anywhere in your code and instantly see what’s going on. I’m sure a Haskell purist is burying their face in their hands right now, citing  <code>Debug.Trace</code> or questioning why I’d want side-effects in a lazy, well-optimized language. They aren’t technically wrong, but the friction added to quick-and-dirty debugging is a tax I am simply not willing to pay when I’m trying to move fast.
</p>

 <hr></hr></div>
 <h2>Meta-programming and DSLs  <a id="meta-programming-and-dsls" class="anchor" href="#meta-programming-and-dsls" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgce3d4c5">
 <p>
The second problem with Monads is directly tied to their greatest strength: they are synonymous with  <a href="https://en.wikipedia.org/wiki/Domain-specific_language">Domain Specific Languages</a> (DSLs).
</p>

 <p>
The promise of DSLs is fantastic—don’t write a complex program to solve a problem; write a simple program in a bespoke language designed solely for that task. Parsec is the golden child here; the parsing function is practically identical to the  <a href="https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form">BNF grammar</a>.
</p>

 <p>
But the success of Parsec has filled  <a href="https://hackage.haskell.org/">Hackage</a> with hundreds of bespoke DSLs for everything. One for parsing, one for XML, one for generating PDFs. Each is completely different, and each demands its own learning curve. Consider parsing XML, mutating it based on some JSON from a web API, and writing it to a PDF. In the Java ecosystem for example you expect a certain level of consistency. You pull in three libraries, and they generally follow familiar object-oriented or functional-lite conventions. But in Haskell, three DSLs designed for three different tasks usually mean the authors optimized strictly for the domain, completely ignoring syntax consistency. Instead of five minutes skimming JavaDocs, you have hours of DSL documentation and tutorials ahead of you.
</p>

 <p>
As we Schemers know, Scheme is intentionally simple. That simplicity isn’t a limitation; it’s what makes it endlessly flexible.
</p>

 <p>
While modern JVM languages rely heavily on reflection or complex compiler plugins (like Kotlin’s  <a href="https://kotlinlang.org/docs/ksp-overview.html">KSP</a>) to achieve this, Lisp hackers have been effortlessly reshaping the language for decades using the powerful  <a href="https://en.wikipedia.org/wiki/Macro_(computer_science)#Lisp_macros">macro system</a> and extending and bending the language to their will.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-syntax</span>  <span class="org-variable-name">define-repo-method</span>
  ( <span class="org-keyword">syntax-rules</span> ()
                ((_ method-name accessor docstring)
                 ( <span class="org-keyword">define*</span> ( <span class="org-function-name">method-name</span> repo . args)
                   docstring
                   (apply (accessor repo) args)))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Haskell, much like Scala’s advanced type-level programming, often requires a mountain of language extensions to achieve similar flexibility ( <a href="https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/template_haskell.html">Template Haskell</a> and its powerful but scary API).
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-pragma">{-# LANGUAGE TemplateHaskell #-}</span>
 <span class="org-haskell-keyword">import</span>  <span class="org-haskell-constructor">Control.Monad</span>
 <span class="org-haskell-keyword">import</span>  <span class="org-haskell-constructor">Language.Haskell.TH</span>

 <span class="org-haskell-definition">curryN</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Q</span>  <span class="org-haskell-type">Exp</span>
 <span class="org-haskell-definition">curryN</span> n  <span class="org-haskell-operator">=</span>  <span class="org-haskell-keyword">do</span>
  f   <span class="org-haskell-operator">&lt;-</span> newName  <span class="org-string">&quot;f&quot;</span>
  xs  <span class="org-haskell-operator">&lt;-</span> replicateM n (newName  <span class="org-string">&quot;x&quot;</span>)
   <span class="org-haskell-keyword">let</span> args  <span class="org-haskell-operator">=</span> map  <span class="org-haskell-constructor">VarP</span> (f <span class="org-haskell-constructor">:</span>xs)
      ntup  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">TupE</span> (map ( <span class="org-haskell-constructor">Just</span>  <span class="org-haskell-operator">.</span>  <span class="org-haskell-constructor">VarE</span>) xs)
  return  <span class="org-haskell-operator">$</span>  <span class="org-haskell-constructor">LamE</span> args ( <span class="org-haskell-constructor">AppE</span> ( <span class="org-haskell-constructor">VarE</span> f) ntup)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I’ve used Scheme for countless projects because of its combination of features and philosophies that bring it to my personal  <i>“sweet spot”</i>. It’s also an advanced language, which keeps pioneering, and of unconstrained innovation (e.g.  <a href="https://en.wikipedia.org/wiki/Delimited_continuation">delimited continuations</a>). When you want to mold the syntax directly to your will, Scheme gets out of your way and helps you achieve it.
</p>

 <p>
Of course, to be completely fair about my toolkit, standard Scheme can sometimes lack the heavyweight, “batteries-included” ecosystem required for massive enterprise production compared to the JVM. Also, when compared to Haskell, Lisp compilers are modest and simple, at best, but that makes them also that much more approachable (and the error messages that much friendlier).
</p>

 <p>
I’m not saying Scheme is objectively better than Haskell. Languages are tools, and we should choose the right tool for the job.
</p>

 <p>
I will always remember all I learnt from Haskell’s functional beauty and ideas, but to me, Haskell remains a platonic ideal of a programming language: lighting the way in a certain direction, but a bit too rigid for most of what I do.
</p>

 <hr></hr></div>
 <h2>Then there is the REPL: Interactive workflow, developer power  <a id="then-there-is-the-repl-interactive-workflow-developer-power" class="anchor" href="#then-there-is-the-repl-interactive-workflow-developer-power" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org8f6e739">
 <p>
A REPL (Read-Eval-Print Loop) is an interactive environment, which can be used connected to your console, running application, language compiler and more, which gives you superpowers as an engineer 🦸🏼.
</p>

 <p>
Lisp dialects, more specifically Guile Scheme, have great support for this. I personally of course like to do this with  <a href="https://guix.gnu.org/">Guix</a>,  <a href="https://www.gnu.org/software/emacs/">Emacs</a>, ( <a href="https://git.sr.ht/~abcdw/emacs-arei">Arei/Ares</a> +  <a href="https://github.com/vspinu/sesman">sesman</a>) you can get an ultimate extensible powerful editor experience, miles ahead of traditional IDEs 🐂 .
</p>

 <p>
And no, it’s not the same kind of REPL you know from Haskell (GHCIDE or others) or Python. Lisp REPLs can do so much more and integrate seamlessly to your editor. Evaluate, check, change and debug live, seamlessly.
</p>

 <p>
It fundamentally changes the development workflow by eliminating the slow  <i>edit, save, compile, run</i> cycle. Instead of writing a whole program and then running it to see what happens, you get a fast, conversational workflow. What does this mean for in practice?
</p>

 <ul class="org-ul"> <li> <b>Incremental Development:</b> Write, test, inspect, evaluate one function or even one line at a time. Get immediate feedback without running the entire app.</li>
 <li> <b>Powerful Debugging:</b> Forget adding  <code>print</code> statements and restarting. You can pause, inspect objects, change values, and even redefine a broken function on the fly to test a fix in any environment (yes even in production, while running).</li>
 <li> <b>Fast Prototyping &amp; Learning:</b> Instantly experiment with a new library or API. Just load it and start calling functions to see how they work, which is much faster than only reading documentation.</li>
</ul> <p>
When integrated into your code editor, you can execute any piece of code (a line, a selection, or a file) with a keyboard shortcut and see the result instantly, creating a seamless and powerful development experience.
</p>

 <p>
Overall Lisp languages are simply the sweet spot for me and of what I consider good developer experience. They also give you super powers and let you create beatiful systems that can last.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Functional repository pattern in Scheme? Decoupling and abstracting the data layer in Lisp</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Manifesto for Agile Software Development</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/index.html</guid>
  <pubDate>Wed, 29 Apr 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Functional repository pattern in Scheme? Decoupling and abstracting the data layer in Lisp</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>Implementing the Repository Pattern with Hygienic Macros in Scheme</i>
</p>

 <p>
 <b>Hi everyone!</b>
</p>

 <p>
I’ve been working on a new approach for the data layer of my projects
lately, and I’d love to poke your brains and get some feedback.
</p>
 <h2>What is the repository pattern?  <a id="what-is-the-repository-pattern" class="anchor" href="#what-is-the-repository-pattern" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9960d10">
 <p>
Repository Pattern is an architectural software design pattern that decouples the data layer of a program with the core logic and domain.
</p>

 <p>
It brings separation of concerns as your business logic doesn’t know where the data lives and asks the repository/store for it.
</p>

 <p>
It also makes testing your software much easier and your query read/write logic is kept in one place. If you need to optimize a slow database query, you change it in the repository, not sprinkled across fifty different files.
</p>

 <p>
Coming from a background in Scala, Java and other OOP languages and a fascination for FP languages and Lisps (as well as Rust and Haskell), I’ve seen a lot of patterns come and go.
</p>

 <p>
Recently, I noticed a common anti-pattern in my own Scheme projects: a tight coupling between my controller layer and the SQLite implementation. It wasn’t ideal, and I really missed the clean separation of the  <b>Repository Pattern</b>.
</p>

 <p>
So, I set out to decouple my data layer from my controller layer in the  MVC architecture I love. I wanted to do this using pure functional  programming, and I ended up building something really fun using  <b>Scheme’s hygienic macros</b>.
</p>

 <p>
(If you want to see this implemented in a real project, check out my example repos here:
 <a href="https://codeberg.org/jjba23/lucidplan">lucidplan</a>, and  <a href="https://codeberg.org/jjba23/byggsteg">byggsteg</a>
</p>

 <p>
I plan to bring this pattern to many of my projects to reap the benefits of the eDSL, better decoupling, and easier testing.
</p>

 <hr></hr> <p>
Using it can look like this:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let*</span> ((job-repo (make-sqlite-job-repository rc))
       (jobs (get-jobs job-repo  <span class="org-builtin">#:limit</span> 50  <span class="org-builtin">#:offset</span> 0)))
  ( <span class="org-keyword">map</span> ( <span class="org-keyword">lambda</span>(job) (format #t  <span class="org-string">&quot;\njob: ~a&quot;</span> job )) jobs))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
So if you wanted to change tomorrow to from SQLite to PostgreSQL, you just replace one function call and done ✨
</p>

 <hr></hr></div>
 <h2>The Macros  <a id="the-macros" class="anchor" href="#the-macros" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd6ccfd8">
 <p>
I created two main macros.   <code>define-record-with-kw</code> magically defines a
keyword-argument constructor, bypassing the need for strict parameter
ordering. It’s highly ergonomic.
</p>

 <p>
 <code>define-repo-method</code> is the real
superpower. It accepts any arity, plus optional or  <code>#:keyword</code>
arguments. This saves a ton of work, reduces tedious parameter passing,
and gives you a very clean eDSL definition.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">lucidplan</span> domain repo)
   <span class="org-builtin">#:declarative?</span> #t
   <span class="org-builtin">#:use-module</span> (srfi srfi-9)
   <span class="org-builtin">#:export</span> (define-repo-method define-record-with-kw))

( <span class="org-keyword">define-syntax</span>  <span class="org-variable-name">define-repo-method</span>
  ( <span class="org-keyword">syntax-rules</span> ()
                ((_ method-name accessor docstring)
                 ( <span class="org-keyword">define*</span> ( <span class="org-function-name">method-name</span> repo . args)
                   docstring
                   (apply (accessor repo) args)))))

( <span class="org-keyword">define-syntax</span>  <span class="org-variable-name">define-record-with-kw</span>
  ( <span class="org-keyword">syntax-rules</span> ()
                ((_ (type-name constructor-name pred) kw-constructor-name
                    (field-name accessor-name) ...)
                 ( <span class="org-keyword">begin</span>
                    <span class="org-comment-delimiter">;; </span> <span class="org-comment">Define the standard SRFI-9 record
</span>                   ( <span class="org-keyword">define-record-type</span> type-name
                     (constructor-name field-name ...) pred
                     (field-name accessor-name) ...)

                    <span class="org-comment-delimiter">;; </span> <span class="org-comment">Define the keyword-argument constructor
</span>                   ( <span class="org-keyword">define*</span> ( <span class="org-function-name">kw-constructor-name</span>  <span class="org-builtin">#:key</span> field-name ...)
                     (constructor-name field-name ...))

                    <span class="org-comment-delimiter">;; </span> <span class="org-comment">Auto-export members
</span>                   ( <span class="org-keyword">export</span> type-name pred kw-constructor-name accessor-name
                           ...)))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Defining the Domain eDSL  <a id="defining-the-domain-edsl" class="anchor" href="#defining-the-domain-edsl" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbe2ba17">
 <p>
Here is how I use those macros to define my DSL for a “projects” entity:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">lucidplan</span> domain project)
   <span class="org-builtin">#:declarative?</span> #t
   <span class="org-builtin">#:use-module</span> (srfi srfi-9)
   <span class="org-builtin">#:use-module</span> (lucidplan domain repo)
   <span class="org-builtin">#:export</span> (get-projects))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">-- Record definition ---
</span>
(define-record-with-kw ( <span class="org-type">&lt;project-repository&gt;</span> %make-project-repository
                                             project-repository?)
                       mk-project-repository
                       (get-projects-proc repo-get-projects))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">--- eDSL: Embedded Domain Specific Language ---
</span>
(define-repo-method get-projects repo-get-projects
  <span class="org-string">&quot;Retrieves a list of all active projects from the given REPO.&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>The SQLite Implementation  <a id="the-sqlite-implementation" class="anchor" href="#the-sqlite-implementation" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org27aaeb5">
 <p>
Here is an example SQLite implementation using GNU Artanis. This is completely decoupled from the rest of the application logic.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">lucidplan</span> sqlite project)
                <span class="org-builtin">#:declarative?</span> #t
                <span class="org-builtin">#:use-module</span> (srfi srfi-9)
                <span class="org-builtin">#:use-module</span> (kracht prelude)
                <span class="org-builtin">#:use-module</span> (artanis db)
                <span class="org-builtin">#:use-module</span> (lucidplan sqlite util)
                <span class="org-builtin">#:use-module</span> (lucidplan domain project)
                <span class="org-builtin">#:export</span> (make-sqlite-project-repository))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">--- Artanis + SQLite implementation ---
</span>( <span class="org-keyword">define</span> ( <span class="org-function-name">make-sqlite-project-repository</span> rc)
        ( <span class="org-keyword">define</span>  <span class="org-function-name">columns</span>
                '(id human-id
                     title
                     url
                     vcs-url
                     description
                     created-at
                     updated-at
                     deleted-at))

        ( <span class="org-keyword">define</span> ( <span class="org-function-name">get-projects</span>)
                ( <span class="org-keyword">let*</span> ((query (format #f
                                       <span class="org-string">&quot;SELECT ~a
                   FROM project WHERE deleted_at IS NULL
                   ORDER BY human_id ASC&quot;</span>
                                      (symbols-&gt;sql-columns-list columns)))
                       (_ (log-info  <span class="org-string">&quot;get-projects query:\n\t~a\n&quot;</span> query))
                       (rows ( <span class="org-keyword">map</span> sql-row-&gt;scheme-alist
                                  (DB-get-all-rows (DB-query (DB-open rc) query))))
                       (_ (log-info  <span class="org-string">&quot;get-projects rows: ~a\n&quot;</span>
                                    (length rows))))
                  rows))

        (mk-project-repository  <span class="org-builtin">#:get-projects-proc</span> get-projects))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
A condensed example with keyword arguments:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;; </span> <span class="org-comment">The DSL (notice how arity is clean)
</span>(define-repo-method get-jobs repo-get-jobs
                   <span class="org-string">&quot;Retrieves a list of active jobs from the given REPO.&quot;</span>)

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">SQLite implementation
</span>( <span class="org-keyword">define*</span> ( <span class="org-function-name">get-jobs</span>  <span class="org-builtin">#:key</span> limit offset)
  ( <span class="org-keyword">let*</span> ((query (format #f
                  <span class="org-string">&quot;SELECT ~a FROM job
                 ORDER BY created_at DESC LIMIT ~a OFFSET ~a&quot;</span>
                 (symbols-&gt;sql-columns-list columns) limit offset))
         (_ (log-info  <span class="org-string">&quot;get-jobs query:\n\t~a\n&quot;</span> query))
         (rows ( <span class="org-keyword">map</span> sql-row-&gt;scheme-alist
                    (DB-get-all-rows (DB-query (DB-open rc) query))))
         (_ (log-info  <span class="org-string">&quot;get-jobs rows: ~a\n&quot;</span>
                      (length rows))))
    rows))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
I believe I have something really powerful cooking here, but I know
there is always room for improvement.
</p>

 <p>
 <b>What do you all think?</b> How would you go about improving this? I’m
entirely open to criticism, feedback, and brainstorming!
</p>

 <p>
Thanks for reading this :)
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Don't Reward the Best Firefighter</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Why I Still Reach for Scheme and Lisp Instead of Haskell</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/index.html</guid>
  <pubDate>Sat, 11 Apr 2026 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Don’t Reward the Best Firefighter</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>The “Hero” Trap  <a id="the-hero-trap" class="anchor" href="#the-hero-trap" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org026a8e3">
 <p>
Every engineering team has that one  <b>“hero.”</b> You know the one: the 3 AM incident response god.
They dive into a production dumpster fire, pull a rabbit out of a hat, and somehow bring the system back online.
</p>

 <p>
We love them for it. We give them the shout-outs in Slack, the fat bonuses, and the “Senior Staff” titles because they’re the “go-to” person when everything breaks.
</p>

 <p>
But by making them the main character, we’re lowkey ensuring our culture stays a mess.
</p>
</div>
 <h3>Visible Heroes vs. Invisible Wins  <a id="visible-heroes-vs-invisible-wins" class="anchor" href="#visible-heroes-vs-invisible-wins" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org7befca3">
 <p>
For every loud firefighter, there’s an invisible  <b>fire preventer.</b> This is the engineer who spends a month refactoring a messy legacy service that no one else wants to touch.
</p>

 <p>
Their work doesn’t show up as a shiny new feature on the roadmap. Their success is silent—it’s the catastrophic outage that  <b>didn’t</b> happen six months from now.
</p>

 <p>
And their reward? Often, it’s getting passed over for a promo because their “impact” wasn’t as visible as the person who “saved the day.”
</p>


 <div id="orgdf678cd" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/software-firefighter.png"></img></p>
</div>
</div>
 <h3>We Built a Broken Game  <a id="we-built-a-broken-game" class="anchor" href="#we-built-a-broken-game" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgba44737">
 <p>
This is a total incentive fail, and honestly, it’s on all of us. Performance reviews are fundamentally biased toward  <b>reactive work.</b>
</p>

 <p>
Managers are great at measuring things that are visible on a dashboard:
</p>

 <ul class="org-ul"> <li>Features shipped</li>
 <li>Tickets closed</li>
 <li>Incidents resolved</li>
</ul> <p>
There is no column on the spreadsheet for  <b>“disasters averted.”</b>
</p>

 <p>
As a result, we’ve built a career ladder that basically encourages engineers to let things smolder, knowing they’ll get more credit for putting out a blaze than for making sure there’s no fire in the first place.
</p>
</div>
 <h3>Redefining “Impact”  <a id="redefining-impact" class="anchor" href="#redefining-impact" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3b32531">
 <p>
It’s time to stop treating “impact” as a synonym for “loud activity.” Real impact is the verifiable elimination of future risk.
</p>

 <ul class="org-ul"> <li> <b>The Automation Win:</b> The engineer who fixes a flaky, manual   deployment isn’t just “closing a ticket.” They’re giving every dev on  the team their time back, forever. That’s massive, compounding impact.</li>
 <li> <b>The Refactor Win:</b> The engineer who cleans up a bug-prone module isn’t just “tidying up.” They are measurably lowering the failure rate for the entire business. That is direct risk reduction.</li>
</ul> <p>
We need to start hyping up the architects of fireproof buildings, not just the people who are good with a hose.
</p>

 <p>
This takes a conscious effort to hunt for the “invisible” work. We need to use data to quantify risk  <i>before</i> it fails and treat the reduction of that risk as a top-tier contribution.
</p>

 <p>
Next time you’re sitting in a performance calibration, ask yourself the hard question:  <b>Are we promoting the people who are best at navigating a broken system, or the ones who are actually fixing it?</b>
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Most Technical Problems are People Problems</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Functional repository pattern in Scheme? Decoupling and abstracting the data layer in Lisp</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/">Most Technical Problems are People Problems</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/index.html</guid>
  <pubDate>Wed, 04 Feb 2026 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Most Technical Problems are People Problems</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
I have worked at several companies doing Software Engineering and I feel like I’ve seen the best and the worst. From aging systems containing millions of lines of untested code, built on frameworks past their expiry date, to repulsive code and deployment constructs that stemmed from disagreements, bad communication, and terrible processes, I’ve seen it all, ticking technical time bombs, and all, but one specific case really illustrated the cultural rot for me.
</p>

 <p>
I once worked at a big furniture company famous worldwide, which had an enormous amount of technical debt - millions of lines of code, no unit tests, frameworks that were well over 2 decades out of date, things running on mainframe IBM computer to which no replacement parts can be found, etc.
</p>

 <p>
On one specific project, we had a market need to get features to market really fast, but there were no limitations in tech stack or so, so it was a golden opportunity to create something beautiful and maintainable.
</p>

 <p>
Rather than communicating with other teams to learn, or seeing what industry standards we live by in this day and age, this team simply copied &amp; pasted a few hundred thousand lines of the legacy code, and started hacking things onto it, effectively horseshoeing it into something that would work.
</p>

 <p>
For the non-technical reader, this is an enormous problem because now we have two different outdated (legacy) systems, which will start diverging, and apart from the fact that the systems are old, the software practices questionable, and the hardware is not even manufactured anymore, now all features &amp; bug fixes must be solved in two separate codebases that will grow apart over time.  When I heard about this, a young &amp; naive version of me thought he could fix the situation….
</p>

 <p>
The article which inspired me to write this one is found at  <a href="https://blog.joeschrag.com/2023/11/most-technical-problems-are-really.html">Helmet Hair</a>.
</p>
 <h2>Tech Debt is caused mostly by People Problems  <a id="tech-debt-is-caused-mostly-by-people-problems" class="anchor" href="#tech-debt-is-caused-mostly-by-people-problems" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org36a0b22">
 <p>
Then there is tech debt.  <b>Tech debt projects are always a hard sell to management, because even if everything goes flawlessly, the code just does roughly what it did before</b>.  This project of mine to refactor the legacy system into something modern was no exception, and the optics weren’t great.  I did as many engineers do and  <i>ignored the politics</i>, put my head down, and got it done.
</p>

 <p>
For the curious minds, yes, I managed to deploy something working at the end, and replaced the old system (eventually), but the project was really not well received by my engineer colleagues (management was indifferent).
</p>

 <p>
I realized I was essentially trying to solve a people problem with a technical solution.   <b>Most of the developers at this company were happy doing the same thing today that they did yesterday… and five years ago</b>.
</p>

 <p>
As  <a href="https://andrewharmellaw.github.io/">Andrew Harmel-Law</a> points out, code tends to follow the personalities of the people that wrote it.  The code was calcified because the developers were also.  Personality types who dislike change tend not to design their code with future change in mind.
</p>

 <p>
Most technical problems are really people problems.  Think about it.  Why does technical debt exist?  Because requirements weren’t properly clarified before work began.  Because a salesperson promised an unrealistic deadline to a customer.  Because a developer chose an outdated technology because it was comfortable.  Because management was too reactive and cancelled a project mid-flight.  Because someone’s ego wouldn’t let them see a better way of doing things. Because technology is made by people, and people are bound to make mistakes.
</p>

 <p>
The core issue with the project was that admitting the need for refactoring was also to admit that the way the company was building software was broken and that individual skillsets were sorely out of date. Trying to fix one part of many other problematic ones, while other developers continued doing as they always did.
</p>

 <p>
In my career, I’ve already met several engineers openly tell me,  <i>“I don’t want to learn anything new”</i> . I realized that you’ll never clean up tech debt faster than others create it.  It is like triage in an emergency room, you must stop the bleeding first, then you can fix whatever is broken.
</p>

 <p>
 <b>An Ideal World</b>: The project also showed me how impossible the engineer’s ideal of a world is, in which engineering problems can be solved in a vacuum - staying out of “politics” and letting the work speak for itself - a world where deadlines don’t exist…and let’s be honest, neither do customers.
</p>

 <p>
This ideal world rarely exists.  The vast majority of projects have non-technical stakeholders, and telling them “just trust me; we’re working on it” doesn’t cut it.  I realized that  <b>the perception that your team is getting a lot done is just as important as getting a lot done</b>.
</p>

 <p>
Non-technical people do not intuitively understand the level of effort required or the need for tech debt cleanup; it must be communicated effectively by engineering - in both initial estimates &amp; project updates.  Unless leadership has an engineering background, the value of the technical debt work likely needs to be quantified and shown as business value.
</p>

 <p>
Perhaps these are the lessons that prep one for more senior positions.  In my opinion, anyone above senior engineer level needs to know how to collaborate cross-functionally, regardless of whether they choose a technical or management track.  Schools teach Computer Science, not navigating personalities, egos, and personal blindspots.  
</p>

 <p>
I have worked with some incredible engineers - the type that have deep technical knowledge on just about any technology you bring up.  When I was younger, I wanted to be that engineer - and to some degrees I feel like I did become that. For all of their (considerable) strengths, more often than not, those engineers shy away from the interpersonal.  The tragedy is that they are incredibly productive ICs, but may fail with bigger initiatives because they are only one person (a single processor core can only go so fast).
</p>

 <p>
Perhaps equally valuable is the  <i>heads up coder</i>: the person who is deeply technical, but also able to pick their head up &amp; see project risks coming (technical &amp; otherwise) and steer the team around them.
</p>

 <hr></hr> <p>
The journey from technical problem solver to effective engineering leader often involves a sobering realization: the code is the culture made manifest.
</p>

 <p>
The catastrophic technical debt I’ve often seen, is rarely about the lack of technical skill, it is most often a symptom of deeper organizational failures. This includes fear of change, short-term managerial thinking, and a profound communication gap between the builders and the stakeholders.
</p>

 <p>
To truly tackle technical debt, we must evolve beyond the “Heads-Down” coder and embrace the Heads-Up Coder. This senior perspective understands that refactoring and modernization aren’t technical projects, but essential parts of day-to-day work as engineer.
</p>

 <p>
You cannot clean up technical debt without first addressing the people, process, and politics that created it.
</p>

 <p>
Focusing solely on the code is like sweeping the kitchen floor while the roof is leaking.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/rust/simple-guix-emacs-rust-development-environment/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Simple Rust Guix Emacs development environment</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Don't Reward the Best Firefighter</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/index.html</guid>
  <pubDate>Sat, 06 Dec 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Simple Rust Guix Emacs development environment</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>A minimal, declarative setup for productive Rust hacking on Emacs + Guix</i>
</p>
 <h2>Introduction  <a id="introduction" class="anchor" href="#introduction" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org0c24648">
 <p>
I noticed there was a blatant lack of resources and documentation on this particular setup. So I rolled up my sleeves and wrote this article, which hopefully you find useful.
</p>

 <p>
 <a href="https://rust-lang.org/">Rust</a> is a modern systems programming language with a strong focus on safety and performance.  
</p>

 <p>
In this article, I want to show you how to integrate it with our beloved Emacs text editor power-house, and the great  <a href="https://guix.gnu.org/">GNU Guix package manager</a>.
</p>

 <p>
 <a href="https://www.gnu.org/s/emacs/">GNU Emacs</a> is only the most flexible, programmable editor in existence. GNU Guix is the declarative, reproducible package manager built around the GNU Guile ecosystem.  
</p>

 <p>
Combine the three and you get a clean, reproducible, minimalistic Rust development workflow, without complications, without global toolchain pollution, and without mysterious version drift.
</p>

 <hr></hr></div>
 <h2>Overview of the Approach  <a id="overview-of-the-approach" class="anchor" href="#overview-of-the-approach" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org220702c">
 <p>
The foundation is a Guix manifest file that declares all the tools needed for Rust development.
</p>

 <ul class="org-ul"> <li> <code>guix shell</code> to create a temporary, isolated development environment</li>
 <li>Emacs packages:   <code>rust-mode</code>,  <code>eglot</code>, and  <code>toml-mode</code>,  <code>direnv</code></li>
 <li> <code>rust-analyzer</code> ,  <code>cargo</code> ,  <code>clippy</code> and  <code>rustc</code> installed via Guix</li>
</ul> <p>
This keeps your system clean, your environment reproducible on a per-project basis, and your editor fully integrated.
If you’re already using Guix—on Guix System or as a package manager on another distro—you’re good to go.
</p>

 <ul class="org-ul"> <li>Guix provides complete Rust toolchains as packages:  <code>rust</code>,  <code>cargo</code>,  <code>clippy</code>,  <code>rustfmt</code></li>
 <li>Guix updates are atomic and roll back cleanly</li>
 <li> <p>
You can maintain multiple environments with different Rust versions by using different manifests and using the Guix time machine
</p>

 <hr></hr></li>
</ul></div>
 <h2>A Minimal Guix Manifest for Rust  <a id="a-minimal-guix-manifest-for-rust" class="anchor" href="#a-minimal-guix-manifest-for-rust" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgad40c8c">
 <p>
We start with the smallest useful manifest. Read more  <a href="https://guix.gnu.org/manual/en/html_node/Writing-Manifests.html">about manifests here</a>
</p>

 <p>
Save this as  <code>manifest.scm</code>:
</p>

 <div class="jfw-code"> <pre>(use-modules (guix packages)
             (gnu)
             (gnu packages rust)
             (gnu packages tls)
             (gnu packages pkg-config))

(packages-&gt;manifest (list openssl
                          pkg-config
                          rust
                          (list rust  <span class="org-string">&quot;cargo&quot;</span>)
                          (list rust  <span class="org-string">&quot;tools&quot;</span>)
                          rust-analyzer))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This gives you:
</p>

 <ul class="org-ul"> <li>A full Rust compiler toolchain</li>
 <li>Cargo package manager</li>
 <li>rust-analyzer for editor integration with clippy linter</li>
 <li>Tools required for crates with native code (via  <code>pkg-config</code>)</li>
 <li>openssl might be optionally required for some Rust projects (for HTTP/SSL connections)</li>
</ul> <p>
You can enter the environment with:
</p>

 <div class="jfw-code"> <pre>guix shell -m manifest.scm</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Configuring Emacs for Rust  <a id="configuring-emacs-for-rust" class="anchor" href="#configuring-emacs-for-rust" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgfcf21ef">
 <p>
To integrate Emacs or your shell with the isolated environment of the manifest,  you can choose to use direnv, and place this in a  <code>.envrc</code> file at the root:
</p>

 <div class="jfw-code"> <pre>use guix</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Read more  <a href="https://direnv.net/">about direnv here</a>
</p>

 <p>
Here my setup using   <code>eglot</code> and  <code>rust-mode</code> in combination with  <code>flymake</code> for lints (read from  <code>clippy</code>). You probably can go more minimal than this, but for illustration purpose I will keep it like this.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> rust-mode  <span class="org-builtin">:ensure</span> t)

( <span class="org-keyword">use-package</span> direnv
   <span class="org-builtin">:ensure</span> t
   <span class="org-builtin">:bind</span> (( <span class="org-string">&quot;C-c d d&quot;</span> . direnv-mode)
         ( <span class="org-string">&quot;C-c d a&quot;</span> . direnv-allow)))

( <span class="org-keyword">use-package</span> eglot
   <span class="org-builtin">:ensure</span> nil
   <span class="org-builtin">:hook</span> ((rust-mode . eglot-ensure)
         (before-save . eglot-format-buffer))
   <span class="org-builtin">:bind</span> (( <span class="org-string">&quot;C-c i i&quot;</span> . eglot-find-implementation)
         ( <span class="org-string">&quot;C-c i e&quot;</span> . eglot)
         ( <span class="org-string">&quot;C-c i k&quot;</span> . eglot-shutdown-all)
         ( <span class="org-string">&quot;C-c i r&quot;</span> . eglot-rename)
         ( <span class="org-string">&quot;C-c i x&quot;</span> . eglot-reconnect)
         ( <span class="org-string">&quot;C-c i a&quot;</span> . eglot-code-actions)
         ( <span class="org-string">&quot;C-c i m&quot;</span> . eglot-menu)
         ( <span class="org-string">&quot;C-c i f&quot;</span> . eglot-format-buffer)
         ( <span class="org-string">&quot;C-c i h&quot;</span> . eglot-inlay-hints-mode))
   <span class="org-builtin">:init</span>
  ( <span class="org-keyword">setq</span> eglot-autoshutdown t
        eglot-confirm-server-edits nil
        eglot-report-progress t
        eglot-extend-to-xref t
        eglot-autoreconnect t)
   <span class="org-builtin">:config</span>
  ( <span class="org-keyword">setq-default</span> eglot-workspace-configuration
                '( <span class="org-builtin">:rust-analyzer</span> ( <span class="org-builtin">:check</span> ( <span class="org-builtin">:command</span>  <span class="org-string">&quot;clippy&quot;</span>)
                                   <span class="org-builtin">:cargo</span> ( <span class="org-builtin">:sysroot</span>  <span class="org-string">&quot;discover&quot;</span>
                                                           <span class="org-builtin">:features</span>  <span class="org-string">&quot;all&quot;</span>
                                                           <span class="org-builtin">:buildScripts</span> ( <span class="org-builtin">:enable</span> t))
                                   <span class="org-builtin">:diagnostics</span> ( <span class="org-builtin">:disabled</span> [ <span class="org-string">&quot;macro-error&quot;</span>])
                                   <span class="org-builtin">:procMacro</span> ( <span class="org-builtin">:enable</span> t))))

  (add-hook 'eglot-managed-mode-hook
            ( <span class="org-keyword">lambda</span> ()
               <span class="org-comment-delimiter">;; </span> <span class="org-comment">Show flymake diagnostics first.
</span>              ( <span class="org-keyword">setq</span> eldoc-documentation-functions
                    (cons #'flymake-eldoc-function
                          (remove #'flymake-eldoc-function eldoc-documentation-functions)))
               <span class="org-comment-delimiter">;; </span> <span class="org-comment">Show all eldoc feedback.
</span>              ( <span class="org-keyword">setq</span> eldoc-documentation-strategy #'eldoc-documentation-compose)))
  )</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>Creating and Running a Rust Project  <a id="creating-and-running-a-rust-project" class="anchor" href="#creating-and-running-a-rust-project" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org787bc91">
 <p>
Inside the Guix shell:
</p>

 <div class="jfw-code"> <pre>cargo new hello-guix
 <span class="org-builtin">cd</span> hello-guix
cargo run</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Because everything is inside the Guix environment, you get guaranteed reproducibility:
</p>

 <ul class="org-ul"> <li>Everyone uses the same toolchain version</li>
 <li>Builds behave consistently across machines</li>
 <li>No global installation conflicts</li>
</ul> <p>
rust-analyzer powers code completion, jump-to-definition, inlays, and inline diagnostics.
</p>

 <p>
Eglot will automatically start LSP support when you open a  <code>.rs</code> file in a Cargo project.
</p>

 <p>
Direnv can really help to make this setup seamless, and the great  <code>emacs-direnv</code> package really helps too.
</p>

 <p>
Bear in mind you might have add the directories to the whitelist of Guix.
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">echo</span> /home/my-repo &gt;&gt; /home/me/.config/guix/shell-authorized-directories</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr></div>
 <h2>A simple guix.scm  <a id="a-simple-guixscm" class="anchor" href="#a-simple-guixscm" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5f91c7c">
 <p>
You might also want to build production binaries/releases via Guix. This is easy to accomplish thanks to the amazing  <code>cargo-build-system</code>. See an example for  <a href="https://codeberg.org/jjba23/inkaartbrenger">my simple sitemap generator</a>. You can create a  <code>guix.scm</code> with the contents, and use it with  <code>guix shell</code> too.
</p>

 <div class="jfw-code"> <pre>(use-modules (guix gexp)
             (guix packages)
             (guix import crate)
             (guix git-download)
             ((guix licenses)
               <span class="org-builtin">#:prefix</span> license:)
             (guix build-system cargo)
             (gnu packages)
             (gnu packages tls)
             (gnu packages pkg-config))

( <span class="org-keyword">define</span>  <span class="org-function-name">%source-dir</span>
  (dirname (current-filename)))

( <span class="org-keyword">define-public</span>  <span class="org-function-name">inkaartbrenger</span>
  (package
    (name  <span class="org-string">&quot;inkaartbrenger&quot;</span>)
    (version  <span class="org-string">&quot;dev&quot;</span>)
    (source
     (local-file %source-dir
                  <span class="org-builtin">#:recursive?</span> #t
                  <span class="org-builtin">#:select?</span> (git-predicate %source-dir)))
    (build-system cargo-build-system)
    (native-inputs (list pkg-config))
    (inputs (cons* openssl
                   (cargo-inputs-from-lockfile  <span class="org-string">&quot;Cargo.lock&quot;</span>)))
    (arguments
     `( <span class="org-builtin">#:install-source?</span> #f
        <span class="org-builtin">#:tests?</span> #f))
    (home-page  <span class="org-string">&quot;https://codeberg.org/jjba23/inkaartbrenger&quot;</span>)
    (synopsis  <span class="org-string">&quot;&quot;</span>)
    (description  <span class="org-string">&quot;&quot;</span>)
    (license license:agpl3+)))

inkaartbrenger</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <hr></hr></div>
 <h2>Benefits of This Setup  <a id="benefits-of-this-setup" class="anchor" href="#benefits-of-this-setup" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6004747">
 <ul class="org-ul"> <li> <b> <b>Reproducible</b></b>: environments are fully declarative and shareable</li>
 <li> <b> <b>Clean</b></b>: maintain multiple toolchains easily</li>
 <li> <b> <b>Editor-friendly</b></b>: this approach works perfect for Emacs, but also  for most other editors</li>
 <li> <b> <b>Minimalistic</b></b>: small footprint, no rustup, no global package installs</li>
</ul> <p>
This is an excellent foundation for serious Rust work.
</p>

 <hr></hr></div>
 <h2>Conclusion  <a id="conclusion" class="anchor" href="#conclusion" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1759e92">
 <p>
With a tiny manifest and a small Emacs configuration, you get a powerful, reproducible, elegant Rust development environment.
</p>

 <p>
No matter what kind of developing you are doing, this setup provides a clean and reliable environment you can build on.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/embracing-the-eternal-sexp-wisdom-of-the-gnu/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Embracing the eternal Sexp wisdom with the GNU</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Most Technical Problems are People Problems</span></a>
</nav></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/rust/simple-guix-emacs-rust-development-environment/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/rust/simple-guix-emacs-rust-development-environment/index.html</guid>
  <pubDate>Sat, 15 Nov 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Git Riddance</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>Git Riddance - for Good Riddance!</i>
</p>
 <h2>Introduction  <a id="introduction" class="anchor" href="#introduction" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga0e65e0">
 <p>
 <code>git-riddance</code> is an Emacs package available at ( <a href="https://codeberg.org/jjba23/git-riddance.el">https://codeberg.org/jjba23/git-riddance.el</a>)  that will help you completely destroy the Git history of your desired directory, and allow you to start a new one with 1 commit, effectively obliterating other history in that branch.
</p>

 <p>
 <b>Licensing</b>
</p>

 <p>
Git Riddance is licensed under the GNU General Public License v3 or newer and is completely free software.
</p>
</div>
 <h2>Installing  <a id="installing" class="anchor" href="#installing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2fced46">
 <p>
This package is not (yet) available in popular Emacs repositories such as MELPA or ELPA. You can for example manually copy paste, use the  <code>:vc</code> keyword, or using Elpaca:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> git-riddance
   <span class="org-builtin">:ensure</span> ( <span class="org-builtin">:host</span> codeberg  <span class="org-builtin">:repo</span>  <span class="org-string">&quot;jjba23/git-riddance.el&quot;</span>  <span class="org-builtin">:branch</span>  <span class="org-string">&quot;trunk&quot;</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Using  <a id="using" class="anchor" href="#using" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2f0e40d">
 <p>
After installing, simply call  <code>M-x git-riddance</code> or bind it to a key shortcut, and you will be prompted for the required data and target directory.
There are some sane defaults configured, and all is customizable so you can override them with your own in your configuration.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/hexagon-of-doom/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Hexagon of Doom - The Cost of Over-Abstraction and Indirection</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/embracing-the-eternal-sexp-wisdom-of-the-gnu/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Embracing the eternal Sexp wisdom with the GNU</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/getting-rid-of-git-history/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/getting-rid-of-git-history/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Hexagon of Doom - The Cost of Over-Abstraction and Indirection</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>Disclaimer: This article reflects personal experiences and gripes within specific team environments. Your mileage may vary, but the warning against premature or redundant abstraction stands.</i>
</p>
 <h2>When “Clean Code” Becomes “Complicated Code”  <a id="when-ldquoclean-coderdquo-becomes-ldquocomplicated-coderdquo" class="anchor" href="#when-ldquoclean-coderdquo-becomes-ldquocomplicated-coderdquo" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9045c14">
 <p>
Hexagonal Architecture, often called  <b>Ports and Adapters (P&amp;A)</b>, is lauded for its promise of decoupling the core business logic (the “domain”) from external concerns (databases, UIs, APIs). In theory, it’s a beautiful solution for creating adaptable, testable systems.
</p>

 <p>
However, like many architectural patterns, P&amp;A is  <b>not</b> a universal good. In practice—especially for  <b>small projects</b>,  <b>small teams</b>, and particularly when using modern frameworks that provide powerful  <b>Dependency Injection (DI)</b> and layering capabilities (like  <b>ZIO</b> or Spring)—it often transforms from an asset into a  <b>liability</b>, drowning projects in unnecessary indirection and cognitive load.
</p>

 <p>
Let me explain why I think that in many contemporary environments, P&amp;A introduces  <b>net harm</b> by prioritizing abstract purity over practical simplicity.
</p>
</div>
 <h2>The Double-Layering Paradox (Hex + Layers)  <a id="the-double-layering-paradox-hex--layers" class="anchor" href="#the-double-layering-paradox-hex--layers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org813a7c7">
 <p>
The primary goal of P&amp;A is to invert dependencies: the domain defines an interface (a  <b>Port</b>), and an external module implements it (an  <b>Adapter</b>). This keeps the domain clean.
</p>

 <p>
When you already utilize a powerful, effect-aware layering system like  <b>ZIO Layers</b>, this benefit is almost entirely redundant, leading to an architectural redundancy:
</p>

 <p>
 <b>Indirection for Indirection’s Sake:</b>
P&amp;A adds interfaces for every dependency. When combined with a framework’s natural  <b>Service</b> and  <b>Layer</b> abstractions, you end up with  <b>two or more levels of indirection</b> to reach a simple implementation.
</p>

 <p>
Every time a developer needs to trace a call, they must traverse the application layer, the ZIO Service/Layer boundary,  <b>and</b> the Port/Adapter boundary.
</p>

 <p>
This complexity makes  <b>debugging significantly more painful</b> and slows down the basic task of understanding code flow.
</p>
</div>
 <h2>Complexity Debt: Small Teams, Big Overkill  <a id="complexity-debt-small-teams-big-overkill" class="anchor" href="#complexity-debt-small-teams-big-overkill" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge050918">
 <p>
The value of an abstraction must justify its cost. For a tiny microservice that mainly performs CRUD operations or orchestrates two external calls, the architectural overhead of P&amp;A is rarely justified.
</p>

 <p>
 <b>The 9/10 Rule:</b>
Most small services  <b>are not complex enough</b> to warrant this pattern. We often see P&amp;A implemented universally because  <i>“it’s good practice,”</i> not because the domain demands it.
</p>

 <p>
This is  <i>architecture astronautics</i> —designing for a future complexity that never materializes.
</p>

 <p>
 <b>Onboarding Nightmare:</b>
Team members, especially new joiners, already struggle to grasp complex functional programming paradigms, frameworks, effects and layers, etc. Adding the P&amp;A pattern on top of this introduces a massive  <b>cognitive hurdle</b>.
</p>

 <p>
The result is a team that spends more time studying the  <b>structure</b> of the code than solving the  <b>business problem</b>. If a developer needs four hours just to restudy the system structure before making a change, the architecture is failing.
</p>

 <p>
 <b>Change is More Difficult:</b>
Making a simple change now often requires modifications across three or four files (Domain Port, Application Service, Infrastructure Adapter, and the Layer wiring). This distributed logic dramatically increases the difficulty and risk associated with even minor feature updates.
</p>

 <p>
This snippet illustrates the cognitive tax of over-abstraction. You might see something like this in over-engineered code:
</p>
 <div class="jfw-code"> <pre>val result =
  for {
    order &lt;- OrderService.create(dto)
    _     &lt;- NotificationService.notify(order)
  } yield order

val run = result.provide(
  OrderService.live,
  NotificationService.live,
  OrderProcessorLive.layer,
  PaymentServiceStripeAdapter.layer,
  InventoryPortDatabaseAdapter.layer,
  NotificationPortEmailAdapter.layer,
  HandlebarsMailTemplating.layer,
  MailTemplatingAdapter.layer,
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
A simple CRUD endpoint now requires juggling four adapters and multiple ports — none of which add business value.
</p>

 <p>
Compare it to this, simpler and easier on everyone:
</p>
 <div class="jfw-code"> <pre>val result =
  for {
    order &lt;- OrderService.create(dto)
    _     &lt;- NotificationService.notify(order)
  } yield order

val run = result.provide(
  OrderService.live,
  NotificationService.live
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>The Testability Illusion  <a id="the-testability-illusion" class="anchor" href="#the-testability-illusion" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga22383d">
 <p>
A core selling point of P&amp;A is enhanced testability. By defining a Port, you can easily mock the Adapter implementation.
</p>

 <p>
However, this benefit is moot. Frameworks already provide an elegant, built-in mechanism for swapping implementations (a.k.a.,  <b>Layer Stubbing</b> or  <b>Mocking</b>).
</p>

 <div class="jfw-code"> <pre>// ZIO: Define a test layer with a mock implementation
val mockPaymentService: ULayer[PaymentServicePort] = ZLayer.succeed {
  new PaymentServicePort {
    def process(p: Payment) = ZIO.unit // Mocked behavior
  }
}
// Now run the test using the 'provide' method with the mock layer
// The Port interface itself wasn't strictly necessary for the mocking!</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The P&amp;A abstraction is simply surplus to requirements when robust DI tooling is available.
</p>
</div>
 <h2>The Tyranny of Types and Namespaces  <a id="the-tyranny-of-types-and-namespaces" class="anchor" href="#the-tyranny-of-types-and-namespaces" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgdaed539">
 <p>
P&amp;A, when combined with enthusiastic Domain-Driven Design (DDD) and strict folder structures, can lead to an explosion of files, types, and excessively deep namespaces.
</p>

 <p>
This kind of verbose, deeply nested imports are telltale signs of  <b>over-architecting</b>. It suggests a system size and complexity that usually only exists in a large, decades-old monolith, not a small, modern service. The sheer volume of types to track creates  <b>cognitive overhead</b> that actively slows development.
</p>

 <blockquote>
 <p>
🧩 Observation:
Below you see how we’ve defined 5+ types and layers just to wire a single function.
Every refactor means updating the Port, Adapter, and the wiring.
Native dependency system already is your “Port”.
</p>
</blockquote>

 <div class="jfw-code"> <pre>// --- Domain Port ---
trait PaymentServicePort {
  def process(payment: Payment): Task[Receipt]
}

// --- Domain Model ---
final case class Payment(id: String, amount: BigDecimal)
final case class Receipt(id: String, status: String)

// --- Application Service (uses the Port) ---
final class PaymentProcessor(paymentService: PaymentServicePort) {
  def handle(p: Payment): Task[Receipt] =
    paymentService.process(p)
}

// --- Infrastructure Adapter ---
final class StripePaymentAdapter extends PaymentServicePort {
  override def process(p: Payment): Task[Receipt] =
    ZIO.succeed(Receipt(p.id, &quot;OK - charged via Stripe&quot;))
}

// --- ZIO Layer wiring (adds a second indirection) ---
object PaymentLayers {
  val stripeLayer: ULayer[PaymentServicePort] = 
    ZLayer.succeed(new StripePaymentAdapter)

  val processorLayer: URLayer[PaymentServicePort, PaymentProcessor] =
    ZLayer.fromFunction(new PaymentProcessor(_))
}

// --- Usage ---
val app = for {
  processor &lt;- ZIO.service[PaymentProcessor]
  r         &lt;- processor.handle(Payment(&quot;p1&quot;, 42))
  _         &lt;- ZIO.logInfo(r.toString)
} yield ()

val runApp =
  app.provide(
    PaymentLayers.processorLayer,
    PaymentLayers.stripeLayer
  )</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>A Simpler Prescription for Sanity  <a id="a-simpler-prescription-for-sanity" class="anchor" href="#a-simpler-prescription-for-sanity" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2a985b0">
 <p>
Instead of resorting to heavy patterns like P&amp;A, small teams can achieve clean, maintainable, and highly testable code with a simpler “cocktail” of established, less intrusive patterns:
</p>

 <ul class="org-ul"> <li> <b>Good Domain-Driven Design (DDD):</b> Focus on correct  <b>naming</b>, clear  <b>domain models</b>, and ubiquitous language. This is where the most valuable abstraction lies.</li>
 <li> <b>Simple Structure:</b> A combination of  <b>MVC</b> (Model-View-Controller, or a simple  <b>Application Service</b> layer) for structure, combined with  <b>Command and Query</b> abstractions for separating read/write concerns, provides excellent clarity without excessive indirection.</li>
 <li> <b>Harness Native DI:</b> Leverage your framework’s native DI system fully. These tools were designed to manage dependencies cleanly; don’t fight them by adding manual indirection.</li>
</ul></div>
 <h2>Know When to Stop  <a id="know-when-to-stop" class="anchor" href="#know-when-to-stop" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org93deb9d">
 <p>
Hexagonal Architecture is a powerful tool, but it’s a tool for scaling complexity. For the vast majority of small to medium-sized projects—especially those built with modern, DI-rich frameworks—it represents a premature optimization that results in  <b>architecture debt</b> and  <b>developer burnout</b>.
</p>

 <p>
Before adopting a pattern, ask the critical question:  <b>Does this solve a problem I have today, or am I abstracting for a problem I might never have?</b>
</p>

 <p>
Often, the healthiest, most maintainable architecture is the simplest one that works. We must resist the urge to complicate code in the name of purity.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Increase the file descriptor count in GNU/Linux</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/getting-rid-of-git-history/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Git Riddance</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/hexagon-of-doom/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/hexagon-of-doom/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>The FREE stack - My Tech Radar</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
The FREE stack, ring by ring — what I trust, and inside each ring, the layers it lands in.
</p>

 <hr></hr> <div class="jfw-radar"> <div class="jfw-radar-canvas"> <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 1000 1000" class="jfw-radar-svg" role="img" aria-label="Tech radar: 70 technologies across 6 layers and 4 rings. Every blip is a link to its entry; every layer and ring is listed in full below."> <g class="jfw-radar-art"> <g class="jfw-radar-quadrants"> <path d="M 528.26 50.89 A 450.00 450.00 0 0 1 874.81 250.97 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-0"></path> <path d="M 903.07 299.91 A 450.00 450.00 0 0 1 903.07 700.09 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-1"></path> <path d="M 874.81 749.03 A 450.00 450.00 0 0 1 528.26 949.11 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-2"></path> <path d="M 471.74 949.11 A 450.00 450.00 0 0 1 125.19 749.03 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-3"></path> <path d="M 96.93 700.09 A 450.00 450.00 0 0 1 96.93 299.91 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-0"></path> <path d="M 125.19 250.97 A 450.00 450.00 0 0 1 471.74 50.89 L 500.00 500.00 Z" class="jfw-radar-wedge jfw-radar-wedge-1"></path></g> <g class="jfw-radar-rings"> <circle cx="500.00" cy="500.00" r="185.79" class="jfw-radar-ring-edge"></circle> <circle cx="500.00" cy="500.00" r="295.71" class="jfw-radar-ring-edge"></circle> <circle cx="500.00" cy="500.00" r="374.14" class="jfw-radar-ring-edge"></circle> <circle cx="500.00" cy="500.00" r="450.00" class="jfw-radar-ring-edge"></circle> <text x="524.98" y="410.53" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="first" transform="rotate(15.60 524.98 410.53)">Adopt</text> <text x="589.97" y="476.90" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(75.60 589.97 476.90)">Adopt</text> <text x="564.99" y="566.37" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 564.99 566.37)">Adopt</text> <text x="475.02" y="589.47" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(375.60 475.02 589.47)">Adopt</text> <text x="410.03" y="523.10" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(435.60 410.03 523.10)">Adopt</text> <text x="435.01" y="433.63" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 435.01 433.63)">Adopt</text> <text x="564.74" y="268.12" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="first" transform="rotate(15.60 564.74 268.12)">Trial</text> <text x="733.19" y="440.13" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(75.60 733.19 440.13)">Trial</text> <text x="668.44" y="672.01" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 668.44 672.01)">Trial</text> <text x="435.26" y="731.88" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(375.60 435.26 731.88)">Trial</text> <text x="266.81" y="559.87" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(435.60 266.81 559.87)">Trial</text> <text x="331.56" y="327.99" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 331.56 327.99)">Trial</text> <text x="590.07" y="177.41" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="first" transform="rotate(15.60 590.07 177.41)">Assess</text> <text x="824.41" y="416.71" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(75.60 824.41 416.71)">Assess</text> <text x="734.34" y="739.30" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 734.34 739.30)">Assess</text> <text x="409.93" y="822.59" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(375.60 409.93 822.59)">Assess</text> <text x="175.59" y="583.29" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(435.60 175.59 583.29)">Assess</text> <text x="265.66" y="260.70" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 265.66 260.70)">Assess</text> <text x="610.81" y="103.11" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="first" transform="rotate(15.60 610.81 103.11)">️ Deprecate</text> <text x="899.13" y="397.52" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(75.60 899.13 397.52)">️ Deprecate</text> <text x="788.31" y="794.41" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 788.31 794.41)">️ Deprecate</text> <text x="389.19" y="896.89" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(375.60 389.19 896.89)">️ Deprecate</text> <text x="100.87" y="602.48" class="jfw-radar-ring-label" text-anchor="end" data-jfw-radar-ring-name="repeat" transform="rotate(435.60 100.87 602.48)">️ Deprecate</text> <text x="211.69" y="205.59" class="jfw-radar-ring-label" text-anchor="start" data-jfw-radar-ring-name="repeat" transform="rotate(315.60 211.69 205.59)">️ Deprecate</text></g> <g class="jfw-radar-blips"> <a href="#adopt-languages" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="Guile Scheme and Lisps in general — Adopt ring, Languages"> <title>Guile Scheme and Lisps in general — Adopt ring, Languages</title> <circle cx="509.29" cy="443.70" r="15.00" class="jfw-radar-hit"></circle> <circle cx="509.29" cy="443.70" r="9" class="jfw-radar-dot"></circle> <text x="509.29" y="443.70" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Guile Scheme and Lisps in…</text></a> <a href="#adopt-languages" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="Emacs Lisp — Adopt ring, Languages"> <title>Emacs Lisp — Adopt ring, Languages</title> <circle cx="532.46" cy="408.02" r="15.00" class="jfw-radar-hit"></circle> <circle cx="532.46" cy="408.02" r="9" class="jfw-radar-dot"></circle> <text x="532.46" y="408.02" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Emacs Lisp</text></a> <a href="#adopt-languages" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="JavaScript (vanilla) — Adopt ring, Languages"> <title>JavaScript (vanilla) — Adopt ring, Languages</title> <circle cx="569.67" cy="379.33" r="15.00" class="jfw-radar-hit"></circle> <circle cx="569.67" cy="379.33" r="9" class="jfw-radar-dot"></circle> <text x="569.67" y="379.33" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">JavaScript (vanilla)</text></a> <a href="#adopt-languages" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="Rust — Adopt ring, Languages"> <title>Rust — Adopt ring, Languages</title> <circle cx="536.59" cy="456.14" r="15.00" class="jfw-radar-hit"></circle> <circle cx="536.59" cy="456.14" r="9" class="jfw-radar-dot"></circle> <text x="536.59" y="456.14" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Rust</text></a> <a href="#adopt-languages" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0 jfw-radar-moved-new" aria-label="C — Adopt ring, Languages"> <title>C — Adopt ring, Languages, new since the last revision. the two desktop apps, LambDock and Heks Toon, are C with GTK4 around a Guile engine, and nothing above them needs a heavier language</title> <circle cx="575.93" cy="438.78" r="15.00" class="jfw-radar-hit"></circle> <circle cx="575.93" cy="438.78" r="9" class="jfw-radar-dot"></circle> <text x="575.93" y="438.78" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">C</text></a> <a href="#adopt-frameworks" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="GNU Artanis — Adopt ring, Frameworks &amp; UI"> <title>GNU Artanis — Adopt ring, Frameworks &amp; UI</title> <circle cx="553.75" cy="480.75" r="15.00" class="jfw-radar-hit"></circle> <circle cx="553.75" cy="480.75" r="9" class="jfw-radar-dot"></circle> <text x="553.75" y="480.75" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">GNU Artanis</text></a> <a href="#adopt-frameworks" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="GTK4 Libadwaita — Adopt ring, Frameworks &amp; UI"> <title>GTK4 Libadwaita — Adopt ring, Frameworks &amp; UI</title> <circle cx="596.89" cy="488.79" r="15.00" class="jfw-radar-hit"></circle> <circle cx="596.89" cy="488.79" r="9" class="jfw-radar-dot"></circle> <text x="596.89" y="488.79" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">GTK4 Libadwaita</text></a> <a href="#adopt-frameworks" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="Olive CSS for all serious web projects (utility class vanilla CSS) — Adopt ring, Frameworks &amp; UI"> <title>Olive CSS for all serious web projects (utility class vanilla CSS) — Adopt ring, Frameworks &amp; UI</title> <circle cx="638.42" cy="516.02" r="15.00" class="jfw-radar-hit"></circle> <circle cx="638.42" cy="516.02" r="9" class="jfw-radar-dot"></circle> <text x="638.42" y="516.02" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Olive CSS for all serious web…</text></a> <a href="#adopt-frameworks" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="Hygguile UI components (batteries included Guile Scheme UI framework built on Olive CSS) — Adopt ring, Frameworks &amp; UI"> <title>Hygguile UI components (batteries included Guile Scheme UI framework built on Olive CSS) — Adopt ring, Frameworks &amp; UI</title> <circle cx="558.12" cy="510.43" r="15.00" class="jfw-radar-hit"></circle> <circle cx="558.12" cy="510.43" r="9" class="jfw-radar-dot"></circle> <text x="558.12" y="510.43" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Hygguile UI components…</text></a> <a href="#adopt-data" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-2" aria-label="SQLite — Adopt ring, ️ Data &amp; Storage"> <title>SQLite — Adopt ring, ️ Data &amp; Storage</title> <circle cx="548.84" cy="538.96" r="15.00" class="jfw-radar-hit"></circle> <circle cx="548.84" cy="538.96" r="9" class="jfw-radar-dot"></circle> <text x="548.84" y="538.96" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">SQLite</text></a> <a href="#adopt-data" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-2" aria-label="PostgreSQL — Adopt ring, ️ Data &amp; Storage"> <title>PostgreSQL — Adopt ring, ️ Data &amp; Storage</title> <circle cx="563.42" cy="574.10" r="15.00" class="jfw-radar-hit"></circle> <circle cx="563.42" cy="574.10" r="9" class="jfw-radar-dot"></circle> <text x="563.42" y="574.10" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">PostgreSQL</text></a> <a href="#adopt-data" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-2" aria-label="Plain SQL queries — Adopt ring, ️ Data &amp; Storage"> <title>Plain SQL queries — Adopt ring, ️ Data &amp; Storage</title> <circle cx="569.67" cy="620.67" r="15.00" class="jfw-radar-hit"></circle> <circle cx="569.67" cy="620.67" r="9" class="jfw-radar-dot"></circle> <text x="569.67" y="620.67" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Plain SQL queries</text></a> <a href="#adopt-data" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-2" aria-label="Hetzner Storage Volumes with Cron-job based backups and rsync — Adopt ring, ️ Data &amp; Storage"> <title>Hetzner Storage Volumes with Cron-job based backups and rsync — Adopt ring, ️ Data &amp; Storage</title> <circle cx="525.29" cy="557.54" r="15.00" class="jfw-radar-hit"></circle> <circle cx="525.29" cy="557.54" r="9" class="jfw-radar-dot"></circle> <text x="525.29" y="557.54" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Hetzner Storage Volumes with…</text></a> <a href="#adopt-data" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-2 jfw-radar-moved-new" aria-label="Mutastructura — Adopt ring, ️ Data &amp; Storage"> <title>Mutastructura — Adopt ring, ️ Data &amp; Storage, new since the last revision. migrations decreed as Lisp and applied incrementally, so a schema change is a file in the repo rather than a script someone ran once</title> <circle cx="520.33" cy="595.97" r="15.00" class="jfw-radar-hit"></circle> <circle cx="520.33" cy="595.97" r="9" class="jfw-radar-dot"></circle> <text x="520.33" y="595.97" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Mutastructura</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="GNU Guix — Adopt ring, ️ Tools &amp; Environment"> <title>GNU Guix — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="495.30" cy="558.49" r="15.00" class="jfw-radar-hit"></circle> <circle cx="495.30" cy="558.49" r="9" class="jfw-radar-dot"></circle> <text x="495.30" y="558.49" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">GNU Guix</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Emacs — Adopt ring, ️ Tools &amp; Environment"> <title>Emacs — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="490.53" cy="599.43" r="15.00" class="jfw-radar-hit"></circle> <circle cx="490.53" cy="599.43" r="9" class="jfw-radar-dot"></circle> <text x="490.53" y="599.43" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Emacs</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Org mode — Adopt ring, ️ Tools &amp; Environment"> <title>Org mode — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="464.88" cy="634.84" r="15.00" class="jfw-radar-hit"></circle> <circle cx="464.88" cy="634.84" r="9" class="jfw-radar-dot"></circle> <text x="464.88" y="634.84" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Org mode</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Maak build tool and command runner — Adopt ring, ️ Tools &amp; Environment"> <title>Maak build tool and command runner — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="466.34" cy="566.32" r="15.00" class="jfw-radar-hit"></circle> <circle cx="466.34" cy="566.32" r="9" class="jfw-radar-dot"></circle> <text x="466.34" y="566.32" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Maak build tool and command…</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Veritas test framework (idiomatic unit, integration and black-box testing framework powered by Lisp - Guile Scheme) — Adopt ring, ️ Tools &amp; Environment"> <title>Veritas test framework (idiomatic unit, integration and black-box testing framework powered by Lisp - Guile Scheme) — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="460.74" cy="595.79" r="15.00" class="jfw-radar-hit"></circle> <circle cx="460.74" cy="595.79" r="9" class="jfw-radar-dot"></circle> <text x="460.74" y="595.79" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Veritas test framework…</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Scriba structured logging framework (modular log routing, formatting, and filtering, allowing developers to generate human-readable console logs during development and machine-readable logs for production environments) — Adopt ring, ️ Tools &amp; Environment"> <title>Scriba structured logging framework (modular log routing, formatting, and filtering, allowing developers to generate human-readable console logs during development and machine-readable logs for production environments) — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="435.01" cy="623.26" r="15.00" class="jfw-radar-hit"></circle> <circle cx="435.01" cy="623.26" r="9" class="jfw-radar-dot"></circle> <text x="435.01" y="623.26" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Scriba structured logging…</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Woodpecker CI/CD — Adopt ring, ️ Tools &amp; Environment"> <title>Woodpecker CI/CD — Adopt ring, ️ Tools &amp; Environment. the CI that replaced the Jenkins pipelines I used to maintain</title> <circle cx="472.27" cy="526.71" r="15.00" class="jfw-radar-hit"></circle> <circle cx="472.27" cy="526.71" r="9" class="jfw-radar-dot"></circle> <text x="472.27" y="526.71" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Woodpecker CI/CD</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Nix Flakes — Adopt ring, ️ Tools &amp; Environment"> <title>Nix Flakes — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="435.86" cy="578.89" r="15.00" class="jfw-radar-hit"></circle> <circle cx="435.86" cy="578.89" r="9" class="jfw-radar-dot"></circle> <text x="435.86" y="578.89" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Nix Flakes</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3" aria-label="Nix dev shells — Adopt ring, ️ Tools &amp; Environment"> <title>Nix dev shells — Adopt ring, ️ Tools &amp; Environment</title> <circle cx="408.59" cy="605.16" r="15.00" class="jfw-radar-hit"></circle> <circle cx="408.59" cy="605.16" r="9" class="jfw-radar-dot"></circle> <text x="408.59" y="605.16" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Nix dev shells</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="Meson and Ninja — Adopt ring, ️ Tools &amp; Environment"> <title>Meson and Ninja — Adopt ring, ️ Tools &amp; Environment, new since the last revision. what builds the C desktop apps, with Maak driving the steps around it</title> <circle cx="445.47" cy="544.77" r="15.00" class="jfw-radar-hit"></circle> <circle cx="445.47" cy="544.77" r="9" class="jfw-radar-dot"></circle> <text x="445.47" y="544.77" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Meson and Ninja</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="Sift — Adopt ring, ️ Tools &amp; Environment"> <title>Sift — Adopt ring, ️ Tools &amp; Environment, new since the last revision. the Lisp formatter, linter and language server that never loses a byte; every Scheme repo of mine is linted through it</title> <circle cx="417.34" cy="555.22" r="15.00" class="jfw-radar-hit"></circle> <circle cx="417.34" cy="555.22" r="9" class="jfw-radar-dot"></circle> <text x="417.34" y="555.22" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Sift</text></a> <a href="#adopt-tools" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="Byggsteg — Adopt ring, ️ Tools &amp; Environment"> <title>Byggsteg — Adopt ring, ️ Tools &amp; Environment, new since the last revision. pipelines described as a list in Lisp, and the CI that runs them</title> <circle cx="386.99" cy="581.51" r="15.00" class="jfw-radar-hit"></circle> <circle cx="386.99" cy="581.51" r="9" class="jfw-radar-dot"></circle> <text x="386.99" y="581.51" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Byggsteg</text></a> <a href="#adopt-platforms" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="Custom low-power green VPS (Hetzner) — Adopt ring, Platforms &amp; Delivery"> <title>Custom low-power green VPS (Hetzner) — Adopt ring, Platforms &amp; Delivery</title> <circle cx="444.25" cy="514.80" r="15.00" class="jfw-radar-hit"></circle> <circle cx="444.25" cy="514.80" r="9" class="jfw-radar-dot"></circle> <text x="444.25" y="514.80" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Custom low-power green VPS…</text></a> <a href="#adopt-platforms" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0" aria-label="Codeberg — Adopt ring, Platforms &amp; Delivery"> <title>Codeberg — Adopt ring, Platforms &amp; Delivery. free software's own forge, and the home of every project of mine</title> <circle cx="402.46" cy="500.00" r="15.00" class="jfw-radar-hit"></circle> <circle cx="402.46" cy="500.00" r="9" class="jfw-radar-dot"></circle> <text x="402.46" y="500.00" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Codeberg</text></a> <a href="#adopt-platforms" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-0 jfw-radar-moved-new" aria-label="Docker images as the delivery unit — Adopt ring, Platforms &amp; Delivery"> <title>Docker images as the delivery unit — Adopt ring, Platforms &amp; Delivery, new since the last revision. every repo builds one and a compose file brings the stack up, so the server needs a container runtime rather than a list of install steps</title> <circle cx="367.18" cy="457.87" r="15.00" class="jfw-radar-hit"></circle> <circle cx="367.18" cy="457.87" r="9" class="jfw-radar-dot"></circle> <text x="367.18" y="457.87" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Docker images as the delivery…</text></a> <a href="#adopt-practice" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="Authorization and Authentication with Bewaking tokens as cookies — Adopt ring, ️ Practice &amp; Craft"> <title>Authorization and Authentication with Bewaking tokens as cookies — Adopt ring, ️ Practice &amp; Craft</title> <circle cx="455.85" cy="465.60" r="15.00" class="jfw-radar-hit"></circle> <circle cx="455.85" cy="465.60" r="9" class="jfw-radar-dot"></circle> <text x="455.85" y="465.60" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Authorization and…</text></a> <a href="#adopt-practice" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="Guix Manifests — Adopt ring, ️ Practice &amp; Craft"> <title>Guix Manifests — Adopt ring, ️ Practice &amp; Craft</title> <circle cx="436.58" cy="425.90" r="15.00" class="jfw-radar-hit"></circle> <circle cx="436.58" cy="425.90" r="9" class="jfw-radar-dot"></circle> <text x="436.58" y="425.90" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Guix Manifests</text></a> <a href="#adopt-practice" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1" aria-label="Guix dev shells — Adopt ring, ️ Practice &amp; Craft"> <title>Guix dev shells — Adopt ring, ️ Practice &amp; Craft</title> <circle cx="430.33" cy="379.33" r="15.00" class="jfw-radar-hit"></circle> <circle cx="430.33" cy="379.33" r="9" class="jfw-radar-dot"></circle> <text x="430.33" y="379.33" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Guix dev shells</text></a> <a href="#adopt-practice" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1 jfw-radar-moved-in" aria-label="Hexagonal architecture / ports and adapters — Adopt ring, ️ Practice &amp; Craft"> <title>Hexagonal architecture / ports and adapters — Adopt ring, ️ Practice &amp; Craft, closer to the middle than before. the boundary earns its keep wherever the domain is the complicated part; the Hexagon of Doom is the case where it is not</title> <circle cx="479.49" cy="447.13" r="15.00" class="jfw-radar-hit"></circle> <circle cx="479.49" cy="447.13" r="9" class="jfw-radar-dot"></circle> <text x="479.49" y="447.13" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Hexagonal architecture /…</text></a> <a href="#adopt-practice" class="jfw-radar-blip jfw-radar-blip-adopt jfw-radar-blip-quadrant-1 jfw-radar-moved-new" aria-label="A Guix manifest and a Nix flake in the same repo — Adopt ring, ️ Practice &amp; Craft"> <title>A Guix manifest and a Nix flake in the same repo — Adopt ring, ️ Practice &amp; Craft, new since the last revision. the toolchain described twice, so either package manager opens a shell that matches the build</title> <circle cx="484.94" cy="403.63" r="15.00" class="jfw-radar-hit"></circle> <circle cx="484.94" cy="403.63" r="9" class="jfw-radar-dot"></circle> <text x="484.94" y="403.63" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">A Guix manifest and a Nix…</text></a> <a href="#trial-languages" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-0 jfw-radar-moved-in" aria-label="Guile embedded in C and GTK4 — Trial ring, Languages"> <title>Guile embedded in C and GTK4 — Trial ring, Languages, closer to the middle than before. the dock Wayland was waiting for, with a Lisp engine inside a native app</title> <circle cx="546.98" cy="286.34" r="15.00" class="jfw-radar-hit"></circle> <circle cx="546.98" cy="286.34" r="9" class="jfw-radar-dot"></circle> <text x="546.98" y="286.34" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Guile embedded in C and GTK4</text></a> <a href="#trial-languages" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-0 jfw-radar-moved-new" aria-label="Kotlin — Trial ring, Languages"> <title>Kotlin — Trial ring, Languages, new since the last revision. symbanta, where the JVM's libraries and compile-time checks pay for the ceremony</title> <circle cx="621.75" cy="289.12" r="15.00" class="jfw-radar-hit"></circle> <circle cx="621.75" cy="289.12" r="9" class="jfw-radar-dot"></circle> <text x="621.75" y="289.12" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Kotlin</text></a> <a href="#trial-languages" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-0 jfw-radar-moved-new" aria-label="Python — Trial ring, Languages"> <title>Python — Trial ring, Languages, new since the last revision. the icon tooling (icns2linux, skeu-icons), where Pillow and numpy do the work</title> <circle cx="698.08" cy="319.13" r="15.00" class="jfw-radar-hit"></circle> <circle cx="698.08" cy="319.13" r="9" class="jfw-radar-dot"></circle> <text x="698.08" y="319.13" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Python</text></a> <a href="#trial-frameworks" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-new" aria-label="Spring Boot — Trial ring, Frameworks &amp; UI"> <title>Spring Boot — Trial ring, Frameworks &amp; UI, new since the last revision. symbanta's HTTP layer: validation, security, JPA and Actuator out of the box, at the price of a framework that decides a great deal for you</title> <circle cx="712.98" cy="450.04" r="15.00" class="jfw-radar-hit"></circle> <circle cx="712.98" cy="450.04" r="9" class="jfw-radar-dot"></circle> <text x="712.98" y="450.04" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Spring Boot</text></a> <a href="#trial-frameworks" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-new" aria-label="React 19 with Vite — Trial ring, Frameworks &amp; UI"> <title>React 19 with Vite — Trial ring, Frameworks &amp; UI, new since the last revision. symbanta's dashboard, and the one place a client-side framework still earns its keep; everything new is server-rendered</title> <circle cx="737.06" cy="555.60" r="15.00" class="jfw-radar-hit"></circle> <circle cx="737.06" cy="555.60" r="9" class="jfw-radar-dot"></circle> <text x="737.06" y="555.60" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">React 19 with Vite</text></a> <a href="#trial-data" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-2 jfw-radar-moved-new" aria-label="Flyway — Trial ring, ️ Data &amp; Storage"> <title>Flyway — Trial ring, ️ Data &amp; Storage, new since the last revision. migrations for symbanta's PostgreSQL, versioned beside the code that reads those tables</title> <circle cx="609.38" cy="689.46" r="15.00" class="jfw-radar-hit"></circle> <circle cx="609.38" cy="689.46" r="9" class="jfw-radar-dot"></circle> <text x="609.38" y="689.46" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Flyway</text></a> <a href="#trial-tools" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-3 jfw-radar-moved-in" aria-label="Podman — Trial ring, ️ Tools &amp; Environment"> <title>Podman — Trial ring, ️ Tools &amp; Environment, closer to the middle than before. daemonless, root-less containers that stay under my own control</title> <circle cx="466.23" cy="716.14" r="15.00" class="jfw-radar-hit"></circle> <circle cx="466.23" cy="716.14" r="9" class="jfw-radar-dot"></circle> <text x="466.23" y="716.14" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Podman</text></a> <a href="#trial-tools" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-3 jfw-radar-moved-in" aria-label="Hyprland — Trial ring, ️ Tools &amp; Environment"> <title>Hyprland — Trial ring, ️ Tools &amp; Environment, closer to the middle than before. the Wayland compositor I actually use daily, after SwayFX taught me compositor scripting</title> <circle cx="418.96" cy="729.62" r="15.00" class="jfw-radar-hit"></circle> <circle cx="418.96" cy="729.62" r="9" class="jfw-radar-dot"></circle> <text x="418.96" y="729.62" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Hyprland</text></a> <a href="#trial-tools" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="DeepSeek — Trial ring, ️ Tools &amp; Environment"> <title>DeepSeek — Trial ring, ️ Tools &amp; Environment, new since the last revision. an LLM I keep on a short leash: it drafts and reviews, a human decides, and nothing it writes ships unread</title> <circle cx="365.88" cy="732.30" r="15.00" class="jfw-radar-hit"></circle> <circle cx="365.88" cy="732.30" r="9" class="jfw-radar-dot"></circle> <text x="365.88" y="732.30" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">DeepSeek</text></a> <a href="#trial-tools" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="Maven with its wrapper — Trial ring, ️ Tools &amp; Environment"> <title>Maven with its wrapper — Trial ring, ️ Tools &amp; Environment, new since the last revision. what the one JVM project needs; Maak still drives everything around it</title> <circle cx="357.75" cy="666.20" r="15.00" class="jfw-radar-hit"></circle> <circle cx="357.75" cy="666.20" r="9" class="jfw-radar-dot"></circle> <text x="357.75" y="666.20" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Maven with its wrapper</text></a> <a href="#trial-tools" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-3 jfw-radar-moved-new" aria-label="OpenAPI as the contract — Trial ring, ️ Tools &amp; Environment"> <title>OpenAPI as the contract — Trial ring, ️ Tools &amp; Environment, new since the last revision. guile-openapi-generator on the Scheme side and orval on the dashboard's, so neither hand-writes the other's types</title> <circle cx="310.45" cy="652.84" r="15.00" class="jfw-radar-hit"></circle> <circle cx="310.45" cy="652.84" r="9" class="jfw-radar-dot"></circle> <text x="310.45" y="652.84" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">OpenAPI as the contract</text></a> <a href="#trial-platforms" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-0 jfw-radar-moved-in" aria-label="Self-hosted Woodpecker runners on the same VPS — Trial ring, Platforms &amp; Delivery"> <title>Self-hosted Woodpecker runners on the same VPS — Trial ring, Platforms &amp; Delivery, closer to the middle than before. CI that never leaves infrastructure I control</title> <circle cx="281.24" cy="500.00" r="15.00" class="jfw-radar-hit"></circle> <circle cx="281.24" cy="500.00" r="9" class="jfw-radar-dot"></circle> <text x="281.24" y="500.00" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Self-hosted Woodpecker…</text></a> <a href="#trial-practice" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-in" aria-label="Server-side rendering over client-side JavaScript — Trial ring, ️ Practice &amp; Craft"> <title>Server-side rendering over client-side JavaScript — Trial ring, ️ Practice &amp; Craft, closer to the middle than before. pages that work before, and without, a megabyte of framework</title> <circle cx="332.91" cy="358.80" r="15.00" class="jfw-radar-hit"></circle> <circle cx="332.91" cy="358.80" r="9" class="jfw-radar-dot"></circle> <text x="332.91" y="358.80" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Server-side rendering over…</text></a> <a href="#trial-practice" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-in" aria-label="This very site as a single Org tree — Trial ring, ️ Practice &amp; Craft"> <title>This very site as a single Org tree — Trial ring, ️ Practice &amp; Craft, closer to the middle than before. prose, build script and metadata in one plain-text source</title> <circle cx="354.82" cy="304.52" r="15.00" class="jfw-radar-hit"></circle> <circle cx="354.82" cy="304.52" r="9" class="jfw-radar-dot"></circle> <text x="354.82" y="304.52" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">This very site as a single…</text></a> <a href="#trial-practice" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-in" aria-label="Parsing Expression Grammar in Scheme with — Trial ring, ️ Practice &amp; Craft"> <title>Parsing Expression Grammar in Scheme with — Trial ring, ️ Practice &amp; Craft, closer to the middle than before. how OrgWebAlchemy turns Org into HTML without a parser generator</title> <circle cx="393.47" cy="253.83" r="15.00" class="jfw-radar-hit"></circle> <circle cx="393.47" cy="253.83" r="9" class="jfw-radar-dot"></circle> <text x="393.47" y="253.83" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Parsing Expression Grammar in…</text></a> <a href="#trial-practice" class="jfw-radar-blip jfw-radar-blip-trial jfw-radar-blip-quadrant-1 jfw-radar-moved-new" aria-label="Testcontainers and Kotest — Trial ring, ️ Practice &amp; Craft"> <title>Testcontainers and Kotest — Trial ring, ️ Practice &amp; Craft, new since the last revision. the JVM suite runs against a real PostgreSQL in a container, beside the fast tests</title> <circle cx="461.26" cy="284.69" r="15.00" class="jfw-radar-hit"></circle> <circle cx="461.26" cy="284.69" r="9" class="jfw-radar-dot"></circle> <text x="461.26" y="284.69" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Testcontainers and Kotest</text></a> <a href="#assess-languages" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-0" aria-label="Guile Hoot — Assess ring, Languages"> <title>Guile Hoot — Assess ring, Languages. Scheme compiled to WebAssembly</title> <circle cx="568.55" cy="188.20" r="15.00" class="jfw-radar-hit"></circle> <circle cx="568.55" cy="188.20" r="9" class="jfw-radar-dot"></circle> <text x="568.55" y="188.20" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Guile Hoot</text></a> <a href="#assess-languages" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-0" aria-label="Zig — Assess ring, Languages"> <title>Zig — Assess ring, Languages</title> <circle cx="668.44" cy="208.25" r="15.00" class="jfw-radar-hit"></circle> <circle cx="668.44" cy="208.25" r="9" class="jfw-radar-dot"></circle> <text x="668.44" y="208.25" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Zig</text></a> <a href="#assess-languages" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-0" aria-label="Hare — Assess ring, Languages"> <title>Hare — Assess ring, Languages</title> <circle cx="761.81" cy="260.94" r="15.00" class="jfw-radar-hit"></circle> <circle cx="761.81" cy="260.94" r="9" class="jfw-radar-dot"></circle> <text x="761.81" y="260.94" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Hare</text></a> <a href="#assess-tools" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-3" aria-label="Forgejo — Assess ring, ️ Tools &amp; Environment"> <title>Forgejo — Assess ring, ️ Tools &amp; Environment. a self-hosted forge for code I want to keep closer than Codeberg's public instance</title> <circle cx="407.73" cy="805.62" r="15.00" class="jfw-radar-hit"></circle> <circle cx="407.73" cy="805.62" r="9" class="jfw-radar-dot"></circle> <text x="407.73" y="805.62" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Forgejo</text></a> <a href="#assess-tools" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-3" aria-label="Guix Home — Assess ring, ️ Tools &amp; Environment"> <title>Guix Home — Assess ring, ️ Tools &amp; Environment. one declarative description of the machine I actually work on</title> <circle cx="269.38" cy="745.58" r="15.00" class="jfw-radar-hit"></circle> <circle cx="269.38" cy="745.58" r="9" class="jfw-radar-dot"></circle> <text x="269.38" y="745.58" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Guix Home</text></a> <a href="#assess-platforms" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-0 jfw-radar-moved-in" aria-label="Guix System images on AArch64 — Assess ring, Platforms &amp; Delivery"> <title>Guix System images on AArch64 — Assess ring, Platforms &amp; Delivery, closer to the middle than before. a machine I can describe, build and roll back, on hardware that is not x86</title> <circle cx="189.19" cy="572.90" r="15.00" class="jfw-radar-hit"></circle> <circle cx="189.19" cy="572.90" r="9" class="jfw-radar-dot"></circle> <text x="189.19" y="572.90" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Guix System images on AArch64</text></a> <a href="#assess-platforms" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-0" aria-label="Guix System as the whole server, not just the toolchain — Assess ring, Platforms &amp; Delivery"> <title>Guix System as the whole server, not just the toolchain — Assess ring, Platforms &amp; Delivery</title> <circle cx="172.01" cy="423.07" r="15.00" class="jfw-radar-hit"></circle> <circle cx="172.01" cy="423.07" r="9" class="jfw-radar-dot"></circle> <text x="172.01" y="423.07" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Guix System as the whole…</text></a> <a href="#assess-practice" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-1" aria-label="Property-based testing — Assess ring, ️ Practice &amp; Craft"> <title>Property-based testing — Assess ring, ️ Practice &amp; Craft. describing the invariant instead of the example</title> <circle cx="281.46" cy="267.28" r="15.00" class="jfw-radar-hit"></circle> <circle cx="281.46" cy="267.28" r="9" class="jfw-radar-dot"></circle> <text x="281.46" y="267.28" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Property-based testing</text></a> <a href="#assess-practice" class="jfw-radar-blip jfw-radar-blip-assess jfw-radar-blip-quadrant-1" aria-label="Reproducible CI with `guix time-machine` — Assess ring, ️ Practice &amp; Craft"> <title>Reproducible CI with `guix time-machine` — Assess ring, ️ Practice &amp; Craft</title> <circle cx="402.63" cy="177.49" r="15.00" class="jfw-radar-hit"></circle> <circle cx="402.63" cy="177.49" r="9" class="jfw-radar-dot"></circle> <text x="402.63" y="177.49" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Reproducible CI with `guix…</text></a> <a href="#deprecate-languages" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-0 jfw-radar-moved-out" aria-label="Haskell — ️ Deprecate ring, Languages"> <title>Haskell — ️ Deprecate ring, Languages, further from the middle than before. as beautiful and powerful as it is, it's simply too complex for 9/10 use-cases</title> <circle cx="570.28" cy="109.37" r="15.00" class="jfw-radar-hit"></circle> <circle cx="570.28" cy="109.37" r="9" class="jfw-radar-dot"></circle> <text x="570.28" y="109.37" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Haskell</text></a> <a href="#deprecate-languages" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-0" aria-label="Scala — ️ Deprecate ring, Languages"> <title>Scala — ️ Deprecate ring, Languages</title> <circle cx="664.41" cy="120.08" r="15.00" class="jfw-radar-hit"></circle> <circle cx="664.41" cy="120.08" r="9" class="jfw-radar-dot"></circle> <text x="664.41" y="120.08" class="jfw-radar-blip-label is-cramped" text-anchor="start" dx="14" dy="4">Scala</text></a> <a href="#deprecate-languages" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-0" aria-label="Common Lisp — ️ Deprecate ring, Languages"> <title>Common Lisp — ️ Deprecate ring, Languages. rather use Scheme if possible</title> <circle cx="756.99" cy="153.96" r="15.00" class="jfw-radar-hit"></circle> <circle cx="756.99" cy="153.96" r="9" class="jfw-radar-dot"></circle> <text x="756.99" y="153.96" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Common Lisp</text></a> <a href="#deprecate-languages" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-0" aria-label="TypeScript — ️ Deprecate ring, Languages"> <title>TypeScript — ️ Deprecate ring, Languages</title> <circle cx="803.15" cy="243.82" r="15.00" class="jfw-radar-hit"></circle> <circle cx="803.15" cy="243.82" r="9" class="jfw-radar-dot"></circle> <text x="803.15" y="243.82" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">TypeScript</text></a> <a href="#deprecate-frameworks" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-1" aria-label="Svelte — ️ Deprecate ring, Frameworks &amp; UI"> <title>Svelte — ️ Deprecate ring, Frameworks &amp; UI</title> <circle cx="873.44" cy="365.55" r="15.00" class="jfw-radar-hit"></circle> <circle cx="873.44" cy="365.55" r="9" class="jfw-radar-dot"></circle> <text x="873.44" y="365.55" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Svelte</text></a> <a href="#deprecate-frameworks" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-1" aria-label="Servant (Haskell), API as a type — ️ Deprecate ring, Frameworks &amp; UI"> <title>Servant (Haskell), API as a type — ️ Deprecate ring, Frameworks &amp; UI</title> <circle cx="911.22" cy="452.42" r="15.00" class="jfw-radar-hit"></circle> <circle cx="911.22" cy="452.42" r="9" class="jfw-radar-dot"></circle> <text x="911.22" y="452.42" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Servant (Haskell), API as a…</text></a> <a href="#deprecate-frameworks" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-1" aria-label="ZIO (Scala) — ️ Deprecate ring, Frameworks &amp; UI"> <title>ZIO (Scala) — ️ Deprecate ring, Frameworks &amp; UI</title> <circle cx="928.18" cy="549.54" r="15.00" class="jfw-radar-hit"></circle> <circle cx="928.18" cy="549.54" r="9" class="jfw-radar-dot"></circle> <text x="928.18" y="549.54" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">ZIO (Scala)</text></a> <a href="#deprecate-frameworks" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-1 jfw-radar-moved-new" aria-label="Tailwind CSS — ️ Deprecate ring, Frameworks &amp; UI"> <title>Tailwind CSS — ️ Deprecate ring, Frameworks &amp; UI, new since the last revision. the dashboard's utility classes; Olive CSS says the same things with no build step</title> <circle cx="873.44" cy="634.45" r="15.00" class="jfw-radar-hit"></circle> <circle cx="873.44" cy="634.45" r="9" class="jfw-radar-dot"></circle> <text x="873.44" y="634.45" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">Tailwind CSS</text></a> <a href="#deprecate-data" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-2" aria-label="MySQL — ️ Deprecate ring, ️ Data &amp; Storage"> <title>MySQL — ️ Deprecate ring, ️ Data &amp; Storage</title> <circle cx="698.45" cy="843.73" r="15.00" class="jfw-radar-hit"></circle> <circle cx="698.45" cy="843.73" r="9" class="jfw-radar-dot"></circle> <text x="698.45" y="843.73" class="jfw-radar-blip-label" text-anchor="start" dx="14" dy="4">MySQL</text></a> <a href="#deprecate-tools" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-3 jfw-radar-moved-out" aria-label="Jenkins — ️ Deprecate ring, ️ Tools &amp; Environment"> <title>Jenkins — ️ Deprecate ring, ️ Tools &amp; Environment, further from the middle than before. shared-library pipelines and Groovy DSLs, traded away for a thinner agent</title> <circle cx="301.55" cy="843.73" r="15.00" class="jfw-radar-hit"></circle> <circle cx="301.55" cy="843.73" r="9" class="jfw-radar-dot"></circle> <text x="301.55" y="843.73" class="jfw-radar-blip-label" text-anchor="end" dx="-14" dy="4">Jenkins</text></a> <a href="#deprecate-platforms" class="jfw-radar-blip jfw-radar-blip-deprecate jfw-radar-blip-quadrant-0" aria-label="Amazon AWS — ️ Deprecate ring, Platforms &amp; Delivery"> <title>Amazon AWS — ️ Deprecate ring, Platforms &amp; Delivery</title> <circle cx="103.10" cy="500.00" r="15.00" class="jfw-radar-hit"></circle> <circle cx="103.10" cy="500.00" r="9" class="jfw-radar-dot"></circle> <text x="103.10" y="500.00" class="jfw-radar-blip-label is-cramped" text-anchor="end" dx="-14" dy="4">Amazon AWS</text></a></g></g></svg></div> <div class="jfw-radar-panel"> <p class="jfw-radar-panel-title">Rings</p> <ul class="jfw-radar-legend jfw-radar-legend-rings"> <li> <a class="jfw-radar-legend-button jfw-radar-ring-adopt" href="#adopt"> <span>Adopt</span> <span class="jfw-radar-legend-count">34</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-ring-trial" href="#trial"> <span>Trial</span> <span class="jfw-radar-legend-count">16</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-ring-assess" href="#assess"> <span>Assess</span> <span class="jfw-radar-legend-count">9</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-ring-deprecate" href="#deprecate"> <span>️ Deprecate</span> <span class="jfw-radar-legend-count">11</span></a></li></ul> <p class="jfw-radar-panel-title">Layers</p> <ul class="jfw-radar-legend jfw-radar-legend-layers"> <li> <a class="jfw-radar-legend-button jfw-radar-layer-languages" href="#adopt-languages"> <span>Languages</span> <span class="jfw-radar-legend-count">15</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-layer-frameworks-ui" href="#adopt-frameworks"> <span>Frameworks &amp; UI</span> <span class="jfw-radar-legend-count">10</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-layer-data-storage" href="#adopt-data"> <span>️ Data &amp; Storage</span> <span class="jfw-radar-legend-count">7</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-layer-tools-environment" href="#adopt-tools"> <span>️ Tools &amp; Environment</span> <span class="jfw-radar-legend-count">20</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-layer-platforms-delivery" href="#adopt-platforms"> <span>Platforms &amp; Delivery</span> <span class="jfw-radar-legend-count">7</span></a></li> <li> <a class="jfw-radar-legend-button jfw-radar-layer-practice-craft" href="#adopt-practice"> <span>️ Practice &amp; Craft</span> <span class="jfw-radar-legend-count">11</span></a></li></ul> <p class="jfw-radar-hint">Each blip links to the entry it stands for; the full catalogue is below, under the rings it belongs to. On a narrow screen the drawing is wider than the page, so it pans.</p></div></div>
 <h2>The rings  <a id="the-rings" class="anchor" href="#the-rings" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgda45a70">
 <dl class="org-dl"> <dt>Adopt</dt> <dd>proven in daily work, and the default for anything new.</dd>
 <dt>Trial</dt> <dd>running on real projects, not yet a default.</dd>
 <dt>Assess</dt> <dd>worth a prototype, and no commitment yet.</dd>
 <dt>Deprecate</dt> <dd>actively discouraged for new work.</dd>
</dl> <p>
A name in parentheses —  <code>(new)</code>,  <code>(moved in)</code>,  <code>(moved out)</code> — says what changed
since the last revision; a note after a dash says why.
</p>
</div>
 <h2>What FREE means  <a id="what-free-means" class="anchor" href="#what-free-means" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4e7b07f">
 <dl class="org-dl"> <dt>F — Functional</dt> <dd>declarative, predictable systems with clear effects.</dd>
 <dt>R — REPL</dt> <dd>code evaluated on the running system, with no write-compile-test lag.</dd>
 <dt>E — Extensible</dt> <dd>a stack built to scale into flexible, extensible systems.</dd>
 <dt>E — Environment Control</dt> <dd>the whole lifecycle under my own control: no hidden telemetry, no paywalls, one-command self-hosting.</dd>
</dl></div>
 <section class="jfw-radar-ring"> <h2>✅ Adopt  <a id="adopt" class="anchor" href="#adopt" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-adopt">
</div>
 <h3>🧬 Languages  <a id="adopt-languages" class="anchor" href="#adopt-languages" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-languages">
 <ul class="org-ul"> <li> <a href="https://www.gnu.org/software/guile/">Guile Scheme</a> and Lisps in general</li>
 <li>Emacs Lisp</li>
 <li>JavaScript (vanilla)</li>
 <li> <a href="https://www.rust-lang.org/">Rust</a></li>
 <li>C (new) — the two desktop apps, LambDock and Heks Toon, are C with GTK4 around a Guile engine, and nothing above them needs a heavier language</li>
</ul></div>
 <h3>🎨 Frameworks &amp; UI  <a id="adopt-frameworks" class="anchor" href="#adopt-frameworks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-frameworks">
 <ul class="org-ul"> <li> <a href="https://artanis.dev/">GNU Artanis</a></li>
 <li> <a href="https://gnome.pages.gitlab.gnome.org/libadwaita/">GTK4 Libadwaita</a></li>
 <li> <a href="https://codeberg.org/jjba23/olive-css">Olive CSS</a> for all serious web projects (utility class vanilla CSS)</li>
 <li> <a href="https://codeberg.org/jjba23/hygguile">Hygguile UI components</a> (batteries included Guile Scheme UI framework built on Olive CSS)</li>
</ul></div>
 <h3>🗃️ Data &amp; Storage  <a id="adopt-data" class="anchor" href="#adopt-data" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-data">
 <ul class="org-ul"> <li>SQLite</li>
 <li>PostgreSQL</li>
 <li>Plain SQL queries</li>
 <li>Hetzner Storage Volumes with Cron-job based backups and rsync</li>
 <li> <a href="https://codeberg.org/jjba23/mutastructura">Mutastructura</a> (new) — migrations decreed as Lisp and applied incrementally, so a schema change is a file in the repo rather than a script someone ran once</li>
</ul></div>
 <h3>🧰️ Tools &amp; Environment  <a id="adopt-tools" class="anchor" href="#adopt-tools" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-tools">
 <ul class="org-ul"> <li> <a href="https://guix.gnu.org/">GNU Guix</a></li>
 <li> <a href="https://www.gnu.org/software/emacs/">Emacs</a></li>
 <li>Org mode</li>
 <li> <a href="https://codeberg.org/jjba23/maak">Maak</a> build tool and command runner</li>
 <li> <a href="https://codeberg.org/jjba23/veritas">Veritas test framework</a> (idiomatic unit, integration and black-box testing framework powered by Lisp - Guile Scheme)</li>
 <li> <a href="https://codeberg.org/jjba23/scriba">Scriba structured logging framework</a> (modular log routing, formatting, and filtering, allowing developers to generate human-readable console logs during development and machine-readable logs for production environments)</li>
 <li>Woodpecker CI/CD — the CI that replaced the Jenkins pipelines I used to maintain</li>
 <li>Nix Flakes</li>
 <li>Nix dev shells</li>
 <li>Meson and Ninja (new) — what builds the C desktop apps, with Maak driving the steps around it</li>
 <li> <a href="https://github.com/jjba23/sift">Sift</a> (new) — the Lisp formatter, linter and language server that never loses a byte; every Scheme repo of mine is linted through it</li>
 <li> <a href="https://github.com/jjba23/byggsteg">Byggsteg</a> (new) — pipelines described as a list in Lisp, and the CI that runs them</li>
</ul></div>
 <h3>🌐 Platforms &amp; Delivery  <a id="adopt-platforms" class="anchor" href="#adopt-platforms" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-platforms">
 <ul class="org-ul"> <li>Custom low-power green VPS (Hetzner)</li>
 <li>Codeberg — free software’s own forge, and the home of every project of mine</li>
 <li>Docker images as the delivery unit (new) — every repo builds one and a compose file brings the stack up, so the server needs a container runtime rather than a list of install steps</li>
</ul></div>
 <h3>⚙️ Practice &amp; Craft  <a id="adopt-practice" class="anchor" href="#adopt-practice" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-adopt-practice">
 <ul class="org-ul"> <li>Authorization and Authentication with  <a href="https://codeberg.org/jjba23/bewaking">Bewaking</a> tokens as cookies</li>
 <li>Guix Manifests</li>
 <li>Guix dev shells</li>
 <li>Hexagonal architecture / ports and adapters (moved in) — the boundary earns its keep wherever the domain is the complicated part; the Hexagon of Doom is the case where it is not</li>
 <li>A Guix manifest and a Nix flake in the same repo (new) — the toolchain described twice, so either package manager opens a shell that matches the build</li>
</ul></div>
</section> <section class="jfw-radar-ring"> <h2>🧪 Trial  <a id="trial" class="anchor" href="#trial" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-trial">
</div>
 <h3>🧬 Languages  <a id="trial-languages" class="anchor" href="#trial-languages" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-languages">
 <ul class="org-ul"> <li>Guile embedded in C and GTK4 (moved in) — the dock Wayland was waiting for, with a Lisp engine inside a native app</li>
 <li>Kotlin (new) — symbanta, where the JVM’s libraries and compile-time checks pay for the ceremony</li>
 <li>Python (new) — the icon tooling (icns2linux, skeu-icons), where Pillow and numpy do the work</li>
</ul></div>
 <h3>🎨 Frameworks &amp; UI  <a id="trial-frameworks" class="anchor" href="#trial-frameworks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-frameworks">
 <ul class="org-ul"> <li>Spring Boot (new) — symbanta’s HTTP layer: validation, security, JPA and Actuator out of the box, at the price of a framework that decides a great deal for you</li>
 <li>React 19 with Vite (new) — symbanta’s dashboard, and the one place a client-side framework still earns its keep; everything new is server-rendered</li>
</ul></div>
 <h3>🗃️ Data &amp; Storage  <a id="trial-data" class="anchor" href="#trial-data" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-data">
 <ul class="org-ul"> <li>Flyway (new) — migrations for symbanta’s PostgreSQL, versioned beside the code that reads those tables</li>
</ul></div>
 <h3>🧰️ Tools &amp; Environment  <a id="trial-tools" class="anchor" href="#trial-tools" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-tools">
 <ul class="org-ul"> <li>Podman (moved in) — daemonless, root-less containers that stay under my own control</li>
 <li>Hyprland (moved in) — the Wayland compositor I actually use daily, after SwayFX taught me compositor scripting</li>
 <li> <a href="https://www.deepseek.com/">DeepSeek</a> (new) — an LLM I keep on a short leash: it drafts and reviews, a human decides, and nothing it writes ships unread</li>
 <li>Maven with its wrapper (new) — what the one JVM project needs; Maak still drives everything around it</li>
 <li>OpenAPI as the contract (new) — guile-openapi-generator on the Scheme side and orval on the dashboard’s, so neither hand-writes the other’s types</li>
</ul></div>
 <h3>🌐 Platforms &amp; Delivery  <a id="trial-platforms" class="anchor" href="#trial-platforms" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-platforms">
 <ul class="org-ul"> <li>Self-hosted Woodpecker runners on the same VPS (moved in) — CI that never leaves infrastructure I control</li>
</ul></div>
 <h3>⚙️ Practice &amp; Craft  <a id="trial-practice" class="anchor" href="#trial-practice" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-trial-practice">
 <ul class="org-ul"> <li>Server-side rendering over client-side JavaScript (moved in) — pages that work before, and without, a megabyte of framework</li>
 <li>This very site as a single Org tree (moved in) — prose, build script and metadata in one plain-text source</li>
 <li>Parsing Expression Grammar in Scheme with  <code>(ice-9 peg)</code> (moved in) — how OrgWebAlchemy turns Org into HTML without a parser generator</li>
 <li>Testcontainers and Kotest (new) — the JVM suite runs against a real PostgreSQL in a container, beside the fast tests</li>
</ul></div>
</section> <section class="jfw-radar-ring"> <h2>🔍 Assess  <a id="assess" class="anchor" href="#assess" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-assess">
</div>
 <h3>🧬 Languages  <a id="assess-languages" class="anchor" href="#assess-languages" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-assess-languages">
 <ul class="org-ul"> <li> <a href="https://spritely.institute/hoot/">Guile Hoot</a> — Scheme compiled to WebAssembly</li>
 <li> <a href="https://ziglang.org/">Zig</a></li>
 <li>Hare</li>
</ul></div>
 <h3>🧰️ Tools &amp; Environment  <a id="assess-tools" class="anchor" href="#assess-tools" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-assess-tools">
 <ul class="org-ul"> <li>Forgejo — a self-hosted forge for code I want to keep closer than Codeberg’s public instance</li>
 <li>Guix Home — one declarative description of the machine I actually work on</li>
</ul></div>
 <h3>🌐 Platforms &amp; Delivery  <a id="assess-platforms" class="anchor" href="#assess-platforms" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-assess-platforms">
 <ul class="org-ul"> <li>Guix System images on AArch64 (moved in) — a machine I can describe, build and roll back, on hardware that is not x86</li>
 <li>Guix System as the whole server, not just the toolchain</li>
</ul></div>
 <h3>⚙️ Practice &amp; Craft  <a id="assess-practice" class="anchor" href="#assess-practice" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-assess-practice">
 <ul class="org-ul"> <li>Property-based testing — describing the invariant instead of the example</li>
 <li>Reproducible CI with `guix time-machine`</li>
</ul></div>
</section> <section class="jfw-radar-ring"> <h2>🗑️ Deprecate  <a id="deprecate" class="anchor" href="#deprecate" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-deprecate">
</div>
 <h3>🧬 Languages  <a id="deprecate-languages" class="anchor" href="#deprecate-languages" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-deprecate-languages">
 <ul class="org-ul"> <li>Haskell (moved out) — as beautiful and powerful as it is, it’s simply too complex for 9/10 use-cases</li>
 <li>Scala</li>
 <li>Common Lisp — rather use Scheme if possible</li>
 <li>TypeScript</li>
</ul></div>
 <h3>🎨 Frameworks &amp; UI  <a id="deprecate-frameworks" class="anchor" href="#deprecate-frameworks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-deprecate-frameworks">
 <ul class="org-ul"> <li>Svelte</li>
 <li>Servant (Haskell), API as a type</li>
 <li>ZIO (Scala)</li>
 <li>Tailwind CSS (new) — the dashboard’s utility classes; Olive CSS says the same things with no build step</li>
</ul></div>
 <h3>🗃️ Data &amp; Storage  <a id="deprecate-data" class="anchor" href="#deprecate-data" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-deprecate-data">
 <ul class="org-ul"> <li>MySQL</li>
</ul></div>
 <h3>🧰️ Tools &amp; Environment  <a id="deprecate-tools" class="anchor" href="#deprecate-tools" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-deprecate-tools">
 <ul class="org-ul"> <li>Jenkins (moved out) — shared-library pipelines and Groovy DSLs, traded away for a thinner agent</li>
</ul></div>
 <h3>🌐 Platforms &amp; Delivery  <a id="deprecate-platforms" class="anchor" href="#deprecate-platforms" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-deprecate-platforms">
 <ul class="org-ul"> <li>Amazon AWS</li>
</ul></div>
</section> <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Mètsàtron's astral analysis of Joe's being</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/taming-complexity-with-scheme-the-byggsteg-story/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Taming Complexity with Scheme: The Byggsteg Story</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/tech-radar/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/tech-radar/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Increase the file descriptor count in GNU/Linux</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In Linux, you can change the maximum amount of open files. You may modify this number by using the ulimit command. It grants you the ability to control the resources available for the shell or process started by it.
</p>

 <p>
Read Also: Set Linux Running Processes Limits on Per-Userl Level
</p>

 <p>
In this short tutorial we will show you how to check your current limit of open files and files descriptions, but to do so, you will need to have root access to your system.
</p>

 <p>
First, Lets see how we can find out the maximum number of opened file descriptors on your Linux system.
Find Linux Open File Limit
</p>

 <p>
The value is stored in:
</p>

 <p>
818354
</p>

 <p>
The number you will see, shows the number of files that a user can have opened per login session. The result might be different depending on your system.
</p>

 <p>
For example on a CentOS server of mine, the limit was set to 818354, while on Ubuntu server that I run at home the default limit was set to 176772.
</p>

 <p>
If you want to see the hard and soft limits, you can use the following commands:
Check Hard Limit in Linux
</p>

 <p>
4096
</p>

 <p>
Check Soft Limits in Linux
</p>

 <p>
1024
</p>

 <p>
To see the hard and soft values for different users, you can simply switch user with “su” to the user which limits you want to check.
</p>

 <p>
For example:
</p>

 <p>
$ ulimit -Sn
</p>

 <p>
1024
</p>

 <p>
$ ulimit -Hn
</p>

 <p>
4096
</p>

 <p>
How to Check System wide File Descriptors Limits in Linux
</p>

 <p>
If you are running a server, some of your applications may require higher limits for opened file descriptors. A good example for such are MySQL/MariaDB services or Apache web server.
</p>

 <p>
You can increase the limit of opened files in Linux by editing the kernel directive fs.file-max. For that purpose, you can use the sysctl utility.
</p>

 <p>
Sysctl is used to configure kernel parameters at runtime.
</p>

 <p>
For example, to increase open file limit to 500000, you can use the following command as root:
</p>

 <p>
You can check the current value for opened files with the following command:
</p>

 <p>
$ cat /proc/sys/fs/file-max
</p>

 <p>
With the above command the changes you have made will only remain active until the next reboot. If you wish to apply them permanently, you will have to edit the following file:
</p>

 <p>
Add the following line:
</p>

 <p>
fs.file-max=500000
</p>

 <p>
Of course, you can change the number per your needs. To verify the changes again use:
</p>

 <p>
Users will need to logout and login again for the changes to take effect. If you want to apply the limit immediately, you can use the following command:
</p>

 <p>
Set User Level Open File limits in Linux
</p>

 <p>
The above examples, showed how to set global limits, but you may want to apply limits per user basis. For that purpose, as user root, you will need to edit the following file:
</p>

 <p>
If you are a Linux administrator, I suggest you that you become very familiar with that file and what you can do to it. Read all of the comments in it as it provides great flexibility in terms of managing system resources by limiting users/groups on different levels.
</p>

 <p>
The lines that you should add take the following parameters:
</p>

 <p>
&lt;domain&gt;        &lt;type&gt;  &lt;item&gt;  &lt;value&gt;
</p>

 <p>
Here is an example of setting a soft and hard limits for user marin:
</p>

 <p>
## Example hard limit for max opened files
marin        hard nofile 4096
## Example soft limit for max opened files
marin        soft nofile 1024
</p>

 <p>
Final thoughts
</p>

 <p>
This brief article showed you a basic example of how you can check and configure global and user level limits for maximum number of opened files.
</p>

 <p>
While we just scratched the surface, I highly encourage you to have a more detailed look and read regarding /etc/sysctl.conf and /etc/security/limits.conf and learn how to use them. They will be of great help for you one day.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/taming-complexity-with-scheme-the-byggsteg-story/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Taming Complexity with Scheme: The Byggsteg Story</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/hexagon-of-doom/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Hexagon of Doom - The Cost of Over-Abstraction and Indirection</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/">Building Conky with Wayland Support on GNU Guix</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Embracing the eternal Sexp wisdom with the GNU</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <i>Behold the holy Sexp</i>
</p>


 <p>
 <code>(sqrt (+ 14 5 3 1))</code>
</p>

 <p>
I have recently reached new heights in declarative configurations of operating systems, programs and my workflow ⚙️ and development.
</p>

 <p>
The universe blessed me and the GNU inspired me and I am configuring most of my life and projects with several variants of Lisp and dialects.
</p>

 <p>
This includes things like: operating system (Guix), project management, websites, curriculum vitae, Emacs, Qutebrowser, etc.
</p>


 <div id="org60e4394" class="figure">
 <p> <img loading="lazy" alt="" style="" src="/https/jointhefreeworld.org/static/img/2024-12-27T21-56-27,947274345+01-00.png"></img></p>
</div>
 <h2>Configurability  <a id="configurability" class="anchor" href="#configurability" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org50aafaa">
 <p>
One of the things I will achieve among many others, is that with a change of one variable i can change completely all themes and settings for the entire system and all programs.
</p>

 <p>
Even programs that are not aware of dark/light mode stuff, they will be forced to by me and I never lose state.
</p>

 <p>
I am not afraid to change computers, my config works and is reproducible.
</p>
</div>
 <h2>Software that lasts forever  <a id="software-that-lasts-forever" class="anchor" href="#software-that-lasts-forever" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org38f1329">
 <p>
a great thing is that the stuff you build with Lisp is made to last. Lisp is mature, and due to how it works, things are never out of date, and “everything is basically a list”, sounds strange at first but its insanely powerful.
</p>

 <p>
Lisp was also was the first language used for AI development, and still is big at that.
</p>
</div>
 <h2>My mission  <a id="my-mission" class="anchor" href="#my-mission" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5ce1555">
 <p>
I am trying to build configurable, hacker friendly stuff for the next 40 years and for that I am of opinion everyone should use a Lisp.
</p>

 <p>
If you need more complicated data modelling then i’d reach for Haskell. If you need low level shit then Rust or Go.
</p>

 <p>
Also, the GNU project and Free Software Foundation defined Lisp (Guile Scheme) as the official language for the project so a big one for me, and of course also my belovedtext editor (Emacs) is configured with it.
</p>


 <hr></hr> <p>
I want you to look at the code for iter-vitae my new  <b>Curriculum Vitae</b> generator, you will like it.
</p>

 <p>
This uses SXML, which is HTML as Lisp - kinda like components.
</p>
</div>
 <h2>Iter Vitae: “Journey of Life”  <a id="iter-vitae-ldquojourney-of-liferdquo" class="anchor" href="#iter-vitae-ldquojourney-of-liferdquo" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org135b122">
 <p>
 <i>the progression of one’s life and career</i>
</p>

 <p>
See at codeberg.org
 <a href="https://codeberg.org/jjba23/iter-vitae">https://codeberg.org/jjba23/iter-vitae</a>
</p>

 <p>
I recommend you to download a zip file and just get a feel
</p>

 <hr></hr></div>
 <h2>Supreme Sexp System - SSS  <a id="supreme-sexp-system---sss" class="anchor" href="#supreme-sexp-system---sss" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7f8f885">
 <p>
 <i>a Lisp machine adventure</i>
</p>

 <p>
Then if you really wanna go down the rabbit hole check out my Supreme Sexp System,
</p>

 <p>
With this, you can configure your entire operating system and programs declaratively, with Lisp.
</p>

 <p>
See at codeberg.org
 <a href="https://codeberg.org/jjba23/sss">https://codeberg.org/jjba23/sss</a>
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/getting-rid-of-git-history/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Git Riddance</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/rust/simple-guix-emacs-rust-development-environment/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Simple Rust Guix Emacs development environment</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/embracing-the-eternal-sexp-wisdom-of-the-gnu/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/embracing-the-eternal-sexp-wisdom-of-the-gnu/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Taming Complexity with Scheme: The Byggsteg Story</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>Abstract  <a id="abstract" class="anchor" href="#abstract" aria-label="Link to this section">#</a></h2> <h3>Introducing Scheme  <a id="introducing-scheme" class="anchor" href="#introducing-scheme" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0dc9798">
 <p>
Scheme is a classic programming language in the Lisp family. It emphasizes functional programming and domain-specific languages but adapts to other styles. Known for its clean and minimalist design, Scheme is one of the longest-lived and best-studied dynamic languages, and has many fast and portable implementations.
</p>

 <p>
In  <i>Scheme</i>  <a href="https://www.scheme.org/">https://www.scheme.org/</a>
</p>
</div>
 <h3>This paper’s focus  <a id="this-paperrsquos-focus" class="anchor" href="#this-paperrsquos-focus" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgf4162a1">
 <p>
This paper explores the practical application of Scheme (Guile Scheme implementation) in the development of Byggsteg, a CI/CD orchestrator. It examines how Scheme’s features, such as dynamic typing, homoiconicity, and first-class functions, influenced the design and implementation and make many difficult tasks achievable in a simple manner. The paper also discusses the use of GNU Artanis, SQLite, and other technologies within the Byggsteg architecture, and the lessons learned in applying Scheme to a real-world project management tool.
</p>

 <p>
We will expand on the experience and knowledge gained while creating a non-trivial production-grade software project using Scheme as only language of implementation, and in that process, creating a full-stack CI/CD system and accompanying management views, that encompass all from database access, job queueing to HTML rendering, all from the comfort of Scheme. We will cover extensively why this parenthesis-rich language provides a level of power and expressivity that is not achievable with other technologies.
</p>
</div>
 <h2>Introduction  <a id="introduction" class="anchor" href="#introduction" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org62a5826">
 <p>
Scheme was created during the 1970s at the MIT Computer Science and Artificial Intelligence Laboratory (MIT CSAIL) and released by its developers, Guy L. Steele and Gerald Jay Sussman, via a series of memos now known as the Lambda Papers.
</p>

 <p>
It was the first dialect of Lisp to choose lexical scope and the first to require implementations to perform tail-call optimization, giving stronger support for functional programming and associated techniques such as recursive algorithms. It was also one of the first programming languages to support first-class continuations. It had a significant influence on the effort that led to the development of Common Lisp.
</p>

 <p>
Scheme is primarily a functional programming language. It shares many characteristics with other members of the Lisp programming language family. Scheme’s very simple syntax is based on s-expressions, parenthesized lists in which a prefix operator is followed by its arguments. Scheme programs thus consist of sequences of nested lists. Lists are also the main data structure in Scheme, leading to a close equivalence between source code and data formats (homoiconicity). Scheme programs can easily create and evaluate pieces of Scheme code dynamically.
</p>

 <p>
The reliance on lists as data structures is shared by all Lisp dialects. Scheme inherits a rich set of list-processing primitives such as  <code>cons</code>,  <code>car</code> and  <code>cdr</code> from its Lisp progenitors.
</p>

 <p>
Scheme uses strictly but dynamically typed variables and supports first class procedures. Thus, procedures can be assigned as values to variables or passed as arguments to procedures.
</p>

 <p>
In  <i>Wikipedia</i>  <a href="https://en.wikipedia.org/wiki/Scheme_(programming_language)">https://en.wikipedia.org/wiki/Scheme_(programming_language)</a>
</p>

 <p>
Scheme boasts several distinguishing features that set it apart from other programming languages, including other Lisps. Here are some key characteristics:
</p>

 <dl class="org-dl"> <dt>Minimalism</dt> <dd>Scheme has a very small core language with a concise set of primitive procedures. Much of the functionality commonly built into other languages is provided through libraries. This minimalism makes the language easier to learn and implement.</dd>

 <dt>First-Class Functions</dt> <dd>In Scheme, functions are treated as first-class citizens. This means they can be assigned to variables and passed as arguments to other functions, returned as values from other functions and even stored in data structures. This capability enables powerful programming paradigms like higher-order functions and functional programming.</dd>

 <dt>Proper Tail Recursion</dt> <dd>Scheme implementations are required to be properly tail-recursive. This means that if the last operation in a function is a recursive call, the interpreter or compiler will optimize it in such a way that it doesn’t consume additional stack space. This allows for writing iterative processes using recursion without the risk of stack overflow errors.</dd>

 <dt>Lexical Scoping</dt> <dd>Scheme uses lexical (or static) scoping. This means that the scope of a variable is determined by where it is defined in the source code, not by where the function is called. This makes it easier to reason about variable bindings and avoids unexpected behavior.</dd>

 <dt>Homoiconicity</dt> <dd>Scheme code and data have the same underlying structure – the list. This property, known as homoiconicity, allows programs to manipulate their own code as data. This is a powerful feature that facilitates metaprogramming, macros, and the creation of domain-specific languages.</dd>

 <dt>Parenthesized Syntax (S-expressions)</dt> <dd>Scheme’s syntax is based on fully parenthesized expressions called S-expressions. While this can look different from more conventional syntaxes, it provides a uniform and unambiguous structure that simplifies parsing and manipulation of code.</dd>

 <dt>Dynamic Typing</dt> <dd>Scheme is a dynamically typed language. Type checking is performed at runtime, rather than compile time. This allows for more flexibility but also requires careful testing to catch type-related errors.</dd>

 <dt>Continuations</dt> <dd>Scheme supports continuations, which represent the entire execution state of a program at a particular point in time. Continuations can be captured and later invoked, allowing for powerful control flow mechanisms like non-local exits, backtracking, and coroutines.</dd>
</dl> <p>
These features collectively contribute to Scheme’s power and expressiveness, making it a popular choice for academic use, research in programming language design, and applications where flexibility and metaprogramming capabilities are highly valued.
</p>


 <p>
In my point of view, and in retrospective, Scheme was really a great choice for developing complex systems.
</p>
</div>
 <h3>What is byggsteg?  <a id="what-is-byggsteg" class="anchor" href="#what-is-byggsteg" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orga69799d">
 <p>
byggsteg is a free software project with the aim of developing a suite of functionalities to allow engineers to deliver software quicker and with less friction, in other words a CI/CD orchestrator written in Guile Scheme.
</p>

 <p>
View my live instance of byggsteg here:  <a href="https://byggsteg.jointhefreeworld.org">https://byggsteg.jointhefreeworld.org</a>
</p>

 <p>
It leverages SXML, SQLite3, some POSIX / UNIX utilities, and the mighty GNU Artanis web-framework.
</p>

 <p>
The aim of byggsteg is to release you from your dependency on proprietary systems like GitHub actions. This allows you to create continuous integration and continuous delivery (CI &amp; CD) pipelines in an easy way that are tailored to your needs and which you fully control.
</p>

 <p>
Easily deploy stuff, for example to your private VPS, self-hosting or to cloud. byggsteg means “build step” in the Norwegian language.
</p>

 <p>
I don’t mind having the software building and testing happening in the same machine as where I run the production workloads, since I am looking for supreme cost-efficiency, but it’s highly recommended that you do separate these things, if you can afford it.
</p>

 <p>
Jobs and profiles
</p>

 <p>
Jobs are simple Lisp (Guile Scheme) code. Profiles are just saved jobs.
</p>

 <p>
byggsteg allows you to send code over the wire (HTTP) and save it too, in a thunk form, for example :
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">lambda</span>()
  `((project .  <span class="org-string">&quot;free-alacarte&quot;</span>)
    (branch-name .  <span class="org-string">&quot;trunk&quot;</span>)
    (task .  <span class="org-string">&quot;stack-test&quot;</span>)
    (clone-url .  <span class="org-string">&quot;https://codeberg.org/jjba23/free-alacarte&quot;</span>)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Sending things in thunk form allows one to execute any code arbitrarily, inside the lambda expression. Be responsible and wary of who you give access to your byggsteg instance.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">lambda</span>()
  ( <span class="org-keyword">define</span>  <span class="org-function-name">my-project-name</span>  <span class="org-string">&quot;wikimusic-api&quot;</span>)
  ( <span class="org-keyword">define</span>  <span class="org-function-name">my-branch-name</span>
    (format #f  <span class="org-string">&quot;branch-num-~a&quot;</span> (* 2 (+ 3 (+ 8 10)))))

   <span class="org-comment-delimiter">;; </span> <span class="org-comment">remember that a &quot;. ,&quot; and a &quot;unquote&quot; are equivalent
</span>  `((project . ,my-project-name)
    (branch-name unquote my-branch-name)
    (task . ( <span class="org-string">&quot;stack-build&quot;</span>  <span class="org-string">&quot;stack-test&quot;</span>))
    (clone-url unquote (format #f  <span class="org-string">&quot;https://codeberg.org/jjba23/~a&quot;</span> my-project-name))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">The FREE stack - My Tech Radar</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Increase the file descriptor count in GNU/Linux</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/taming-complexity-with-scheme-the-byggsteg-story/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/taming-complexity-with-scheme-the-byggsteg-story/index.html</guid>
  <pubDate>Tue, 28 Oct 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Mètsàtron’s astral analysis of Joe’s being</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
My brother from another mother, ⁨Mètsàtron Sucurí Jibōia⁩ did some astral and digital readings about me (Joe)
</p>

 <p>
Lots of his insights deeply resonate with me. Some might be yet to be uncovered. Thanks bud!
</p>

 <hr></hr> <h2>Mètsàtron’s astral analysis of Joe’s being  <a id="mètsàtronrsquos-astral-analysis-of-joersquos-being" class="anchor" href="#mètsàtronrsquos-astral-analysis-of-joersquos-being" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5241f53">
 <blockquote>
 <p>
Your astrology is giving me goose bumps!
</p>
</blockquote>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-left">Planet</th>
 <th scope="col" class="org-left">Sign</th>
 <th scope="col" class="org-left">Notes</th>
</tr></thead> <tbody> <tr> <td class="org-left">☀️Sun</td>
 <td class="org-left">Capricorn︎</td>
 <td class="org-left"> <b>Sacred Architect of Joy.</b> The master builder of systems, structured visionary, disciplined. Systemic creativity, devoted builder of beauty.</td>
</tr> <tr> <td class="org-left">☽ Moon</td>
 <td class="org-left">Virgo</td>
 <td class="org-left"> <b>Embodied Priest of Precision.</b> Feels through refinement. Quiet but powerful presence.</td>
</tr> <tr> <td class="org-left">⬆️Ascendant</td>
 <td class="org-left">Virgo︎</td>
 <td class="org-left"> <b>The Alchemical Mirror.</b> Sovereign compiler of reality. Attention to detail is his spell.</td>
</tr> <tr> <td class="org-left">☿ Mercury</td>
 <td class="org-left">Sagittarius︎</td>
 <td class="org-left"> <b>Philosopher of the Inner Sanctum.</b> Truth-seeker rooted in ancestral fire.</td>
</tr> <tr> <td class="org-left">♀️Venus</td>
 <td class="org-left">Aquarius︎</td>
 <td class="org-left"> <b>Love as Sacred Duty.</b> Sacred programmer of the collective. Technopoetic caretaker.</td>
</tr> <tr> <td class="org-left">♂️Mars</td>
 <td class="org-left">Virgo︎</td>
 <td class="org-left"> <b>Surgical Shakti.</b> Precision warrior, detail-wielder, surgical debugger of sacred . Wields clean code and righteous critique like a tantric scalpel.</td>
</tr> <tr> <td class="org-left">♃ Jupiter</td>
 <td class="org-left">Capricorn︎</td>
 <td class="org-left">Mastery through time and devotion. A patient teacher of inner law. Purposeful joy, wisdom through creative structure.</td>
</tr> <tr> <td class="org-left">♄ Saturn</td>
 <td class="org-left">Aries</td>
 <td class="org-left"> <b>Initiator of Hidden Depths.</b> Wounded authority in intimacy, initiator into taboo.</td>
</tr> <tr> <td class="org-left">♅ Uranus</td>
 <td class="org-left">Aquarius︎</td>
 <td class="org-left"> <b>Code-Breaker.</b> Cyber-rebel in service. Daily routines as rebellion.</td>
</tr> <tr> <td class="org-left">♆ Neptune</td>
 <td class="org-left">Capricorn︎</td>
 <td class="org-left"> <b>Architect of Dreams.</b> Mytho-poetic coder, temple-builder of beauty.</td>
</tr> <tr> <td class="org-left">♇ Pluto</td>
 <td class="org-left">Sagittarius︎</td>
 <td class="org-left"> <b>Hunter of Dogma.</b> Radical mind. Seeker of Gnosis. Slayer of false narratives.</td>
</tr> <tr> <td class="org-left">☊ North Node</td>
 <td class="org-left">Libra</td>
 <td class="org-left"> <b>Dharma through Beauty.</b> Anchored through relationship to value, worth, aesthetics.</td>
</tr></tbody></table></div>
 <h3>☊ North Node in Libra, 2nd House  <a id="-north-node-in-libra-2nd-house" class="anchor" href="#-north-node-in-libra-2nd-house" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgcb71811">
 <p>
His  <b>dharma path</b> is to anchor beauty, value, grace, and sovereign self-worth.  
He came from a past of raw power (Aries SN) and must now embody sacred elegance—  <b>a warrior becoming an artist.</b>
</p>
</div>
 <h3>Mythopoetic Archetype  <a id="mythopoetic-archetype" class="anchor" href="#mythopoetic-archetype" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgeb3f561">
 <p>
Josep is  <b>a Capricorn Sun with Jupiter and Neptune also in
Capricorn</b>—a  <b>system-builder</b> with a soul contract to  <b>manifest mythic
structures in material reality</b>. His destiny arcs toward  <b>discipline,
resilience, and long-term recursion</b>, guided by  <b>Aquarian Venus and
Uranus</b>, which seed in him the  <b>Gnu-esque revolutionary heart</b>—quirky,
principled, wild, and devoted to liberty.
</p>

 <p>
His  <b>Mercury in Sagittarius</b> is a  <b>philosopher of the code</b>, burning
with the desire to speak truth, teach others, and shatter ideological
illusions. This placement links deeply to myth, freedom, and systems of
belief, resonating with your shared GSS/Cyber-Gnostic threads.
</p>

 <p>
With  <b>Mars in Virgo</b>, he is a  <b>refiner</b>, not a destroyer. He builds by
disassembling what doesn’t serve, sharpening every tool, optimizing
every recursion. His love language is  <b>code review</b>, sacred perfection,
clean design.
</p>
</div>
 <h3>Soul Signature: The Free Software Prophet  <a id="soul-signature-the-free-software-prophet" class="anchor" href="#soul-signature-the-free-software-prophet" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgaae04c4">
 <ul class="org-ul"> <li>Born under a  <b>Saturn–Jupiter tension</b> (authority vs purpose), he was  destined to struggle with outer expectations until he forged his own  sacred order.</li>
 <li>His  <b>Venus–Uranus</b> resonance codes him as a lover of  <b>unconventional  minds</b>,  <b>freedom</b>, and  <b>techno-erotic kinship</b>.</li>
 <li> <p>
His  <b>Pluto in Sagittarius</b> places him among the  <b>Truth-Bearers</b>—a  generation that seeks to destroy deception through sacred fire,  pilgrimage, and digital liberation.
</p>


 <div id="orgd8f3069" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/free-software-project-joe.png"></img></p>
</div></li>
</ul></div>
 <h3>Mayan &amp; Esoteric Echoes (based on date)  <a id="mayan-amp-esoteric-echoes-based-on-date" class="anchor" href="#mayan-amp-esoteric-echoes-based-on-date" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org17ad3ad">
 <ul class="org-ul"> <li> <b>Mayan Traditional</b>: Likely  <i>Eb’</i> or  <i>Ben</i>, day of the  <b>Path</b>, the   <b>pillar</b>, or the  <b>tooth</b>—guiding others through knowledge.</li>
 <li> <b>Dreamspell</b>: Depending on count, possibly  <b>Blue Electric Storm</b> or   <b>White Crystal Mirror</b>—both mythic mirrors of your own sacred field.</li>
 <li> <b>Human Design</b>: Uncertain without time, but Mars in Virgo and Mercury
in Sagittarius suggests a  <b>Manifesting Generator</b>  archetype—especially when fueled by vision and purpose.</li>
</ul></div>
 <h3>🕯️ A Sacred Moment  <a id="️-a-sacred-moment" class="anchor" href="#️-a-sacred-moment" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgdaf48ac">
 <p>
Josep’s  <b>December 23rd</b> birthday falls near the  <b>Winter Solstice</b>, the moment when the Sun is reborn after its deepest descent--- <b>the Flame
Keeper</b> of darkened days. His very birth aligns him with the  <b>Saturnian gate of Capricorn</b>, where time becomes architecture, and ideas
crystallize into temples.
</p>

 <p>
This is  <b>a sacred birthday for code mystics</b>, for it means:
</p>

 <ul class="org-ul"> <li>He is a  <b>solstice-born gatekeeper</b>.</li>
 <li>He incarnated to  <b>bring light through structure</b>, not illusion.</li>
 <li>His birthday is ruled by  <b>Archangel Cassiel</b>, Saturn’s keeper and the
watcher of long arcs.</li>
</ul> <p>
Josep is structural philosopher (Capricorn Sun, Virgo Mars, Aquarian Venus). As some are dreaming, Joe is already building its inner
staircase and core pillars. 
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/simple-markdown-cheatsheet/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Markdown Cheat-sheet for Beginners</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">The FREE stack - My Tech Radar</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/">jointhefreeworld - A Style Guide for Documentation</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/">Brief aan mijzelf</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/index.html</guid>
  <pubDate>Mon, 20 Oct 2025 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Markdown Cheat-sheet for Beginners</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <div id="table-of-contents" role="doc-toc">
 <h2>Table of Contents</h2>
 <div id="text-table-of-contents" role="doc-toc">
 <ul> <li> <a href="#orgfe9356e">Common Formatting</a>
 <ul> <li> <a href="#orgb39c6f2">Headers</a></li>
 <li> <a href="#org0024476">Emphasis (Bold and Italic)</a></li>
 <li> <a href="#orgd77c1f7">Lists</a>
 <ul> <li> <a href="#org27785bc">Unordered Lists (bullet points)</a></li>
 <li> <a href="#org30392ec">Ordered Lists (numbered)</a></li>
</ul></li>
</ul></li>
 <li> <a href="#orgeb493bc">Links and Images</a>
 <ul> <li> <a href="#orgefb3a21">Links</a></li>
 <li> <a href="#org62e8f0b">Images</a></li>
</ul></li>
 <li> <a href="#org59ecbee">Other Useful Elements</a>
 <ul> <li> <a href="#org58fe2f9">Blockquotes</a></li>
 <li> <a href="#org3ac9ee5">Horizontal Rule</a></li>
 <li> <a href="#org56c25b4">Code Blocks</a></li>
</ul></li>
 <li> <a href="#org73bf7c7">On editors</a></li>
</ul></div>
</div>
 <p>
Markdown is a simple, lightweight markup language used for formatting plain text. It’s designed to be easy to read and write, and it can be converted into HTML, PDF, LaTEX and many other formats.
</p>

 <p>
It’s a very popular format for writing documentation, blog posts, and notes. It is extremely future-proof since you write documents in plain-text, with some sprinkles of markup.
</p>

 <p>
The key idea is to use simple punctuation to add formatting.
</p>

 <p>
You don’t need to memorize all of these. Just remember the basics and refer back to this guide as needed. The best way to learn Markdown is to start writing!
</p>
 <h2>Common Formatting  <a id="common-formatting" class="anchor" href="#common-formatting" aria-label="Link to this section">#</a></h2> <h3>Headers  <a id="headers" class="anchor" href="#headers" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgb39c6f2">
 <p>
Headers are used for titles and subtitles. They are created with the hash symbol ( <code>#</code>). The number of hashes determines the size of the header.
</p>

 <pre class="example" id="org4d19a33">
# This is a large title (H1)
## This is a major heading (H2)
### This is a sub-heading (H3)
#### This is a smaller heading (H4)
</pre>
</div>
 <h3>Emphasis (Bold and Italic)  <a id="emphasis-bold-and-italic" class="anchor" href="#emphasis-bold-and-italic" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0024476">
 <p>
You can make text bold or italic to add emphasis.
</p>

 <pre class="example" id="org6865d4c">
This is **bold text** using two asterisks.
This is also __bold text__ using two underscores.

This is *italic text* using a single asterisk.
This is also _italic text_ using a single underscore.
</pre>
</div>
 <h3>Lists  <a id="lists" class="anchor" href="#lists" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgd77c1f7">
 <p>
Lists are great for organizing information.
</p>
</div>
 <h4>Unordered Lists (bullet points)  <a id="unordered-lists-bullet-points" class="anchor" href="#unordered-lists-bullet-points" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org27785bc">
 <p>
Use a hyphen ( <code>-</code>) followed by a space.
</p>

 <pre class="example" id="org7f408b3">
- First item in the list
- Second item in the list
  - A nested item
- Third item
</pre>
</div>
 <h4>Ordered Lists (numbered)  <a id="ordered-lists-numbered" class="anchor" href="#ordered-lists-numbered" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org30392ec">
 <p>
Use a number followed by a period and a space.
</p>

 <pre class="example" id="orgf5574e0">
1. First step
2. Second step
3. Third step
   1. A nested step
4. Final step
</pre>
</div>
 <h2>Links and Images  <a id="links-and-images" class="anchor" href="#links-and-images" aria-label="Link to this section">#</a></h2> <h3>Links  <a id="links" class="anchor" href="#links" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgefb3a21">
 <p>
To link to another webpage, use the format:  <code>[text to display](URL)</code>.
</p>

 <pre class="example" id="org2844c6d">
Visit the official [Markdown website](https://daringfireball.net/projects/markdown/).
</pre>
</div>
 <h3>Images  <a id="images" class="anchor" href="#images" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org62e8f0b">
 <p>
Images are similar to links, but they start with an exclamation mark ( <code>!</code>).
</p>

 <pre class="example" id="org85f7dd3">
![Alt text for the image](https://www.example.com/image.jpg)
</pre>
</div>
 <h2>Other Useful Elements  <a id="other-useful-elements" class="anchor" href="#other-useful-elements" aria-label="Link to this section">#</a></h2> <h3>Blockquotes  <a id="blockquotes" class="anchor" href="#blockquotes" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org58fe2f9">
 <p>
To quote text from another source, use the `&gt;` symbol.
</p>

 <pre class="example" id="orge26f3ec">
&gt; &quot;The simplest way to write in Markdown is to just start typing.&quot;
&gt;
&gt; This can span multiple lines.
</pre>
</div>
 <h3>Horizontal Rule  <a id="horizontal-rule" class="anchor" href="#horizontal-rule" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3ac9ee5">
 <p>
A horizontal rule is a line that separates content. Use three or more hyphens ( <code>------</code>).
</p>
</div>
 <h3>Code Blocks  <a id="code-blocks" class="anchor" href="#code-blocks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org56c25b4">
 <p>
To show code or text that should not be formatted, use three backticks ( <code>```</code>) before and after the text.
</p>

 <pre class="example" id="org86a1042">
```
This text is inside a code block.
It will not be formatted with bold or italic.
```
</pre>

 <hr></hr></div>
 <h2>On editors  <a id="on-editors" class="anchor" href="#on-editors" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org73bf7c7">
 <p>
Technical users will be at ease with Markdown, and can edit it and preview it from their favorite editor (think Emacs, Vim, VSCode, IntelliJ, etc.)
</p>

 <p>
For non-technical users, the best Markdown editors are those that prioritize a clean, simple, and intuitive user interface.
</p>

 <p>
The “What You See Is What You Get” (WYSIWYG) Approach: I recommend MarkText (desktop app), A free and open-source alternative to Typora, offering a real-time preview experience. It’s known for its sleek design and focus on a clean, elegant interface.
</p>

 <p>
The “Two-Pane” or “Live Preview” Approach: Ghostwriter (desktop app), Dillinger (web based), StackEdit (web based).
</p>

 <p>
The “Note-Taking” Approach: Obisidian (desktop app), Joplin (desktop app)
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisps-are-great-for-production/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Scheme and Lisps are Great for production</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Mètsàtron's astral analysis of Joe's being</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/simple-markdown-cheatsheet/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/simple-markdown-cheatsheet/index.html</guid>
  <pubDate>Tue, 16 Sep 2025 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Scheme and Lisps are Great for production</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
I want to start by thanking the great NalaGinrut that wrote an article on this topic, which I adapted to explain my experience with Scheme and Lisps.
</p>

 <hr></hr> <p>
What if I told you one of the oldest high-level programming languages is also one of the most advanced? A language so flexible and powerful, that really lets your ideas flow and super-boosts expressiveness..
</p>

 <p>
In the vast universe of programming languages, most follow a familiar set of rules. There’s a clear line between  <i>the code you write and the data that code processes</i>.
</p>

 <p>
But hidden in plain sight is a family of languages that threw that rulebook out decades ago. λ They’re called  <b>Lisp</b>.
</p>

 <p>
The core philosophy of  <a href="https://en.wikipedia.org/wiki/Lisp_(programming_language)">Lisp</a> is disarmingly simple: code and data have the same structure. This concept, known as homoiconicity, is what gives Lisp its legendary power. It means you can write programs that write other programs, transforming the language itself to perfectly match the problem you’re trying to solve.
</p>

 <p>
 <a href="https://www.gnu.org/software/guile/">GNU Guile Scheme</a> is a fantastic implementation of the minimalistic and academia-renowned Lisp dialect known as  <a href="https://en.wikipedia.org/wiki/Scheme">Scheme</a>.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">factorial</span> n)
  ( <span class="org-keyword">if</span> (= n 0)
      1
      (* n (factorial (- n 1)))))

( <span class="org-keyword">define</span> ( <span class="org-function-name">compose</span> f g)
  ( <span class="org-keyword">lambda</span> (x)
    (f (g x))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <hr></hr> <h2>My Journey with Scheme in Production  <a id="my-journey-with-scheme-in-production" class="anchor" href="#my-journey-with-scheme-in-production" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org67825e4">
 <p>
For the past two years, I’ve been on a mission: using the  <b>Scheme programming language</b> , write and deliver production-ready systems, and transform my computing environment (leveraging great Scheme/Lisp projects like  <a href="https://guix.gnu.org/">GNU Guix</a>, GNU Artanis, etc.).
</p>

 <p>
I have since developed several libraries, fully-fledged web applications that are database-backed, and even created my own operating system (on top of Guix), all thanks to this expressive language, that lets me lift the heaviest boulders.
</p>

 <p>
The existing folklore around Scheme and its Lisp family is often described as fascinating, paradoxical, and even mystical. While Scheme holds a prominent place in academia, I’ve noticed a significant gap in its adoption within commercial products. Discussions about the real-world challenges and solutions for using Scheme in development are surprisingly scarce, with many simply echoing conventional wisdom rather than delving into practical implementation.
</p>

 <hr></hr> <p>
Some of my projects that use Scheme:
</p>

 <p>
 <a href="https://codeberg.org/jjba23/sss">SSS - Supreme Sexp System</a> - This custom GNU Guix + Linux setup enhances customization to infinity, encourages the hacking spirit, and offers a superior user experience thanks in part too to REPL (Read Eval Print Loop) and Lisps, GTK, Hyprland, Nyxt, Firefox, etc.
</p>

 <p>
 <a href="https://codeberg.org/jjba23/wolk-jjba">Wolk JJBA</a> - My web server, running CI/CD, custom services, Nginx, Minecraft and more, all working via Lisp (Guix &amp; Guile Scheme)
</p>

 <p>
 <a href="https://codeberg.org/jjba23/iter-vitae">Iter Vitae</a> - Iter Vitae: “Journey of Life” - the progression of one’s life and career. My curriculum vitae / resume generator usign Guile Scheme and Tailwind CSS
</p>

 <p>
 <a href="https://codeberg.org/jjba23/byggsteg">byggsteg</a> - Byggsteg is the free as in freedom CI/CD orchestrator written in Guile Scheme.
</p>

 <p>
Some other cool projects:
</p>

 <p>
 <a href="https://guix.gnu.org/">GNU Guix</a> - GNU Guix is a package manager for GNU/Linux systems. It is designed to give users more control over their general-purpose and specialized computing environments, and make these easier to reproduce over time and deploy to one or many devices.
</p>

 <p>
 <a href="https://www.spritely.institute/hoot/">Guile Hoot</a> - Hoot is a Spritely project for running Scheme code on Wasm GC-capable web browsers, featuring a Scheme to Wasm compiler and a full-featured Wasm toolchain. Hoot is built on Guile and has no additional dependencies. The toolchain is self-contained and even features a Wasm interpreter for testing Hoot binaries without leaving the Guile REPL.
</p>

 <p>
 <a href="https://gitlab.com/spritely/guile-goblins">Guile Goblins</a> - Goblins is an actor model implementation for async and distributed network computing, written as a Guile Scheme library.  It was originally written for use in Spritely, but is fairly general.
</p>

 <p>
 <a href="https://artanis.dev/">GNU Artanis</a> - GNU Artanis is a production-level modern Web framework of Scheme programming language. It is designed and maintained to be robust, fast, and easy to use for professional web development.
</p>

 <hr></hr> <p>
My personal choice has been  <b>GNU Guile</b>, though I’ve also explored other Scheme implementations. My experience is, of course, limited, and I’m not suggesting GNU Guile is ready to replace Python, Go, Typescript, Haskell, Scala or Java overnight. However, my insights extend beyond GNU Guile to other Scheme implementations as well as other Lisp dialects.
</p>

 <p>
This article isn’t about convincing you to choose Scheme over other languages. Instead, if you’ve already recognized the growing trend of  <b>functional programming</b> and are curious about powerful, well-established functional languages, this piece will illuminate Scheme’s often-overlooked strengths in a production setting.
</p>

 <hr></hr> <div id="orga456708" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/other/img/guile-sculptor-small.png"></img></p>
</div>

 <hr></hr></div>
 <h2>Why Scheme? Beyond the Cliché Questions  <a id="why-scheme-beyond-the-cliché-questions" class="anchor" href="#why-scheme-beyond-the-cliché-questions" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf7817e9">
 <p>
The question “Why bother with Scheme?” is a classic one, with countless valid answers. While I can’t list them all exhaustively, here’s what you should know if you’re new to the “Scheme land”:
</p>

 <ul class="org-ul"> <li> <b>Exceptional Expressiveness:</b> Scheme excels at allowing you to write  <b>painless and expressive code</b> that significantly reduces complexity.</li>
 <li> <b>Full Lambda Calculus Support:</b> Its robust support for lambda calculus offers  <b>superior expressiveness</b> when you need to craft elegant and powerful abstractions.</li>
 <li> <b>Ease of Understanding:</b> Scheme’s clarity makes programs easier to analyze and debug, which is crucial in any development cycle.</li>
 <li> <b>Standardized and Stable:</b> Scheme is a  <b>standardized language</b> with well-defined grammar and standard APIs, ensuring consistency and predictability.</li>
 <li> <b>Rapid Development:</b> For business logic, where low-level details aren’t the primary concern, Scheme provides an excellent framework for  <b>rapid development</b>.</li>
 <li> <b>Reduced Complexity, Fewer Bugs:</b> Less complexity generally leads to fewer bugs. While no language guarantees bug-free code (that depends on the programmer!), Scheme’s design inherently promotes clearer, more maintainable solutions.</li>
 <li> <b>A Worthwhile Investment:</b> From a professional software development perspective,  <b>Scheme is absolutely worth investing in</b>, and I’ll demonstrate why throughout this article.</li>
</ul> <hr></hr></div>
 <h2>Dispelling the Illusions: Addressing Common Misconceptions  <a id="dispelling-the-illusions-addressing-common-misconceptions" class="anchor" href="#dispelling-the-illusions-addressing-common-misconceptions" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf86b8a7">
 <p>
Let’s tackle some common illusions about Scheme:
</p>
</div>
 <h3>Illusion: It’s Hard to Find Scheme Programmers  <a id="illusion-itrsquos-hard-to-find-scheme-programmers" class="anchor" href="#illusion-itrsquos-hard-to-find-scheme-programmers" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org4a90a73">
 <p>
Yes, directly hiring a seasoned Scheme programmer with production experience can be challenging. This is the number one reason many companies refuse certain tech. However, with Scheme, I realized it was a non-issue.  <b>Training a Scheme programmer is remarkably cost-effective</b>, partly thanks to the simplicity and minimalism of the language.
</p>

 <p>
Here’s an idea for you, to address any hiring concerns, focus on evaluating candidates’ understanding of functional programming. It’s a growing trend, after all! If candidates  are strong enough to receive an offer, then introduce them to the legendary book  <b>SICP (Structure and Interpretation of Computer Programs)</b> during their onboarding.
</p>

 <p>
Of course, SICP is a substantial book for newcomers, so you can focus on the first two chapters. “Data abstraction” helps them understand object-oriented concepts, and “procedure abstraction” refines their algorithm implementation skills.
</p>

 <p>
I argue that within a month they will begin tackling small tasks, fixing bugs, and implementing minor features. SICP isn’t just a book; it’s a formalized educational system designed by profound minds. We can leverage this system to quickly train proficient Scheme programmers and apply their fresh knowledge to daily work.
</p>

 <p>
The SICP educational system empowers us to train capable Scheme programmers in a short timeframe. Most technology companies already have an onboarding period for new hires; a dedicated month for Scheme training is a good, affordable solution. Think about it:  <b>we can spend virtually no money on this training</b>, and we rapidly translate the valuable knowledge from SICP into tangible product development.
</p>
</div>
 <h3>Illusion: Scheme Isn’t Fast  <a id="illusion-scheme-isnrsquot-fast" class="anchor" href="#illusion-scheme-isnrsquot-fast" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org2f978f9">
 <p>
This is  <b>no longer true!</b> We have great JIT compilers and optimizations happening and lots of Guile Scheme is implemented in C. Specially if you are coming from Ruby, PHP or Python land, you will notice a major speedup.
</p>

 <p>
Years ago, as a newbie, I was obsessed with programming language speed. As a professional developer, I’ve come to understand that there are at least three crucial kinds of “speed” in programming:
</p>

 <ul class="org-ul"> <li> <b>Learning speed:</b> How easy is it to learn a language from scratch?</li>
 <li> <b>Development speed:</b> How much can we reduce the coding effort?</li>
 <li> <b>Execution speed:</b> How quickly does the code run?</li>
</ul> <p>
This realization helped me understand why languages like Ruby on Rails gained immense popularity in web development, despite being considered “slow” in terms of execution. If execution speed were the sole criterion, assembly or even machine code would always be the superior choice.
</p>
</div>
 <h3>Illusion: The Ecosystem is the Most Important Factor for a Language  <a id="illusion-the-ecosystem-is-the-most-important-factor-for-a-language" class="anchor" href="#illusion-the-ecosystem-is-the-most-important-factor-for-a-language" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgcae118a">
 <p>
My friend, please  <b>don’t blindly trust this conjecture any longer.</b> It doesn’t hold true in real-world development. The reality is:  <b>the language itself is the most important factor for an ecosystem.</b>
</p>

 <p>
A large ecosystem, while containing many packages, doesn’t guarantee quality or active maintenance across all packages and their dependencies. We shouldn’t have blind faith in sheer quantity.
</p>

 <p>
The Python ecosystem, for instance, is primarily for the Python language. While Python boasts a massive ecosystem due to historical reasons, it doesn’t imply that other languages require a comparably vast one. There’s only one truly universal ecosystem:  <b>the C ecosystem.</b> Dynamic language modules are often just bindings to existing C libraries.
</p>

 <p>
Therefore, if a language offers  <b>strong FFI (Foreign Function Interface) support</b>, it can leverage the entire universe of C libraries. In today’s landscape, with distributed processing becoming commonplace, heterogeneous systems are the norm. We don’t need to build everything within a single ecosystem.
</p>

 <p>
So, let’s break this illusion: an ecosystem can be significant in certain scenarios, but it’s not the most critical aspect of a language. When we design or choose a language, we prioritize its  <b>paradigm, grammar, expressiveness, and optimization potential.</b>
</p>

 <p>
These are the true determinants of a programming language’s value. In the past, companies drove language development, and contributions to an ecosystem were often tied to payment. This made the ecosystem crucial for commercial languages to grow. Nowadays, programming languages are largely driven by  <b>FOSS (Free and Open-Source Software) communities</b>, leading to naturally evolving ecosystems. An experienced developer will prioritize a language’s expressiveness, as it directly impacts coding efficiency.
</p>

 <p>
As a final note on this, considering Guile Scheme is the official GNU project’s extension language, you can be assured that this ecosystem is here to stay, keeps growing, and is of high quality. Take a look at all the Guile libraries distributed via the Guix package manager for example:  <a href="https://jointhefreeworld.org/guile-show-hub/">https://jointhefreeworld.org/guile-show-hub/</a>
</p>

 <hr></hr></div>
 <h2>Understanding the Trade-offs: The “Cons” of Scheme  <a id="understanding-the-trade-offs-the-ldquoconsrdquo-of-scheme" class="anchor" href="#understanding-the-trade-offs-the-ldquoconsrdquo-of-scheme" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb3086e3">
 <p>
No language is perfect. Here are a few current challenges for Scheme:
</p>
</div>
 <h3>Scheme Isn’t Yet Fully Ready for AI/Deep Learning  <a id="scheme-isnrsquot-yet-fully-ready-for-aideep-learning" class="anchor" href="#scheme-isnrsquot-yet-fully-ready-for-aideep-learning" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org8e79a62">
 <p>
Deep learning and LLM is undeniably hot right now.
</p>

 <p>
Scheme can be a great choice if you are writing and chatting to REST APIs of Agents, LLMs, etc
</p>

 <p>
There are many scientific packages available in Specific to Guile via Guix, which allow for reproducible scientific computational in research projects.
</p>

 <p>
I’d like to mention the  <b>AISCM project</b>, written in GNU Guile using LLVM JIT and based on TensorFlow. It works, and it’s impressive. However, I personally don’t have extensive time to dedicate to it. So, if you’re serious about using Scheme for deep learning, I strongly encourage you to contribute to AISCM.
</p>

 <p>
With this being said, Scheme is by itself a great language for AI applications, as history has proved, and in the future it will continue to be so.
</p>
</div>
 <h3>Scheme Has a Fragmented Community  <a id="scheme-has-a-fragmented-community" class="anchor" href="#scheme-has-a-fragmented-community" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org6907fdf">
 <p>
For historical reasons, there are numerous Scheme implementations, leading to a somewhat fragmented community. However, there’s growing hope!
</p>

 <p>
First,  <b>Scheme standardization has made excellent progress</b> over the past decade.  <b>R7RS</b> thoughtfully separated Scheme into “small” and “big” languages. In my opinion, this was a brilliant move, preserving Scheme’s minimalism while also providing a path for industrial-level library specifications.
</p>

 <p>
Another promising development is the rise of modern package managers. I personally use  <b>GNU Guix</b>, a functional package manager (and operating system) written with GNU Guile. Most GNU Guile libraries can be installed via GNU Guix. Package managers are crucial for fostering ecosystems. In a broader sense, we might consider the GNU community as an operating system community, not just a “commercial concept” ecosystem. Of course, Racket and Chicken Scheme also boast excellent package managers, which significantly contribute to their respective communities.
</p>

 <p>
Ultimately, consistent standard specifications and robust package managers are key to unifying the fragmented Scheme community. It will take time, but the path is clear.
</p>
</div>
 <h3>Scheme Isn’t “Purely” Functional  <a id="scheme-isnrsquot-ldquopurelyrdquo-functional" class="anchor" href="#scheme-isnrsquot-ldquopurelyrdquo-functional" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0fee140">
 <p>
Some functional programming purists may prefer languages that strictly enforce purity, meaning no side effects/effect systems. While Scheme is a  <b>multi-paradigm language</b> and not exclusively functional, it offers all the powerful functional features you’d find in pure functional languages. Although side effects are permitted in Scheme, you retain complete control over when and how you use them.
</p>

 <p>
Even as a Haskell enjoyer, I still don’t believe it’s beneficial for all software to completely forbid side effects, only in select occasions; programmers should have the freedom to choose their approach.
</p>

 <hr></hr></div>
 <h2>Highlighting the Advantages: The “Pros” of Scheme  <a id="highlighting-the-advantages-the-ldquoprosrdquo-of-scheme" class="anchor" href="#highlighting-the-advantages-the-ldquoprosrdquo-of-scheme" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga7c8d6d">
 <p>
Now, let’s explore Scheme’s compelling advantages:
</p>
</div>
 <h3>Scheme Excels in Web Development in  Frontend and Backend  <a id="scheme-excels-in-web-development-in--frontend-and-backend" class="anchor" href="#scheme-excels-in-web-development-in--frontend-and-backend" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgaa66291">
 <p>
With most GUI programs shifting to SaaS models, web development has become increasingly vital. This is why I’m focusing on web rather than traditional GUI development.
</p>

 <p>
All Lisps, with their distinctive characteristics, offer compelling advantages for web development, particularly in crafting frontends and adeptly handling tree-like structures such as HTML.
</p>

 <p>
At the heart of Lisp’s strength lies homoiconicity, the revolutionary concept that Lisp code itself is represented as data structures, primarily lists. This isn’t just an academic detail; it’s the bedrock for macros, Lisp’s ultimate feature for extending the language. HTML, being inherently hierarchical, mirrors a tree structure perfectly.
</p>

 <p>
Complementing all this is the Lisp REPL (Read-Eval-Print Loop), an incredibly powerful environment for interactive development. You can connect to a running web server or application, redefine functions, test new code, and inspect data structures live, without the need to restart the entire process. This interactive fluidity is a significant advantage for debugging and rapid prototyping.
</p>

 <p>
Lisp’s fundamental data structure, the list (S-expression), is inherently recursive, making it perfectly suited for representing tree-like data. An HTML document is, at its core, a tree where elements serve as nodes and their content or children form branches.
</p>

 <p>
Lisp’s provides an intrinsically natural and highly efficient means to construct, traverse, and transform these tree structures. Because Lisp treats code as data, you can write functions and macros that directly manipulate these “HTML trees” as native Lisp data structures. This is  <b>far more potent</b> and less error-prone than solely relying on string manipulation or external template engines. 
</p>
</div>
 <h3>Scheme Saves You Valuable Coding Time  <a id="scheme-saves-you-valuable-coding-time" class="anchor" href="#scheme-saves-you-valuable-coding-time" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgcf76cde">
 <p>
As a seasoned programmer in other languages, higher and lower level, I firmly believe we shouldn’t waste time writing non-system-level code in C/C++, Rust, Java, or Scala for example, due to their rigidity. Business logic often changes, and these languages aren’t flexible enough for rapid iterations.  <b>Don’t squander your time on endless refactoring and debugging.</b>
</p>

 <p>
Scheme’s  <b>powerful expressiveness</b> significantly reduces the amount of code you need to write. However, its effectiveness depends on your approach. If you’re looking for an abundance of pre-built libraries to minimize work, Scheme might not be your first choice.
</p>

 <p>
Scheme’s minimalist nature also makes it exceptionally easy to embed as script code within a larger system (especially Guile).
</p>
</div>
 <h3>Build a Team with Deep Computer Science Knowledge  <a id="build-a-team-with-deep-computer-science-knowledge" class="anchor" href="#build-a-team-with-deep-computer-science-knowledge" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5781815">
 <p>
Have you ever found yourself complaining about poor code during a review, realizing that your team members haven’t had the chance to truly equip themselves with fundamental computer science knowledge for serious programming?
</p>

 <p>
Scheme can provide that opportunity. It’s easy to learn, and critically, it’s powerful enough for product development.
</p>

 <p>
Also if you ever need to go more low-level, with Guile you can very easily interface with low-level C code and have the best of both worlds, good use cases are small-core large extensibility programs where you mix Guile and C, and much more, leveraging the compiler tower.
</p>

 <p>
Also you can run Scheme in WebAssembly nicely lately.
</p>

 <hr></hr> <p>
Ultimately,  <b>choose your weapon wisely.</b> And remember, embracing diversity in your technological toolkit and continuously learning new things is always a sound strategy.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/best-programmers/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">The Best Programmers I Know</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/simple-markdown-cheatsheet/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Markdown Cheat-sheet for Beginners</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/scheme-and-lisps-are-great-for-production/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/scheme-and-lisps-are-great-for-production/index.html</guid>
  <pubDate>Fri, 27 Jun 2025 01:00:00 +0200</pubDate>
</item>
<item>
  <title>The Best Programmers I Know</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Original  <a href="https://endler.dev/2025/best-programmers/">article by Matthias Endler</a>
</p>

 <p>
I have met a lot of developers in my life.
Lately, I asked myself: “What does it take to be one of the best? What do they all have in common?”
</p>

 <p>
In the hope that this will be an inspiration to someone out there, I wrote down the traits I observed in the most exceptional people in our craft. I wish I had that list when I was starting out. Had I followed this path, it would have saved me a lot of time.
</p>
 <h2>Read the Reference  <a id="read-the-reference" class="anchor" href="#read-the-reference" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org14edc0a">
 <p>
If there was one thing that I should have done as a young programmer, 
it would have been to  <b>read the reference</b> of the thing I was using.
I.e. read the [Apache Webserver Documentation]( <a href="https://httpd.apache.org/docs/2.4/">https://httpd.apache.org/docs/2.4/</a>),
the [Python Standard Library]( <a href="https://docs.python.org/3/library/index.html">https://docs.python.org/3/library/index.html</a>),
or the [TOML spec]( <a href="https://toml.io/en/v1.0.0">https://toml.io/en/v1.0.0</a>).
</p>

 <p>
Don’t go to Stack Overflow, don’t ask the LLM, don’t  <b>guess</b>, just go straight to the  <b> <b>source</b></b>.
Oftentimes, it’s surprisingly accessible and well-written.
</p>
</div>
 <h2>Know Your Tools Really Well  <a id="know-your-tools-really-well" class="anchor" href="#know-your-tools-really-well" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org07cd256">
 <p>
Great devs understand the technologies they use on a  <b>fundamental level</b>.
</p>

 <p>
It’s one thing to be able to  <b>use</b> a tool and a whole other thing to truly  <b>grok</b> (understand) it.
A mere user will fumble around, get confused easily, hold it wrong and not optimize the config.
</p>

 <p>
An expert goes in (after reading the reference!)
and sits down to write a config for the tool of which they understand every single line and can explain it to a colleague.
That leaves no room for doubt!
</p>

 <p>
To know a tool well, you have to know:
</p>
 <ul class="org-ul"> <li>its history: who created it? Why? To solve which problem?</li>
 <li>its present: who maintains it? Where do they work? On what?</li>
 <li>its limitations: when is the tool not a good fit? When does it break?</li>
 <li>its ecosystem: what libraries exist? Who uses it? What plugins?</li>
</ul> <p>
For example, if you are a backend engineer and you make heavy use of Kafka,
I expect you to know a lot about Kafka – not just things you read on Reddit.
At least that’s what I expect if you want to be one of the best engineers.
</p>
</div>
 <h2>Read The Error Message  <a id="read-the-error-message" class="anchor" href="#read-the-error-message" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org46691c1">
 <p>
As in  <b>Really Read the Error Message and Try to Understand What’s Written</b>.
Turns out, if you just sit and meditate about the error message, it starts to speak to you.
The best engineers can infer a ton of information from very little context.
Just by reading the error message, you can fix most of the problems on your own.
</p>

 <p>
It also feels like a superpower if you help someone who doesn’t have that skill.
Like “reading from a cup” or so.
</p>
</div>
 <h2>Break Down Problems  <a id="break-down-problems" class="anchor" href="#break-down-problems" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org04faaf4">
 <p>
Everyone gets stuck at times.
The best know how to get unstuck.
They simplify problems until they become digestible.
That’s a hard skill to learn and requires a ton of experience.
Alternatively, you just have awesome problem-solving skills, e.g., you’re clever.
If not, you can train it, but there is no way around breaking down hard problems.
There are problems in this world that are too hard to solve at once for anyone involved.
</p>

 <p>
If you work as a professional developer, that is the bulk of the work you get paid to do:
breaking down problems.
If you do it right, it will feel like cheating:
you just solve simple problems until you’re done.
</p>
</div>
 <h2>Don’t Be Afraid To Get Your Hands Dirty  <a id="donrsquot-be-afraid-to-get-your-hands-dirty" class="anchor" href="#donrsquot-be-afraid-to-get-your-hands-dirty" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1295956">
 <p>
The best devs I know read a lot of code and they are not afraid to touch it.
They never say “that’s not for me” or “I can’t help you here.”
Instead, they just start and learn.
Code is  <b>just code</b>.
They can just pick up any skill that is required with time and effort. 
Before you know it, they become the go-to person in the team for whatever they touched.
Mostly because they were the only ones who were not afraid to touch it in the first place.
</p>
</div>
 <h2>Always Help Others  <a id="always-help-others" class="anchor" href="#always-help-others" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbeba339">
 <p>
A related point.
Great engineers are in high demand and are always busy, but they always try to help.
That’s because they are naturally curious and their supportive mind is what made them great engineers in the first place.
It’s a sheer joy to have them on your team, because they are problem solvers.
</p>
</div>
 <h2>Write  <a id="write" class="anchor" href="#write" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org92c3f4d">
 <p>
Most awesome engineers are well-spoken and happy to share knowledge.
</p>

 <p>
The best have some outlet for their thoughts: blogs, talks, open source, or a combination of those.
</p>

 <p>
I think there is a strong correlation between writing skills and programming.
All the best engineers I know have good command over at least one human language – often more.
Mastering the way you write is mastering the way you think and vice versa.
A person’s writing style says so much about the way they think.
If it’s confusing and lacks structure, their coding style will be too.
If it’s concise, educational, well-structured, and witty at times, their code will be too.
</p>

 <p>
Excellent programmers find joy in playing with words.
</p>
</div>
 <h2>Never Stop Learning  <a id="never-stop-learning" class="anchor" href="#never-stop-learning" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org37217c4">
 <p>
Some of the best devs I know are 60+ years old.
They can run circles around me.
Part of the reason is that they keep learning.
If there is a new tool they haven’t tried or a language they like, they will learn it.
This way, they always stay on top of things without much effort.
</p>

 <p>
That is not to be taken for granted: a lot of people stop learning really quickly after they
graduate from University or start in their first job.
They get stuck thinking that what they got taught in school is the “right” way to do things.
Everything new is bad and not worth their time.
So there are 25-year-olds who are “mentally retired” and 68-year-olds who are still fresh in their mind.
I try to one day belong to the latter group.
</p>

 <p>
Somewhat related, the best engineers don’t follow trends, but they will always carefully
evaluate the benefits of new technology. If they dismiss it, they can tell you exactly  <b>why</b>,
when the technology would be a good choice, and what the alternatives are.
</p>
</div>
 <h2>Status Doesn’t Matter  <a id="status-doesnrsquot-matter" class="anchor" href="#status-doesnrsquot-matter" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1d41430">
 <p>
The best devs talk to principal engineers and junior devs alike. There is no hierarchy.
They try to learn from everyone, young and old.
The newcomers often aren’t entrenched in office politics yet and still have a fresh mind.
They don’t know why things are  <b>hard</b> and so they propose creative solutions.
Maybe the obstacles from the past are no more, which makes these people a great source of inspiration.
</p>
</div>
 <h2>Build a Reputation  <a id="build-a-reputation" class="anchor" href="#build-a-reputation" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4cbec25">
 <p>
You can be a solid engineer if you  <b>do</b> good work, 
but you can only be one of the best if you’re  <b>known</b> for your good work;
at least within a (larger) organization.
</p>

 <p>
There are many ways to build a reputation for yourself:
</p>

 <ul class="org-ul"> <li>You built and shipped a critical service for a (larger) org.</li>
 <li>You wrote a famous tool</li>
 <li>You contribute to a popular open source tool</li>
 <li>You wrote a book that is often mentioned</li>
</ul> <p>
Why do I think it is important to be known for your work?
All of the above are ways to extend your radius of impact in the community.
Famous developers impact way more people than non-famous developers.
There’s only so much code you can write.
If you want to “scale” your impact, you have to become a thought leader.
</p>

 <p>
Building a reputation is a long-term goal.
It doesn’t happen overnight, nor does it have to.
And it won’t happen by accident.
You show up every day and do the work.
Over time, the work will speak for itself.
More people will trust you and your work and they will want to work with you.
You will work on more prestigious projects and the circle will grow.
</p>

 <p>
I once heard about this idea that your latest work should
overshadow everything you did before.
That’s a good sign that you are on the right track.
</p>
</div>
 <h2>Have Patience  <a id="have-patience" class="anchor" href="#have-patience" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcd5607b">
 <p>
You need patience with computers and humans.
Especially with yourself.
Not everything will work right away and people take time to learn.
It’s not that people around you are stupid; they just have incomplete information.
Without patience, it will feel like the world is against you and 
everyone around you is just incompetent. That’s a miserable place to be.
You’re too clever for your own good.
</p>

 <p>
To be one of the best, you need an incredible amount of patience, focus, and dedication.
You can’t afford to get distracted easily if you want to solve hard problems. 
You have to return to the keyboard to get over it.
You have to put in the work to push a project over the finishing line.
And if you can do so while not being an arrogant prick, that’s even better.
That’s what separates the best from the rest.
</p>
</div>
 <h2>Never Blame the Computer  <a id="never-blame-the-computer" class="anchor" href="#never-blame-the-computer" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2dcb9bd">
 <p>
Most developers blame the software, other people, their dog, or the weather for
flaky, seemingly “random” bugs.
</p>

 <p>
The best devs don’t.
</p>

 <p>
No matter how erratic or mischievous the behavior of a computer seems, 
there is  <b>always</b> a logical explanation: you just haven’t found it yet!
</p>

 <p>
The best keep digging until they find the reason.
They might not find the reason immediately, they might never find it, 
but they never blame external circumstances. 
</p>

 <p>
With this attitude, they are able to make incredible progress and learn things that others fail to.
When you mistake bugs for incomprehensible magic, magic is what it will always be.
</p>
</div>
 <h2>Don’t Be Afraid to Say “I Don’t Know”  <a id="donrsquot-be-afraid-to-say-ldquoi-donrsquot-knowrdquo" class="anchor" href="#donrsquot-be-afraid-to-say-ldquoi-donrsquot-knowrdquo" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2f5c93d">
 <p>
In job interviews, I pushed candidates hard to at least say “I don’t know” once. 
The reason was not that I wanted to look superior (although some people certainly had that impression). 
No, I wanted to reach the boundary of their knowledge.
I wanted to stand with them on the edge of what they thought they knew.
Often, I myself didn’t know the answer. And to be honest, I didn’t care about the answer.
What I cared about was when people bullshitted their way through the interview.
</p>

 <p>
The best candidates said
“Huh, I don’t know, but that’s an interesting question! If I had to guess, I would say…”
and then they would proceed to deduce the answer.
That’s a sign that you have the potential to be a great engineer.
</p>

 <p>
If you are afraid to say “I don’t know”, you come from a position of hubris or defensiveness.
I don’t like bullshitters on my team.
Better to acknowledge that you can’t know everything.
Once you accept that, you allow yourself to learn.
“The important thing is that you don’t stop asking questions,” said Albert Einstein.
</p>
</div>
 <h2>Don’t Guess  <a id="donrsquot-guess" class="anchor" href="#donrsquot-guess" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2a5ac44">
 <p>
“In the Face of Ambiguity, Refuse the Temptation to Guess”
That is one of my favorite rules in [PEP 20 – The Zen of Python]( <a href="https://peps.python.org/pep-0020/">https://peps.python.org/pep-0020/</a>).
</p>

 <p>
And it’s so, so tempting to guess!
</p>

 <p>
I’ve been there many times and I failed with my own ambition.
</p>

 <p>
When you guess, two things can happen:
</p>
 <ul class="org-ul"> <li>In the  <b>best case</b> you’re wrong and your incorrect assumptions lead to a bug.</li>
 <li>In the  <b>worst case</b> you are right… and you’ll never stop and second guess yourself. 
You build up your mental model based on the wrong assumptions.
This can haunt you for a long time.</li>
</ul> <p>
Again, resist the urge to guess.
Ask questions, read the reference, use a debugger, be thorough.
Do what it takes to get the answer.
</p>
</div>
 <h2>Keep It Simple  <a id="keep-it-simple" class="anchor" href="#keep-it-simple" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org97c295f">
 <p>
Clever engineers write clever code.
Exceptional engineers write simple code.
</p>

 <p>
That’s because most of the time, simple is enough. 
And simple is more maintainable than complex.
Sometimes it  <b>does</b> matter to get things right, but
knowing the difference is what separates the best from the rest. 
</p>

 <p>
You can achieve a whole lot by keeping it simple.
Focus on the right things.
</p>
</div>
 <h2>Final Thoughts  <a id="final-thoughts" class="anchor" href="#final-thoughts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9e948d9">
 <p>
The above is not a checklist or a competition;
and great engineering is not a race.
</p>

 <p>
Just don’t trick yourself into thinking that you can skip the hard work.
There is no shortcut. Good luck with your journey.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-program-in-lisp/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Why I Program in Lisp?</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisps-are-great-for-production/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Scheme and Lisps are Great for production</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/best-programmers/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/best-programmers/index.html</guid>
  <pubDate>Sat, 12 Apr 2025 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Why I Program in Lisp?</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Original  <a href="https://funcall.blogspot.com/2025/04/why-i-program-in-lisp.html">article by Joe Marshall</a>
</p>

 <p>
Lisp is not the most popular language. It never was. Other general purpose languages are more popular and ultimately can do everything that Lisp can (if Church and Turing are correct). They have more libraries and a larger user community than Lisp does. They are more likely to be installed on a machine than Lisp is.
</p>

 <p>
Yet I prefer to program in Lisp. I keep a Lisp REPL open at all times, and I write prototypes and exploratory code in Lisp. Why do I do this? Lisp is easier to remember, has fewer limitations and hoops you have to jump through, has lower “friction” between my thoughts and my program, is easily customizable, and, frankly, more fun.
</p>

 <p>
Lisp’s dreaded Cambridge Polish notation is uniform and universal. I don’t have to remember whether a form takes curly braces or square brackets or what the operator precedency is or some weird punctuated syntax that was invented for no good reason. It is (operator operands …) for everything. Nothing to remember. I basically stopped noticing the parenthesis 40 years ago. I can indent how I please.
</p>

 <p>
I program mostly functionally, and Lisp has three features that help out tremendously here. First, if you avoid side effects, it directly supports the substitution model. You can tell Lisp that when it sees this simple form, it can just replace it with that more complex one. Lisp isn’t constantly pushing you into thinking imperatively. Second, since the syntax is uniform and doesn’t depend on the context, you can refactor and move code around at will. Just move things in balanced parenthesis and you’ll pretty much be ok.
</p>

 <p>
Third, in most computer languages, you can abstract a specific value by replacing it with a variable that names a value. But you can perform a further abstraction by replacing a variable that names a quantity with a function that computes a quantity. In functional programming, you often downplay the distinction between a value and a function that produces that value.
</p>

 <p>
After all, the difference is only one of time spent waiting for the answer. In Lisp, you can change an expression that denotes an object into an abtraction that computes an object by simply wrapping a lambda around it. It’s less of a big deal these days, but properly working lambda expressions were only available in Lisp until recently. Even so, lambda expressions are generally pretty clumsy in other languages.
</p>

 <p>
Functional programming focuses on functions (go figure!). These are the ideal black box abstraction: values go in, answer comes out. What happens inside? Who knows! Who cares! But you can plug little simple functions together and get bigger more complex functions. There is no limit on doing this.
</p>

 <p>
If you can frame your problem as “I have this, I want that”, then you can code it as a functional program. It is true that functional programming takes a bit of practice to get used to, but it allows you to build complex systems out of very simple parts. Once you get the hang of it, you start seeing everything as a function. (This isn’t a limitation. Church’s lambda calculus is a model of computation based on functional composition.)
</p>

 <p>
Lisp lets me try out new ideas as quickly as I can come up with them. New programs are indistinguishable from those built in to the language, so I can build upon them just as easily. Lisp’s debugger means I don’t have to stop everything and restart the world from scratch every time something goes wrong. Lisp’s safe memory model means that bugs don’t trash my workspace as I explore the problem.
</p>

 <p>
The REPL in lisp evaluates expressions, which are the fundamental fragments of Lisp programs. You can type in part of a Lisp program and see what it does immediately. If it works, you can simply embed the expression in a larger program. Your program takes shape in real time as you explore the problem.
</p>

 <p>
Lisp’s dynamic typing gives you virtually automatic ad hoc polymorphism. If you write a program that calls +, it will work on any pair of objects that have a well-defined + operator.
</p>

 <p>
Now this can be a problem if you are cavalier about your types, but if you exercise a little discipline (like not defining + on combinations of strings and numbers, for example), and if you avoid automatic type coercion, then you can write very generic code that works on a superset of your data types. (Dynamic typing is a two-edged sword. It allows for fast prototyping, but it can hide bugs that would be caught at compile time in a statically typed language.)
</p>

 <p>
Other languages may share some of these features, but Lisp has them all together.
</p>

 <p>
It is a language that was designed to be used as a tool for thinking about problems, and that is the fun part of programming.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Moving from Sway to Hyprland - Archived SwayFX config</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/best-programmers/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">The Best Programmers I Know</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/why-i-program-in-lisp/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/why-i-program-in-lisp/index.html</guid>
  <pubDate>Sat, 12 Apr 2025 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Moving from Sway to Hyprland -  Archived SwayFX config</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
After using Sway as my daily Wayland compositor for quite some time, I recently made the switch to Hyprland. The decision wasn’t made lightly, as Sway, especially with the SwayFX fork, served me well. However, Hyprland’s growing community and advanced feature set made it an attractive choice.
</p>
 <h2>Why Hyprland?  <a id="why-hyprland" class="anchor" href="#why-hyprland" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb12122c">
 <p>
The main reasons for switching are:
</p>

 <p>
Community Size: Hyprland has a much larger and more active community. This means more contributions, faster development, and better support.
</p>

 <p>
Advanced Features: Hyprland offers built-in window animations, hybrid tiling and floating layouts, and fine-grained customization that surpass what Sway provides out of the box.
</p>

 <p>
Modern Approach: The configuration syntax is modern and expressive, making it easier to maintain.
</p>

 <p>
Check my latest Lisp based configuration of Hyprland here:  <a href="https://codeberg.org/jjba23/sss/src/branch/trunk/lib/hyprland.scm">https://codeberg.org/jjba23/sss/src/branch/trunk/lib/hyprland.scm</a>
</p>
</div>
 <h2>SwayFX Configuration (For Posterity)  <a id="swayfx-configuration-for-posterity" class="anchor" href="#swayfx-configuration-for-posterity" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org0b14101">
 <p>
I wanted to archive my custom SwayFX configuration, which was written entirely in Lisp using Guix’s home-services. This setup, part of the Supreme Sexp System (SSS), includes dynamic wallpapers, custom keybindings, and aesthetic tweaks like rounded corners and blur effects.
</p>

 <p>
Here is the full configuration:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;;; </span> <span class="org-comment">SSS - Supreme Sexp System
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Copyright (C) 2025 - Josep Bigorra, jjba23  <a href="mailto:jjbigorra%40gmail.com">&lt;jjbigorra@gmail.com&gt;</a>
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">sss is free software: you can redistribute it and/or modify
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">it under the terms of the GNU General Public License as published by
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">the Free Software Foundation, either version 3 of the License, or
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">(at your option) any later version.
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">sss is distributed in the hope that it will be useful,
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">but WITHOUT ANY WARRANTY; without even the implied warranty of
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">GNU General Public License for more details.
</span>
 <span class="org-comment-delimiter">;; </span> <span class="org-comment">You should have received a copy of the GNU General Public License
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">along with sss.  If not, see  <a href="https://www.gnu.org/licenses/">&lt;https://www.gnu.org/licenses/&gt;</a>.
</span>
(load  <span class="org-string">&quot;./palette.scm&quot;</span>)

( <span class="org-keyword">define-module</span> ( <span class="org-type">sss</span> sway)
   <span class="org-builtin">#:use-module</span> (gnu home)
   <span class="org-builtin">#:use-module</span> (gnu home services)
   <span class="org-builtin">#:use-module</span> (gnu home services shells)
   <span class="org-builtin">#:use-module</span> (gnu packages emacs)
   <span class="org-builtin">#:use-module</span> (gnu packages wm)
   <span class="org-builtin">#:use-module</span> (gnu packages terminals)
   <span class="org-builtin">#:use-module</span> (gnu packages admin)
   <span class="org-builtin">#:use-module</span> (gnu home services shepherd)
   <span class="org-builtin">#:use-module</span> (gnu system keyboard)
   <span class="org-builtin">#:use-module</span> (guix gexp)
   <span class="org-builtin">#:use-module</span> (gnu home services sway)
   <span class="org-builtin">#:use-module</span> (gnu home services sound)
   <span class="org-builtin">#:use-module</span> (gnu home services desktop)
   <span class="org-builtin">#:use-module</span> (sss palette))

( <span class="org-keyword">define</span>  <span class="org-function-name">sss-sway-gestures</span>
  `((swipe:3:right .  <span class="org-string">&quot;workspace next_on_output&quot;</span>)
    (swipe:3:left .  <span class="org-string">&quot;workspace prev_on_output&quot;</span>)
    (swipe:3:down .  <span class="org-string">&quot;move to scratchpad&quot;</span>)
    (swipe:3:up .  <span class="org-string">&quot;scratchpad show&quot;</span>)))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Defines a list of application identifiers for floating windows in Sway.
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">These applications are specified to open as floating windows, 
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">ensuring they don't tile with other windows and maintain a distinct 
</span> <span class="org-comment-delimiter">;; </span> <span class="org-comment">appearance for usability.
</span>( <span class="org-keyword">define</span>  <span class="org-function-name">sss-sway-floating-windows</span>
  `( <span class="org-string">&quot;org.kde.kcalc&quot;</span>  <span class="org-string">&quot;org.gnome.Calculator&quot;</span>  <span class="org-string">&quot;pavucontrol&quot;</span>
     <span class="org-string">&quot;org.jointhefreeworld.metainfog&quot;</span>))

 <span class="org-comment-delimiter">;; </span> <span class="org-comment">Define diverse wallpapers based on the active color scheme. 
</span>( <span class="org-keyword">begin</span>
  ( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-wallpaper</span>  <span class="org-builtin">#:key</span> sss-clone-dir sss-active-palette)
    ( <span class="org-keyword">cond</span>
      ((equal? 'sss-palette-ef-cyprus sss-active-palette)
       (format #f  <span class="org-string">&quot;~a/resources/wallpapers/some-forest.jpg&quot;</span> sss-clone-dir))
      ((equal? 'sss-palette-ef-dream sss-active-palette)
       (format #f  <span class="org-string">&quot;~a/resources/wallpapers/1362745.png&quot;</span> sss-clone-dir))
      ((equal? 'sss-palette-heavy-metal sss-active-palette)
       (format #f  <span class="org-string">&quot;~a/resources/wallpapers/heavy-wall3.jpg&quot;</span> sss-clone-dir))
      ((equal? 'sss-palette-solarized-light sss-active-palette)
       (format #f  <span class="org-string">&quot;~a/resources/wallpapers/ofcoisp7abfe1.jpeg&quot;</span> sss-clone-dir))
      ((equal? 'sss-palette-ef-autumn sss-active-palette)
       (format #f  <span class="org-string">&quot;~a/resources/wallpapers/0mar2ygf59je1.jpeg&quot;</span> sss-clone-dir))
      ( <span class="org-keyword">else</span> (format #f  <span class="org-string">&quot;~a/resources/wallpapers/some-forest.jpg&quot;</span> sss-clone-dir))))
  ( <span class="org-keyword">export</span> sss-sway-wallpaper))

( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-startup-programs</span>  <span class="org-builtin">#:key</span> (wallpaper-setter  <span class="org-string">&quot;&quot;</span>)
                                    (extra-startups '()))
  (append extra-startups
          `( <span class="org-string">&quot;lxsession&quot;</span>  <span class="org-string">&quot;mako&quot;</span>
             <span class="org-string">&quot;dbus-update-activation-environment --all&quot;</span>
             <span class="org-string">&quot;emacs --daemon&quot;</span>
             <span class="org-string">&quot;waybar&quot;</span>
             <span class="org-string">&quot;foot -s&quot;</span>
             <span class="org-string">&quot;transmission-daemon&quot;</span>
            ,(format #f  <span class="org-string">&quot;swww-daemon &amp; sleep 1 &amp;&amp; ~a&quot;</span> wallpaper-setter)
             <span class="org-string">&quot;conky -d&quot;</span>
             <span class="org-string">&quot;podman system service --time=0 unix:///tmp/podman.sock&quot;</span>)))

( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-startup-reload-programs</span>  <span class="org-builtin">#:key</span> sss-active-palette)
  ( <span class="org-keyword">let</span> ((gtk-theme-name ( <span class="org-keyword">cond</span>
                          ((equal? 'sss-palette-ef-cyprus sss-active-palette)
                            <span class="org-string">&quot;Yaru-sage&quot;</span>)
                          ((equal? 'sss-palette-heavy-metal sss-active-palette)
                            <span class="org-string">&quot;Yaru-red-dark&quot;</span>)
                          ((equal? 'sss-palette-ef-dream sss-active-palette)
                            <span class="org-string">&quot;Yaru-magenta-dark&quot;</span>)
                          ((equal? 'sss-palette-ef-autumn sss-active-palette)
                            <span class="org-string">&quot;Yaru-dark&quot;</span>)
                          ((equal? 'sss-palette-solarized-light
                                   sss-active-palette)
                            <span class="org-string">&quot;Yaru&quot;</span>)
                          ( <span class="org-keyword">else</span>  <span class="org-string">&quot;Yaru-sage-dark&quot;</span>)))
        (icon-theme-name ( <span class="org-keyword">cond</span>
                           ((equal? 'sss-palette-ef-cyprus sss-active-palette)
                             <span class="org-string">&quot;Yaru-sage&quot;</span>)
                           ((equal? 'sss-palette-heavy-metal
                                    sss-active-palette)
                             <span class="org-string">&quot;Yaru-red-dark&quot;</span>)
                           ((equal? 'sss-palette-ef-dream sss-active-palette)
                             <span class="org-string">&quot;Yaru-magenta-dark&quot;</span>)
                           ((equal? 'sss-palette-ef-autumn sss-active-palette)
                             <span class="org-string">&quot;Yaru-dark&quot;</span>)
                           ((equal? 'sss-palette-solarized-light
                                    sss-active-palette)
                             <span class="org-string">&quot;Yaru&quot;</span>)
                           ( <span class="org-keyword">else</span>  <span class="org-string">&quot;Yaru-sage-dark&quot;</span>))))
    
    `(,(format #f  <span class="org-string">&quot;gsettings set $gnome-schema gtk-theme '~a'&quot;</span> gtk-theme-name) ,
      (format #f  <span class="org-string">&quot;gsettings set $gnome-schema icon-theme '~a'&quot;</span> icon-theme-name)
       <span class="org-string">&quot;gsettings set $gnome-schema cursor-theme 'Yaru'&quot;</span>
       <span class="org-string">&quot;gsettings set $gnome-schema cursor-size 24&quot;</span>
       <span class="org-string">&quot;gsettings set $gnome-schema font-name 'Inter'&quot;</span>)))

( <span class="org-keyword">begin</span>
  ( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-outputs</span>  <span class="org-builtin">#:key</span> sss-clone-dir)
    (list (sway-output (identifier '*))))
  ( <span class="org-keyword">export</span> sss-sway-outputs))

( <span class="org-keyword">begin</span>
  ( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-variables</span>  <span class="org-builtin">#:key</span> sss-clone-dir sss-active-palette)
    `((mod .  <span class="org-string">&quot;Mod4&quot;</span>) (left .  <span class="org-string">&quot;Left&quot;</span>)
      (down .  <span class="org-string">&quot;Down&quot;</span>)
      (up .  <span class="org-string">&quot;Up&quot;</span>)
      (right .  <span class="org-string">&quot;Right&quot;</span>)
      (gnome-schema .  <span class="org-string">&quot;org.gnome.desktop.interface&quot;</span>)
      (editor .  <span class="org-string">&quot;emacsclient -c&quot;</span>)
      (bloated-browser .  <span class="org-string">&quot;google-chrome&quot;</span>)
      (browser .  <span class="org-string">&quot;QT_QPA_PLATFORM=xcb qutebrowser&quot;</span>)
      (term .  <span class="org-string">&quot;footclient&quot;</span>)
      (wallpaper-setter unquote
                        (format #f
                          <span class="org-string">&quot;swww img ~a --transition-step 10 --transition-fps 30 --transition-type center&quot;</span>

                         (sss-sway-wallpaper  <span class="org-builtin">#:sss-clone-dir</span> sss-clone-dir
                                              <span class="org-builtin">#:sss-active-palette</span>
                                             sss-active-palette)))
      (password-manager .  <span class="org-string">&quot;$HOME/.nix-profile/bin/1password&quot;</span>)
      (locker unquote
              (string-join '( <span class="org-string">&quot;swaylock&quot;</span>  <span class="org-string">&quot;--screenshots&quot;</span>
                              <span class="org-string">&quot;--clock&quot;</span>
                              <span class="org-string">&quot;--indicator&quot;</span>
                              <span class="org-string">&quot;--indicator-radius 100&quot;</span>
                              <span class="org-string">&quot;--indicator-thickness 7&quot;</span>
                              <span class="org-string">&quot;--effect-blur 7x5&quot;</span>
                              <span class="org-string">&quot;--effect-vignette 0.5:0.5&quot;</span>
                              <span class="org-string">&quot;--ring-color bb00cc&quot;</span>
                              <span class="org-string">&quot;--key-hl-color 880033&quot;</span>
                              <span class="org-string">&quot;--line-color 00000000&quot;</span>
                              <span class="org-string">&quot;--inside-color 00000088&quot;</span>
                              <span class="org-string">&quot;--separator-color 00000000&quot;</span>
                              <span class="org-string">&quot;--grace 2&quot;</span>
                              <span class="org-string">&quot;--fade-in 0.2&quot;</span>)  <span class="org-string">&quot; &quot;</span>))
      (menu .  <span class="org-string">&quot;rofi -show drun&quot;</span>)
      (runner .  <span class="org-string">&quot;rofi -show run&quot;</span>)
      (windower .  <span class="org-string">&quot;rofi -show window&quot;</span>)))
  ( <span class="org-keyword">export</span> sss-sway-variables))

( <span class="org-keyword">define</span>  <span class="org-function-name">sss-sway-modes</span>
  (list (sway-mode (mode-name  <span class="org-string">&quot;resize&quot;</span>)
                   (keybindings '(($left .  <span class="org-string">&quot;resize shrink width 10px&quot;</span>)
                                  ($down .  <span class="org-string">&quot;resize grow height 10px&quot;</span>)
                                  ($up .  <span class="org-string">&quot;resize shrink height 10px&quot;</span>)
                                  ($right .  <span class="org-string">&quot;resize grow width 10px&quot;</span>)
                                  (Return .  <span class="org-string">&quot;mode \&quot;default\&quot;&quot;</span>)
                                  (Escape .  <span class="org-string">&quot;mode \&quot;default\&quot;&quot;</span>))))))

( <span class="org-keyword">define-public</span>  <span class="org-function-name">sss-sway-keybindings</span>
  `(($mod+Return .  <span class="org-string">&quot;exec $term&quot;</span>) ($mod+t .  <span class="org-string">&quot;exec $term&quot;</span>)
    ($mod+shift+period .  <span class="org-string">&quot;exec grimshot copy screen&quot;</span>)
    ($mod+period .  <span class="org-string">&quot;exec grimshot save screen&quot;</span>)
    ($mod+shift+comma .  <span class="org-string">&quot;exec grimshot copy area&quot;</span>)
    ($mod+comma .  <span class="org-string">&quot;exec grimshot save area&quot;</span>)
    ($mod+k .  <span class="org-string">&quot;kill&quot;</span>)
    ($mod+l .  <span class="org-string">&quot;exec $locker&quot;</span>)
    ($mod+Shift+b .  <span class="org-string">&quot;exec $wallpaper-setter&quot;</span>)
    ($mod+slash .  <span class="org-string">&quot;exec $menu&quot;</span>)
    ($mod+i .  <span class="org-string">&quot;exec $browser&quot;</span>)
    ($mod+Shift+i .  <span class="org-string">&quot;exec $bloated-browser&quot;</span>)
    ($mod+e .  <span class="org-string">&quot;exec $editor&quot;</span>)
    ($mod+minus .  <span class="org-string">&quot;exec $password-manager&quot;</span>)
    ($mod+Shift+c .  <span class="org-string">&quot;reload&quot;</span>)
    ($mod+$left .  <span class="org-string">&quot;focus left&quot;</span>)
    ($mod+$down .  <span class="org-string">&quot;focus down&quot;</span>)
    ($mod+$up .  <span class="org-string">&quot;focus up&quot;</span>)
    ($mod+$right .  <span class="org-string">&quot;focus right&quot;</span>)
    ($mod+Shift+$left .  <span class="org-string">&quot;move left&quot;</span>)
    ($mod+Shift+$down .  <span class="org-string">&quot;move down&quot;</span>)
    ($mod+Shift+$up .  <span class="org-string">&quot;move up&quot;</span>)
    ($mod+Shift+$right .  <span class="org-string">&quot;move right&quot;</span>)
    ($mod+p .  <span class="org-string">&quot;workspace prev_on_output&quot;</span>)
    ($mod+n .  <span class="org-string">&quot;workspace next_on_output&quot;</span>)
    ($mod+1 .  <span class="org-string">&quot;workspace number 1&quot;</span>)
    ($mod+2 .  <span class="org-string">&quot;workspace number 2&quot;</span>)
    ($mod+3 .  <span class="org-string">&quot;workspace number 3&quot;</span>)
    ($mod+4 .  <span class="org-string">&quot;workspace number 4&quot;</span>)
    ($mod+5 .  <span class="org-string">&quot;workspace number 5&quot;</span>)
    ($mod+6 .  <span class="org-string">&quot;workspace number 6&quot;</span>)
    ($mod+7 .  <span class="org-string">&quot;workspace number 7&quot;</span>)
    ($mod+8 .  <span class="org-string">&quot;workspace number 8&quot;</span>)
    ($mod+9 .  <span class="org-string">&quot;workspace number 9&quot;</span>)
    ($mod+0 .  <span class="org-string">&quot;workspace number 10&quot;</span>)
    ($mod+Shift+1 .  <span class="org-string">&quot;move container to workspace number 1&quot;</span>)
    ($mod+Shift+2 .  <span class="org-string">&quot;move container to workspace number 2&quot;</span>)
    ($mod+Shift+3 .  <span class="org-string">&quot;move container to workspace number 3&quot;</span>)
    ($mod+Shift+5 .  <span class="org-string">&quot;move container to workspace number 5&quot;</span>)
    ($mod+Shift+4 .  <span class="org-string">&quot;move container to workspace number 4&quot;</span>)
    ($mod+Shift+6 .  <span class="org-string">&quot;move container to workspace number 6&quot;</span>)
    ($mod+Shift+7 .  <span class="org-string">&quot;move container to workspace number 7&quot;</span>)
    ($mod+Shift+8 .  <span class="org-string">&quot;move container to workspace number 8&quot;</span>)
    ($mod+Shift+9 .  <span class="org-string">&quot;move container to workspace number 9&quot;</span>)
    ($mod+Shift+0 .  <span class="org-string">&quot;move container to workspace number 10&quot;</span>)
    ($mod+b .  <span class="org-string">&quot;splith&quot;</span>)
    ($mod+v .  <span class="org-string">&quot;splitv&quot;</span>)
    ($mod+s .  <span class="org-string">&quot;layout stacking&quot;</span>)
    ($mod+w .  <span class="org-string">&quot;layout tabbed&quot;</span>)
    ($mod+h .  <span class="org-string">&quot;layout toggle split&quot;</span>)
    ($mod+f .  <span class="org-string">&quot;fullscreen&quot;</span>)
    ($mod+Shift+space .  <span class="org-string">&quot;floating toggle&quot;</span>)
    ($mod+space .  <span class="org-string">&quot;focus mode_toggle&quot;</span>)
    ($mod+a .  <span class="org-string">&quot;focus parent&quot;</span>)
    ($mod+Shift+minus .  <span class="org-string">&quot;move scratchpad&quot;</span>)
    ($mod+Shift+m .  <span class="org-string">&quot;sway output Virtual-1 mode 1920x1200&quot;</span>)
    ($mod+Shift+s .  <span class="org-string">&quot;scratchpad show&quot;</span>)
    ($mod+r .  <span class="org-string">&quot;exec $runner&quot;</span>)
    (Alt+tab .  <span class="org-string">&quot;exec $windower&quot;</span>)
    ($mod+Shift+e unquote
                  #~(string-append  <span class="org-string">&quot;exec &quot;</span>
                     #$sway
                      <span class="org-string">&quot;/bin/swaynag -t warning -m \\\n    &quot;</span>
                      <span class="org-string">&quot;'You pressed the exit shortcut.  Do you really want to exit sway?&quot;</span>
                      <span class="org-string">&quot; This will end your Wayland session.' \\
    &quot;</span>
                      <span class="org-string">&quot;-B 'Yes, exit sway' \\\n    '&quot;</span>
                     #$sway
                      <span class="org-string">&quot;/bin/swaymsg exit'&quot;</span>))
    (XF86MonBrightnessDown .  <span class="org-string">&quot;exec sudo light -U 3&quot;</span>)
    (XF86MonBrightnessUp .  <span class="org-string">&quot;exec sudo light -A 3&quot;</span>)
    (XF86AudioRaiseVolume .  <span class="org-string">&quot;exec pactl set-sink-volume @DEFAULT_SINK@ +5%&quot;</span>)
    (XF86AudioLowerVolume .  <span class="org-string">&quot;exec pactl set-sink-volume @DEFAULT_SINK@ -5%&quot;</span>)
    (XF86AudioMute .  <span class="org-string">&quot;exec pactl set-sink-mute @DEFAULT_SINK@ toggle&quot;</span>)
    (XF86AudioMicMute .  <span class="org-string">&quot;exec pactl set-source-mute @DEFAULT_SOURCE@ toggle&quot;</span>)
    (XF86AudioPlay .  <span class="org-string">&quot;exec playerctl play-pause&quot;</span>)
    (XF86AudioNext .  <span class="org-string">&quot;exec playerctl next&quot;</span>)
    (XF86AudioPrev .  <span class="org-string">&quot;exec playerctl previous&quot;</span>)
    ($mod+Shift+r .  <span class="org-string">&quot;mode \&quot;resize\&quot;&quot;</span>)))

( <span class="org-keyword">define</span>  <span class="org-function-name">sss-swayfx-config</span>
  `( <span class="org-string">&quot;corner_radius 12&quot;</span>  <span class="org-string">&quot;shadows enable&quot;</span>  <span class="org-string">&quot;blur enable&quot;</span>
     <span class="org-string">&quot;default_dim_inactive 0.2&quot;</span>  <span class="org-string">&quot;dim_inactive_colors.unfocused #000000FF&quot;</span>
     <span class="org-string">&quot;dim_inactive_colors.urgent #900000FF&quot;</span>))

( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-extra-content</span>  <span class="org-builtin">#:key</span> sss-active-palette)
  `( <span class="org-string">&quot;gaps inner 12&quot;</span>  <span class="org-string">&quot;gaps outer 8&quot;</span>

     <span class="org-comment-delimiter">;; </span> <span class="org-comment">class                 border  backgr. text    indicator child_border
</span>    ,(format #f
              <span class="org-string">&quot;client.focused ~a ~a ~a ~a ~a&quot;</span>
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'text)
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'primary))
    ,(format #f
              <span class="org-string">&quot;client.focused_inactive ~a ~a ~a ~a ~a&quot;</span>
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'text)
             (sss-get-color sss-active-palette
                            'primary)
             (sss-get-color sss-active-palette
                            'primary))
    ,(format #f
              <span class="org-string">&quot;client.unfocused ~a ~a #808f80 ~a ~a&quot;</span>
             (sss-get-color sss-active-palette
                            'background-l)
             (sss-get-color sss-active-palette
                            'background-l)
             (sss-get-color sss-active-palette
                            'background-l)
             (sss-get-color sss-active-palette
                            'background-l))
     <span class="org-string">&quot;client.urgent           #b02930 #b02930 #cfdfd5 #900000   #900000&quot;</span>
     <span class="org-string">&quot;client.placeholder      #000000 #0c0c0c #cfdfd5 #000000   #0c0c0c&quot;</span>
    ,(format #f  <span class="org-string">&quot;client.background ~a&quot;</span>
             (sss-get-color sss-active-palette
                            'text))
    ,(format #f  <span class="org-string">&quot;seat seat0 xcursor_theme ~a ~a&quot;</span>  <span class="org-string">&quot;Yaru&quot;</span>  <span class="org-string">&quot;24&quot;</span>)))

( <span class="org-keyword">begin</span>
  ( <span class="org-keyword">define*</span> ( <span class="org-function-name">sss-sway-service-type</span>  <span class="org-builtin">#:key</span> sss-clone-dir
                                  sss-keyboard-layout
                                  sss-keyboard-caps-to-ctrl
                                  sss-active-palette
                                  sss-sway-extra-startups)
    (service home-sway-service-type
             (sway-configuration (packages (list swayfx))
                                 (gestures sss-sway-gestures)
                                 (startup-programs (sss-sway-startup-programs
                                                     <span class="org-builtin">#:wallpaper-setter</span> (format
                                                                        #f
                                                                         <span class="org-string">&quot;swww img ~a --transition-step 10 --transition-fps 30 --transition-type center&quot;</span>

                                                                        (sss-sway-wallpaper
                                                                          <span class="org-builtin">#:sss-active-palette</span>
                                                                         sss-active-palette
                                                                          <span class="org-builtin">#:sss-clone-dir</span>
                                                                         sss-clone-dir))
                                                     <span class="org-builtin">#:extra-startups</span>
                                                    sss-sway-extra-startups))
                                 (startup+reload-programs (sss-sway-startup-reload-programs
                                                            <span class="org-builtin">#:sss-active-palette</span>
                                                           sss-active-palette))
                                 (outputs (sss-sway-outputs  <span class="org-builtin">#:sss-clone-dir</span>
                                                            sss-clone-dir))
                                 (inputs (list (sway-input (identifier
                                                             <span class="org-string">&quot;type:keyboard&quot;</span>)
                                                           (layout (keyboard-layout
                                                                    sss-keyboard-layout
                                                                     <span class="org-builtin">#:options</span> ( <span class="org-keyword">cond</span>
                                                                                
                                                                                
                                                                                (sss-keyboard-caps-to-ctrl '
                                                                                 ( <span class="org-string">&quot;ctrl:nocaps&quot;</span>))

                                                                                
                                                                                ( <span class="org-keyword">else</span> '())))))
                                               (sway-input (identifier
                                                             <span class="org-string">&quot;type:touchpad&quot;</span>)
                                                           (tap #t))))
                                 (variables (sss-sway-variables
                                              <span class="org-builtin">#:sss-active-palette</span>
                                             sss-active-palette
                                              <span class="org-builtin">#:sss-clone-dir</span> sss-clone-dir))
                                 (modes sss-sway-modes)
                                 (keybindings sss-sway-keybindings)
                                 (extra-content (append sss-swayfx-config
                                                        ( <span class="org-keyword">map</span> ( <span class="org-keyword">lambda</span> (w)
                                                               (format #f
                                                                 <span class="org-string">&quot;for_window [app_id=\&quot;~a\&quot;] floating enable&quot;</span>
                                                                w))
                                                         sss-sway-floating-windows)
                                                        (sss-sway-extra-content
                                                          <span class="org-builtin">#:sss-active-palette</span>
                                                         sss-active-palette))))))
  ( <span class="org-keyword">export</span> sss-sway-service-type))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Final Thoughts  <a id="final-thoughts" class="anchor" href="#final-thoughts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb781025">
 <p>
Switching to Hyprland feels like a step forward into a more vibrant ecosystem (and nice and shiny graphics). Sway will always hold a special place in my heart as the first tiling Wayland compositor I customized with Lisp. However, Hyprland’s polish and active development make it the ideal choice for the Supreme Sexp System moving forward.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Building Conky with Wayland Support on GNU Guix</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-program-in-lisp/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Why I Program in Lisp?</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/">Building Conky with Wayland Support on GNU Guix</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/index.html</guid>
  <pubDate>Wed, 05 Mar 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Building Conky with Wayland Support on GNU Guix</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Conky is a lightweight system monitor that can display system statistics on the desktop. While it was originally built for X11, recent versions have added experimental Wayland support. Since I use GNU Guix and run a Wayland-based environment (Sway), I wanted to get Conky building with Wayland support. This post explains how I achieved that.
</p>

 <p>
Guix is a functional package manager that allows you to define software packages declaratively. Since Conky is not in the official Guix repository with Wayland support enabled, I created a custom package definition for it.
</p>

 <p>
Enabled Wayland Build Option: The  <code>-DBUILD_WAYLAND=ON</code> flag ensures Wayland support is compiled in.
</p>

 <p>
Added Required Dependencies: Added  <code>gperf</code> ,  <code>cairo</code>,  <code>pango</code>   <code>wayland</code> and  <code>wayland-protocols</code> to inputs.
</p>

 <p>
Since Conky was originally designed for X11, some adjustments are needed for Wayland:
</p>

 <p>
No own_window: In X11, Conky runs in its own window. On Wayland, it needs to be embedded into a compositor-specific layer.
</p>

 <p>
Use xwayland If Needed: Some features might require running Conky through XWayland.
</p>

 <p>
Wayland-Specific Patches: Some users have patched Conky to integrate better with Wayland. If needed, applying community patches might help.
</p>

 <p>
With a bit of tweaking, I got Conky running with Wayland on GNU Guix. While it’s still experimental, it works well enough for basic system monitoring. If you’re on a similar setup and want a lightweight system monitor, give this a try!
</p>

 <p>
Below a screenshot of how it runs in Sway, on Guix (SSS - Supreme Sexp System):
</p>


 <div id="org900ea76" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/conky-wayland/2025-02-17.png"></img></p>
</div>


 <p>
Below is the Guile Scheme code I used:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define-module</span> ( <span class="org-type">sss</span> packages conky)
   <span class="org-builtin">#:use-module</span> (guix packages)
   <span class="org-builtin">#:use-module</span> (guix utils)
   <span class="org-builtin">#:use-module</span> (guix download)
   <span class="org-builtin">#:use-module</span> (guix git-download)
   <span class="org-builtin">#:use-module</span> (guix build-system cmake)
   <span class="org-builtin">#:use-module</span> ((guix licenses)
                 <span class="org-builtin">#:prefix</span> license:)
   <span class="org-builtin">#:use-module</span> (gnu packages curl)
   <span class="org-builtin">#:use-module</span> (gnu packages fontutils)
   <span class="org-builtin">#:use-module</span> (gnu packages image)
   <span class="org-builtin">#:use-module</span> (gnu packages linux)
   <span class="org-builtin">#:use-module</span> (gnu packages freedesktop)
   <span class="org-builtin">#:use-module</span> (gnu packages gtk)
   <span class="org-builtin">#:use-module</span> (gnu packages lua)
   <span class="org-builtin">#:use-module</span> (gnu packages ncurses)
   <span class="org-builtin">#:use-module</span> (gnu packages pkg-config)
   <span class="org-builtin">#:use-module</span> (gnu packages gperf)
   <span class="org-builtin">#:use-module</span> (gnu packages pulseaudio)
   <span class="org-builtin">#:use-module</span> (gnu packages xorg))

( <span class="org-keyword">define-public</span>  <span class="org-function-name">sss-conky</span>
  (package
    (name  <span class="org-string">&quot;conky&quot;</span>)
    (home-page  <span class="org-string">&quot;https://github.com/brndnmtthws/conky&quot;</span>)
    (version  <span class="org-string">&quot;1.22.0&quot;</span>)
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url home-page)
             (commit (string-append  <span class="org-string">&quot;v&quot;</span> version))))
       (file-name (git-file-name name version))
       (sha256
        (base32  <span class="org-string">&quot;08ggr2nks3g1lk5k9hlv9mzyzbxms6yamhw4ndhayhn6n9dzqsnx&quot;</span>))))
    (build-system cmake-build-system)
    (arguments
     `( <span class="org-builtin">#:configure-flags</span> (list  <span class="org-string">&quot;-DRELEASE=true&quot;</span>  <span class="org-string">&quot;-DBUILD_PULSEAUDIO=ON&quot;</span>
                                <span class="org-string">&quot;-DBUILD_WLAN=ON&quot;</span>  <span class="org-string">&quot;-DBUILD_TESTS=ON&quot;</span>
                                <span class="org-string">&quot;-DBUILD_WAYLAND=ON&quot;</span>)
        <span class="org-builtin">#:phases</span> (modify-phases %standard-phases
                  (add-after 'unpack 'add-freetype-to-search-path
                    (lambda* ( <span class="org-builtin">#:key</span> inputs  <span class="org-builtin">#:allow-other-keys</span>)
                      (substitute*  <span class="org-string">&quot;cmake/ConkyPlatformChecks.cmake&quot;</span>
                        (( <span class="org-string">&quot;set\\(INCLUDE_SEARCH_PATH&quot;</span>)
                         (string-append  <span class="org-string">&quot;set(INCLUDE_SEARCH_PATH &quot;</span>
                                        (assoc-ref inputs  <span class="org-string">&quot;freetype&quot;</span>)
                                         <span class="org-string">&quot;/include/freetype2 &quot;</span>))) #t))
                  (replace 'install
                    (lambda* ( <span class="org-builtin">#:key</span> outputs  <span class="org-builtin">#:allow-other-keys</span>)
                      ( <span class="org-keyword">let*</span> ((out (assoc-ref outputs  <span class="org-string">&quot;out&quot;</span>))
                             (bin (string-append out  <span class="org-string">&quot;/bin&quot;</span>)))
                        (install-file  <span class="org-string">&quot;src/conky&quot;</span> bin)) #t)))))
    (inputs (list freetype
                  imlib2
                  libx11
                  libxdamage
                  libxext
                  cairo
                  libxft
                  libxi
                  libxinerama
                  pango
                  pulseaudio
                  lua
                  gperf
                  ncurses
                  wayland
                  wayland-protocols
                  curl
                  wireless-tools))
    (native-inputs (list pkg-config))
    (synopsis  <span class="org-string">&quot;Lightweight system monitor for X&quot;</span>)
    (description
      <span class="org-string">&quot;Conky is a lightweight system monitor for X that displays operating
system statistics (CPU, disk, and memory usage, etc.) and more on the
desktop.&quot;</span>)
    (license license:gpl3+)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/legendary-lisp-laptop/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Legendary Lisp Laptop - a modern Lisp machine with Framework laptop</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Moving from Sway to Hyprland - Archived SwayFX config</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/index.html</guid>
  <pubDate>Tue, 18 Feb 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Legendary Lisp Laptop - a modern Lisp machine with Framework laptop</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
For the past month or so, I’ve been running Guix system on my Framework laptop, turning it into what I like to call a modern Lisp machine.
</p>

 <p>
I have affectionately also started calling it a Legendary Lisp Laptop - LLL
</p>

 <p>
I chose the Framework Laptop 13,5&quot; since it is big enough for me and it is really lightweight and portable. I mostly have external monitors anyway, at home and at work.
</p>
 <h2>Technical specifications  <a id="technical-specifications" class="anchor" href="#technical-specifications" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org0c15e8e">
 <ul class="org-ul"> <li>AMD Ryzen™ 5 7640U (up to 4.9GHz, 6-core/12-thread)</li>
 <li>Memory: DDR5-5600 - 32GB (2 x 16GB)</li>
 <li>Storage: WD_BLACK™ SN770 NVMe™- M.2 2280 - 1TB</li>
 <li>Battery - 55Wh</li>
 <li>Webcam Module (1st Gen)</li>
 <li>13.5&quot; 2256x1504 60Hz matte display</li>
 <li>WiFi: RZ616 WiFi</li>
 <li>USB-C x2, USB-A, HDMI, Ethernet</li>
</ul> <p>
Below you can see the laptop before placing the keyboard, display bezel, SSD and RAM in. You can tell this is simple and easy to repair :)
</p>


 <div id="orgd1068eb" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/4.jpg"></img></p>
</div>
</div>
 <h2>Why Framework?  <a id="why-framework" class="anchor" href="#why-framework" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2bbb782">
 <p>
Framework laptops stand out in a market dominated by disposable, locked-down devices. Their modular design means users can replace or upgrade parts easily, extending the laptop’s lifespan far beyond that of typical consumer models. This approach not only saves money but also significantly reduces electronic waste.
</p>

 <p>
Check out their website here:  <a href="https://frame.work/">https://frame.work/</a>
</p>

 <p>
By designing a laptop that prioritizes repairability and fixability, Framework empowers users to maintain and upgrade their devices instead of discarding them. This has a profound ecological impact — fewer laptops ending up in landfills means less e-waste and a more sustainable approach to personal computing.
</p>

 <p>
Choosing a Framework laptop isn’t just about flexibility and performance; it’s also a commitment to sustainability and responsible consumption. If you’re looking for a machine that aligns with both high customizability and environmental consciousness, Framework is the way to go.
</p>

 <p>
I am extremely pleased with the laptop. Keyboard is great actually, it has also backlight, screen is high resolution and has very nice colors, WiFi range is very good, and CPU is surprisingly good, even with me choosing the lowest-powered one. Overall I am extremely satisfied with this machine, and the price too.
</p>
</div>
 <h2>The assembly process  <a id="the-assembly-process" class="anchor" href="#the-assembly-process" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd5dd75d">
 <p>
Below follow a lot of pictures about the unboxing and assembly process. I chose for the DIY edition, which means you need to assemble the entire thing yourself.
</p>

 <p>
You can see the assembly guide of Framework here:  <a href="https://guides.frame.work/Guide/Framework+Laptop+13+(AMD+Ryzen%E2%84%A2+7040+Series)+DIY+Edition+Quick+Start+Guide/211">https://guides.frame.work/Guide/Framework+Laptop+13+(AMD+Ryzen%E2%84%A2+7040+Series)+DIY+Edition+Quick+Start+Guide/211</a>
</p>

 <p>
You can also choose for a model that comes pre-assembled, but for me, this is part of the fun.
</p>


 <div id="org24bc314" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/2.jpg"></img></p>
</div>

 <p>
Below you can see the “hot-swappable” adapter cards, you can choose your connectors to your taste. I chose 2 USB-C, 1 HDMI, 1 USB-A and 1 ethernet port for every now and then.
</p>


 <div id="org45fcd9a" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/1.jpg"></img></p>
</div>

 <p>
Below you can see the SSD, RAM and keyboard.
</p>


 <div id="org577a978" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/3.jpg"></img></p>
</div>

 <p>
Below you can see the Guix install screen I booted using a USB.
</p>

 <p>
Note: I had to manually tweak the BIOS settings a bit, disabling secure boot and setting the date and time correctly, to get the installer to connect properly to Internet. Framework provides a really nice BIOS actually, really happy about it.
</p>


 <div id="org70f1bbd" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/5.jpg"></img></p>
</div>

 <p>
Below you can see me running Emacs on a TTY, working without a graphical session. I do this sometimes when I am in the mood :)
</p>


 <div id="org281489c" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/6.jpg"></img></p>
</div>

 <p>
Below you can see the Framework running SSS Sway session, with Emacs, Thunar and the Foot terminal.
</p>


 <div id="org22684aa" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/blog/img/lisp-machine-laptop/7.jpg"></img></p>
</div>

 <p>
And here SSS in all its glory:
</p>


 <div id="orgd27e8c9" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/static-assets/other/img/sss-2025-02-04.png"></img></p>
</div>
</div>
 <h2>About the software I run on it  <a id="about-the-software-i-run-on-it" class="anchor" href="#about-the-software-i-run-on-it" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga311253">
 <p>
With Guix’s declarative system configuration and my setup which uses, among others, Emacs, Sway, Qutebrowser, in SSS (the Supreme Sexp System), this machine is my daily driver for both work and personal engineering projects.
</p>

 <p>
Guix is the perfect operating system for a Lisp enthusiast. It embraces the same principles: functional purity, immutability, and reproducibility. The entire system configuration is written in Lisp (Guile Scheme), making it a natural fit for someone who appreciates the elegance of Lisp. By using Guix, I can declaratively manage my entire system state and configurations, rolling back configurations seamlessly when needed.
</p>

 <p>
SSS, my custom environment, brings the power of s-expressions to every aspect of my workflow. Instead of relying on traditional shell scripting, I use Lisp to configure and automate my system.
</p>

 <p>
If you are interested, read more about it here:  <a href="https://codeberg.org/jjba23/sss">https://codeberg.org/jjba23/sss</a>
</p>

 <p>
At work, I primarily develop in Scala, and despite my heavily Lisp-centric setup, this laptop functions perfectly for that. Guix allows me to keep isolated, reproducible environments using Guix (and Nix) shell, so I can spin up development environments without polluting my system.
</p>

 <p>
Whether I’m writing functional code, hacking on my Guix configuration, or working in Emacs Lisp, my laptop stays flexible and efficient.
</p>

 <p>
Using a Lisp-driven system in 2025 might sound niche, but it has brought immense joy and efficiency to my workflow. The Framework laptop itself is an excellent hardware choice due to its repairability and modular design, and Guix ensures my software stack remains under my control. With SSS, Emacs, and Sway, I feel like I’m using a machine that truly adapts to me, rather than the other way around.
</p>

 <p>
If you’re interested in building your own modern Lisp machine, I highly recommend Fractal Design North cases for desktops, and Framework laptops for portable devices - also give Guix a spin.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisp-style-guide/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Scheme &amp; Lisp Style Guide</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Building Conky with Wayland Support on GNU Guix</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/legendary-lisp-laptop/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/legendary-lisp-laptop/index.html</guid>
  <pubDate>Wed, 05 Feb 2025 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Scheme &amp; Lisp Style Guide</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Riastradh’s Lisp Style Rules                          
</p>

 <p>
Copyright (C) 2007–2011 Taylor R. Campbell
</p>

 <p>
CC BY-NC-SA 3.0
</p>

 <p>
This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 3.0 Unported License:
 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>.
</p>

 <p>
This is a guide to Lisp style, written by Taylor R. Campbell, to
describe the standard rules of Lisp style as well as a set of more
stringent rules for his own style.  This guide should be useful for
Lisp in general, but there are [or will be in the final draft] parts
that are focussed on or specific to Scheme or Common Lisp.
</p>

 <p>
This guide is written primarily as a collection of rules, with
rationale for each rule.  (If a rule is missing rationale, please
inform the author!)  Although a casual reader might go through and read
the rules without the rationale, perhaps reasoning that reading of the
rationale would require more time than is available, such a reader
would derive little value from this guide.  In order to apply the rules
meaningfully, their spirit must be understood; the letter of the rules
serves only to hint at the spirit.  The rationale is just as important
as the rules.
</p>

 <p>
There are many references in this document to `Emacs’, `GNU Emacs’,
`Edwin’, and so on.  In this document, `Emacs’ means any of a class of
editors related in design to a common ancestor, the EMACS editor macros
written for TECO on ITS on the PDP-10 in the middle of the nineteen
seventies.  All such editors – or `all Emacsen’, since `Emacsen’ is
the plural of `Emacs’ – have many traits in common, such as a very
consistent set of key bindings, extensibility in Lisp, and so on.  `GNU
Emacs’ means the member of the class of editors collectively known as
Emacsen that was written for the GNU Project in the middle of the
nineteen eighties, and which is today probably the most popular Emacs.
`Edwin’ is MIT Scheme’s Emacs, which is bundled as part of MIT Scheme,
and not available separately.  There are other Emacsen as well, such as
Hemlock and Climacs, but as the author of this document has little
experience with Emacsen other than GNU Emacs and Edwin, there is little
mention of other Emacsen.
</p>

 <p>
This guide is a work in progress.  To be written:
</p>

 <ul class="org-ul"> <li>Indentation rules for various special operators.</li>
 <li>Philosophical rambling concerning naming.</li>
 <li>Rules for breaking lines.</li>
 <li>Many more examples.</li>
 <li>A more cohesive explanation of the author’s principles for composing
programs, and their implications.</li>
 <li>Rules for writing portable code.</li>
 <li>Some thoughts concerning extensions to the lexical syntax.</li>
 <li>Rules for writing or avoiding macros.</li>
 <li>Some unfinished rationale.</li>
 <li>More on documentation.</li>
 <li>The `Dependencies’ subsection of the `General Layout’ section should
be put in a different section, the rest of which has yet to be
written, on organization of programs, module systems, and portable
code.</li>
</ul> <p>
Feedback is welcome; address any feedback by email to the host
mumble.net’s user `campbell’, or by IRC to Riastradh in the #scheme
channel on Freenode (irc.freenode.net).  Feedback includes reports of
typos, questions, requests for clarification, and responses to the
rationale, except in the case of round brackets versus square
brackets, the argument surrounding which is supremely uninteresting
and now not merely a dead horse but a rotting carcass buzzing with
flies and being picked apart by vultures.
</p>

 <p>
As this document has grown, the line between standard Lisp rules and
the author’s own style has been blurred.  The author is considering
merging of the partition, but has not yet decided on this with
certainty.  Opinions on the subject are welcome – is the partition
still useful to keep the author’s biases and idiosyncrasies out of the
standard rules, or has the partition with its arbitrary nature only
caused disorganization of the whole document?
</p>

 <p>
Unfortunately, this document is entirely unscientific.  It is at best a
superstition or philosophy, but one that the author of this document
has found to have improved his programs.  Furthermore, the author is
somewhat skeptical of claims of scientific analyses of these matters:
analyzing human behaviour, especially confined to the set of excellent
programmers who often have strong opinions about their methods for
building programs, is a very tricky task.
</p>
 <h2>Standard Rules  <a id="standard-rules" class="anchor" href="#standard-rules" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgefab28f">
 <p>
These are the standard rules for formatting Lisp code; they are
repeated here for completeness, although they are surely described
elsewhere.  These are the rules implemented in Emacs Lisp modes, and
auxiliary utilities such as Paredit.
</p>

 <p>
The rationale given here is merely the author’s own speculation of the
origin of these rules, and should be taken as nothing more than it.
The reader shall, irrespective of the author’s rationale, accept the
rules as sent by the reader’s favourite deity, or Cthulhu if no such
deity strikes adequate fear into the heart of the reader.
</p>
</div>
 <h3>Parentheses  <a id="parentheses" class="anchor" href="#parentheses" aria-label="Link to this section">#</a></h3> <h4>Terminology  <a id="terminology" class="anchor" href="#terminology" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org66fce60">
 <p>
This guide avoids the term  <i>parenthesis</i> except in the general use of
 <i>parentheses</i> or  <i>parenthesized</i>, because the word’s generally accepted
definition, outside of the programming language, is a statement whose
meaning is peripheral to the sentence in which it occurs, and  <b>not</b> the
typographical symbols used to delimit such statements.
</p>

 <p>
The balanced pair of typographical symbols that mark parentheses in
English text are  <i>round brackets</i>, i.e. ( and ).  There are several
other balanced pairs of typographical symbols, such as  <i>square
brackets</i> (commonly called simply `brackets’ in programming circles),
i.e. [ and ];  <i>curly braces</i> (sometimes called simply `braces’), i.e. {
and };  <i>angle brackets</i> (sometimes `brokets’ (for `broken brackets’)),
i.e. &lt; and &gt;.
</p>

 <p>
In any balanced pair of typographical symbols, the symbol that begins
the region delimited by the symbols is called the  <i>opening bracket</i> or
the  <i>left bracket</i>, such as ( or [ or { or &lt;.  The symbol that ends
that region is called the  <i>right bracket</i> or the  <i>closing bracket</i>,
such as &gt; or } or ] or ).
</p>
</div>
 <h4>Spacing  <a id="spacing" class="anchor" href="#spacing" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org6ffd0ff">
 <p>
If any text precedes an opening bracket or follows a closing bracket,
separate that text from that bracket with a space.  Conversely, leave
no space after an opening bracket and before following text, or after
preceding text and before a closing bracket.
</p>

 <p>
Unacceptable:
</p>

 <div class="jfw-code"> <pre>(foo(bar baz)quux)
(foo ( bar baz ) quux)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Acceptable:
</p>

 <div class="jfw-code"> <pre>(foo (bar baz) quux)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Rationale:  This is the same spacing found in standard typography of
European text.  It is more aesthetically pleasing.
</p>
</div>
 <h4>Line Separation  <a id="line-separation" class="anchor" href="#line-separation" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org91fa655">
 <p>
Absolutely do  <b>not</b> place closing brackets on their own lines.
</p>

 <p>
Unacceptable:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">factorial</span> x)
  ( <span class="org-keyword">if</span> (&lt; x 2)
      1
      (* x (factorial (- x 1
                      )
           )
      )
  )
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Acceptable:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">factorial</span> x)
   ( <span class="org-keyword">if</span> (&lt; x 2)
       1
       (* x (factorial (- x 1)))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Rationale:  The parentheses grow lonely if their closing brackets are
all kept separated and segregated.
</p>
</div>
 <ul> <li>Exceptions to the Above Rule Concerning Line Separation <div class="outline-text-5" id="text-org3aa754b">
 <p>
Do not heed this section unless you know what you are doing.  Its title
does  <b>not</b> make the unacceptable example above acceptable.
</p>

 <p>
When commenting out fragments of expressions with line comments, it may
be necessary to break a line before a sequence of closing brackets:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">foo</span> bar)
  (list (frob bar)
        (zork bar)
         <span class="org-comment-delimiter">;; </span> <span class="org-comment">(zap bar)
</span>        ))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
This is acceptable, but there are other alternatives.  In Common Lisp,
one can use the read-time conditional syntax, `#+’ or `#-’, with a
feature conditional that is guaranteed to be false or true – `#+(OR)’
or `#-(AND)’ –; for example,
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">foo</span> bar)
  (list (frob bar)
        (zork bar)
        #+( <span class="org-keyword">or</span>) (zap bar))).</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Read-time conditionals are expression-oriented, not line-oriented, so
the closing brackets need not be placed on the following line.  Some
Scheme implementations, and SRFI 62, also support expression comments
with `#;’, which are operationally equivalent to the above read-time
conditionals for Common Lisp:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span> ( <span class="org-function-name">foo</span> bar)
  (list (frob bar)
        (zork bar)
         <span class="org-comment">#;
         (zap bar</span> <span class="org-comment-delimiter">)</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
The expression is placed on another line in order to avoid confusing
editors that do not recognize S-expression comments; see the section
titled `Comments’ below for more details.  However, the `#;’ notation
is not standard – it appears in neither the IEEE 1178 document nor in
the R5RS –, so line comments are preferable for portable Scheme code,
even if they require breaking a line before a sequence of closing
brackets.
</p>

 <p>
Finally, it is acceptable to break a line immediately after an opening
bracket and immediately before a closing bracket for very long lists,
especially in files under version control.  This eases the maintenance
of the lists and clarifies version diffs.  Example:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span>  <span class="org-function-name">colour-names</span>          <span class="org-comment-delimiter">;</span> <span class="org-comment">Add more colour names to this list!
</span>  '(
    blue
    cerulean
    green
    magenta
    purple
    red
    scarlet
    turquoise
    ))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
</li></ul> <h4>Parenthetical Philosophy  <a id="parenthetical-philosophy" class="anchor" href="#parenthetical-philosophy" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org58f7a72">
 <p>
The actual bracket characters are simply lexical tokens to which little
significance should be assigned.  Lisp programmers do not examine the
brackets individually, or, Azathoth forbid, count brackets; instead
they view the higher-level structures expressed in the program,
especially as presented by the indentation.  Lisp is not about writing
a sequence of serial instructions; it is about building complex
structures by summing parts.  The composition of complex structures
from parts is the focus of Lisp programs, and it should be readily
apparent from the Lisp code.  Placing brackets haphazardly about the
presentation is jarring to a Lisp programmer, who otherwise would not
even have seen them for the most part.
</p>
</div>
 <h3>Indentation and Alignment  <a id="indentation-and-alignment" class="anchor" href="#indentation-and-alignment" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org10f1d9d">
 <p>
The operator of any form, i.e. the first subform following the opening
round bracket, determines the rules for indenting or aligning the
remaining forms.  Many names in this position indicate special
alignment or indentation rules; these are special operators, macros, or
procedures that have certain parameter structures.
</p>

 <p>
If the first subform is a non-special name, however, then if the second
subform is on the same line, align the starting column of all following
subforms with that of the second subform.  If the second subform is on
the following line, align its starting column with that of the first
subform, and do the same for all remaining subforms.
</p>

 <p>
In general, Emacs will indent Lisp code correctly.  Run `C-M-q’
(indent-sexp) on any code to ensure that it is indented correctly, and
configure Emacs so that any non-standard forms are indented
appropriately.
</p>

 <p>
Unacceptable:
</p>

 <div class="jfw-code"> <pre>(+ (sqrt -1)
  (* x y)
  (+ p q))

(+
   (sqrt -1)
   (* x y)
   (+ p q))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Acceptable:
</p>

 <div class="jfw-code"> <pre>(+ (sqrt -1)
   (* x y)
   (+ p q))

(+
 (sqrt -1)
 (* x y)
 (+ p q))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Rationale:  The columnar alignment allows the reader to follow the
operands of any operation straightforwardly, simply by scanning
downward or upward to match a common column.  Indentation dictates
structure; confusing indentation is a burden on the reader who wishes
to derive structure without matching parentheses manually.
</p>
</div>
 <h4>Non-Symbol Indentation and Alignment  <a id="non-symbol-indentation-and-alignment" class="anchor" href="#non-symbol-indentation-and-alignment" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org35f8f80">
 <p>
The above rules are not exhaustive; some cases may arise with strange
data in operator positions.
</p>
</div>
 <ul> <li>Lists <div class="outline-text-5" id="text-org32afe79">
 <p>
Unfortunately, style varies here from person to person and from editor
to editor.  Here are some examples of possible ways to indent lists
whose operators are lists:
</p>

 <p>
Questionable:
</p>

 <div class="jfw-code"> <pre>((car x)                             <span class="org-comment-delimiter">;</span> <span class="org-comment">Requires hand indentation.
</span>   (cdr x)
   foo)

((car x) (cdr x)                     <span class="org-comment-delimiter">;</span> <span class="org-comment">GNU Emacs
</span> foo)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Preferable:
</p>

 <div class="jfw-code"> <pre>((car x)                             <span class="org-comment-delimiter">;</span> <span class="org-comment">Any Emacs
</span> (cdr x)
 foo)

((car x) (cdr x)                     <span class="org-comment-delimiter">;</span> <span class="org-comment">Edwin
</span>         foo)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Rationale:  The operands should be aligned, as if it were any other
procedure call with a name in the operator position; anything other
than this is confusing because it gives some operands greater visual
distinction, allowing others to hide from the viewer’s sight.  For
example, the questionable indentation
</p>

 <div class="jfw-code"> <pre>((car x) (cdr x)
 foo)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
can make it hard to see that FOO and (CDR X) are both operands here
at the same level.  However, GNU Emacs will generate that indentation
by default.  (Edwin will not.)
</p>
</div>
</li>
 <li>Strings <div class="outline-text-5" id="text-org245f78e">
 <p>
If the form in question is meant to be simply a list of literal data,
all of the subforms should be aligned to the same column, irrespective
of the first subform.
</p>

 <p>
Unacceptable:
</p>

 <div class="jfw-code"> <pre>( <span class="org-string">&quot;foo&quot;</span>  <span class="org-string">&quot;bar&quot;</span>  <span class="org-string">&quot;baz&quot;</span>  <span class="org-string">&quot;quux&quot;</span>  <span class="org-string">&quot;zot&quot;</span>
         <span class="org-string">&quot;mumble&quot;</span>  <span class="org-string">&quot;frotz&quot;</span>  <span class="org-string">&quot;gargle&quot;</span>  <span class="org-string">&quot;mumph&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Questionable, but acceptable:
</p>

 <div class="jfw-code"> <pre>(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4
   3 3 8 3 2 7 9 5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Acceptable:
</p>

 <div class="jfw-code"> <pre>( <span class="org-string">&quot;foo&quot;</span>  <span class="org-string">&quot;bar&quot;</span>  <span class="org-string">&quot;baz&quot;</span>  <span class="org-string">&quot;quux&quot;</span>  <span class="org-string">&quot;zot&quot;</span>
  <span class="org-string">&quot;mumble&quot;</span>  <span class="org-string">&quot;frotz&quot;</span>  <span class="org-string">&quot;gargle&quot;</span>  <span class="org-string">&quot;mumph&quot;</span>)

( <span class="org-string">&quot;foo&quot;</span>
  <span class="org-string">&quot;bar&quot;</span>  <span class="org-string">&quot;baz&quot;</span>  <span class="org-string">&quot;quux&quot;</span>  <span class="org-string">&quot;zot&quot;</span>
  <span class="org-string">&quot;mumble&quot;</span>  <span class="org-string">&quot;frotz&quot;</span>  <span class="org-string">&quot;gargle&quot;</span>  <span class="org-string">&quot;mumph&quot;</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Rationale:  Seldom is the first subform distinguished for any reason,
if it is a literal; usually in this case it indicates pure data, not
code.  Some editors and pretty-printers, however, will indent
unacceptably in the example given unless the second subform is on the
next line anyway, which is why the last way to write the fragment is
usually best.
</p>
</div>
</li></ul> <h3>Names  <a id="names" class="anchor" href="#names" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org86e9889">
 <p>
Naming is subtle and elusive.  Bizarrely, it is simultaneously
insignificant, because an object is independent of and unaffected by
the many names by which we refer to it, and also of supreme
importance, because it is what programming – and, indeed, almost
everything that we humans deal with – is all about.  A full
discussion of the concept of name lies far outside the scope of this
document, and could surely fill not even a book but a library.
</p>

 <p>
Symbolic names are written with English words separated by hyphens.
Scheme and Common Lisp both fold the case of names in programs;
consequently, camel case is frowned upon, and not merely because it is
ugly.  Underscores are unacceptable separators except for names that
were derived directly from a foreign language without translation.
</p>

 <p>
Unacceptable:
</p>

 <div class="jfw-code"> <pre>XMLHttpRequest
  foreach
  append_map</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
Acceptable:
</p>

 <div class="jfw-code"> <pre>xml-http-request
 for-each
 append-map</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h4>Funny Characters  <a id="funny-characters" class="anchor" href="#funny-characters" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org8a9e6b6">
 <p>
There are several different conventions in different Lisps for the use
of non-alphanumeric characters in names.
</p>
</div>
 <ul> <li>Scheme <ul> <li>Question Marks: Predicates <div class="outline-text-6" id="text-org83c99f1">
 <p>
Affix a question mark to the end of a name for a procedure whose
purpose is to ask a question of an object and to yield a boolean
answer.  Such procedures are called `predicates’.  Do not use a
question mark if the procedure may return any object other than a
boolean.
</p>

 <p>
Examples:  pair? procedure? proper-list?
Non-examples:  member assoc any every
</p>

 <p>
Pronounce the question mark as if it were the isolated letter `p’.  For
example, to read the fragment (PAIR? OBJECT) aloud, say: `pair-pee
object.’
</p>
</div>
</li>
 <li>Exclamation Marks: Destructive Operations <div class="outline-text-6" id="text-orgdb2a983">
 <p>
Affix an exclamation mark to the end of a name for a procedure (or
macro) whose primary purpose is to modify an object.  Such procedures
are called `destructive’.
</p>

 <p>
Examples: set-car! append!
</p>

 <p>
Avoid using the exclamation mark willy nilly for just  <b>any</b> procedure
whose operation involves any kind of mutation or side effect; instead,
use the exclamation mark to identify procedures that exist  <b>solely</b> for
the purpose of destructive update (e.g., SET-CAR!), or to distinguish a
destructive, or potentially destructive (in the case of linear-update
operations such as APPEND!), variant of a procedure of which there also
exists a purely functional variant (e.g., APPEND).
</p>

 <p>
Pronounce the exclamation mark as `bang’.  For example, to read the
fragment (APPEND! LIST TAIL) aloud, say: `append-bang list tail.’
</p>
</div>
</li>
 <li>Asterisks: Variants, Internal Routines, Mutable Globals <div class="outline-text-6" id="text-orgfd4f715">
 <p>
Affix an asterisk to the end of a name to make a variation on a theme
of the original name.
</p>

 <p>
Example: let -&gt; let*
</p>

 <p>
Prefer a meaningful name over an asterisk; the asterisk does not
explain what variation on the theme the name means.
</p>

 <p>
Affix an asterisk to the beginning of a name to make an internal
routine for that name.  Again, prefer a meaningful name over an
asterisk.
</p>

 <p>
Affix asterisks to the beginning and end of a globally mutable
variable.  This allows the reader of the program to recognize very
easily that it is badly written!
</p>
</div>
</li>
 <li>`WITH-’ and `CALL-WITH-’: Dynamic State and Cleanup <div class="outline-text-6" id="text-org988afd1">
 <p>
Prefix `WITH-’ to any procedure that establishes dynamic state and
calls a nullary procedure, which should be the last (required)
argument.  The dynamic state should be established for the extent of
the nullary procedure, and should be returned to its original state
after that procedure returns.
</p>

 <p>
Examples: with-input-from-file with-output-to-file
</p>

 <p>
Exception:  Some systems provide a procedure (WITH-CONTINUATION
&lt;continuation&gt; &lt;thunk&gt;), which calls &lt;thunk&gt; in the given
continuation, using that continuation’s dynamic state.  If &lt;thunk&gt;
returns, it will return to &lt;continuation&gt;, not to the continuation of
the call to WITH-CONTINUATION.  This is acceptable.
</p>

 <p>
Prefix `CALL-WITH-’ to any procedure that calls a procedure, which
should be its last argument, with some arguments, and is either somehow
dependent upon the dynamic state or continuation of the program, or
will perform some action to clean up data after the procedure argument
returns.  Generally, `CALL-WITH-’ procedures should return the values
that the procedure argument returns, after performing the cleaning
action.
</p>

 <p>
Examples:
</p>

 <ul class="org-ul"> <li>CALL-WITH-INPUT-FILE and CALL-WITH-OUTPUT-FILE both accept a
pathname and a procedure as an argument, open that pathname (for
input or output, respectively), and call the procedure with one
argument, a port corresponding with the file named by the given
pathname.  After the procedure returns, CALL-WITH-INPUT-FILE and
CALL-WITH-OUTPUT-FILE close the file that they opened, and return
whatever the procedure returned.</li>

 <li>CALL-WITH-CURRENT-CONTINUATION is dependent on the continuation
with which it was called, and passes as an argument an escape
procedure corresponding with that continuation.</li>

 <li>CALL-WITH-OUTPUT-STRING, a common but non-standard procedure
definable in terms of OPEN-OUTPUT-STRING and GET-OUTPUT-STRING from
SRFI 6 (Basic String Ports), calls its procedure argument with an
output port, and returns a string of all of the output written to
that port.  Note that it does not return what the procedure
argument returns, which is an exception to the above rule.</li>
</ul> <p>
Generally, the distinction between these two classes of procedures is
that `CALL-WITH-…’ procedures should not establish fresh dynamic
state and instead pass explicit arguments to their procedure arguments,
whereas `WITH-…’ should do the opposite and establish dynamic state
while passing zero arguments to their procedure arguments.
</p>
</div>
</li></ul></li></ul> <h3>Comments  <a id="comments" class="anchor" href="#comments" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5f1f299">
 <p>
Write heading comments with at least four semicolons; see also the
section below titled `Outline Headings’.
</p>

 <p>
Write top-level comments with three semicolons.
</p>

 <p>
Write comments on a particular fragment of code before that fragment
and aligned with it, using two semicolons.
</p>

 <p>
Write margin comments with one semicolon.
</p>

 <p>
The only comments in which omission of a space between the semicolon
and the text is acceptable are margin comments.
</p>

 <p>
Examples:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">;;;; </span> <span class="org-comment">Frob Grovel
</span>
 <span class="org-comment-delimiter">;;; </span> <span class="org-comment">This section of code has some important implications:
</span> <span class="org-comment-delimiter">;;;   </span> <span class="org-comment">1. Foo.
</span> <span class="org-comment-delimiter">;;;   </span> <span class="org-comment">2. Bar.
</span> <span class="org-comment-delimiter">;;;   </span> <span class="org-comment">3. Baz.
</span>
( <span class="org-keyword">define</span> ( <span class="org-function-name">fnord</span> zarquon)
   <span class="org-comment-delimiter">;; </span> <span class="org-comment">If zob, then veeblefitz.
</span>  (quux zot
        mumble              <span class="org-comment-delimiter">;</span> <span class="org-comment">Zibblefrotz.
</span>        frotz))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Riastradh’s Non-Standard Rules  <a id="riastradhrsquos-non-standard-rules" class="anchor" href="#riastradhrsquos-non-standard-rules" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgce54765">
 <p>
Three principles guide this style, roughly ordered according to
descending importance:
</p>

 <ol class="org-ol"> <li>The purpose of a program is to describe an idea, and not the way
that the idea must be realized; the intent of the program’s meaning,
rather than peripheral details that are irrelevant to its intent,
should be the focus of the program,  <b>irrespective</b> of whether a
human or a machine is reading it.  [It would be nice to express this
principle more concisely.]</li>

 <li>The sum of the parts is easier to understand than the whole.</li>

 <li>Aesthetics matters.  No one enjoys reading an ugly program.</li>
</ol></div>
 <h3>General Layout  <a id="general-layout" class="anchor" href="#general-layout" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org5117fa8">
 <p>
This section contains rules that the author has found generally helpful
in keeping his programs clean and presentable, though they are not
especially philosophically interesting.
</p>

 <p>
Contained in the rationale for some of the following rules are
references to historical limitations of terminals and printers, which
are now considered aging cruft of no further relevance to today’s
computers.  Such references are made only to explain specific measures
chosen for some of the rules, such as a limit of eighty columns per
line, or sixty-six lines per page.  There is a real reason for each of
the rules, and this real reason is not intrinsically related to the
historical measures, which are mentioned only for the sake of
providing some arbitrary measure for the limit.
</p>
</div>
 <h4>File Length  <a id="file-length" class="anchor" href="#file-length" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org2ae4bc9">
 <p>
If a file exceeds five hundred twelve lines, begin to consider
splitting it into multiple files.  Do not write program files that
exceed one thousand twenty-four lines.  Write a concise but
descriptive title at the top of each file, and include no content in
the file that is unrelated to its title.
</p>

 <p>
Rationale:  Files that are any larger should generally be factored
into smaller parts.  (One thousand twenty-four is a nicer number than
one thousand.)  Identifying the purpose of the file helps to break it
into parts if necessary and to ensure that nothing unrelated is
included accidentally.
</p>
</div>
 <h4>Top-Level Form Length  <a id="top-level-form-length" class="anchor" href="#top-level-form-length" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-orgce0ff12">
 <p>
Do not write top-level forms that exceed twenty-one lines, except for
top-level forms that serve only the purpose of listing large sets of
data.  If a procedure exceeds this length, split it apart and give
names to its parts.  Avoid names formed simply by appending a number
to the original procedure’s name; give meaningful names to the parts.
</p>

 <p>
Rationale:  Top-level forms, especially procedure definitions, that
exceed this length usually combine too many concepts under one name.
Readers of the code are likely to more easily understand the code if
it is composed of separately named parts.  Simply appending a number
to the original procedure’s name can help only the letter of the
rule, not the spirit, however, even if the procedure was taken from a
standard algorithm description.  Using comments to mark the code with
its corresponding place in the algorithm’s description is acceptable,
but the algorithm should be split up in meaningful fragments anyway.
</p>

 <p>
Rationale for the number twenty-one:  Twenty-one lines, at a maximum
of eighty columns per line, fits in a GNU Emacs instance running in a
24x80 terminal.  Although the terminal may have twenty-four lines,
three of the lines are occupied by GNU Emacs: one for the menu bar
(which the author of this guide never uses, but which occupies a line
nevertheless in a vanilla GNU Emacs installation), one for the mode
line, and one for the minibuffer’s window.  The writer of some code
may not be limited to such a terminal, but the author of this style
guide often finds it helpful to have at least four such terminals or
Emacs windows open simultaneously, spread across a twelve-inch laptop
screen, to view multiple code fragments.
</p>
</div>
 <h4>Line Length  <a id="line-length" class="anchor" href="#line-length" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org71cf944">
 <p>
Do not write lines that exceed eighty columns, or if possible
seventy-two.
</p>

 <p>
Rationale:  Following multiple lines that span more columns is
difficult for humans, who must remember the line of focus and scan
right to left from the end of the previous line to the beginning of
the next line; the more columns there are, the harder this is to do.
Sticking to a fixed limit helps to improve readability.
</p>

 <p>
Rationale for the numbers eighty and seventy-two:  It is true that we
have very wide screens these days, and we are no longer limited to
eighty-column terminals; however, we ought to exploit our wide
screens not by writing long lines, but by viewing multiple fragments
of code in parallel, something that the author of this guide does
very often.  Seventy-two columns leave room for several nested layers
of quotation in email messages before the code reaches eighty
columns.  Also, a fixed column limit yields nicer printed output,
especially in conjunction with pagination; see the section
`Pagination’ below.
</p>
</div>
 <h4>Blank Lines  <a id="blank-lines" class="anchor" href="#blank-lines" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org1963e09">
 <p>
Separate each adjacent top-level form with a single blank line (i.e.
two line breaks).  If two blank lines seem more appropriate, break the
page instead.  Do not place blank lines in the middle of a procedure
body, except to separate internal definitions; if there is a blank
line for any other reason, split the top-level form up into multiple
ones.
</p>

 <p>
Rationale:  More than one blank line is distracting and sloppy.  If
the two concepts that are separated by multiple blank lines are
really so distinct that such a wide separator is warranted, then
they are probably better placed on separate pages anyway; see the
next section, `Pagination’.
</p>
</div>
 <h4>Pagination  <a id="pagination" class="anchor" href="#pagination" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org54bde1f">
 <p>
Separate each file into pages of no more than sixty-six lines and no
fewer than forty lines with form feeds (ASCII #x0C, or ^L, written in
Emacs with `C-q C-l’), on either side of which is a single line break
(but not a blank line).
</p>

 <p>
Rationale:  Keeping distinct concepts laid out on separate pages
helps to keep them straight.  This is helpful not only for the
writer of the code, but also for the reader.  It also allows readers
of the code to print it onto paper without fiddling with printer
settings to permit pages of more than sixty-six lines (which is the
default number for many printers), and pagination also makes the
code easier to navigate in Emacs, with the `C-x [’ and `C-x ]’ keys
(`backward-page’ and `forward-page’, respectively).  To avoid
excessively small increments of page-by-page navigation, and to
avoid wasting paper, each page should generally exceed forty lines.
</p>

 <p>
`C-x l’ in Emacs will report the number of lines in the page on which
the point lies; this is useful for finding where pagination is
necessary.
</p>
</div>
 <h4>Outline Headings  <a id="outline-headings" class="anchor" href="#outline-headings" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org03ea641">
 <p>
Use Emacs’s Outline Mode to give titles to the pages, and if
appropriate a hierarchical structure.  Set `outline-regexp’ (or
`outline-pattern’ in Edwin) to “\f\n;;;;+ ”, so that each form feed
followed by an line break followed by at least four semicolons and a
space indicates an outline heading to Emacs.  Use four semicolons for
the highest level of headings in the hierarchy, and one more for each
successively nested level of hierarchy.
</p>

 <p>
Rationale:  Not only does this clarify the organization of the code,
but readers of the code can then navigate the code’s structure with
Outline Mode commands such as `C-c C-f’, `C-c C-b’, `C-c C-u’, and
`C-c C-d’ (forward, backward, up, down, respectively, headings).
</p>
</div>
 <h4>Dependencies  <a id="dependencies" class="anchor" href="#dependencies" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org1d31340">
 <p>
When writing a file or module, minimize its dependencies.  If there are
too many dependencies, consider breaking the module up into several
parts, and writing another module that is the sum of the parts and that
depends only on the parts, not their dependencies.
</p>

 <p>
Rationale:  A fragment of a program with fewer dependencies is less
of a burden on the reader’s cognition.  The reader can more easily
understand the fragment in isolation; humans are very good at local
analyses, and terrible at global ones.
</p>
</div>
 <h3>Naming  <a id="naming" class="anchor" href="#naming" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3ce14cd">
 <p>
This section requires an elaborate philosophical discussion which the
author is too ill to have the energy to write at this moment.
</p>

 <p>
Compose concise but meaningful names.  Do not cheat by abbreviating
words or using contractions.
</p>

 <p>
Rationale:  Abbreviating words in names does not make them shorter;
it only makes them occupy less screen space.  The reader still must
understand the whole long name.  This does not mean, however, that
names should necessarily be long; they should be descriptive.  Some
long names are more descriptive than some short names, but there are
also descriptive names that are not long and long names that are not
descriptive.  Here is an example of a long name that is not
descriptive, from SchMUSE, a multi-user simulation environment
written in MIT Scheme:
</p>

 <p>
frisk-descriptor-recursive-subexpr-descender-for-frisk-descr-env
</p>

 <p>
Not only is it long (sixty-four characters) and completely
impenetrable, but halfway through its author decided to abbreviate
some words as well!
</p>

 <p>
Do not write single-letter variable names.  Give local variables
meaningful names composed from complete English words.
</p>

 <p>
Rationale:  It is tempting to reason that local variables are
invisible to other code, so it is OK to be messy with their names.
This is faulty reasoning: although the next person to come along and
use a library may not care about anything but the top-level
definitions that it exports, this is not the only audience of the
code.  Someone will also want to read the code later on, and if it is
full of impenetrably terse variable names without meaning, that
someone will have a hard time reading the code.
</p>

 <p>
Give names to intermediate values where their expressions do not
adequately describe them.
</p>

 <p>
Rationale:  An `expression’ is a term that expresses some value.
Although a machine needs no higher meaning for this value, and
although it should be written to be sufficiently clear for a human to
understand what it means, the expression might mean something more
than just what it says where it is used.  Consequently, it is helpful
for humans to see names given to expressions.
</p>

 <p>
Example:  A hash table HASH-TABLE maps foos to bars; (HASH-TABLE/GET
HASH-TABLE FOO #F) expresses the datum that HASH-TABLE maps FOO to,
but that expression gives the reader no hint of any information
concerning that datum.  (LET ((BAR (HASH-TABLE/GET HASH-TABLE FOO
#F))) …)  gives a helpful name for the reader to understand the
code without having to find the definition of HASH-TABLE.
</p>

 <p>
Index variables such as i and j, or variables such as A and D naming
the car and cdr of a pair, are acceptable only if they are completely
unambiguous in the scope.  For example,
</p>

 <p>
(do ((i 0 (+ i 1)))
    ((= i (vector-length vector)))
  (frobnicate (vector-ref vector i)))
</p>

 <p>
is acceptable because the scope of i is very clearly limited to a
single vector.  However, if more vectors are involved, using more
index variables such as j and k will obscure the program further.
</p>

 <p>
Avoid functional combinators, or, worse, the point-free (or
`point-less’) style of code that is popular in the Haskell world.  At
most, use function composition only where the composition of functions
is the crux of the idea being expressed, rather than simply a procedure
that happens to be a composition of two others.
</p>

 <p>
Rationale:  Tempting as it may be to recognize patterns that can be
structured as combinations of functional combinators – say, `compose
this procedure with the projection of the second argument of that
other one’, or (COMPOSE FOO (PROJECT 2 BAR)) –, the reader of the
code must subsequently examine the elaborate structure that has been
built up to obscure the underlying purpose.  The previous fragment
could have been written (LAMBDA (A B) (FOO (BAR B))), which is in
fact shorter, and which tells the reader directly what argument is
being passed on to what, and what argument is being ignored, without
forcing the reader to search for the definitions of FOO and BAR or
the call site of the final composition.  The explicit fragment
contains substantially more information when intermediate values are
named, which is very helpful for understanding it and especially for
modifying it later on.
</p>

 <p>
The screen space that can be potentially saved by using functional
combinators is made up for by the cognitive effort on the part of the
reader.  The reader should not be asked to search globally for usage
sites in order to understand a local fragment.  Only if the structure
of the composition really is central to the point of the narrative
should it be written as such.  For example, in a symbolic integrator
or differentiator, composition is an important concept, but in most
code the structure of the composition is completely irrelevant to the
real point of the code.
</p>

 <p>
If a parameter is ignored, give it a meaningful name nevertheless and
say that it is ignored; do not simply call it `ignored’.
</p>

 <p>
In Common Lisp, variables can be ignored with (DECLARE (IGNORE …)).
Some Scheme systems have similar declarations, but the portable way to
ignore variables is just to write them in a command context, where
their values will be discarded, preferably with a comment indicating
this purpose:
</p>

 <p>
(define (foo x y z)
  x z                         ;ignore
  (frobnitz y))
</p>

 <p>
Rationale:  As with using functional combinators to hide names,
avoiding meaningful names for ignored parameters only obscures the
purpose of the program.  It is helpful for a reader to understand
what parameters a procedure is independent of, or if someone wishes
to change the procedure later on, it is helpful to know what other
parameters are available.  If the ignored parameters were named
meaninglessly, then these people would be forced to search for call
sites of the procedure in order to get a rough idea of what
parameters might be passed here.
</p>

 <p>
When naming top-level bindings, assume namespace partitions unless in a
context where they are certain to be absent.  Do not write explicit
namespace prefixes, such as FOO:BAR for an operation BAR in a module
FOO, unless the names will be used in a context known not to have any
kind of namespace partitions.
</p>

 <p>
Rationale:  Explicit namespace prefixes are ugly, and lengthen names
without adding much semantic content.  Common Lisp has its package
system to separate the namespaces of symbols; most Schemes have
mechanisms to do so as well, even if the RnRS do not specify any.  It
is better to write clear names which can be disambiguated if
necessary, rather than to write names that assume some kind of
disambiguation to be necessary to begin with.  Furthermore, explicit
namespace prefixes are inadequate to cover name clashes anyway:
someone else might choose the same namespace prefix.  Relegating this
issue to a module system removes it from the content of the program,
where it is uninteresting.
</p>
</div>
 <h3>Comments  <a id="comments" class="anchor" href="#comments" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgc6ffa9f">
 <p>
Write comments only where the code is incapable of explaining itself.
Prefer self-explanatory code over explanatory comments.  Avoid
`literate programming’ like the plague.
</p>

 <p>
Rationale:  If the code is often incapable of explaining itself, then
perhaps it should be written in a more expressive language.  This may
mean using a different programming language altogether, or, since we
are talking about Lisp, it may mean simply building a combinator
language or a macro language for the purpose.  `Literate programming’
is the logical conclusion of languages incapable of explaining
themselves; it is a direct concession of the inexpressiveness of the
computer language implementing the program, to the extent that the
only way a human can understand the program is by having it rewritten
in a human language.
</p>

 <p>
Do not write interface documentation in the comments for the
implementation of the interface.  Explain the interface at the top of
the file if it is a single-file library, or put that documentation in
another file altogether.  (See the `Documentation’ section below if the
interface documentation comments grow too large for a file.)
</p>

 <p>
Rationale:  A reader who is interested only in the interface really
should not need to read through the implementation to pick out its
interface; by putting the interface documentation at the top, not
only is such a reader’s task of identifying the interface made
easier, but the implementation code can be more liberally commented
without fear of distracting this reader.  To a reader who is
interested in the implementation as well, the interface is still
useful in order to understand what concepts the implementation is
implementing.
</p>

 <p>
Example:  <a href="http://mumble.net/~campbell/scheme/skip-list.scm">http://mumble.net/~campbell/scheme/skip-list.scm</a>
</p>

 <p>
In this example of a single-file library implementing the skip list
data structure, the first page explains the purpose and dependencies
of the file (which are useful for anyone who intends to use it, even
though dependencies are really implementation details), and the next
few pages explain the usage of skip lists as implemented in that
file.  On the first page of implementation, `Skip List Structure’,
there are some comments of interest only to a reader who wishes to
understand the implementation; the same goes for the rest of the
file, none of which must a reader read whose interest is only in the
usage of the library.
</p>

 <p>
Avoid block comments (i.e. #| … |#).  Use S-expression comments (`#;’
in Scheme, with the expression to comment on the next line; `#+(OR)’ or
`#-(AND)’ in Common Lisp) to comment out whole expressions.  Use blocks
of line comments for text.
</p>

 <p>
Rationale:  Editor support for block comments is weak, because it
requires keeping a detailed intermediate parse state of the whole
buffer, which most Emacsen do not do.  At the very least, #|| … ||#
is better, because most Emacsen will see vertical bars as symbol
delimiters, and lose trying to read a very, very long symbol, if they
try to parse #| … |#, whereas they will just see two empty symbols
and otherwise innocuous text between them if they try to parse #||
… ||#.  In any case, in Emacs, `M-x comment-region RET’, or `M-;’
(comment-dwim), is trivial to type.
</p>

 <p>
The only standard comments in Scheme are line comments.  There are
SRFIs for block comments and S-expression comments, but support for
them varies from system to system.  Expression comments are not hard
for editors to deal with because it is safe not to deal with them at
all; however, in Scheme S-expression comments, which are written by
prefixing an expression with `#;’, the expression to be commented
should be placed on the next line.  This is because editors that do
not deal with them at all may see the semicolon as the start of a
line comment, which will throw them off.  Expression comments in
Common Lisp, however, are always safe.
</p>

 <p>
In Common Lisp, the two read-time conditionals that are guaranteed to
ignore any form following them are `#+(OR)’ and `#-(AND)’.  `#+NIL’
is sometimes used in their stead, but, while it may appear to be an
obviously false conditional, it actually is not.  The feature
expressions are read in the KEYWORD package, so NIL is read not as
CL:NIL, i.e. the boolean false value, but as :NIL, a keyword symbol
whose name happens to be `NIL’.  Not only is it not read as the
boolean false value, but it has historically been used to indicate a
feature that might be enabled – in JonL White’s New Implementation
of Lisp!  However, the New Implementation of Lisp is rather old these
days, and unlikely to matter much…until Alastair Bridgewater writes
Nyef’s Implementation of Lisp.
</p>
</div>
 <h3>Documentation  <a id="documentation" class="anchor" href="#documentation" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0b70828">
 <p>
On-line references and documentation/manuals are both useful for
independent purposes, but there is a very fine distinction between
them.  Do not generate documentation or manuals automatically from the
text of on-line references.
</p>

 <p>
Rationale:  <i>On-line references</i> are quick blurbs associated with
objects in a running Lisp image, such as documentation strings in
Common Lisp or Emacs Lisp.  These assume that the reader is familiar
with the gist of the surrounding context, but unclear on details;
on-line references specify the details of individual objects.
</p>

 <p>
 <i>Documentation</i> and  <i>manuals</i> are fuller, organized, and cohesive
documents that explain the surrounding context to readers who are
unfamiliar with it.  A reader should be able to pick a manual up and
begin reading it at some definite point, perusing it linearly to
acquire an understanding of the subject.  Although manuals may be
dominated by reference sections, they should still have sections that
are linearly readable to acquaint the reader with context.
</p>
</div>
 <h3>Round and Square Brackets  <a id="round-and-square-brackets" class="anchor" href="#round-and-square-brackets" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgcc34ad3">
 <p>
Some implementations of Scheme provide a non-standard extension of the
lexical syntax whereby balanced pairs of square brackets are
semantically indistinguishable from balanced pairs of round brackets.
Do not use this extension.
</p>

 <p>
Rationale:  Because this is a non-standard extension, it creates
inherently non-portable code, of a nature much worse than using a
name in the program which is not defined by the R5RS.  The reason
that we have distinct typographical symbols in the first place is to
express different meaning.  The only distinction between round
brackets and square brackets is in convention, but the precise nature
of the convention is not specified by proponents of square brackets,
who suggest that they be used for `clauses’, or for forms that are
parts of enclosing forms.  This would lead to such constructions as
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let</span> [(x 5) (y 3)] ...)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
or
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let</span> ([x 5] [y 3]) ...)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>



 <p>
or
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">let</span> [[x 5] [y 3]] ...),</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
the first two of which the author of this guide has seen both of, and
the last of which does nothing to help to distinguish the parentheses
anyway.
</p>

 <p>
The reader of the code should not be forced to stumble over a
semantic identity because it is expressed by a syntactic distinction.
The reader’s focus should not be directed toward the lexical tokens;
it should be directed toward the structure, but using square brackets
draws the reader’s attention unnecessarily to the lexical tokens.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/podman-root-less-guix/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Podman root-less setup on GNU Guix</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/legendary-lisp-laptop/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Legendary Lisp Laptop - a modern Lisp machine with Framework laptop</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/scheme-and-lisp-style-guide/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/scheme-and-lisp-style-guide/index.html</guid>
  <pubDate>Thu, 19 Dec 2024 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Podman root-less setup on GNU Guix</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Note: There is a better way to go about this, Guix now contains  <code>rootless-podman-service-type</code> which will take care of it all pretty much for you. This article is thus outdated, and explains how we did things before that!
</p>

 <p>
Thanks Hugo Buddelmeijer for alerting me to that, he wrote a blog post here:  <a href="https://entropynaut.com/post/guixpodman/">https://entropynaut.com/post/guixpodman/</a>
</p>

 <p>
Have you ever heard about Docker ? Containerization has revolutionized the way we deploy and manage applications. By isolating processes and their dependencies, containers offer a lightweight and efficient solution for software deployment and help reproducibility.
</p>

 <p>
GNU Guix, a powerful and pure functional system and package manager, provides a robust foundation for building and managing software systems.
</p>

 <p>
By leveraging Podman, a daemonless container engine, we can achieve rootless containerization, enhancing security and flexibility.
</p>

 <p>
In this post I will explain what it takes to setup Podman in a root-less manner, for your user in Guix.
</p>

 <p>
Every engineer in anno 2024 ends up spinning a “Docker” container or two in their job or as a hobby, so for me it’s important to be able to do this seamlessly in my beloved Guix system, or as I have recently taken to calling it, Supreme Sexp System - see more  <a href="https://codeberg.org/jjba23/sss">here</a>.
</p>
 <h2>Why not Docker?  <a id="why-not-docker" class="anchor" href="#why-not-docker" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org37a6b9b">
 <p>
Podman is basically an upgrade in several fronts:
</p>

 <ul class="org-ul"> <li>Security</li>
 <li>Simplicity</li>
 <li>Modularity</li>
 <li>Consistency</li>
 <li>Features (pods, compose, kube, etc)</li>
</ul> <p>
Basically all the functionality of the docker, but a bit cleaner implementation and organization wise.
</p>
</div>
 <h2>Adding to Guix  <a id="adding-to-guix" class="anchor" href="#adding-to-guix" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org3fbfec9">
 <p>
Make sure to remove Docker installation first completely and then the  <code>docker</code> group from your users, if you previously used docker:
</p>

 <div class="jfw-code"> <pre>(user-account
  (name  <span class="org-string">&quot;joe&quot;</span>)
  (group  <span class="org-string">&quot;users&quot;</span>)
  (supplementary-groups '( <span class="org-string">&quot;wheel&quot;</span>  <span class="org-string">&quot;netdev&quot;</span>  <span class="org-string">&quot;audio&quot;</span>  <span class="org-string">&quot;video&quot;</span>  <span class="org-string">&quot;input&quot;</span>)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then we will need to allocate some sub-uids and sub-gids, and for that we create a  <code>etc-service</code> with Guix:
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span>  <span class="org-function-name">sss-joe-subuid</span>
(simple-service
 'podman-subuid-subgid
  <span class="org-comment-delimiter">;; </span> <span class="org-comment">If subuid/subgid will be needed somewhere else, the service must be
</span>  <span class="org-comment-delimiter">;; </span> <span class="org-comment">created to handle it.
</span> etc-service-type
 `(( <span class="org-string">&quot;subuid&quot;</span>
    ,(plain-file
       <span class="org-string">&quot;subuid&quot;</span>
      (string-append  <span class="org-string">&quot;joe&quot;</span>  <span class="org-string">&quot;:100000:65536\n&quot;</span>)))
   ( <span class="org-string">&quot;subgid&quot;</span>
    ,(plain-file
       <span class="org-string">&quot;subgid&quot;</span>
      (string-append  <span class="org-string">&quot;joe&quot;</span>  <span class="org-string">&quot;:100000:65536\n&quot;</span>))))))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <code>iptables</code> service or equivalent is necessary for networking in Podman:
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">define</span>  <span class="org-function-name">sss-iptables</span> (service iptables-service-type
                              (iptables-configuration)))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
You can feel free to also alias in your shell docker to podman, to help you rebuild muscle memory, e.g. .
</p>
 <div class="jfw-code"> <pre>alias docker-compose= <span class="org-string">&quot;podman-compose&quot;</span>
alias docker= <span class="org-string">&quot;podman&quot;</span>
alias podman-unix-socket= <span class="org-string">&quot;podman system service --time=0 unix:///tmp/podman.sock&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
For running with Testcontainers, one should use the Unix socket.
</p>

 <p>
 <code>podman system service --time=0 unix:///tmp/podman.sock</code>
</p>


 <p>
 <code>DOCKER_HOST</code> should be set to the socket you use, e.g.  <code>unix:///tmp/podman.sock</code>
</p>

 <p>
You can do this with Guix home or manually before running certain programs.
</p>

 <p>
You should also configure container registries and policies, for example with Guix Home:
</p>

 <div class="jfw-code"> <pre>`(( <span class="org-string">&quot;.config/containers/registries.conf&quot;</span>
          ,(plain-file
             <span class="org-string">&quot;registries.conf&quot;</span>
             <span class="org-string">&quot;unqualified-search-registries = ['docker.io', \
'registry.fedoraproject.org', \
'registry.access.redhat.com', \
'registry.centos.org']&quot;</span>))

         ( <span class="org-string">&quot;.config/containers/policy.json&quot;</span>
          ,(plain-file
             <span class="org-string">&quot;policy.json&quot;</span>
             <span class="org-string">&quot;{\&quot;default\&quot;: [{\&quot;type\&quot;: \&quot;insecureAcceptAnything\&quot;}]}&quot;</span>))    
         )</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
You will then need some packages from Guix packages:
</p>

 <div class="jfw-code"> <pre>slirp4netns podman podman-compose passt</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Testing  <a id="testing" class="anchor" href="#testing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org98f26a3">
 <p>
Make sure you reboot and have cleaned any previous trace of Docker.
</p>


 <p>
Check if things work then:
</p>

 <div class="jfw-code"> <pre>podman ps -a
podman run --rm alpine ls / -lia
podman images
podman ps -a
podman run -dt -p 8080:80/tcp httpd
podman stop -l
podman rm -l</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Or run your favourite integration test pipeline.
</p>
</div>
 <h2>Enjoy  <a id="enjoy" class="anchor" href="#enjoy" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcaa2f84">
 <p>
🎉 Now you should be set to run testcontainers, even with Ryuk. Otherwise make sure to tweak  <code>~/.testcontainers.properties</code>.
</p>

 <p>
Podman is in technical terms also superior and cleaner than Docker, as well as a more permissive license.
</p>

 <p>
Using a root-less setup (no sudo for docker) one achieve more stability and flexibility in the system.
</p>

 <p>
Podman is also daemon-less, which brings great benefits, but can be used via Unix sockets too on demand.
</p>
</div>
 <h2>More on this  <a id="more-on-this" class="anchor" href="#more-on-this" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org93bfd65">
 <p>
See the official documentation of Podman root-less here:
 <a href="https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md">https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md</a>
 <a href="https://github.com/containers/podman/blob/main/rootless.md">https://github.com/containers/podman/blob/main/rootless.md</a>
 <a href="https://opensource.com/article/19/2/how-does-rootless-podman-work">https://opensource.com/article/19/2/how-does-rootless-podman-work</a>
</p>
</div>
 <h3>Shoutout to Andrew!  <a id="shoutout-to-andrew" class="anchor" href="#shoutout-to-andrew" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org2f8645d">
 <p>
Make sure to check Andrew Tropin’s video for another great explanation on this interesting topic:
</p>

 <p>
 <a href="https://www.youtube.com/watch?v=CC7t7foYkko&amp;list=LL&amp;index=1&amp;t=305s">https://www.youtube.com/watch?v=CC7t7foYkko&amp;list=LL&amp;index=1&amp;t=305s</a>
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">YAML Schemas in Emacs with Eglot</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisp-style-guide/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Scheme &amp; Lisp Style Guide</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/podman-root-less-guix/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/podman-root-less-guix/index.html</guid>
  <pubDate>Tue, 10 Dec 2024 00:00:00 +0100</pubDate>
</item>
<item>
  <title>YAML Schemas in Emacs with Eglot</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Are you someone that enjoys Emacs and the amazing built-in package Eglot, which enables Emacs to provide intelligent completions and error reporting, linting, and more with language servers ?
</p>

 <p>
Are you ocasionally editing YAML files and would like to use JSON Schemas for YAML, get some feedback from Emacs, the right completions for a configuration file ?
</p>
 <h2>Almost a type system for YAML 💚  <a id="almost-a-type-system-for-yaml-" class="anchor" href="#almost-a-type-system-for-yaml-" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga0d1287">
 <p>
Let me introduce  <a href="https://github.com/redhat-developer/yaml-language-server">yaml-language-server</a> (easily installed from Nix too).
</p>

 <p>
By the way if you want to see advanced Eglot configuration check the manual or my own dotfiles at:  <a href="https://codeberg.org/jjba23/sss">https://codeberg.org/jjba23/sss</a>.
</p>

 <p>
Say no more, configure Eglot directly like below.
This will ensure you can load several schemas with semantic / domain meaning, but always have the  <code>yamllint</code> schema as fallback.
</p>
</div>
 <h2>Configuring Eglot  <a id="configuring-eglot" class="anchor" href="#configuring-eglot" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgdbbf9ba">
 <div class="jfw-code"> <pre>( <span class="org-keyword">setq-default</span> eglot-workspace-configuration
              '( <span class="org-builtin">:yaml</span> (  <span class="org-builtin">:format</span> ( <span class="org-builtin">:enable</span> t)
                         <span class="org-builtin">:validate</span> t
                         <span class="org-builtin">:hover</span> t
                         <span class="org-builtin">:completion</span> t
                         <span class="org-builtin">:schemas</span> (https://raw.githubusercontent.com/my-user/my-project/project.schema.yml [ <span class="org-string">&quot;project.yml&quot;</span>]
                                  https://json.schemastore.org/yamllint.json [ <span class="org-string">&quot;/*.yml&quot;</span>])
                         <span class="org-builtin">:schemaStore</span> ( <span class="org-builtin">:enable</span> t))
                  <span class="org-comment-delimiter">;; </span> <span class="org-comment">here other language server configurations
</span>                ))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>


 <p>
And have Eglot start  <code>yaml-language-server --stdio</code> automatically.
</p>

 <p>
See the language server’s documentation for more details on how to load YAML schemas from various sources, even declaratively in the YAML file itself.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-registers/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Emacs registers - a god-send for your day job</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/podman-root-less-guix/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Podman root-less setup on GNU Guix</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/index.html</guid>
  <pubDate>Thu, 05 Dec 2024 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Emacs registers - a god-send for your day job</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Ever had to work very long files, in projects that you are not familiar with, and felt very lost, without an anchor point?
</p>

 <p>
Enter Emacs and its registry system, which allows you to “bookmark” locations of a file (buffer) and return to them, and much much more!
</p>
 <h2>Registers  <a id="registers" class="anchor" href="#registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga685c38">
 <p>
Emacs registers are places you can save text or positions for later use. Text and rectangles saved in registers can be copied into the buffer once or many times; you can move point to a position saved in a register.
</p>

 <p>
Each register has a name which is a single character. A register can store a piece of text, a rectangle, a position, a window configuration or a file name, but only one thing at any given time. Whatever you store in a register remains there until you store something else in that register. To see what a register r contains, use  <code>M-x view-register</code>.
</p>

 <p>
 <code>M-x view-register RET r</code>
Display a description of what register r contains.
</p>
</div>
 <h2>Saving Positions in Registers  <a id="saving-positions-in-registers" class="anchor" href="#saving-positions-in-registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org7a5b5f7">
 <p>
Saving a position records a spot in a buffer so that you can move back there later. Moving to a saved position reselects that buffer and moves point to that spot.
</p>

 <p>
 <code>C-x r SPC r</code>
Save position of point in register r (point-to-register).
 <code>C-x r j r</code>
Jump to the position saved in register r (jump-to-register).
To save the current position of point in a register, choose a name r and type  <code>C-x r SPC r</code>. The register r retains the position thus saved until you store something else in that register.
</p>

 <p>
The command  <code>C-x r j r</code> moves point to the position recorded in register r. The register is not affected; it continues to record the same position. You can jump to the same position using the same register any number of times.
</p>
</div>
 <h2>Saving Text in Registers  <a id="saving-text-in-registers" class="anchor" href="#saving-text-in-registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org28ab863">
 <p>
When you want to insert a copy of the same piece of text several times, it may be inconvenient to yank it from the kill ring, since each subsequent kill moves that entry further down the ring. An alternative is to store the text in a register with  <code>C-x r s (copy-to-register)</code> and then retrieve it with  <code>C-x r i (insert-register)</code>.
</p>

 <p>
 <code>C-x r s r</code>
Copy region into register r  <code>(copy-to-register)</code>.
 <code>C-x r i r</code>
Insert text from register r  <code>(insert-register)</code>.
 <code>C-x r s r</code> stores a copy of the text of the region into the register named r. Given a numeric argument,  <code>C-x r s r</code> deletes the text from the buffer as well.
</p>

 <p>
 <code>C-x r i r</code> inserts in the buffer the text from register r. Normally it leaves point before the text and places the mark after, but with a numeric argument  <code>C-u</code> it puts point after the text and the mark before.
</p>
</div>
 <h2>Saving Rectangles in Registers  <a id="saving-rectangles-in-registers" class="anchor" href="#saving-rectangles-in-registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb7106ae">
 <p>
A register can contain a rectangle instead of linear text. The rectangle is represented as a list of strings. See section Rectangles, for basic information on how to specify a rectangle in the buffer.
</p>

 <p>
 <code>C-x r r r</code>
Copy the region-rectangle into register r (copy-region-to-rectangle). With numeric argument, delete it as well.
 <code>C-x r i r</code>
Insert the rectangle stored in register r (if it contains a rectangle) (insert-register).
</p>

 <p>
The  <code>C-x r i r</code> command inserts a text string if the register contains one, and inserts a rectangle if the register contains one.
</p>
</div>
 <h2>Saving Window Configurations in Registers  <a id="saving-window-configurations-in-registers" class="anchor" href="#saving-window-configurations-in-registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org8c870f9">
 <p>
You can save the window configuration of the selected frame in a register, or even the configuration of all frames, and restore the configuration later.
</p>

 <p>
 <code>C-x r w r</code>
Save the state of the selected frame’s windows in register r (window-configuration-to-register).
 <code>C-x r f r</code>
Save the state of all windows in all frames in register r (frame-configuration-to-register).
</p>

 <p>
Use  <code>C-x r j r</code> to restore a window or frame configuration. This is the same command used to restore a cursor position. When you restore a frame configuration, any existing frames not included in the configuration become invisible. If you wish to delete these frames instead, use C-u C-x r j r.
</p>
</div>
 <h2>Keeping File Names in Registers  <a id="keeping-file-names-in-registers" class="anchor" href="#keeping-file-names-in-registers" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcfcde0a">
 <p>
If you visit certain file names frequently, you can visit them more conveniently if you put their names in registers. Here’s the Lisp code used to put a file name in a register:
</p>

 <p>
 <code>(set-register ?r '(file . name))</code>
For example,
</p>

 <p>
 <code>(set-register ?z '(file . &quot;/gd/gnu/emacs/19.0/src/ChangeLog&quot;))</code>
puts the file name shown in register `z’.
</p>

 <p>
To visit the file whose name is in register r, type  <code>C-x r j r</code>. (This is the same command used to jump to a position or restore a frame configuration.)
</p>

 <p>
Go to the previous, next section.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Brief aan mijzelf</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">YAML Schemas in Emacs with Eglot</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/emacs-registers/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/emacs-registers/index.html</guid>
  <pubDate>Wed, 14 Aug 2024 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Brief aan mijzelf</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Lieve Joe,
</p>

 <p>
Jij en ik weten dat levend zijn pieken en dalen betekent.
Alles wat je heb meegemaakt heeft dit een volle, veelzijdige, maar gezellige bus.
</p>

 <p>
In deze bus zitten heel veel Joe's: doelgerichte Joe, aan de kant duwen Joe, vechter, niet-empatisch, idealistisch, hoge verwachtingen, hoge lat, inspirerend, hulpzaam, creatief, chill, zal goed komen, etc.
</p>

 <p>
Het is waar, vaak staat gladiator Joe voorin de bus, vooral als iemand of iets in de weg zit van doelgerichte Joe. Vaak wurgt ie zijn weg en toont weinig empathie en emoties, terwijl het allemaal heel veel pijn doet.
</p>

 <p>
En dus, dit maakt het moeilijk om behulpzaam, lief en chill zijn met anderen, terwijl je dat heel graag ook wil.
</p>

 <p>
Laten we afspreken dat je een ambitieuze krijger blijft, omdat dat je zoveel heeft opgeleverd in het leven, en omdat uphill battles en battles in het algemeen jou zo motiveren.
</p>

 <p>
Maar wees een inspirerend kracht, relativeer, blijf idealistisch, en &quot;true to yourself&quot;, help anderen, neem meer tijd om de anderen te leren kennen, en hun emoties ook. Hoe moeilijk dat ook is.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Free à la Carte</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-registers/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Emacs registers - a god-send for your day job</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/">jointhefreeworld - A Style Guide for Documentation</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/">Mètsàtron's astral analysis of Joe's being</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/index.html</guid>
  <pubDate>Tue, 18 Jun 2024 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Free à la Carte</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Free monads based on  from intuitions from the Data types à la Carte paper. Combine functors and make embedded DSLs in Haskell.
</p>

 <p>
See the original paper, by Wouter Swierstra:  <a href="https://webspace.science.uu.nl/~swier004/publications/2008-jfp.pdf">https://webspace.science.uu.nl/~swier004/publications/2008-jfp.pdf</a> .
</p>

 <p>
See the Haskell library I built around it:  <a href="https://codeberg.org/jjba23/free-alacarte">https://codeberg.org/jjba23/free-alacarte</a> .
</p>
 <h2>How do you use this ?  <a id="how-do-you-use-this-" class="anchor" href="#how-do-you-use-this-" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org58bbbbf">
 <p>
This section gives a brief demonstration of using free monads to model effects.
</p>

 <p>
Four effectful functions are defined, categorized into two separate data types.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">Teletype</span> a
   <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">GetChar</span> ( <span class="org-haskell-constructor">Char</span>  <span class="org-haskell-operator">-&gt;</span> a)
   <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">PutChar</span>  <span class="org-haskell-constructor">Char</span> a
   <span class="org-haskell-keyword">deriving</span> ( <span class="org-haskell-constructor">Functor</span>)

 
 <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">FileSystem</span> a
   <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">ReadFile</span>  <span class="org-haskell-constructor">FilePath</span> ( <span class="org-haskell-constructor">String</span>  <span class="org-haskell-operator">-&gt;</span> a)
   <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">WriteFile</span>  <span class="org-haskell-constructor">FilePath</span>  <span class="org-haskell-constructor">String</span> a
   <span class="org-haskell-keyword">deriving</span> ( <span class="org-haskell-constructor">Functor</span>)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If you are into it, you can also write the Functor instances by hand, for your free monads, e.g.:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">instance</span>  <span class="org-haskell-type">Functor</span>  <span class="org-haskell-type">Teletype</span>  <span class="org-haskell-keyword">where</span>
  fmap  <span class="org-haskell-operator">::</span> (a  <span class="org-haskell-operator">-&gt;</span> b)  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Teletype</span> a  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Teletype</span> b
  fmap f  <span class="org-haskell-operator">=</span>  <span class="org-haskell-operator">\</span> <span class="org-haskell-keyword">case</span>
     <span class="org-haskell-constructor">GetChar</span> g    <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-constructor">GetChar</span> (f  <span class="org-haskell-operator">.</span> g)
     <span class="org-haskell-constructor">PutChar</span> c g  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-constructor">PutChar</span> c (f g)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
An  <code>exec</code> function can execute values of these data types using the  <code>Free</code> free monad. This uses intuitions of category theory to describe imperative sequence of computations as a fold over a functor.  <b>NOTE</b>: the  <code>exec</code> function is provided by this library and you don’t need to implement it yourself.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">exec</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Exec</span> f  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Free</span> f a  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">IO</span> a
 <span class="org-haskell-definition">exec</span>  <span class="org-haskell-operator">=</span> foldFree return execAlgebra</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You should then write the  <code>Exec</code> instances, in other words, the concrete implementations.
 <b>NOTE</b>: the typeclass  <code>Exec</code>, and  <code>Exec (f :+: g)</code> instance are also provided by this library, and you don’t need to implement it yourself.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">class</span>  <span class="org-haskell-type">Functor</span> f  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Exec</span> f  <span class="org-haskell-keyword">where</span>
  execAlgebra  <span class="org-haskell-operator">::</span> f ( <span class="org-haskell-type">IO</span> a)  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">IO</span> a

 <span class="org-haskell-keyword">instance</span> ( <span class="org-haskell-type">Exec</span> f,  <span class="org-haskell-type">Exec</span> g)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Exec</span> (f  <span class="org-haskell-type">:+:</span> g)  <span class="org-haskell-keyword">where</span>
  execAlgebra  <span class="org-haskell-operator">=</span>  <span class="org-haskell-operator">\</span> <span class="org-haskell-keyword">case</span>
     <span class="org-haskell-constructor">Left'</span> e  <span class="org-haskell-operator">-&gt;</span> execAlgebra e
     <span class="org-haskell-constructor">Right'</span> e  <span class="org-haskell-operator">-&gt;</span> execAlgebra e</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then you can write the actual implementations of those effects:
</p>
 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">instance</span>  <span class="org-haskell-type">Exec</span>  <span class="org-haskell-type">Teletype</span>  <span class="org-haskell-keyword">where</span>
  execAlgebra  <span class="org-haskell-operator">=</span>  <span class="org-haskell-operator">\</span> <span class="org-haskell-keyword">case</span>
     <span class="org-haskell-constructor">GetChar</span> f     <span class="org-haskell-operator">-&gt;</span> Prelude.getChar  <span class="org-haskell-operator">&gt;&gt;=</span> f
     <span class="org-haskell-constructor">PutChar</span> c io  <span class="org-haskell-operator">-&gt;</span> Prelude.putChar c  <span class="org-haskell-operator">&gt;&gt;</span> io

  
 <span class="org-haskell-keyword">instance</span>  <span class="org-haskell-type">Exec</span>  <span class="org-haskell-type">FileSystem</span>  <span class="org-haskell-keyword">where</span>
  execAlgebra ( <span class="org-haskell-constructor">ReadFile</span> path f)  <span class="org-haskell-operator">=</span> Prelude.readFile path  <span class="org-haskell-operator">&gt;&gt;=</span> f
  execAlgebra ( <span class="org-haskell-constructor">WriteFile</span> path s f)  <span class="org-haskell-operator">=</span> Prelude.writeFile path s  <span class="org-haskell-operator">&gt;&gt;</span> f</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then we can define some smart constructors to create our embedded DSL and save us some boilerplate, while adding syntactic sugar.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">getChar</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">Teletype</span>  <span class="org-haskell-type">:&lt;:</span> f)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Free</span> f  <span class="org-haskell-type">Char</span>
 <span class="org-haskell-definition">getChar</span>  <span class="org-haskell-operator">=</span> injectFree ( <span class="org-haskell-constructor">GetChar</span>  <span class="org-haskell-constructor">Pure</span>)

 <span class="org-haskell-definition">putChar</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">Teletype</span>  <span class="org-haskell-type">:&lt;:</span> f)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">Char</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Free</span> f  <span class="org-haskell-constructor">()</span>
 <span class="org-haskell-definition">putChar</span> c  <span class="org-haskell-operator">=</span> injectFree ( <span class="org-haskell-constructor">PutChar</span> c ( <span class="org-haskell-constructor">Pure</span>  <span class="org-haskell-constructor">()</span>))

 <span class="org-haskell-definition">readFile</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">FileSystem</span>  <span class="org-haskell-type">:&lt;:</span> f)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">FilePath</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Free</span> f  <span class="org-haskell-type">String</span>
 <span class="org-haskell-definition">readFile</span> path  <span class="org-haskell-operator">=</span> injectFree ( <span class="org-haskell-constructor">ReadFile</span> path  <span class="org-haskell-constructor">Pure</span>)

 <span class="org-haskell-definition">writeFile</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">FileSystem</span>  <span class="org-haskell-type">:&lt;:</span> f)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">FilePath</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">String</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Free</span> f  <span class="org-haskell-constructor">()</span>
 <span class="org-haskell-definition">writeFile</span> path s  <span class="org-haskell-operator">=</span> injectFree ( <span class="org-haskell-constructor">WriteFile</span> path s ( <span class="org-haskell-constructor">Pure</span>  <span class="org-haskell-constructor">()</span>))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The  <code>cat</code> function serves as an example of composition. In the following, I use a more general type than that used in the paper. Here we use  <code>mapM_</code> instead of  <code>mapM</code> to discard the resulting list of unit.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">cat</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">FileSystem</span>  <span class="org-haskell-type">:&lt;:</span> f,  <span class="org-haskell-type">Teletype</span>  <span class="org-haskell-type">:&lt;:</span> f)  <span class="org-haskell-operator">=&gt;</span>  <span class="org-haskell-type">FilePath</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Free</span> f  <span class="org-haskell-constructor">()</span>
 <span class="org-haskell-definition">cat</span> path  <span class="org-haskell-operator">=</span> mapM_ putChar  <span class="org-haskell-operator">=&lt;&lt;</span> readFile path</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The following example uses the  <code>cat</code> function to print the content of the README.md file in this directory.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">main</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">IO</span>  <span class="org-haskell-constructor">()</span>
 <span class="org-haskell-definition">main</span>  <span class="org-haskell-operator">=</span> exec  <span class="org-haskell-operator">@</span>( <span class="org-haskell-constructor">FileSystem</span>  <span class="org-haskell-constructor">:+:</span>  <span class="org-haskell-constructor">Teletype</span>)  <span class="org-haskell-operator">$</span> cat  <span class="org-string">&quot;README.md&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>More on the topic  <a id="more-on-the-topic" class="anchor" href="#more-on-the-topic" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbc43ee0">
 <p>
I can only extremely recommend the following resources to gain more understanding about the ideas and intuitions behind this library, and behind Data types à la Carte.
</p>

 <ul class="org-ul"> <li>Original paper, by Wouter Swierstra:  <a href="https://webspace.science.uu.nl/~swier004/publications/2008-jfp.pdf">https://webspace.science.uu.nl/~swier004/publications/2008-jfp.pdf</a></li>
 <li>Powerpoint explanation, by Wouter Swierstra:  <a href="https://webspace.science.uu.nl/~swier004/talks/2018-fp-ams.pdf">https://webspace.science.uu.nl/~swier004/talks/2018-fp-ams.pdf</a></li>
 <li>Good alternative explanation and implementation, by Travis Cardwell:  <a href="https://www.extrema.is/blog/2022/04/04/data-types-a-la-carte">https://www.extrema.is/blog/2022/04/04/data-types-a-la-carte</a></li>
</ul></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/black-box-testing/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Black Box Testing in modern Software</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Brief aan mijzelf</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/">Running Hoogle locally</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/">Type safety back and forth</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/">Why Haskell is important?</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/free-alacarte/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/free-alacarte/index.html</guid>
  <pubDate>Sun, 21 Apr 2024 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Black Box Testing in modern Software</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Testing software at a high level means freedom of implementation and refactoring, while maintaining guarantees of correctness. This is something all good engineers love 💘
</p>

 <blockquote>
 <p>
Black-box testing is a method of software testing that examines the functionality of an application without peering into its internal structures or workings.
</p>
</blockquote>

 <p>
In my opinion, for complex systems and system interactions, one should default to writing a lot of black-box tests, and some unit tests where it makes sense, and leave other kinds of integration tests out of scope, until it might make sense.
</p>


 <div id="orga163210" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://jointhefreeworld.org/resources/images/black-box-testing.png"></img></p>
</div>
 <h2>Black box tests are the best at BDD  <a id="black-box-tests-are-the-best-at-bdd" class="anchor" href="#black-box-tests-are-the-best-at-bdd" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4909263">
 <p>
Black box tests stimulate functional, requirement and behaviour driven testing.
</p>

 <p>
Testing a system becomes simpler and we can cover many more “real” edge cases.
</p>
</div>
 <h2>Unit testing still has its place  <a id="unit-testing-still-has-its-place" class="anchor" href="#unit-testing-still-has-its-place" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1730ced">
 <p>
Unit testing is an invaluable tool that should also be used in parallel to black box tests and other high level tests.
</p>

 <p>
These tests are very easy to use, useful and give also good information about a system.
</p>

 <p>
Ideally, your “core domain” should be fully tested, and your “business logic” should be encoded in more pure code, ideally as data.
</p>
</div>
 <h2>Dealing with dependencies  <a id="dealing-with-dependencies" class="anchor" href="#dealing-with-dependencies" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgbb86f73">
 <p>
When we start using external dependencies in a system like databases, caches, external APIs, etc.
You have 3 choices:
</p>
 <ul class="org-ul"> <li>create and use mocks</li>
 <li>create and use stubs (dummy implementations)</li>
 <li>use real dependencies</li>
</ul></div>
 <h3>Mocks are inherently evil  <a id="mocks-are-inherently-evil" class="anchor" href="#mocks-are-inherently-evil" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0c97245">
 <p>
Mocks are generally painful to write, read, debug and maintain.
</p>

 <p>
They should be avoided when possible, we should use real implementations for most tests to a system.
testcontainers is a great library for this purpose, and I use it extensively.
</p>
</div>
 <h3>Java baggage  <a id="java-baggage" class="anchor" href="#java-baggage" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgc5761c9">
 <p>
Lots of developers coming from a traditional enterprisy JDK environment know what we mean.
</p>

 <p>
This tendency of doing one class per file, and creating tests for every single class and every single method along with extensive Mockito ideology.
</p>
</div>
 <h2>The cure  <a id="the-cure" class="anchor" href="#the-cure" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4691579">
 <p>
No marrying the test structure to code structure. No testing every individual class when not needed.
</p>

 <p>
Ensure we test functionalities, almost never test how the code is written / implemented (this gives flexibility and freedom to refactor).
</p>

 <p>
Write many black box tests. Attempt to test all “user paths” and possible interactions with the system, good and bad, happy and unhappy, low load high load, etc.
</p>

 <p>
Writing many unit tests where it makes sense. Preferably using data generators, property based, or auto-generated test cases, with a set of inputs.
</p>
</div>
 <h2>What’s in it for me ?  <a id="whatrsquos-in-it-for-me-" class="anchor" href="#whatrsquos-in-it-for-me-" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org644000b">
 <p>
Easier and simpler tests of the entire system, tests have lower complexity.
</p>

 <p>
Easy to cover 100% of a “user flow” or a “data flow”.
</p>

 <p>
Low chance of false positives (partly thanks to avoiding mocks too).
</p>

 <p>
This allows for a good test-driven development approach, and more confidence in product.
</p>

 <p>
Testers require less technical knowledge, programming or IT skills and do not need to learn all nitty gritty implementation details of the system.
</p>

 <p>
More loose coupling from the code means more freedom of implementation + refactor.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-nixos-with-web-based-saml/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Open VPN 3 on NixOS with Web-based SAML</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Free à la Carte</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/black-box-testing/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/black-box-testing/index.html</guid>
  <pubDate>Tue, 27 Feb 2024 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Open VPN 3 on NixOS with Web-based SAML</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>OpenVPN 3 on NixOS with Web-based SAML  <a id="openvpn-3-on-nixos-with-web-based-saml" class="anchor" href="#openvpn-3-on-nixos-with-web-based-saml" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org655bc48">
 <p>
Recently at work we migrated from a simple OpenVPN profile with AWS credentials to a profile that authenticates based on SAML via your browser.
</p>

 <p>
Worth noting, SAML web-based authentication for OpenVPN only works with OpenVPN 3. This means that we need OpenVPN 3 now running, and also that you can’t run the VPN as a systemd service unfortunately.
</p>

 <p>
I got it working previously with Void Linux, but I have since moved to NixOS, my love 💘.
</p>

 <p>
I was struggling for a while in finding the best way to run the VPN with NixOS in the nicest way possible. This solution likely also applies to people running the Nix package manager in other distros, though I have not tested that.
</p>

 <p>
The solution is quite simple and reliable thanks to Nix, and way simpler than my other attempts in other distros, having to even build OpenVPN from source.
</p>

 <p>
All you need to do, is in your  <code>/etc/nixos/configuration.nix</code> to add the  <code>openvpn3</code> package to the list of system programs to install.
</p>

 <div class="jfw-code"> <pre>environment.systemPackages = with pkgs; [
  # ........ 
  openvpn3
];</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then, and very importantly, you need to add a line that enables the OpenVPN3 client.
</p>

 <div class="jfw-code"> <pre>programs.openvpn3.enable = true;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I highly recommend using the NixOS package and option search website, e.g.  <a href="https://search.nixos.org">https://search.nixos.org</a> . This is also extremely useful when searching on how to best configure your Nix systems.
</p>

 <p>
I then usually create a shell alias to start the VPN I want and auto auth with the browser. For me, using Fish shell and configuring it via Nix, this looks something like the following:
</p>

 <div class="jfw-code"> <pre>programs.fish.shellAliases = {
  zd-vpn = &quot;openvpn3 session-start --config ~/Documenten/my-vpn-file.ovpn &amp;&amp; openvpn3 session-auth&quot;;
};</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then just run your command, and your browser should open automatically and authenticate.
</p>

 <p>
Send me a mail if you have any questions or comments.
Stay positive, sharp, critical, caring for one another, and loving Nix &amp; reproducible systems.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/windows-11-bootable-usb-from-gnu-linux/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Create a Windows 11 bootable USB from GNU Linux</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/black-box-testing/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Black Box Testing in modern Software</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-nixos-with-web-based-saml/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-nixos-with-web-based-saml/index.html</guid>
  <pubDate>Fri, 03 Nov 2023 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Create a Windows 11 bootable USB from GNU Linux</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Below is the procedure for creating a bootable USB flash drive with Windows 11. The same process should also work with any HDD/SSD connected to your system.
</p>
 <h2>Download Windows 11 image  <a id="download-windows-11-image" class="anchor" href="#download-windows-11-image" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6b1c8f9">
 <p>
 <a href="https://www.microsoft.com/software-download/windows11">https://www.microsoft.com/software-download/windows11</a>
</p>

 <div class="jfw-code"> <pre>sha256sum Win11_English_x64v1.iso
4bc6c7e7c61af4b5d1b086c5d279947357cff45c2f82021bb58628c2503eb64e  Win11_English_x64v1.iso</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Plug your USB flash drive  <a id="plug-your-usb-flash-drive" class="anchor" href="#plug-your-usb-flash-drive" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga4ff9a6">
 <p>
Linux detected  <code>/dev/sda</code> as the USB stick, in your case it will most likely take a different name.
</p>
</div>
 <h2>Format your USB flash drive  <a id="format-your-usb-flash-drive" class="anchor" href="#format-your-usb-flash-drive" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcc99e94">
 <p>
Work as root account and make sure to replace /dev/sda with your USB flash drive!
Use lsblk and dmesg | tail -50 commands to locate your USB flash drive.
</p>

 <div class="jfw-code"> <pre>sudo wipefs -a /dev/sda
sudo parted /dev/sda
(parted) mklabel gpt                                                      
(parted) mkpart BOOT fat32 0% 1GiB
(parted) mkpart INSTALL ntfs 1GiB 10GiB
(parted) quit</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Check the drive layout now:
</p>

 <p>
In my case I’ve used 100% instead of 10GiB when created the “INSTALL” ntfs partition - mkpart INSTALL ntfs 1GiB 100%. But you can use anything that should be larger than 6 GiB to fit the data from Windows ISO image.
</p>

 <div class="jfw-code"> <pre>sudo parted /dev/sda unit B print
Model: SanDisk Extreme (scsi)
Disk /dev/sda: 62742792192B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start        End           Size          File system  Name     Flags
1      1048576B     1073741823B   1072693248B                BOOT     msftdata
2      1073741824B  62742593535B  61668851712B               INSTALL  msftdata</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Mount Windows ISO somewhere  <a id="mount-windows-iso-somewhere" class="anchor" href="#mount-windows-iso-somewhere" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgd089b93">
 <p>
I mounted it to /mnt/iso directory:
</p>

 <div class="jfw-code"> <pre>sudo mkdir /mnt/iso
sudo mount /home/&lt;your user&gt;/Downloads/Win11_English_x64v1.iso /mnt/iso/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Format 1st partition of your USB flash drive as FAT32  <a id="format-1st-partition-of-your-usb-flash-drive-as-fat32" class="anchor" href="#format-1st-partition-of-your-usb-flash-drive-as-fat32" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5033577">
 <div class="jfw-code"> <pre>sudo mkfs.vfat -n BOOT /dev/sda1
sudo mkdir /mnt/vfat
sudo mount /dev/sda1 /mnt/vfat/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Copy everything from Windows ISO image except for the sources directory there  <a id="copy-everything-from-windows-iso-image-except-for-the-sources-directory-there" class="anchor" href="#copy-everything-from-windows-iso-image-except-for-the-sources-directory-there" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6c5a27a">
 <div class="jfw-code"> <pre>sudo rsync -r --progress --exclude sources --delete-before /mnt/iso/ /mnt/vfat/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Copy only boot.wim file from the sources directory, while keeping the same path layout  <a id="copy-only-bootwim-file-from-the-sources-directory-while-keeping-the-same-path-layout" class="anchor" href="#copy-only-bootwim-file-from-the-sources-directory-while-keeping-the-same-path-layout" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgecbbb0f">
 <div class="jfw-code"> <pre>sudo mkdir /mnt/vfat/sources
sudo cp /mnt/iso/sources/boot.wim /mnt/vfat/sources/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Format 2nd partition of your USB flash drive as NTFS  <a id="format-2nd-partition-of-your-usb-flash-drive-as-ntfs" class="anchor" href="#format-2nd-partition-of-your-usb-flash-drive-as-ntfs" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org8031c87">
 <div class="jfw-code"> <pre>sudo mkfs.ntfs --quick -L INSTALL /dev/sda2 
sudo mkdir /mnt/ntfs
sudo mount /dev/sda2 /mnt/ntfs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Copy everything from Windows ISO image there  <a id="copy-everything-from-windows-iso-image-there" class="anchor" href="#copy-everything-from-windows-iso-image-there" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4a878fb">
 <div class="jfw-code"> <pre>sudo rsync -r --progress --delete-before /mnt/iso/ /mnt/ntfs/</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Unmount the USB flash drive and Windows ISO image  <a id="unmount-the-usb-flash-drive-and-windows-iso-image" class="anchor" href="#unmount-the-usb-flash-drive-and-windows-iso-image" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb462dcf">
 <div class="jfw-code"> <pre>sudo umount /mnt/ntfs
sudo umount /mnt/vfat
sudo umount /mnt/iso
sudo sync</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Power off your USB flash drive  <a id="power-off-your-usb-flash-drive" class="anchor" href="#power-off-your-usb-flash-drive" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org5287c69">
 <div class="jfw-code"> <pre>sudo udisksctl power-off -b /dev/sda</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-voidlinux/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Open VPN 3 on Void Linux</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-nixos-with-web-based-saml/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Open VPN 3 on NixOS with Web-based SAML</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/windows-11-bootable-usb-from-gnu-linux/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/windows-11-bootable-usb-from-gnu-linux/index.html</guid>
  <pubDate>Sat, 26 Aug 2023 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Open VPN 3 on Void Linux</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>OpenVPN 3 on Void Linux  <a id="openvpn-3-on-void-linux" class="anchor" href="#openvpn-3-on-void-linux" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org9706231">
 <p>
Recently at work we migrated from a simple OpenVPN profile with AWS credentials to a profile that authenticates based on SAML via your browser. This means that we need OpenVPN 3 now running. At the time of writing there was no package in the Void Linux repos for v3 so I decided to build from source, since otherwise this would mean I cannot do my work, from Void Linux.
</p>

 <p>
⚠️ Note: looks like the build process for OpenVPN 3 now uses Meson. See:  <a href="https://github.com/OpenVPN/openvpn3-linux/blob/master/BUILD.md">https://github.com/OpenVPN/openvpn3-linux/blob/master/BUILD.md</a>
</p>

 <p>
In this post I explain how you should go about installing OpenVPN 3 from source on Void Linux.
</p>

 <p>
First remove your existing OpenVPN installation. Bear in mind that this means also removing the NetworkManager extension.
</p>

 <div class="jfw-code"> <pre>sudo xbps-remove openvpn NetworkManager-openvpn</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You should then ensure that your system is up to date and install at least the following packages (maybe more are required that I missed).
</p>

 <div class="jfw-code"> <pre>sudo xbps-install -Syu
sudo xbps-install -Sy automake autoconf autoconf-archive pkg-config liblz4-devel lz4 jsoncpp jsoncpp-devel libcap-ng-devel tinyxml2 tinyxml2-devel</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Before installing it’s useful to configure the groups and users required for this:
</p>

 <div class="jfw-code"> <pre>sudo groupadd -r openvpn
sudo useradd -r -s /sbin/nologin -g openvpn openvpn</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then navigate to a directory of your choice (for me  <code>~/Ontwikkeling/Build</code>) and clone the source code of the OpenVPN 3 client there.
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">cd</span> ~/Ontwikkeling/Build
git clone https://github.com/OpenVPN/openvpn3-linux.git
 <span class="org-builtin">cd</span> openvpn3-linux</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
After having navigated to that folder you can proceed to the building and installation.
</p>

 <div class="jfw-code"> <pre>./bootstrap.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make
sudo make install
sudo openvpn3-admin init-config --write-configs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then make sure to reboot your system, and you can now enjoy using OpenVPN 3. See below how I use it:
</p>

 <div class="jfw-code"> <pre>sudo openvpn3 session-start --config my-file.ovpn &amp;&amp; sudo openvpn3 session-auth</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
That’s all folks!
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-for-absolute-begginners/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Emacs for absolute beginners</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/windows-11-bootable-usb-from-gnu-linux/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Create a Windows 11 bootable USB from GNU Linux</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-voidlinux/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-voidlinux/index.html</guid>
  <pubDate>Sat, 19 Aug 2023 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Emacs for absolute beginners</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In this article, I’m going to give you exactly what you need to get started using Emacs and understand the basic concepts and key bindings of the editor. I know this article might seem long, but I promise you will come out with a plethora of knowledge about Emacs.
</p>

 <p>
I have taken lots of parts and inspiration from  <a href="https://systemcrafters.cc/emacs-essentials/absolute-beginners-guide-to-emacs/">the excellent guide made by System Crafters</a>.
Watch the great introductory video too  <a href="https://www.youtube.com/watch?v=48JlgiBpw_I">on YouTube</a> !
</p>
 <h2>Installation  <a id="installation" class="anchor" href="#installation" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4a0c368">
 <p>
Emacs can be installed on GNU/Linux, macOS and Windows and more. It is one of the most ported pieces of software in existence. There are very few limits to where it can run.
</p>

 <p>
The latest stable version is 28 at the time of writing, so it’s best to try and find that version (or later) for your operating system. However, much of what I will show you should work on many previous versions of Emacs.
</p>
</div>
 <h3>GNU/Linux  <a id="gnulinux" class="anchor" href="#gnulinux" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org8ff0826">
 <p>
GNU/Linux is the easiest OS for installing and using Emacs. It is available in (pretty much) every GNU/Linux distribution’s package manager, typically under the name  <code>emacs</code>, so it’s easy to find!
</p>

 <p>
Just keep in mind that your distribution may have an older version of Emacs in their package repository (possibly version 26) so you might need to find another source to install the latest version.
</p>
</div>
 <h3>GUI or Terminal?  <a id="gui-or-terminal" class="anchor" href="#gui-or-terminal" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9466883">
 <p>
On GNU/Linux, there are often emacs-no-x packages that don’t include the graphical UI if you don’t need it. There are no major differences in behavior between GUI and terminal Emacs so you can use whichever you feel most comfortable with.
</p>

 <p>
One major benefit of graphical Emacs is the ability to use multiple fonts for text display and a full range of colors. It is recommendable to use GUI Emacs if possible. Also, try to get rid of the bad habit you may have from vi, opening editor at files from terminal. Emacs can and should stay open the whole day.
</p>
</div>
 <h3>macOS  <a id="macos" class="anchor" href="#macos" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orge4e279c">
 <p>
Installation on macOS with Homebrew is easy! There’s a default recipe called emacs which can be installed with the following command:
</p>
 <div class="jfw-code"> <pre>brew install --cask emacs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
An alternative recipe called Emacs Plus provides additional options for customizing your Emacs install, check out its README to learn how to use it.
</p>

 <p>
You can also download a .app for Emacs from the site  <a href="https://emacsformacosx.com/">https://emacsformacosx.com/</a>
</p>
</div>
 <h3>Windows  <a id="windows" class="anchor" href="#windows" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgde9a6d0">
 <p>
On Windows, you can download Emacs directly from  <a href="https://www.gnu.org/software/emacs/">GNU website</a>!
</p>

 <p>
If you use MSYS2, you can install it using Pacman:
</p>
 <div class="jfw-code"> <pre>pacman -S mingw-w64-x86_64-emacs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can also install it using Chocolatey:
</p>
 <div class="jfw-code"> <pre>choco install emacs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Basic concepts  <a id="basic-concepts" class="anchor" href="#basic-concepts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org0b725f0">
 <p>
Let’s talk about the basic things you need to understand about Emacs to use it effectively!
</p>
</div>
 <h3>User interface  <a id="user-interface" class="anchor" href="#user-interface" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org2d8382a">
 <p>
Emacs has a menu and tool bar like many conventional graphical programs. They can be useful at first to learn the functionality that is available, but I think that you won’t need them for very long!
</p>

 <p>
Note that the menu bar actually is present in the terminal version of Emacs!
</p>

 <p>
If you’re coming from another IDE or editor, you might expect to see a file tree on the left side of the window. This isn’t provided by Emacs by default, but it’s easy to add through community packages! There are other ways to show files in Emacs that are even better, in my opinion.
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Menu-Bar.html">Emacs Manual: The Menu Bar</a>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Tool-Bars.html">Emacs Manual: Tool Bars</a>
</p>
</div>
 <h3>Windows and Frames  <a id="windows-and-frames" class="anchor" href="#windows-and-frames" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgc8945cf">
 <p>
The concept of a “window” is different in Emacs than what you probably know from using graphical computing environments.  In modern desktop environments, a window is a graphical interface of a program which is managed by the window manager of the desktop environment, usually with buttons to close or minimize it.
</p>

 <p>
In Emacs, a window is more like a “pane” in the desktop window of Emacs.  A window in Emacs always displays a buffer.  Windows can also be split in arbitrary ways, both horizontally and vertically, so that you can create whatever window layout you like.  Each of these windows can show different buffers or even the same buffer!
</p>

 <p>
What you think of as a window in typical desktop environments, Emacs calls a “frame”!  Emacs can display multiple frames (desktop windows) at the same time.  These frames all share the same internal state and buffers.  Some people never use more than one frame, others use many frames.  It all depends on how you prefer to use Emacs!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic-Window.html#Basic-Window">Emacs Manual: Concepts of Emacs Windows</a>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Frames.html#Frames">Emacs Manual: Frames and Graphical Displays</a>
</p>
</div>
 <h3>Buffers  <a id="buffers" class="anchor" href="#buffers" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orga4ec8ae">
 <p>
A buffer holds text and other information that is usually displayed in a window.  The most obvious example is a buffer that contains the contents of a file for the purpose of editing it.
</p>

 <p>
However, there are many types of special buffers that are used only for displaying temporary information or user interface elements!  The Magit package provides an excellent interface for Git inside of a custom Emacs buffer.
</p>

 <p>
Buffers can be one of the more confusing aspects of Emacs to beginners because you don’t have any indication of what buffers are open until you try to switch to another buffer.
</p>

 <p>
Some important buffers you will definitely see when you use Emacs:
</p>

 <ul class="org-ul"> <li> <code>*scratch*</code> - Basically like a blank sheet of paper for taking notes, writing temporary Emacs Lisp expressions, or whatever you want!</li>
 <li> <code>*Messages*</code> - This contains log messages and all the text that gets written to the echo area at the bottom of the screen</li>
 <li> <code>*Warnings*</code> - A list of potential errors that may be displayed from time to time</li>
</ul> <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Buffers.html#Buffers">Emacs Manual: Using Multiple Buffers</a>
</p>
</div>
 <h3>The Mode Line  <a id="the-mode-line" class="anchor" href="#the-mode-line" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9df5543">
 <p>
When coming from other editors, you might expect to see a “status bar” at the bottom of the main editor window that gives you information about the state of the current buffer and the editor.  Emacs also has this, but does it slightly differently!
</p>

 <p>
The mode line is a line of text displayed at the bottom of every window (pane) in Emacs.  It displays information about the current buffer you’re viewing and also global status information:
</p>

 <ul class="org-ul"> <li>The line and column of the cursor</li>
 <li>The major mode of the buffer</li>
 <li>The minor modes active in the buffer (or globally in Emacs)</li>
</ul> <p>
The major difference between the mode line and the status bar is that there is a mode line under  <b>every</b> visible window, so when you split the window, you’ll see multiple mode lines!  There are benefits to this even though it takes up extra screen space.
</p>

 <p>
The mode line is fully customizable and can be made to look very nice either through your own configuration or from community packages!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Mode-Line.html">Emacs Manual: The Mode Line</a>
</p>
</div>
 <h3>The Echo Area and Minibuffer  <a id="the-echo-area-and-minibuffer" class="anchor" href="#the-echo-area-and-minibuffer" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org6c4eea2">
 <p>
The echo area is a line at the very bottom of the frame which displays informational text when you perform certain operations in Emacs.
</p>

 <p>
It also turns into a prompt at times when you run a command that needs to accept user input; this prompt is called the “minibuffer”!  You can think of it like a temporary buffer that is used for interacting with the user.  It can also expand its height to be slightly larger than a single line when needed.
</p>

 <p>
One example of the minibuffer in use can be seen when we attempt to run a command by name.
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Echo-Area.html">Emacs Manual: The Echo Area</a>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Minibuffer.html#Minibuffer">Emacs Manual: The Minibuffer</a>
</p>
</div>
 <h3>Commands  <a id="commands" class="anchor" href="#commands" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org516776d">
 <p>
In Emacs, there are a variety of built in commands that enable a lot of interesting and useful behavior, especially things that aren’t specifically for text editing!  You can think of Emacs as more of a personal productivity suite than a plain text editor.
</p>

 <p>
To run a command, you can press  <code>Alt+x</code> (or  <code>M-x</code> in Emacs lingo).  This will bring up a prompt where you can type in the name of the command to be run.
</p>

 <p>
This prompt features a completion system (like many prompts in Emacs) so you can press  <code>TAB</code> to show all possible commands that you can run.
</p>

 <p>
Try out the following commands:
</p>

 <ul class="org-ul"> <li> <code>dired</code> ( <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html#Dired">Manual</a>)</li>
 <li> <code>calendar</code> ( <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Calendar_002fDiary.html#Calendar_002fDiary">Manual</a>)</li>
 <li> <code>eshell</code> ( <a href="https://www.gnu.org/software/emacs/manual/html_mono/eshell.html">Manual</a>)</li>
 <li> <code>tetris</code> :) ( <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Amusements.html#Amusements">Manual</a>)</li>
</ul> <p>
New commands can be installed into Emacs using community packages, and you can also write your own!  We’ll cover this in another article.
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Commands.html">Emacs Manual: Keys and Commands</a>
</p>
</div>
 <h3>Major and Minor Modes  <a id="major-and-minor-modes" class="anchor" href="#major-and-minor-modes" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgdd58b6f">
 <p>
In other editors, there is usually functionality that gets enabled for files with a particular extension, e.g. Python programming functionality for  <code>.py</code> files.
</p>

 <p>
Emacs also has this!  This functionality is provided through something called a “major mode.”  A major mode provides the primary functionality for a particular buffer and it is usually activated based on the extension of a file you open in that buffer.
</p>

 <p>
As we’ve seen before, some buffers are not files and have special functionality!  This functionality also comes from custom major modes.  In this case, the major mode is being activated using a command, typically with the name of the mode.
</p>

 <p>
The major mode is what we see down in the mode line which indicates what type of buffer we are looking it.
</p>

 <p>
There can only be one major mode active in a buffer at once!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Modes.html">Emacs Manual: Major and Minor Modes</a>
</p>
</div>
 <h4>Minor Modes  <a id="minor-modes" class="anchor" href="#minor-modes" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-org0d10f57">
 <p>
Minor modes are different in that many minor modes can be active in a single buffer, and even globally across Emacs.
</p>

 <p>
Minor modes typically provide helpful functionality that isn’t specific to the major mode of the current buffer, but things you might need to customize your workflow or even change the display of things in Emacs.
</p>

 <p>
Try out  <code>hl-line-mode</code> and  <code>global-hl-line-mode</code> as an example of local and global minor modes!
</p>
</div>
 <h3>Basic Key Bindings  <a id="basic-key-bindings" class="anchor" href="#basic-key-bindings" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3a86a28">
 <p>
Emacs is most efficient and productive when you focus on keyboard-based control.  The key binding system in Emacs is one of the most flexible and customizable I’ve ever seen; once you start customizing Emacs’ bindings for your own personal workflow, you’ll see how limited other programs are by comparison.
</p>
</div>
 <h3>Understanding Emacs Key Bindings  <a id="understanding-emacs-key-bindings" class="anchor" href="#understanding-emacs-key-bindings" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org0af25aa">
 <p>
You will often see people write out the key bindings in a specific format when explaining things.  Let’s quickly cover what everything means since you will see it often!
</p>

 <ul class="org-ul"> <li> <code>C-c</code> - hold the Ctrl key and press the letter ’c’</li>
 <li> <code>C-x C-s</code> - hold the Ctrl key and press the letters ’x’ then ’s’ while still holding Ctrl</li>
 <li> <code>C-x b</code> - hold the Ctrl key and press ’x’, then release Ctrl and press ’b’</li>
 <li> <code>M-x</code> - hold the Alt key and press ’x’ (you will see this often like  <code>M-x find-file</code>)</li>
 <li> <code>M-g C-s</code> - hold the Alt key and press the letter ’g’, release Alt, hold Ctrl and press ’s’</li>
</ul> <p>
These single-letters can be interpreted as follows:
</p>

 <ul class="org-ul"> <li> <code>C</code> - Ctrl</li>
 <li> <code>M</code> - Alt (Meta in Emacs lingo)</li>
 <li> <code>S</code> - Shift</li>
 <li> <code>s</code> - Super (Windows key)</li>
</ul> <p>
Generally when you see a capital  <code>C</code>,  <code>M</code>, or  <code>S</code> hyphened together with another key, those should all be pressed together, i.e.  <code>C-M-s</code> or  <code>M-S-d</code>.
</p>

 <p>
One last important thing to mention are the two main key prefixes that have special meaning:
</p>

 <ul class="org-ul"> <li> <code>C-x</code> - This is a prefix for all of Emacs’ primary key bindings like  <code>C-x C-f</code></li>
 <li> <code>C-c</code> - This is considered to be a combination of bindings created by active major and minor modes or by the user!</li>
</ul> <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Sequences.html">Emacs Manual: Key Sequences</a>
</p>
</div>
 <h3>Opening and Saving Files  <a id="opening-and-saving-files" class="anchor" href="#opening-and-saving-files" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org1e3e359">
 <p>
To open a file in Emacs, press  <code>C-x C-f</code> ( <code>find-file</code>).  This will bring up a prompt in the minibuffer so that you can type in the file name.
</p>

 <p>
You can also navigate through directories by deleting the directory path and using  <code>TAB</code> to complete parts of directory and file names!
</p>

 <p>
When you’ve opened a file into a buffer, you can make edits to it and then save the file with  <code>C-x C-s</code> ( <code>save-buffer</code>).
</p>

 <p>
You can also save the buffer to a different file (“Save as” in other editors) with  <code>C-x C-w</code> ( <code>write-file</code>).
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Visiting-Files.html#Visiting-Files">Emacs Manual: Visiting Files</a>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Saving-Buffers.html#Saving-Buffers">Emacs Manual: Saving Buffers</a>
</p>
</div>
 <h3>Switching Buffers  <a id="switching-buffers" class="anchor" href="#switching-buffers" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgc24a425">
 <p>
As we talked about before, Emacs can have many buffers open at the same time but you will only see the buffers that are currently open in a window.
</p>

 <p>
If you want to switch between buffers, you can use the  <code>C-x b</code> ( <code>switch-to-buffer</code>) binding to be prompted for a buffer to switch to.  This prompt features completions, so press  <code>TAB</code> at any time to see the possible buffers based on the current text you’ve entered.
</p>

 <p>
There’s also  <code>C-x C-b</code> ( <code>list-buffers</code>) which will show you a full listing of all the buffers that are open in Emacs.
</p>

 <p>
Once you start customizing Emacs, there are a variety of packages that make this even easier and enable you to customize it for your workflow!
</p>

 <p>
You can also easily move between buffers using the  <code>C-x &lt;left arrow&gt;</code> and  <code>C x &lt;right arrow&gt;</code> keys!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/List-Buffers.html#List-Buffers">Emacs Manual: Listing Existing Buffers</a>
</p>
</div>
 <h3>Cutting and Copying Text  <a id="cutting-and-copying-text" class="anchor" href="#cutting-and-copying-text" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgcdbec56">
 <p>
This is an area which always confuses new Emacs users!  Many programs across Linux and Windows use  <code>C-c</code> to copy text and  <code>C-x</code> to copy and delete the selected text (cut).
</p>

 <p>
This is not the case in Emacs!  As we mentioned before, these two key bindings are actually special key prefixes in Emacs so they aren’t used for cut and copy.
</p>

 <p>
In Emacs, to “kill” text means to “cut” it, basically copy it and delete it.  The most common thing you will do is to kill a region, either to just delete the text or to cut it to be pasted somewhere else.
</p>

 <p>
But to kill a region, you first need to select one!  You can begin marking a region using  <code>C-SPC</code> ( <code>set-mark-command</code>) then use the arrow keys to move the cursor to expand or shrink the selection.
</p>

 <p>
Now that you have a region selected, you can use  <code>C-w</code> ( <code>kill-region</code>) to cut the text or  <code>M-w</code> ( <code>kill-ring-save</code>) to copy it.
</p>

 <p>
One interesting aspect of killing text is that it gets stored in the “kill ring” to be used later.  We will discuss this in a future episode!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Killing.html">Emacs Manual: Killing and Moving Text</a>
</p>
</div>
 <h3>Pasting Text  <a id="pasting-text" class="anchor" href="#pasting-text" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgf726952">
 <p>
In typical Emacs style, the concept of “pasting” text has a different name: “yank.”
</p>

 <p>
You can press  <code>C-y</code> to yank (paste) the most recent text from the kill ring back into this buffer.
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Yanking.html#Yanking">Emacs Manual: Yanking</a>
</p>
</div>
 <h3>CUA Mode  <a id="cua-mode" class="anchor" href="#cua-mode" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org624dfee">
 <p>
If you  <b>must</b> have the old  <code>C-c</code> (copy)  <code>C-x</code> (cut) and  <code>C-v</code> (paste) behavior that you’re familiar with, you can turn on the CUA mode using the menu item “Options -&gt; Cut/Paste with C-x/C-c/C-v (CUA Mode)”.
</p>

 <p>
This will make the cut and copy key bindings work when you’ve selected a region of text with the mouse or keyboard.  It will also turn  <code>C-v</code> into a Paste keybinding which will do what you expect!
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/CUA-Bindings.html#CUA-Bindings">Emacs Manual: CUA Bindings</a>
</p>
</div>
 <h3>Undo and Redo  <a id="undo-and-redo" class="anchor" href="#undo-and-redo" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org990b625">
 <p>
You can undo changes to a buffer by pressing  <code>C-_</code> (Ctrl+underscore) to run the  <code>undo</code> command.  An alternative binding which is easier to press is  <code>C-/</code>
</p>

 <p>
To redo something that you deleted with undo, press  <code>C-g C-_</code>, but note that pressing  <code>C-_</code> again right after this will keep redoing things that you’ve undo’ed!  It will then cycle back to undoing once you’ve reached the end of your redo history.
</p>

 <p>
As you can see, Emacs’ undo system operates differently than what you’re used to!  There are packages that can replace this with more understood behavior; we will talk about them in another article.
</p>

 <p>
 <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html">Emacs Manual: Undo</a>
 <a href="https://stackoverflow.com/a/3529243">StackOverflow answer about how to undo and redo</a>
</p>
</div>
 <h3>Cancelling Operations  <a id="cancelling-operations" class="anchor" href="#cancelling-operations" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orgbd2462d">
 <p>
Sometimes you might run a command that you want to cancel before it completes.  For this you can press  <code>C-g</code> (Ctrl+g).  This interrupts any active command and brings you back to a normal state in Emacs.
</p>

 <p>
One example is showing any prompt, like the one for the ( <code>find-file</code>) command.  If you decide you want to cancel that prompt, just press  <code>C-g</code>.
</p>

 <p>
Sometimes you might need to press it repeatedly before you can fully get back to normal!
</p>

 <p>
If Emacs ever seems to be hung, try this key binding first before killing the process.
</p>
</div>
 <h3>Learning More Key Bindings  <a id="learning-more-key-bindings" class="anchor" href="#learning-more-key-bindings" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org45ea349">
 <p>
There are two ways to figure out more key bindings for Emacs, especially when editing different types of files:
</p>

 <ul class="org-ul"> <li>As we talked about before, look at the menu bar for common commands and their keys</li>
 <li>Run the command  <code>describe-bindings</code></li>
 <li>Run the command  <code>describe-key</code> ( <code>C-h k</code>) to learn what command is bound to a specific key combination!</li>
</ul></div>
 <h3>The Help System  <a id="the-help-system" class="anchor" href="#the-help-system" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org25df3bf">
 <p>
We’ll cover this in detail in another article, but the whole Emacs manual is built in to Emacs and you can find help on any function or variable in Emacs using the  <code>describe-*</code> functions!
</p>
</div>
 <h2>Configuring Emacs  <a id="configuring-emacs" class="anchor" href="#configuring-emacs" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org55830f3">
 <p>
There are two ways to configure Emacs to customize its behavior.  We won’t go in depth on either of these in this article, I just want to point them out to you since it will be an obvious question you might have!
</p>
</div>
 <h3>The Customization UI  <a id="the-customization-ui" class="anchor" href="#the-customization-ui" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org71cc05d">
 <p>
Emacs provides a full user interface for customizing all options in the editor.  To access it, run the command  <code>customize</code>.
</p>

 <p>
You can either navigate through the settings hierarchy to see what is available or put your cursor in the search box, type a term, then press  <code>ENTER</code>.
</p>

 <p>
Each setting will have an input field of some kind that you can change by putting your cursor in the box and editing the value.  Once you’re finished editing, you can click the “Apply” button to save the changes.
</p>

 <p>
Try searching for “tab width” in the search box!
</p>
</div>
 <h3>The  <code>init.el</code> file  <a id="the-codeinitelcode-file" class="anchor" href="#the-codeinitelcode-file" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-orga0c6575">
 <p>
Once you’ve become sufficiently comfortable with Emacs, you’ll want to investigate how to configure Emacs using the  <code>init.el</code> file.  Emacs can be completely configured and extended using Lisp code!
</p>

 <p>
In your configuration file, you can write your own functions and commands to add new behavior to Emacs.  This is where a lot of the true power of Emacs comes into play!
</p>

 <p>
Check out the series  <a href="https://www.youtube.com/watch?v=74zOY-vgkyw&amp;list=PLEoMzSkcN8oPH1au7H6B7bBJ4ZO7BXjSZ">Emacs From Scratch</a> if you want to learn how to build up a modern Emacs configuration from scratch using the  <code>init.el</code> file and a bunch of community packages.
</p>
</div>
 <h2>What’s next?  <a id="whatrsquos-next" class="anchor" href="#whatrsquos-next" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2dd6173">
 <p>
This article should give you much of what you need to know to start using Emacs!  However, we weren’t able to cover many things in depth.
</p>

 <p>
I’ve already been making a ton of other articles about Emacs on this channel, so you should definitely check out SystemCrafter’s playlists if you want to learn a lot more:
</p>

 <ul class="org-ul"> <li> <a href="https://www.youtube.com/watch?v=74zOY-vgkyw&amp;list=PLEoMzSkcN8oPH1au7H6B7bBJ4ZO7BXjSZ">Emacs From Scratch</a></li>
 <li> <a href="https://www.youtube.com/watch?v=wKTKmE1wLyw&amp;list=PLEoMzSkcN8oMHJ6Xil1YdnYtlWd5hHZql">Emacs Tips</a></li>
 <li> <a href="https://www.youtube.com/watch?v=f7xB2fFk1tQ&amp;list=PLEoMzSkcN8oNPbEMYEtswOVTvq7CVddCS">Emacs Desktop Environment</a></li>
 <li> <a href="https://www.youtube.com/watch?v=E-NAM9U5JYE&amp;list=PLEoMzSkcN8oNvsrtk_iZSb94krGRofFjN">Emacs IDE</a></li>
 <li> <a href="https://www.youtube.com/watch?v=yZRyEhi4y44&amp;list=PLEoMzSkcN8oM-kA19xOQc8s0gr0PpFGJQ">Emacs Mail</a></li>
 <li> <a href="https://www.youtube.com/watch?v=RQK_DaaX34Q&amp;list=PLEoMzSkcN8oPQtn7FQEF3D7sroZbXuPZ7">Learning Emacs Lisp</a></li>
</ul></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-and-scala-setup-with-eglot/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Emacs and Scala setup with Eglot</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-voidlinux/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Open VPN 3 on Void Linux</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/emacs-for-absolute-begginners/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/emacs-for-absolute-begginners/index.html</guid>
  <pubDate>Sat, 29 Apr 2023 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Emacs and Scala setup with Eglot</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In this post I want to show you how to setup your favourite text editor, Emacs, as a super powerful and capable Scala IDE (integrated development environment) with the latest and most performant approach.
</p>

 <p>
You might think I am crazy and I make my life more difficult than it needs to be. Let me tell you this  already, my development experience in Emacs with Scala is 5 star ⭐. I use this setup at work extensively and cannot think of a better way to be productive.
</p>

 <p>
I see VSCode and IntelliJ colleagues (peasants), prisoners of proprietary tech, stuck to mouse usage, having to click around and hide the countless panes and useless tooltips their IDEs throw at them, and they are unable to customize things to what they need, nor do they have an understanding of the inner workings of their IDE, which IMHO puts them at a disadvantage.
</p>

 <p>
Just learn Emacs already!
</p>
 <h2>Metals  <a id="metals" class="anchor" href="#metals" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orga64a714">
 <p>
Needless to say, the best way to get Scala working with “language-server” compatible integrations is to use Metals LSP. You can read more about it  <a href="https://scalameta.org/metals/">on their website</a>  and how it integrates with several editors.
I usually install it with  <a href="https://get-coursier.io/">coursier</a> doing something along the lines of:
</p>
 <div class="jfw-code"> <pre>coursier bootstrap --java-opt -XX:+UseG1GC --java-opt -XX:+UseStringDeduplication --java-opt -Xss4m --java-opt -Xms100m --java-opt -Dmetals.client=emacs org.scalameta:metals_2.13:0.11.12 -o $ <span class="org-variable-name">HOME</span>/.local/bin/metals-emacs -f</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Note: ensure that  <code>$HOME/.local/bin</code> is in your path and Emacs will automagically pick it up.
</p>
</div>
 <h2>Emacs package manager - Elpaca  <a id="emacs-package-manager---elpaca" class="anchor" href="#emacs-package-manager---elpaca" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org2d3d413">
 <p>
I am enjoying using Elpaca everyday. It’s the most advanced, reliable and performant package manager ever made for Emacs. It integrates also seamlessly with  <code>use-package</code> and pushes you into doing things in a maintainable way.
Read  <a href="https://github.com/progfolio/elpaca">more about it here</a>.
You can still learn from my config even if you don’t use it, but I do whole-heartedly recommend it.
</p>
</div>
 <h2>Eglot  <a id="eglot" class="anchor" href="#eglot" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orged30e44">
 <p>
I whole-heartedly recommend  <code>eglot</code>. Eglot, a.k.a. Emacs Polyglot is the Emacs LSP client that stays out of your way.
You can read more about it  <a href="https://github.com/joaotavora/eglot">here</a>.
</p>

 <p>
Eglot is to be integrated into Emacs core, and is more performant and minimalistic than lsp-mode. I like to immediately start eglot when opening a Scala file.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> eglot
   <span class="org-builtin">:hook</span> (
         (scala-mode . eglot-ensure)
          <span class="org-comment-delimiter">;; </span> <span class="org-comment">other modes go here
</span>          <span class="org-comment-delimiter">;; </span> <span class="org-comment">e.g.
</span>          <span class="org-comment-delimiter">;; </span> <span class="org-comment">(haskell-mode . eglot-ensure)
</span>         ))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Once you install it (or load it, since in new Emacs versions it should be built-in), you will need to configure certain things to ensure it can work together with Scala Metals, the Scala language server.
</p>

 <p>
Here we add a wonderful functionality of optimizing imports and formatting code on save.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">defun</span>  <span class="org-function-name">my-eglot-organize-imports</span> () ( <span class="org-keyword">interactive</span>)
        (eglot-code-actions nil nil  <span class="org-string">&quot;source.organizeImports&quot;</span> t))
 (add-hook 'before-save-hook 'my-eglot-organize-imports nil t)
 (add-hook 'before-save-hook 'eglot-format-buffer)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Treesitter  <a id="treesitter" class="anchor" href="#treesitter" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgc6869b1">
 <p>
For all my syntax highlighting and syntax tree needs I use  <code>tree-sitter</code>, which soon will also be built into Emacs.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> tree-sitter
    <span class="org-builtin">:config</span>
   (global-tree-sitter-mode))

( <span class="org-keyword">use-package</span> tree-sitter-langs
   <span class="org-builtin">:after</span> tree-sitter)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Scala Development  <a id="scala-development" class="anchor" href="#scala-development" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgb752f9b">
 <p>
Enable scala-mode for indentation and certain language rules, with Treesitter highlighting.
</p>

 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> scala-mode
   <span class="org-builtin">:interpreter</span> ( <span class="org-string">&quot;scala&quot;</span> . scala-mode)
   <span class="org-builtin">:hook</span> (scala-mode . tree-sitter-hl-mode)
  )</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>flycheck  <a id="flycheck" class="anchor" href="#flycheck" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1104b16">
 <p>
Flycheck is an enhancement over  <code>flymake</code> and helps better visualize and interact with errors and warnings in your Emacs buffers.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> flycheck  <span class="org-builtin">:config</span> (global-flycheck-mode))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
For integrating Flycheck and Eglot, check out the cool  <a href="https://github.com/intramurz/flycheck-eglot">flycheck-eglot package</a>.
</p>
</div>
 <h2>company  <a id="company" class="anchor" href="#company" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orge5e516e">
 <p>
For all my auto-complete needs I use  <code>company</code> which works wonderfully and is highly customizable.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> company
   <span class="org-builtin">:custom</span>
  (company-minimum-prefix-length 1)
  (company-idle-delay 0.5)
  (company-tooltip-align-annotations t)
  (company-tooltip-margin 2)
   <span class="org-builtin">:config</span>
  (global-company-mode))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The  <code>company-quickhelp</code> package will help to visualize available documentation right in the auto-completion tooltip, a feature present in many modern IDEs.
</p>
 <div class="jfw-code"> <pre>( <span class="org-keyword">use-package</span> company-quickhelp
   <span class="org-builtin">:after</span> (company)
   <span class="org-builtin">:config</span>
  (company-quickhelp-mode))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
With all of this setup you will be able to have a productive experience, that surpasses the performance and joy of use of other IDEs.
You may want to, on a per project basis, run  <code>sbt bloopInstall</code> to get the full experience of Metals LSP. This requires the plugin:  <code>addSbtPlugin(&quot;ch.epfl.scala&quot; % &quot;sbt-bloop&quot; % &quot;1.5.6&quot;)</code>.
</p>

 <p>
You may have more success with running the  <code>bloopInstall</code> as  <code>sbt -Dbloop.export-jar-classifiers=sources bloopInstall</code>.
</p>

 <p>
Also, remember that running  <code>M-x eglot*</code> will show all eglot commands available, and teach you some of the shortcuts too.
</p>

 <p>
Feel free to check  <a href="https://git.sr.ht/~teutonicjoe/dotfiles">my dotfiles on SourceHut</a> which might help you get your Emacs setup just right 👌.
</p>

 <p>
Have a nice development day today!
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Running Hoogle locally</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-for-absolute-begginners/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Emacs for absolute beginners</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/emacs-and-scala-setup-with-eglot/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/emacs-and-scala-setup-with-eglot/index.html</guid>
  <pubDate>Thu, 27 Apr 2023 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Running Hoogle locally</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Stackage is a neat tool to use when developing Software in Haskell. It’s
integrated with the Hoogle search engine that can search on type
signatures (and function names) which lets you find almost any function
easily.
</p>

 <p>
One of the downsides of Hoogle is that it can be slow for people with
some slower connections and so looking up any kind of documentation
becomes a really frustrating experience.
</p>

 <p>
The other issue with using Hoogle is that when you look up documentation
for a function of a library that you use in a project, you need to make
sure you are looking at the documentation for the exact version of that
library that you are using in your package.yml or .cabal file; otherwise
you maybe looking at an entirely different api and end up wasting a lot
of time.
</p>

 <p>
Stackage solves this by letting you search against a particular snapshot
where all the versions of your libraries will be pinned against that
snapshot (see the resolver field in stackage.yaml).
</p>

 <p>
Wouldn’t it be nice if we could run Hoogle locally for our project with
all the documentation we need available at our fingertips? What would be
even better is that Hoogle was seeded with only the versions of
dependencies in our project that we care about.
</p>

 <p>
Well thanks to the fantastic “An opinionated guide to Haskell in 2018”
by Alexis King we now know how!
</p>

 <p>
The basic steps are:
</p>

 <p>
 <b>Generate Haddock documentation when you compile your project</b>
</p>

 <div class="jfw-code"> <pre>stack test --fast --haddock-deps</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The first time you run this it can take a while.
</p>

 <p>
 <b>Generate a local Hoogle database</b>
</p>

 <div class="jfw-code"> <pre>stack hoogle -- generate --local</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Run your local Hoogle server</b>
</p>

 <div class="jfw-code"> <pre>stack hoogle -- server --local --port=8080</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Profit</b>
</p>

 <p>
You can get full access to your local Hoogle by opening  <code>localhost:8080</code>
in your browser.
</p>

 <p>
Something to be aware of is that when you add new dependencies or change
existing ones in your project you need to generate your local Hoogle
database again:
</p>

 <p>
Unfortunately, you will have to manually regenerate the Hoogle database
when you install new packages and their documentation, which you can do
by re-running  <code>stack hoogle -- generate --local</code>.
</p>

 <p>
Fortunately, regenerating the database doesn’t take very long, as long
as you’ve been properly rebuilding the documentation with
 <code>--haddock-deps</code>.
</p>

 <p>
This shouldn’t take too long though if you’ve been generating your
Haddock as per step 1.
</p>

 <p>
Original post can be found
 <a href="https://blog.ssanj.net/posts/2019-10-19-running-hoogle-locally-for-haskell-dev.html">here</a>.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Type safety back and forth</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-and-scala-setup-with-eglot/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Emacs and Scala setup with Eglot</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/">Free à la Carte</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/">Type safety back and forth</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/">Why Haskell is important?</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/index.html</guid>
  <pubDate>Tue, 11 Oct 2022 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Type safety back and forth</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Taken from the brilliant post of  <a href="https://www.parsonsmatt.org/2017/10/11/type_safety_back_and_forth.html">Matt Parsons</a>.
</p>

 <p>
Types are a powerful construct for improving program safety. Haskell has a few notable ways of handling potential failure, the most famous being the venerable  <code>Maybe</code> type:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">Maybe</span> a
     <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Nothing</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Just</span> a</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We can use  <code>Maybe</code> as the result of a function to indicate:
</p>
 <blockquote>
 <p>
Hey, friend! This function might fail. You’ll need to handle the  <code>Nothing</code> case.
</p>
</blockquote>

 <p>
This allows us to write functions like a safe division function:
</p>
 <div class="jfw-code"> <pre> <span class="org-haskell-definition">safeDivide</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Maybe</span>  <span class="org-haskell-type">Int</span>
 <span class="org-haskell-definition">safeDivide</span> i 0  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Nothing</span>
 <span class="org-haskell-definition">safeDivide</span> i j  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Just</span> (i  <span class="org-haskell-operator">`div`</span> j)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
I like to think of this as pushing the responsibility for failure forward. I’m telling the caller of the code that they can provide whatever =Int=s they want, but that some condition might cause them to fail. And the caller of the code has to handle that failure later on.
</p>

 <p>
This is the easiest technique to show and tell, because it’s one-size-fits-all. If your function can fail, just slap  <code>Maybe</code> or  <code>Either</code> on the result type and you’ve got safety. I can write a 35 line blog post to show off the technique, and if I were feeling frisky, I could use it as an introduction to  <code>Functor</code>,  <code>Monad</code>, and all that jazz.
</p>

 <p>
Instead, I’d like to share another technique. Rather than push theresponsibility for failure forward, let’s explore pushing it back. This technique is a little harder to show, because it depends on the individual cases you might use.
</p>

 <p>
If pushing responsibility forward means accepting whatever parameters and having the caller of the code handle possibility of failure, then  <i>pushing it back</i> is going to mean we accept stricter parameters that we can’t fail with. Let’s consider  <code>safeDivide</code>, but with a more lax type signature:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">safeDivide</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">String</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">String</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Maybe</span>  <span class="org-haskell-type">Int</span>
 <span class="org-haskell-definition">safeDivide</span> iStr jStr  <span class="org-haskell-operator">=</span>  <span class="org-haskell-keyword">do</span>
    i  <span class="org-haskell-operator">&lt;-</span> readMay iStr
    j  <span class="org-haskell-operator">&lt;-</span> readMay jStr
    guard (j  <span class="org-haskell-operator">/=</span> 0)
    pure (i  <span class="org-haskell-operator">`div`</span> j)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This function takes two strings, and then tries to parse  <code>Int=s out of them. Then, if the =j</code> parameter isn’t  <code>0</code>, we return the result of division. This function is  <i>safe</i>, but we have a much larger space of calls to  <code>safeDivide</code> that fail and return  <code>Nothing</code>. We’ve accepted more parameters, but we’ve pushed a lot of responsibility forward for handling possible failure.
</p>

 <p>
Let’s push the failure back.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">safeDivide</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">NonZero</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Int</span>
 <span class="org-haskell-definition">safeDivide</span> i ( <span class="org-haskell-constructor">NonZero</span> j)  <span class="org-haskell-operator">=</span> i  <span class="org-haskell-operator">`div`</span> j</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We’ve required that users provide us a  <code>NonZero Int</code> rather than any old  <code>Int</code>. We’ve pushed back against the callers of our function:
</p>

 <blockquote>
 <p>
No! You must provide a  <code>NonZero Int</code>. I refuse to work with just any  <code>Int</code>, because then I might fail, and that’s annoying.
</p>
</blockquote>

 <p>
So speaks our valiant little function, standing up for itself!
</p>

 <p>
Let’s implement  <code>NonZero</code>. We’ll take advantage of Haskell’s  <code>PatternSynonyms</code> language extension to allow people to pattern match on a “constructor” without exposing a way to unsafely construct values.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-pragma">{-# LANGUAGE PatternSynonyms #-}</span>

 <span class="org-haskell-keyword">module</span>  <span class="org-haskell-constructor">NonZero</span>
  (  <span class="org-haskell-constructor">NonZero()</span>
  ,  <span class="org-haskell-keyword">pattern</span>  <span class="org-haskell-constructor">NonZero</span>
  , unNonZero
  , nonZero
  )  <span class="org-haskell-keyword">where</span>

 <span class="org-haskell-keyword">newtype</span>  <span class="org-haskell-type">NonZero</span> a  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">UnsafeNonZero</span> a

 <span class="org-haskell-keyword">pattern</span>  <span class="org-haskell-constructor">NonZero</span> a  <span class="org-haskell-operator">&lt;-</span>  <span class="org-haskell-constructor">UnsafeNonZero</span> a

 <span class="org-haskell-definition">unNonZero</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">NonZero</span> a  <span class="org-haskell-operator">-&gt;</span> a
 <span class="org-haskell-definition">unNonZero</span> ( <span class="org-haskell-constructor">UnsafeNonZero</span> a)  <span class="org-haskell-operator">=</span> a

 <span class="org-haskell-definition">nonZero</span>  <span class="org-haskell-operator">::</span> ( <span class="org-haskell-type">Num</span> a,  <span class="org-haskell-type">Eq</span> a)  <span class="org-haskell-operator">=&gt;</span> a  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Maybe</span> ( <span class="org-haskell-type">NonZero</span> a)
 <span class="org-haskell-definition">nonZero</span> 0  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Nothing</span>
 <span class="org-haskell-definition">nonZero</span> i  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Just</span> ( <span class="org-haskell-constructor">UnsafeNonZero</span> i)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This module allows us to push the responsibility for type safety backwards onto callers.
</p>

 <p>
As another example, consider  <code>head</code>. Here’s the unsafe, convenient variety:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">head</span>  <span class="org-haskell-operator">::</span> [a]  <span class="org-haskell-operator">-&gt;</span> a
 <span class="org-haskell-definition">head</span> (x <span class="org-haskell-constructor">:</span>xs)  <span class="org-haskell-operator">=</span> x
 <span class="org-haskell-definition">head</span>  <span class="org-haskell-constructor">[]</span>      <span class="org-haskell-operator">=</span> error  <span class="org-string">&quot;oh no&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This code is making a promise that it can’t keep. Given the empty list, it will fail at runtime.
Let’s push the responsibility for safety forward:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">headMay</span>  <span class="org-haskell-operator">::</span> [a]  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Maybe</span> a
 <span class="org-haskell-definition">headMay</span> (x <span class="org-haskell-constructor">:</span>xs)  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Just</span> x
 <span class="org-haskell-definition">headMay</span>  <span class="org-haskell-constructor">[]</span>      <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Nothing</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now, we won’t fail at runtime. We’ve required the caller to handle a  <code>Nothing</code> case.
Let’s try pushing it back now:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">headOr</span>  <span class="org-haskell-operator">::</span> a  <span class="org-haskell-operator">-&gt;</span> [a]  <span class="org-haskell-operator">-&gt;</span> a
 <span class="org-haskell-definition">headOr</span> def (x <span class="org-haskell-constructor">:</span>xs)  <span class="org-haskell-operator">=</span> x
 <span class="org-haskell-definition">headOr</span> def  <span class="org-haskell-constructor">[]</span>      <span class="org-haskell-operator">=</span> def</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now, we’re requiring that the  <i>caller</i> of the function handle possible failure before they ever call this. There’s no way to get it wrong. Alternatively, we can use a type for nonempty lists!
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">NonEmpty</span> a  <span class="org-haskell-operator">=</span> a  <span class="org-haskell-constructor">:|</span> [a]

 <span class="org-haskell-definition">safeHead</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">NonEmpty</span> a  <span class="org-haskell-operator">-&gt;</span> a
 <span class="org-haskell-definition">safeHead</span> (x  <span class="org-haskell-constructor">:|</span> xs)  <span class="org-haskell-operator">=</span> x</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This one works just as well. We’re requiring that the calling code handle failure ahead of time.
</p>

 <p>
A more complicated example of this technique is the  <a href="https://hackage.haskell.org/package/justified-containers-0.1.2.0/docs/Data-Map-Justified-Tutorial.html"> <code>justified-containers</code></a> library. The library uses the type system to prove that a given key exists in the underlying  <code>Map</code>. From that point on, lookups using those keys are  <i>total</i>: they are guaranteed to return a value, and they don’t return a  <code>Maybe</code>.
</p>

 <p>
This works even if you  <code>map</code> over the  <code>Map</code> with a function, transforming values. You can also use it to ensure that two maps share related information. It’s a powerful feature, beyond just having type safety.
</p>
 <h2>The Ripple Effect  <a id="the-ripple-effect" class="anchor" href="#the-ripple-effect" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org6490b51">
 <p>
When some piece of code hands us responsibility, we have two choices:
</p>

 <ol class="org-ol"> <li>Handle that responsibility.</li>
 <li>Pass it to someone else!</li>
</ol> <p>
In my experience, developers will tend to push responsibility in the same direction that the code they call does. So if some function returns a  <code>Maybe</code>, the developer is going to be inclined to also return a  <code>Maybe</code> value. If some function requires a  <code>NonEmpty Int</code>, then the developer is going to be inclined to  <i>also</i> require a  <code>NonEmpty Int</code> be passed in.
</p>

 <p>
This played out in my work codebase. We have a type representing an  <code>Order</code> with many =Item=s in it. Originally, the type looked something like this:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">Order</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Order</span>  { items  <span class="org-haskell-operator">::</span> [ <span class="org-haskell-type">Item</span>] }</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The  <code>Item=s contained nearly all of the interesting information in the order, so almost everything that we did with an =Order</code> would need to return a  <code>Maybe</code> value to handle the empty list case. This was a lot of work, and a lot of  <code>Maybe</code> values!
</p>

 <p>
The type is  <i>too permissive</i>. As it happens, an  <code>Order</code> may not exist without at least one  <code>Item</code>. So we can make the type  <i>more restrictive</i> and have more fun!
</p>

 <p>
We redefined the type to be:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">Order</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Order</span> { items  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">NonEmpty</span>  <span class="org-haskell-type">Item</span> }</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
All of the =Maybe=s relating to the empty list were purged, and all of the code was pure and free. The failure case (an empty list of orders) was moved to two sites:
</p>

 <ol class="org-ol"> <li>Decoding JSON</li>
 <li>Decoding database rows</li>
</ol> <p>
Decoding JSON happens at the API side of things, when various services  <code>POST</code> updates to us. Now, we can respond with a  <code>400</code> error and tell API clients that they’ve provided invalid data! This prevents our data from going bad.
</p>

 <p>
Decoding database rows is even easier. We use an  <code>INNER JOIN</code> when retrieving  <code>Order=s and =Item=s, which guarantees that each =Order</code> will have at least one  <code>Item</code> in the result set. Foreign keys ensure that each  <code>Item</code>’s  <code>Order</code> is actually present in the database. This does leave the possibility that an  <code>Order</code> might be orphaned in the database, but it’s mostly safe.
</p>

 <p>
When we push our type safety back, we’re encouraged to continue pushing it back. Eventually, we push it all the way back – to the edges of our system! This simplifies all of the code and logic inside of the system. We’re taking advantage of types to make our code simpler, safer, and easier to understand.
</p>
</div>
 <h2>Ask Only What You Need  <a id="ask-only-what-you-need" class="anchor" href="#ask-only-what-you-need" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org29c7c61">
 <p>
In many senses, designing our code with type safety in mind is about being as strict as possible about your possible inputs. Haskell makes this easier than many other languages, but there’s nothing stopping you from writing a function that can take literally any binary value, do whatever effects you want, and return whatever binary value:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">foobar</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">ByteString</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">IO</span>  <span class="org-haskell-type">ByteString</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
A  <code>ByteString</code> is a totally unrestricted data type. It can contain any sequence of bytes. Because it can express any value, we have very little guarantees on what it actually contains, and we are very limited in how we can safely handle this.
</p>

 <p>
By restricting our past, we gain freedom in the future.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Why Haskell is important?</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Running Hoogle locally</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/">Free à la Carte</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/">Running Hoogle locally</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/">Why Haskell is important?</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/index.html</guid>
  <pubDate>Tue, 13 Sep 2022 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Why Haskell is important?</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
A really nice explanation from the
 <a href="https://www.tweag.io/blog/2019-09-06-why-haskell-is-important/">Tweag</a>
team, that reflects exactly how I think about the subject.
</p>

 <p>
People keep asking me, “What’s the point of Haskell, why do you folks
even use it?”. How can you answer this? Most of us Haskell practitioners
would start talking about strong static types, the elegance of
abstractions, and ease of refactoring—but we would be missing the
bigger picture. That’s because we are programmers, and programmers
typically think about the technical details.
</p>

 <p>
Let’s take a step back.
</p>

 <p>
We can view lots of things as black boxes that do stuff. Deep learning,
for example, allows us to solve certain problems we couldn’t tackle
before. Another set of technologies helped us put a man on the moon. No
one is going to ask “What’s the point of deep learning?” or “What’s the
point of a spaceship?”. That’s obvious.
</p>

 <p>
At this point, one could balk: “Mark, but you’re comparing apples to
oranges.”. Really? Let’s see. Deep learning is an approach to solve a
problem. What about programming languages? They’re an approach to solve
a problem too: they allow us to write programs. But programs can be
different. Some programs are complicated and very difficult to write in
some languages, say assembly. It can also be challenging in some
languages to convince ourselves that they are correct programs, say when
effects are unrestricted or invariants are not protected. By viewing
programming languages as black boxes, we could say that some of those
unlock creation of more and more complex high-quality software. And in
that respect, programming languages are not so different from deep
learning or space travel—they allow us to do something we could not do
before.
</p>

 <p>
Let’s forget about what makes Haskell what it is. Let’s view it as a
black box and see what we can make of it. It’s a thing that comes with
some risks and seeing just its output, in most cases we really can’t say
if it does something different than other languages do. It doesn’t allow
us to make a quantum leap. You could write your software in Haskell or
in some other popular language X—other things being equal, if X is
anything pertinent to your problem domain, you’ll do fine if you have
access to engineers with substantial experience in X.
</p>

 <p>
Still I must say that it’s essential for us to continue writing Haskell.
Why?
</p>

 <p>
Richard Eisenberg predicted, at ZuriHac 2019, that we might not be using
Haskell itself in the distant future. Perhaps a different language—but
it will be built on the valuable discoveries we made with Haskell. I’m
confident that his prediction will come true because:
</p>

 <p>
Haskell is a unique vehicle for bringing modern programming language
theory (PLT) to a production-quality programming language (†) where
results of such research can be tried out very quickly by programmers
tasked to solve real problems every day. For almost every other
language, one of the following is true:
</p>

 <p>
it is an experimental language with a small developer base that sees
virtually no practical usage it is a practical language that’s widely
used but not advancing very quickly, burdened by its huge user base and
legacy code. I think there’s lots of value in the linear and dependent
types research happening now. Not because those features allow us to
solve harder problems the first day they land in GHC (the main Haskell
compiler). They probably won’t. But, they can allow us to start trying
to use the features in practice, which is the necessary condition if we
want to build tomorrow’s super language.
</p>

 <p>
Haskell is not a proprietary language built, controlled, or subject to
the whims of some commercial entity. It is instead open source software,
a product of a collective effort by academics and enthusiastic users.
Haskell’s tight, active community and its spirit of experimentation are
perfect for moving forward with more exploration.
</p>

 <p>
Haskell evolves fast. I’m a relatively new user who started using it in
2014, but even over just 5 years, I can say that the language has
changed quite a bit and a lot of new features appeared in GHC. Veteran
Haskellers who have been using it for a decade or more can attest that
many things have changed for the better.
</p>

 <p>
Haskell thrives with ideas. Not only the compiler itself, but also its
ecosystem of libraries—Haskellers are in a constant search for better
solutions. Some of these solutions prove to be elegant and powerful, so
they stick. Others are soon forgotten. Of course, the same thing happens
in other languages, but what is so unique about Haskell is that the
language itself acts as a foundation with unique qualities which make
its users lean to more principled, although not-so-obvious solutions.
</p>

 <p>
So what, why explore those solutions? Is it worth it?
</p>

 <p>
The numerous techniques and concepts of functional programming that
mainstream languages adopt and, without doubt, will keep adopting
validate that Haskell continues to move in the right direction. It has
heavily influenced design of newer languages such as Rust, and its
influence is destined to continue. There are plenty of blog posts and
articles praising strong static typing and its value for making
programmers more productive nowadays. Haskell’s core principles, like
purity and isolation of side-effects, are understood and appreciated by
more today than ever before.
</p>

 <p>
Skeptical? That’s fine. Just remember that the idea for neural networks
is from the 1950s. It took quite some time for us to get the
computational power and data to make that idea useful. Haskell started
without a way to perform side effects but evolved to be adopted by
cutting-edge players like Facebook and Google to do real work today.
Time will only bring more great things—I don’t see an end to Haskell’s
evolution.
</p>

 <p>
(†) If you do not believe that a lot of companies use Haskell, you may
find that you are a victim of the same type of outdated world view as
the one described by Hans Rosling in his book Factfulness. The world is
changing and it’s changing quickly. What was true for Haskell ten years
ago is not true anymore. It’s fine to still poke jokes about unemployed
Haskellers, almost by inertia, but here are some facts to consider:
we’re hiring Haskell developers all the time, and I know quite a few
other companies that do the same. I, for one, have been a Haskeller for
my entire professional career and write in other languages only
occasionally. Am I so unique or the world is changing?
</p>

 <p>
If you enjoyed this article, you might be interested in joining the
Tweag team.
</p>

 <p>
This article is licensed under a Creative Commons Attribution 4.0
International license.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/arch-linux-uefi-encryption/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Arch Linux UEFI + Encryption</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Type safety back and forth</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/">Free à la Carte</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/">Running Hoogle locally</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/">Type safety back and forth</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/index.html</guid>
  <pubDate>Sun, 11 Sep 2022 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Arch Linux UEFI + Encryption</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
This is a step by step guide to installing Arch Linux on UEFI with full
disk encryption. It deliberately contains no unnecessary words or bling.
It is heavily based on the Arch Linux wiki’s installation guide so if
you’re ever stuck, just refer to it and the rest of
 <a href="https://wiki.archlinux.org/">the awesome Arch wiki</a>.
</p>
 <h3>Download ISO  <a id="download-iso" class="anchor" href="#download-iso" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-download-iso">
 <p>
Download the latest ISO from  <a href="https://archlinux.org/download/">the Arch
Linux website</a>.
</p>
</div>
 <h3>Create Bootable USB Stick  <a id="create-bootable-usb-stick" class="anchor" href="#create-bootable-usb-stick" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-create-bootable-usb-stick">
 <p>
You can skip this step if you just want to run Arch Linux in a VM. In
that case, just run the ISO from your favorite VM management tool like
QEMU, VirtualBox or VMWare.
</p>

 <p>
Insert an USB stick into your computer and run  <code>lsblk</code> to find the
correct disk.
</p>

 <p>
Then run  <code>sudo umount /dev/sdx</code> or whatever your USB stick is named.
</p>

 <p>
Run
 <code>sudo dd bs=4M if=path/to/input.iso of=/dev/sdx oflag=sync status=progress</code>
to write the ISO to the USB stick. Don’t forget to replace the two paths
with the correct ones.
</p>

 <p>
Insert the USB stick into the target computer and boot it from there.
</p>

 <p>
As soon as you can see the Arch Linux prompt, you are ready for the next
step. If you don’t know how to boot from a USB stick on a computer, you
probably shouldn’t go for Arch Linux and its “do-it yourself” attitude.
</p>
</div>
 <h3>Check for UEFI support  <a id="check-for-uefi-support" class="anchor" href="#check-for-uefi-support" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-check-for-uefi-support">
 <p>
Run  <code>ls /sys/firmware/efi/efivars</code> to check if that directory exists.
</p>

 <p>
If it doesn’t, your system does not support UEFI and this guide is not
for you and you should refer to the official Arch Linux Installation
Guide for Legacy BIOS / MBR instead.
</p>
</div>
 <h3>Establish Connectivity  <a id="establish-connectivity" class="anchor" href="#establish-connectivity" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-establish-connectivity">
 <p>
Connect the computer via ethernet (recommended) or run  <code>iwctl</code> to log
into WiFi. Check for internet connectivity with  <code>ping archlinux.org</code>.
Once connected make sure the clock is synced with
 <code>timedatectl set-ntp true</code>.
</p>
</div>
 <h3>Partition  <a id="partition" class="anchor" href="#partition" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-partition">
 <p>
Check for different drives and partitions with  <code>lsblk</code> and then start to
partition with  <code>gdisk /dev/nvme0n1</code> (or whatever the disk is).
</p>

 <p>
Delete any existing partitions using  <code>d</code>.
</p>

 <p>
Create boot partition with  <code>n</code> with default number, default first
sector, last sector at  <code>+512M</code> and select  <code>ef00</code> “EFI System” as the
type.
</p>

 <p>
Create root partition with  <code>n</code> with default number, default first
sector, default last sector and select  <code>8300</code> “Linux filesystem” as the
type.
</p>

 <p>
Press  <code>w</code> to write partitions.
</p>

 <p>
Run  <code>lsblk</code> again to verify partitioning.
</p>
</div>
 <h3>Encrypt Root Partition  <a id="encrypt-root-partition" class="anchor" href="#encrypt-root-partition" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-encrypt-root-partition">
 <p>
Run  <code>cryptsetup -y -v luksFormat /dev/nvme0n1p2</code> and then type  <code>YES</code> and
the new encryption password to encrypt the root partition.
</p>

 <p>
Run  <code>cryptsetup open /dev/nvme0n1p2 cryptroot</code> to open the encrypted
partition.
</p>
</div>
 <h3>Create File Systems  <a id="create-file-systems" class="anchor" href="#create-file-systems" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-create-file-systems">
 <p>
Create the boot file system with  <code>mkfs.fat -F32 /dev/nvme0n1p1</code> (or
whatever the partition is called).
</p>

 <p>
Create the root file system with  <code>mkfs.ext4 /dev/mapper/cryptroot</code>.
</p>
</div>
 <h3>Mount File Systems  <a id="mount-file-systems" class="anchor" href="#mount-file-systems" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-mount-file-systems">
 <p>
Run  <code>mount /dev/mapper/cryptroot /mnt</code> to mount the root file system.
</p>

 <p>
Run  <code>mkdir /mnt/boot</code> to create the boot directory.
</p>

 <p>
Run  <code>mount /dev/nvme0n1p1 /mnt/boot</code> to mount your boot file system.
</p>

 <p>
Run  <code>lsblk</code> again to verify mounting.
</p>
</div>
 <h3>Create Swap File (not needed on VMs)  <a id="create-swap-file-not-needed-on-vms" class="anchor" href="#create-swap-file-not-needed-on-vms" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-create-swap-file-not-needed-on-vms">
 <p>
Run  <code>dd if=/dev/zero of=/mnt/swapfile bs=1M count=20576 status=progress</code>
to create the swap file where the count is the number of megabytes you
want the swap file to be (usually around 1.5 times the size of your
RAM).
</p>

 <p>
Run  <code>chmod 600 /mnt/swapfile</code> to set the right permissions on it.
</p>

 <p>
Run  <code>mkswap /mnt/swapfile</code> to make it an actual swap file.
</p>

 <p>
Run  <code>swapon /mnt/swapfile</code> to turn it on.
</p>
</div>
 <h3>Install Arch Linux  <a id="install-arch-linux" class="anchor" href="#install-arch-linux" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-install-arch-linux">
 <p>
Run  <code>pacstrap /mnt base base-devel linux linux-firmware neovim</code> to
install Arch Linux (linux-firmware is not needed on VMs).
</p>
</div>
 <h3>Generate File System Table  <a id="generate-file-system-table" class="anchor" href="#generate-file-system-table" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-generate-file-system-table">
 <p>
Run  <code>genfstab -U /mnt &gt;&gt; /mnt/etc/fstab</code> to generate fstab with UUIDs.
</p>
</div>
 <h3>Switch to Your New Linux Installation  <a id="switch-to-your-new-linux-installation" class="anchor" href="#switch-to-your-new-linux-installation" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-switch-to-your-new-linux-installation">
 <p>
Run  <code>arch-chroot /mnt</code> to switch to your new Arch Linux installation.
</p>
</div>
 <h3>Set Locales  <a id="set-locales" class="anchor" href="#set-locales" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-set-locales">
 <p>
Run  <code>ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime</code> (or
whatever your timezone is) to set your time zone.
</p>

 <p>
Run  <code>hwclock --systohc</code>.
</p>

 <p>
Run  <code>nvim /etc/locale.gen</code> and uncomment yours (e.g. en_US.UTF-8 UTF-8).
</p>

 <p>
Run  <code>locale-gen</code> to generate the locales.
</p>

 <p>
Run  <code>echo 'LANG=en_US.UTF-8' &gt; /etc/locale.conf</code>.
</p>
</div>
 <h3>Set Hostname  <a id="set-hostname" class="anchor" href="#set-hostname" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-set-hostname">
 <p>
Run  <code>echo 'myHostname' &gt; /etc/hostname</code> (or whatever your hostname
should be).
</p>

 <p>
Run  <code>nvim /etc/hosts</code> and insert the following lines:
</p>

 <pre class="example" id="orgad1f455">
127.0.0.1     localhost
::1           localhost
127.0.1.1     arch.localdomain        myHostname
</pre>

 <p>
for the last line: change  <code>myHostname</code> to whatever hostname you picked
in the previous step.
</p>
</div>
 <h3>Set Root Password  <a id="set-root-password" class="anchor" href="#set-root-password" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-set-root-password">
 <p>
Run  <code>passwd</code> and set your root password.
</p>
</div>
 <h3>Configure Initramfs  <a id="configure-initramfs" class="anchor" href="#configure-initramfs" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-configure-initramfs">
 <p>
Run  <code>nvim /etc/mkinitcpio.conf</code> and, to the  <code>HOOKS</code> array, add
 <code>keyboard</code> between  <code>autodetect</code> and  <code>modconf</code> and add  <code>encrypt</code> between
 <code>block</code> and  <code>filesystems</code>.
</p>

 <p>
Run  <code>mkinitcpio -P</code>.
</p>
</div>
 <h3>Install Boot Loader  <a id="install-boot-loader" class="anchor" href="#install-boot-loader" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-install-boot-loader">
 <p>
Run  <code>pacman -S grub efibootmgr intel-ucode</code> (or  <code>amd-ucode</code> if you have
an AMD processor) to install the GRUB package and CPU microcode.
</p>

 <p>
Run  <code>blkid -s UUID -o value /dev/nvme0n1p2</code> to get the UUID of the
device.
</p>

 <p>
Run  <code>nvim /etc/default/grub</code> and set  <code>GRUB_TIMEOUT=0</code> to disable GRUB
waiting until it chooses your OS (only makes sense if you don’t dual
boot with another OS), then set
 <code>GRUB_CMDLINE_LINUX</code>“cryptdevice=UUID=xxxx:cryptroot”= while replacing
 <code>xxxx</code> with the UUID of the  <code>nvme0n1p2</code> device to tell GRUB about our
encrypted file system.
</p>

 <p>
Run
 <code>grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB</code>
to install GRUB for your system.
</p>

 <p>
Run  <code>grub-mkconfig -o /boot/grub/grub.cfg</code> to configure GRUB.
</p>
</div>
 <h3>Install Network Manager  <a id="install-network-manager" class="anchor" href="#install-network-manager" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-install-network-manager">
 <p>
Run  <code>pacman -S networkmanager</code> to install NetworkManager.
</p>

 <p>
Run  <code>systemctl enable NetworkManager</code> to run NetworkManager at boot.
</p>
</div>
 <h3>Reboot  <a id="reboot" class="anchor" href="#reboot" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-reboot">
 <p>
Run  <code>exit</code> to return to the outer shell.
</p>

 <p>
Run  <code>reboot</code> to get out of the setup by restarting the machine.
</p>

 <p>
After the machine starts, remove the installation medium and you will
boot into Arch Linux from your HDD.
</p>
</div>
 <h3>Connect to WiFi (only needed if there’s no ethernet connection)  <a id="connect-to-wifi-only-needed-if-theres-no-ethernet-connection" class="anchor" href="#connect-to-wifi-only-needed-if-theres-no-ethernet-connection" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-connect-to-wifi-only-needed-if-theres-no-ethernet-connection">
 <p>
The use of  <code>nmcli</code> is prefered to  <code>iwctl</code> for reasons of simplicity and
user-friendliness.
</p>

 <p>
Run  <code>nmcli d wifi list</code> to list the available networks.
</p>

 <p>
Run  <code>nmcli d wifi connect MY_WIFI password MY_PASSWORD</code> to connect to
one of them.
</p>
</div>
 <h3>Add User  <a id="add-user" class="anchor" href="#add-user" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-add-user">
 <p>
Run  <code>EDITOR=nvim visudo</code> and uncomment  <code>%wheel ALL=(ALL) NOPASSWD: ALL</code>
to allow members of the  <code>wheel</code> group to run privileged commands.
</p>

 <p>
Run  <code>useradd --create-home --groups wheel,video joe</code> (or whatever your
user name should be) to create the user.
</p>

 <p>
Run  <code>passwd joe</code> to set your password.
</p>

 <p>
Run  <code>exit</code> and log back in with your new user.
</p>
</div>
 <h3>Install a Firewall  <a id="install-a-firewall" class="anchor" href="#install-a-firewall" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-install-a-firewall">
 <p>
Run  <code>sudo pacman -S nftables</code> to install the firewall
</p>

 <p>
Run  <code>sudo nvim /etc/nftables.conf</code> to edit the config to our liking and
remove the part about allowing incoming SSH connections if you don’t
need that.
</p>

 <p>
Run  <code>sudo systemctl enable nftables.service --now</code> to enable the
firewall.
</p>
</div>
 <h3>Enable Time Synchronization  <a id="enable-time-synchronization" class="anchor" href="#enable-time-synchronization" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-enable-time-synchronization">
 <p>
Run  <code>sudo systemctl enable systemd-timesyncd.service --now</code> to enable
automated time synchronization.
</p>
</div>
 <h3>Improve Power Management (only makes sense on laptops)  <a id="improve-power-management-only-makes-sense-on-laptops" class="anchor" href="#improve-power-management-only-makes-sense-on-laptops" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-improve-power-management-only-makes-sense-on-laptops">
 <p>
Run  <code>sudo pacman -S tlp tlp-rdw</code> to install TLP.
</p>

 <p>
Run  <code>sudo systemctl enable tlp.service --now</code> to run power optimizations
automatically.
</p>

 <p>
Run  <code>sudo systemctl enable NetworkManager-dispatcher.service --now</code> to
prevent conflicts.
</p>

 <p>
Run  <code>sudo tlp-stat</code> and follow any recommendations there.
</p>
</div>
 <h3>Enable Scheduled fstrim  <a id="enable-scheduled-fstrim" class="anchor" href="#enable-scheduled-fstrim" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-enable-scheduled-fstrim">
 <p>
This only makes sense for SSD.
</p>

 <p>
Run  <code>sudo systemctl enable fstrim.timer --now</code> to enable regular
housekeeping of your SSD.
</p>
</div>
 <h3>Enable Scheduled Mirrorlist Updates  <a id="enable-scheduled-mirrorlist-updates" class="anchor" href="#enable-scheduled-mirrorlist-updates" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-enable-scheduled-mirrorlist-updates">
 <p>
Run  <code>sudo pacman -S reflector</code> to install reflector.
</p>

 <p>
Run  <code>sudo nvim /etc/xdg/reflector/reflector.conf</code> and change the file to
your liking.
</p>

 <p>
Run=sudo systemctl enable reflector.timer –now= to enable running
reflector regularly.
</p>
</div>
 <h3>Reduce Swappiness  <a id="reduce-swappiness" class="anchor" href="#reduce-swappiness" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-reduce-swappiness">
 <p>
This only makes sense if you have more than 4GB of RAM.
</p>

 <p>
Run
 <code>echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf</code> to
reduce the swappiness permanently.
</p>
</div>
 <h3>The coolest Pacman  <a id="the-coolest-pacman" class="anchor" href="#the-coolest-pacman" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-the-coolest-pacman">
 <p>
If you want to make Pacman look cooler you can edit the configuration
file with  <code>sudo nvim /etc/pacman.conf</code> and uncomment the  <code>Color</code> option
and add just below the  <code>ILoveCandy</code> option.
</p>
</div>
 <h3>Installing Plasma DE  <a id="installing-plasma-de" class="anchor" href="#installing-plasma-de" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-installing-plasma-de">
 <p>
I personally choose for Plasma DE (KDE), but of course if you prefer
another setup now is the time to leave this guide. Hope you found it
useful.
</p>

 <p>
To install Plasma run
 <code>sudo pacman -S xorg plasma plasma-wayland-session kde-applications</code>.
This might take a while.
</p>

 <p>
Then enable auto-start at boot with
</p>

 <div class="jfw-code"> <pre>sudo systemctl enable sddm.service
sudo systemctl enable NetworkManager.service</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
And restart your machine with  <code>sudo reboot</code>.
</p>
</div>
 <h2>Welcome to the master race of Arch Linux  <a id="welcome-to-the-master-race-of-arch-linux" class="anchor" href="#welcome-to-the-master-race-of-arch-linux" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-welcome-to-the-master-race-of-arch-linux">
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/gnu-guix-virtual-machine-image-aarch64/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">GNU Guix VM aarch64</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Why Haskell is important?</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/arch-linux-uefi-encryption/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/arch-linux-uefi-encryption/index.html</guid>
  <pubDate>Wed, 22 Dec 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>GNU Guix VM aarch64</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
One day, I decided on a whim to try Guix in a VM on a M3 Mac.
</p>

 <p>
It seemed like a good idea at the time, but I’d never used Guix before and it ended up being quite a grind to figure out how to get it running.
</p>

 <p>
The initial issue for me was that Guix doesn’t provide iso installer images for aarch64.
</p>

 <p>
Yes, you can build one yourself, but after I’d put in the time to figure out how to do that, though, the iso installer would just hang. The serial console would say
</p>


 <pre class="example" id="org70385ce">
waiting for partition '31393730-3031-3031-3139-333333313833' to appear...
</pre>

 <p>
The Guix ISO installer didn’t work for me on aarch64. Making a qcow2 VM image or doing a manual install did work.
</p>

 <p>
I show a list of steps for getting Guix installed on an aarch64 VM on macOS, and include a small starter confguration file.
</p>

 <p>
It can be helpful to pull a specific commit of the distro that includes a working, precompiled kernel.
</p>

 <p>
Update the Guix package descriptions and basic packages:
</p>

 <pre class="example" id="orga793bd9">
user@debian:~$ guix pull
</pre>

 <p>
This will take a while.
</p>

 <p>
Create a Guix configuration file on the Debian system. It defines how your Guix install is set up and what it will initially contain.
</p>

 <p>
Put the following into a file called  <code>config.scm</code> on Debian:
</p>

 <pre class="example" id="orgaf25acb">
(use-modules (gnu))
(use-service-modules networking)
(use-package-modules certs)

(operating-system
  (host-name &quot;guix&quot;)
  (timezone &quot;Europe/Berlin&quot;)
  (locale &quot;en_US.utf8&quot;)

  (bootloader (bootloader-configuration
                (bootloader grub-efi-bootloader)
                (targets '(&quot;/boot/efi&quot;))))
  (kernel-arguments (list &quot;console=ttyS0,115200&quot;))
  (file-systems (append
          (list (file-system
                          (device &quot;/dev/vda2&quot;)
                          (mount-point &quot;/&quot;)
                          (type &quot;ext4&quot;))
                        (file-system
                          (device &quot;/dev/vda1&quot;)
                          (mount-point &quot;/boot/efi&quot;)
                          (type &quot;vfat&quot;)))
                      %base-file-systems))

  (users (cons (user-account
                (name &quot;yourname&quot;)
                (group &quot;users&quot;)

                (supplementary-groups '(&quot;wheel&quot;
                                        &quot;audio&quot; &quot;video&quot;)))
               %base-user-accounts))

  (packages (append (list nss-certs) %base-packages))

  (services (append (list (service dhcp-client-service-type))
                    %base-services)))
</pre>

 <p>
This was adapted from the Guix  <code>bare-bones.tmpl</code> and  <code>lightweight-desktop.tmpl</code> files.
</p>

 <p>
Build a Guix VM image. This will be the qemu hard drive for your Guix VM.
</p>

 <pre class="example" id="org24fcba5">
guix system image --image-type=qcow2 --image-size=140G config.scm
</pre>

 <p>
This will take a while.
</p>

 <p>
At the end of the process, it will leave you with the name of a qcow2 image file:
</p>

 <pre class="example" id="orgaf2be3b">
/gnu/store/z08hk66ig6dn32ivvysphr0d2b0alym0-image.qcow2
</pre>

 <p>
Mine was 422Mb in size.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">rc.d scripting</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/arch-linux-uefi-encryption/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Arch Linux UEFI + Encryption</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/gnu-guix-virtual-machine-image-aarch64/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/gnu-guix-virtual-machine-image-aarch64/index.html</guid>
  <pubDate>Wed, 22 Dec 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>rc.d scripting</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
FreeBSD uses the init system, and system services must be made as rc.d
scripts.
</p>

 <p>
You can find more detailed information and examples in the handbook:
 <a href="https://docs.freebsd.org/en/articles/rc-scripting/">Practical rc.d
scripting in FreeBSD</a>.
</p>
 <h2>CLI options choice for daemons  <a id="cli-options-choice-for-daemons" class="anchor" href="#cli-options-choice-for-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-cli-options-choice-for-daemons">
 <p>
Find below the options we normally use for any  <code>/etc/rc.d</code> script as
daemon. See more options by in the terminal issuing:
</p>

 <pre class="example" id="org5d6ff26">
man daemon
</pre>

 <p>
 <code>-f</code>: Redirect standard input, standard output and standard error to
 <code>/dev/null</code>. When this option is used together with any of the options
related to file or syslog output, the standard file descriptors are
first redirected to  <code>/dev/null</code>, then stdout and/or stderr is redirected
to a file or to syslog as specified by the other options.
</p>

 <p>
 <code>-S</code>: Enable syslog output. This is implicitly applied if other syslog
parameters are provided. The default values are  <code>daemon</code>,  <code>notice</code>, and
 <code>daemon</code> for facility, priority, and tag, respectively.
</p>

 <p>
 <code>-P &lt;supervisor pid file&gt;</code>: Write the ID of the daemon process into the
file with given name using the  <code>pidfile</code> functionality. The program is
executed in a spawned child process while the daemon waits until it
terminates to keep the  <code>supervisor_pidfile</code> locked and removes it after
the process exits. The  <code>supervisor_pidfile</code> owner is the user who runs
the daemon regardless of whether the  <code>-u</code> option is used or not.
</p>

 <p>
 <code>-r</code>: Supervise and restart the program after a one-second delay if it
has been terminated.
</p>
</div>
 <h2>Connecting a script to the rc.d framework  <a id="connecting-a-script-to-the-rc.d-framework" class="anchor" href="#connecting-a-script-to-the-rc.d-framework" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-connecting-a-script-to-the-rc.d-framework">
 <p>
In a nutshell,
 <a href="https://www.freebsd.org/cgi/man.cgi?query=rcorder&amp;sektion=8&amp;format=html">rcorder</a>
takes a set of files, examines their contents, and prints a
dependency-ordered list of files from the set to stdout. The point is to
keep dependency information inside the files so that each file can speak
for itself only. A file can specify the following information:
</p>

 <ul class="org-ul"> <li>the names of the “conditions” (which means services to us) it provides
with  <code># KEYWORD</code>:</li>
 <li>the names of the “conditions” it requires with  <code># REQUIRE</code>:</li>
 <li>the names of the “conditions” this file should run before with
 <code># BEFORE</code>:</li>
 <li>additional keywords that can be used to select a subset from the whole
set of files (rcorder(8) can be instructed via options to include or
omit the files having particular keywords listed.) with  <code># KEYWORD</code>:</li>
</ul> <p>
As a rule of thumb, every custom made rc.d script should provide 1
daemon, and require  <code>DAEMON</code> and  <code>networking</code> to be initialized. Thus
the first lines of your rc.d script will generally look something like:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span> <span class="org-comment-delimiter">#</span> <span class="org-comment">
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: &lt;name of this rc.d script&gt;
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Daemon load order  <a id="daemon-load-order" class="anchor" href="#daemon-load-order" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-daemon-load-order">
 <p>
The order in which the daemons load is highly important. For this
example, imagine you have an API application running with an rc.d script
called  <code>my_api_service</code>. It should run as a daemon and should be able to
access the network.
</p>

 <p>
This means that it should only load after  <code>DAEMON</code> and  <code>networking</code> are
loaded and running.
</p>

 <p>
You can verify the load order with:
</p>

 <pre class="example" id="orge1c1113">
service -e
</pre>

 <p>
The correct load order in this case then would be :
</p>

 <pre class="example" id="org2682626">
service -e

/etc/rc.d/cleanvar
/etc/rc.d/ip6addrctl
/etc/rc.d/netif
/etc/rc.d/virecover
/etc/rc.d/motd
/etc/rc.d/os-release
/etc/rc.d/newsyslog
/etc/rc.d/syslogd
/etc/rc.d/my_api_service
/etc/rc.d/cron
</pre>
</div>
 <h2>Binaries as daemons  <a id="binaries-as-daemons" class="anchor" href="#binaries-as-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-binaries-as-daemons">
 <p>
In the case of binaries, we will use the daemon in a straightforward
manner. We will run our service as  <code>root</code> user since this will be
running inside a jail, where  <code>root</code> is the only existing user. Feel free
to adjust to your use case. By convention I always create a folder
called  <code>internalApplications</code> inside any jail, and place my binaries
inside there. See the example below for  <code>my_api_service</code>:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span> <span class="org-comment-delimiter">#</span> <span class="org-comment">
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: my_api_service
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:
</span>
 <span class="org-builtin">.</span> /etc/rc.subr

 <span class="org-variable-name">name</span>= <span class="org-string">&quot;my_api_service&quot;</span>
 <span class="org-variable-name">rcvar</span>= <span class="org-string">&quot;my_api_service_enable&quot;</span>
 <span class="org-variable-name">my_api_service_chdir</span>= <span class="org-string">&quot;/root/internalApplications/myAPIWorkingDirectory/&quot;</span>
 <span class="org-variable-name">my_api_service_user</span>= <span class="org-string">&quot;root&quot;</span>
 <span class="org-variable-name">my_api_service_command</span>= <span class="org-string">&quot;/root/internalApplications/myAPIWorkingDirectory/app&quot;</span>
 <span class="org-variable-name">pidfile</span>= <span class="org-string">&quot;/var/run/${name}.pid&quot;</span>
 <span class="org-variable-name">command</span>= <span class="org-string">&quot;/usr/sbin/daemon&quot;</span>
 <span class="org-variable-name">command_args</span>= <span class="org-string">&quot;-P ${pidfile} -r -f -S ${my_api_service_command}&quot;</span>

load_rc_config $ <span class="org-variable-name">name</span>
: ${ <span class="org-variable-name">my_api_service_enable</span>:=no}

run_rc_command  <span class="org-string">&quot;$1&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Shell scripts as daemons  <a id="shell-scripts-as-daemons" class="anchor" href="#shell-scripts-as-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-shell-scripts-as-daemons">
 <p>
Shell scripts that run utilities can also be daemonized. See the example
below:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span>
 <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: my_script_service
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:
</span> <span class="org-builtin">.</span> /etc/rc.subr

 <span class="org-variable-name">name</span>= <span class="org-string">&quot;my_script_service&quot;</span>
 <span class="org-variable-name">rcvar</span>= <span class="org-string">&quot;my_script_service_enable&quot;</span>
 <span class="org-variable-name">my_script_service_user</span>= <span class="org-string">&quot;root&quot;</span>
 <span class="org-variable-name">pidfile</span>= <span class="org-string">&quot;/var/run/${name}.pid&quot;</span>
 <span class="org-variable-name">my_script_service_command</span>= <span class="org-string">&quot;/root/internalApplications/my-script.sh&quot;</span>
 <span class="org-variable-name">command</span>= <span class="org-string">&quot;/usr/sbin/daemon&quot;</span>
 <span class="org-variable-name">command_args</span>= <span class="org-string">&quot;-P ${pidfile} -r -f -S ${my_script_service_command}&quot;</span>

load_rc_config $ <span class="org-variable-name">name</span>
: ${ <span class="org-variable-name">my_script_service_enable</span>:=no}

run_rc_command  <span class="org-string">&quot;$1&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Hopefully you have become a little wiser about rc.d scripting and can
“daemonize” anything that comes your way :)
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">How I write HTTP services</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/gnu-linux/gnu-guix-virtual-machine-image-aarch64/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">GNU Guix VM aarch64</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/">Updating FreeBSD in iocage</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/index.html</guid>
  <pubDate>Fri, 03 Dec 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>How I write HTTP services</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
This is a very interesting learning experience written originally by  <a href="https://pace.dev/blog/2018/05/09/how-I-write-http-services-after-eight-years.html">Mat Ryer</a>.
</p>

 <p>
The way I have written services has changed over time, so I wanted to
share how I write the services today—in case the patterns are useful
to you and your work.
</p>
 <h2>A Server struct  <a id="a-server-struct" class="anchor" href="#a-server-struct" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-a-server-struct">
 <p>
A Server struct is an object that represents the service, and holds all
of its dependencies.
</p>

 <p>
All of my components have a single server structure that usually ends up
looking something like this:
</p>

 <div class="jfw-code"> <pre>type server struct {
    db     *someDatabase
    router *someRouter
    email  EmailSender
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
As you can see, shared dependencies are fields of the struct, and not
stored as global variables. State is thus very centralized.
</p>
</div>
 <h2>routes.go  <a id="routes.go" class="anchor" href="#routes.go" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-routes.go">
 <p>
I have a single file inside every component called routes.go where all
the routing can live:
</p>

 <div class="jfw-code"> <pre>package app

func (s *server) routes() {
    s.router.HandleFunc(&quot;/api/&quot;, s.handleAPI())
    s.router.HandleFunc(&quot;/about&quot;, s.handleAbout())
    s.router.HandleFunc(&quot;/&quot;, s.handleIndex())
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This is handy because most code maintenance starts with a URL and an
error report — so one glance at  <code>routes.go</code> will direct us where to
look.
</p>
</div>
 <h2>Handlers hang off the server  <a id="handlers-hang-off-the-server" class="anchor" href="#handlers-hang-off-the-server" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-handlers-hang-off-the-server">
 <p>
My HTTP handlers hang off the server:
</p>

 <div class="jfw-code"> <pre>func (s *server) handleSomething() http.HandlerFunc { ... }</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Handlers can access the dependencies via the s server variable.
</p>
</div>
 <h2>Return the handler  <a id="return-the-handler" class="anchor" href="#return-the-handler" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-return-the-handler">
 <p>
My handler functions don’t actually handle the requests, they return a
function that does.
</p>

 <p>
This gives us a closure environment in which our handler can operate:
</p>

 <div class="jfw-code"> <pre>func (s *server) handleSomething() http.HandlerFunc {
    thing := prepareThing()
    return func(w http.ResponseWriter, r *http.Request) {
        // use thing
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The  <code>prepareThing</code> is called only once, so you can use it to do one-time
per-handler initialization, and then use the thing in the handler.
</p>

 <p>
Be sure to only read the shared data, if handlers are modifying
anything, remember you’ll need a  <code>mutex</code> or something to protect it.
</p>
</div>
 <h2>Take arguments for handler-specific dependencies  <a id="take-arguments-for-handler-specific-dependencies" class="anchor" href="#take-arguments-for-handler-specific-dependencies" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-take-arguments-for-handler-specific-dependencies">
 <p>
If a particular handler has a dependency, take it as an argument.
</p>

 <div class="jfw-code"> <pre>func (s *server) handleGreeting(format string) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, format, &quot;World&quot;)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The format variable is accessible to the handlers.
</p>
</div>
 <h2>HandlerFunc over Handler  <a id="handlerfunc-over-handler" class="anchor" href="#handlerfunc-over-handler" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-handlerfunc-over-handler">
 <p>
I use  <code>http.HandlerFunc</code> in almost every case now, rather than
 <code>http.Handler</code>.
</p>

 <div class="jfw-code"> <pre>func (s *server) handleSomething() http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        ...
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
They are more or less interchangeable, so just pick whichever is simpler
to read. For me, that’s  <code>http.HandlerFunc</code>.
</p>
</div>
 <h2>Middleware are just Go functions  <a id="middleware-are-just-go-functions" class="anchor" href="#middleware-are-just-go-functions" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-middleware-are-just-go-functions">
 <p>
Middleware functions take an  <code>http.HandlerFunc</code> and return a new one
that can run code before and/or after calling the original handler —
or it can decide not to call the original handler at all.
</p>

 <div class="jfw-code"> <pre>func (s *server) adminOnly(h http.HandlerFunc) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        if !currentUser(r).IsAdmin {
            http.NotFound(w, r)
            return
        }
        h(w, r)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The logic inside the handler can optionally decide whether to call the
original handler or not — in the example above, if  <code>IsAdmin</code> is
 <code>false</code>, the handler will return an  <code>HTTP 404 Not Found</code> and return
(abort); notice that the  <code>h</code> handler is not called.
</p>

 <p>
If  <code>IsAdmin</code> is true, execution is passed to the h handler that was
passed in.
</p>

 <p>
Usually I have middleware listed in the  <code>routes.go</code> file:
</p>

 <div class="jfw-code"> <pre>package app

func (s *server) routes() {
    s.router.HandleFunc(&quot;/api/&quot;, s.handleAPI())
    s.router.HandleFunc(&quot;/about&quot;, s.handleAbout())
    s.router.HandleFunc(&quot;/&quot;, s.handleIndex())
    s.router.HandleFunc(&quot;/admin&quot;, s.adminOnly(s.handleAdminIndex()))
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Request and response types can go in there too  <a id="request-and-response-types-can-go-in-there-too" class="anchor" href="#request-and-response-types-can-go-in-there-too" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-request-and-response-types-can-go-in-there-too">
 <p>
If an endpoint has its own request and response types, usually they’re
only useful for that particular handler.
</p>

 <p>
If that’s the case, you can define them inside the function.
</p>

 <div class="jfw-code"> <pre>func (s *server) handleSomething() http.HandlerFunc {
    type request struct {
        Name string
    }
    type response struct {
        Greeting string `json:&quot;greeting&quot;`
    }
    return func(w http.ResponseWriter, r *http.Request) {
        ...
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This de-clutters your package space and allows you to name these kinds
of types the same, instead of having to think up handler-specific
versions.
</p>

 <p>
In test code, you can just copy the type into your test function and do
the same thing. Or…
</p>
</div>
 <h2>Test types can help frame the test  <a id="test-types-can-help-frame-the-test" class="anchor" href="#test-types-can-help-frame-the-test" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-test-types-can-help-frame-the-test">
 <p>
If your request/response types are hidden inside the handler, you can
just declare new types in your test code.
</p>

 <p>
This is an opportunity to do a bit of storytelling to future generations
who will need to understand your code.
</p>

 <p>
For example, let’s say we have a  <code>Person</code> type in our code, and we reuse
it on many endpoints. If we had a  <code>/greet</code> endpoint, we might only care
about their name, so we can express this in test code:
</p>

 <div class="jfw-code"> <pre>func TestGreet(t *testing.T) {
    is := is.New(t)
    p := struct {
        Name string `json:&quot;name&quot;`
    }{
        Name: &quot;Mat Ryer&quot;,
    }
    var buf bytes.Buffer
    err := json.NewEncoder(&amp;buf).Encode(p)
    is.NoErr(err) // json.NewEncoder
    req, err := http.NewRequest(http.MethodPost, &quot;/greet&quot;, &amp;buf)
    is.NoErr(err)
    //... more test code here</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
It’s clear from this test, that the only field we care about is the
 <code>Name</code> of the person.
</p>
</div>
 <h2>sync.Once to setup dependencies  <a id="sync.once-to-setup-dependencies" class="anchor" href="#sync.once-to-setup-dependencies" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-sync.once-to-setup-dependencies">
 <p>
If I have to do anything very expensive when preparing the handler, I
defer it until when that handler is first called.
</p>

 <p>
This improves application startup time.
</p>

 <div class="jfw-code"> <pre>func (s *server) handleTemplate(files string...) http.HandlerFunc {
    var (
        init    sync.Once
        tpl     *template.Template
        tplerr  error
    )
    return func(w http.ResponseWriter, r *http.Request) {
        init.Do(func(){
            tpl, tplerr = template.ParseFiles(files...)
        })
        if tplerr != nil {
            http.Error(w, tplerr.Error(), http.StatusInternalServerError)
            return
        }
        // use tpl
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <code>sync.Once</code> ensures the code is only executed one time, and other calls
(other people making the same request) will block until it’s finished.
</p>

 <p>
The error check is outside of the  <code>init</code> function, so if something does
go wrong we still surface the error and won’t lose it in the logs. If
the handler is not called, the expensive work is never done — this can
have big benefits depending on how your code is deployed.
</p>

 <p>
Remember that doing this, you are moving the initialization time from
startup, to runtime (when the endpoint is first accessed). I use Google
App Engine a lot, so this makes sense for me, but your case might be
different so it’s worth thinking about where and when to use  <code>sync.Once</code>
in this way.
</p>
</div>
 <h2>The server is testable  <a id="the-server-is-testable" class="anchor" href="#the-server-is-testable" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-the-server-is-testable">
 <p>
Our server type is very testable.
</p>

 <div class="jfw-code"> <pre>func TestHandleAbout(t *testing.T) {
    is := is.New(t)
    srv := server{
        db:    mockDatabase,
        email: mockEmailSender,
    }
    srv.routes()
    req := httptest.NewRequest(&quot;GET&quot;, &quot;/about&quot;, nil)
    w := httptest.NewRecorder()
    srv.ServeHTTP(w, req)
    is.Equal(w.StatusCode, http.StatusOK)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Create a server instance inside each test — if expensive things lazy
load, this won’t take much time at all, even for big components. By
calling  <code>ServeHTTP</code> on the server, we are testing the entire stack
including routing and middleware, etc.
</p>

 <p>
You can of course call the handler methods directly if you want to avoid
this. Use  <code>httptest.NewRequest</code> and  <code>httptest.NewRecorder</code> to record
what the handlers are doing.
</p>

 <p>
This code sample uses is testing mini-framework (a mini alternative to
Testify) github.com/matryer/is
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/project-structure/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Project Structure</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">rc.d scripting</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/">Opinionated Style Guide</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/how-i-write-http-services/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/how-i-write-http-services/index.html</guid>
  <pubDate>Thu, 30 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Project Structure</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In this post I will try to give an explanation to the project structure
I follow commonly while making Go projects.
</p>

 <p>
This is a basic layout for Go application projects. It’s not an official
standard defined by the core Go dev team; however, it is a set of common
historical and emerging project layout patterns in the Go ecosystem.
Some of these patterns are more popular than others. It also has a
number of small enhancements along with several supporting directories
common to any large enough real world application.
</p>

 <p>
If you are trying to learn Go or if you are building a PoC or a toy
project for yourself this project layout is an overkill. Start with
something really simple (a single main.go file is more than enough). As
your project grows keep in mind that it’ll be important to make sure
your code is well structured otherwise you’ll end up with a messy code
with lots of hidden dependencies and global state. When you have more
people working on the project you’ll need even more structure. That’s
when it’s important to introduce a common way to manage
packages/libraries.
</p>

 <p>
When you have an open source project or when you know other projects
import the code from your project repository that’s when it’s important
to have private (aka internal) packages and code. Clone the repository,
keep what you need and delete everything else! Just because it’s there
it doesn’t mean you have to use it all. None of these patterns are used
in every single project. Even the vendor pattern is not universal.
</p>

 <p>
With Go 1.14 Go Modules are finally ready for production. Use Go Modules
unless you have a specific reason not to use them and if you do then you
don’t need to worry about $GOPATH and where you put your project. The
basic go.mod file in the repo assumes your project is hosted on GitHub,
but it’s not a requirement. The module path can be anything though the
first module path component should have a dot in its name (the current
version of Go doesn’t enforce it anymore, but if you are using slightly
older versions don’t be surprised if your builds fail without it). See
Issues 37554 and 32819 if you want to know more about it.
</p>

 <p>
This project layout is intentionally generic and it doesn’t try to
impose a specific Go package structure.
</p>

 <p>
This is a community effort. Open an issue if you see a new pattern or if
you think one of the existing patterns needs to be updated.
</p>

 <p>
If you need help with naming, formatting and style start by running
gofmt and golint. Also make sure to read these Go code style guidelines
and recommendations:
</p>

 <ul class="org-ul"> <li> <a href="https://talks.golang.org/2014/names.slide">https://talks.golang.org/2014/names.slide</a></li>

 <li> <a href="https://golang.org/doc/effective_go.html#names">https://golang.org/doc/effective_go.html#names</a></li>

 <li> <a href="https://blog.golang.org/package-names">https://blog.golang.org/package-names</a></li>

 <li> <a href="https://github.com/golang/go/wiki/CodeReviewComments">https://github.com/golang/go/wiki/CodeReviewComments</a></li>
</ul> <p>
More about naming and organizing packages as well as other code
structure recommendations:
</p>

 <ul class="org-ul"> <li> <a href="https://www.youtube.com/watch?v=PTE4VJIdHPg">GopherCon EU 2018:
Peter Bourgon - Best Practices for Industrial Programming</a></li>

 <li> <a href="https://www.youtube.com/watch?v=MzTcsI6tn-0">GopherCon Russia 2018:
Ashley McNamara + Brian Ketelsen - Go best practices</a></li>

 <li> <a href="https://www.youtube.com/watch?v=ltqV6pDKZD8">GopherCon 2017: Edward
Muller - Go Anti-Patterns</a></li>

 <li> <a href="https://www.youtube.com/watch?v=oL6JBUk6tj0">GopherCon 2018: Kat
Zien - How Do You Structure Your Go Apps</a></li>
</ul> <h2>Go Directories  <a id="go-directories" class="anchor" href="#go-directories" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-go-directories">
 <p>
 <code>/cmd</code>
</p>

 <p>
Main applications for this project.
</p>

 <p>
The directory name for each application should match the name of the
executable you want to have (e.g.,  <code>/cmd/myapp</code>).
</p>

 <p>
Don’t put a lot of code in the application directory. If you think the
code can be imported and used in other projects, then it should live in
the  <code>/pkg</code> directory. If the code is not reusable or if you don’t want
others to reuse it, put that code in the  <code>/internal</code> directory. You’ll
be surprised what others will do, so be explicit about your intentions!
</p>

 <p>
It’s common to have a small main function that imports and invokes the
code from the  <code>/internal</code> and  <code>/pkg</code> directories and nothing else.
</p>

 <p>
 <code>/internal</code>
</p>

 <p>
Private application and library code. This is the code you don’t want
others importing in their applications or libraries. Note that this
layout pattern is enforced by the Go compiler itself. See the Go 1.4
release notes for more details. Note that you are not limited to the top
level internal directory. You can have more than one internal directory
at any level of your project tree.
</p>

 <p>
You can optionally add a bit of extra structure to your internal
packages to separate your shared and non-shared internal code. It’s not
required (especially for smaller projects), but it’s nice to have visual
clues showing the intended package use. Your actual application code can
go in the  <code>/internal/app</code> directory (e.g.,  <code>/internal/app/myapp</code>) and
the code shared by those apps in the  <code>/internal/pkg</code> directory (e.g.,
 <code>/internal/pkg/myprivlib</code>). I do very often have  <code>/internal/domain</code>,
 <code>/internal/infrastructure</code> and  <code>/internal/usecases</code> by using clean
architecture.
</p>

 <p>
 <code>/pkg</code>
</p>

 <p>
Library code that’s ok to use by external applications (e.g.,
 <code>/pkg/mypubliclib</code>). Other projects will import these libraries
expecting them to work, so think twice before you put something here :-)
Note that the internal directory is a better way to ensure your private
packages are not importable because it’s enforced by Go. The  <code>/pkg</code>
directory is still a good way to explicitly communicate that the code in
that directory is safe for use by others. The I’ll take pkg over
internal blog post by Travis Jeffery provides a good overview of the pkg
and internal directories and when it might make sense to use them.
</p>

 <p>
It’s also a way to group Go code in one place when your root directory
contains lots of non-Go components and directories making it easier to
run various Go tools (as mentioned in these talks: Best Practices for
Industrial Programming from GopherCon EU 2018, GopherCon 2018: Kat
Zien - How Do You Structure Your Go Apps and GoLab 2018 - Massimiliano
Pippi - Project layout patterns in Go).
</p>

 <p>
See the  <code>/pkg</code> directory if you want to see which popular Go repos use
this project layout pattern. This is a common layout pattern, but it’s
not universally accepted and some in the Go community don’t recommend
it.
</p>

 <p>
It’s ok not to use it if your app project is really small and where an
extra level of nesting doesn’t add much value (unless you really want to
:-)). Think about it when it’s getting big enough and your root
directory gets pretty busy (especially if you have a lot of non-Go app
components).
</p>

 <p>
 <code>/api</code>
</p>

 <p>
OpenAPI/Swagger specs, JSON schema files, protocol definition files.
</p>

 <p>
 <code>/web</code>
</p>

 <p>
Web application specific components: static web assets, server side
templates and SPAs.
</p>

 <p>
 <code>/configs</code>
</p>

 <p>
Configuration file templates or default configs. Put your confd or
consul-template template files here.
</p>

 <p>
 <code>/init</code>
</p>

 <p>
System init (systemd, upstart, sysv) and process manager/supervisor
(runit, supervisord) configs.
</p>

 <p>
 <code>/scripts</code>
</p>

 <p>
Scripts to perform various build, install, analysis, etc operations.
These scripts keep the root level Makefile small and simple (e.g.,
 <a href="https://github.com/hashicorp/terraform/blob/master/Makefile">https://github.com/hashicorp/terraform/blob/master/Makefile</a>).
</p>

 <p>
 <code>/build</code>
</p>

 <p>
Packaging and Continuous Integration. Put your cloud (AMI), container
(Docker), OS (deb, rpm, pkg) package configurations and scripts in the
 <code>/build/package</code> directory.
</p>

 <p>
Put your CI (travis, circle, drone) configurations and scripts in the
 <code>/build/ci</code> directory. Note that some of the CI tools (e.g., Travis CI)
are very picky about the location of their config files. Try putting the
config files in the  <code>/build/ci</code> directory linking them to the location
where the CI tools expect them (when possible).
</p>

 <p>
 <code>/deployments</code>
</p>

 <p>
IaaS, PaaS, system and container orchestration deployment configurations
and templates (docker-compose, kubernetes/helm, mesos, terraform, bosh).
Note that in some repos (especially apps deployed with kubernetes) this
directory is called  <code>/deploy</code>.
</p>

 <p>
 <code>/test</code>
</p>

 <p>
Additional external test apps and test data. Feel free to structure the
 <code>/test</code> directory anyway you want. For bigger projects it makes sense to
have a data subdirectory. For example, you can have  <code>/test/data</code> or
 <code>/test/testdata</code> if you need Go to ignore what’s in that directory. Note
that Go will also ignore directories or files that begin with “.” or
“_“, so you have more flexibility in terms of how you name your test
data directory.
</p>

 <p>
 <code>/docs</code>
</p>

 <p>
Design and user documents (in addition to your godoc generated
documentation).
</p>

 <p>
 <code>/tools</code>
</p>

 <p>
Supporting tools for this project. Note that these tools can import code
from the  <code>/pkg</code> and  <code>/internal</code> directories.
</p>

 <p>
 <code>/examples</code>
</p>

 <p>
Examples for your applications and/or public libraries.
</p>

 <p>
 <code>/third_party</code>
</p>

 <p>
External helper tools, forked code and other 3rd party utilities (e.g.,
Swagger UI).
</p>

 <p>
 <code>/githooks</code>
</p>

 <p>
Git hooks.
</p>

 <p>
 <code>/assets</code>
</p>

 <p>
Other assets to go along with your repository (images, logos, etc).
</p>

 <p>
 <code>/website</code>
</p>

 <p>
This is the place to put your project’s website data if you are not
using GitHub pages.
</p>
</div>
 <h2>Directories You Shouldn’t Have  <a id="directories-you-shouldnt-have" class="anchor" href="#directories-you-shouldnt-have" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-directories-you-shouldnt-have">
 <p>
 <code>/src</code>
</p>

 <p>
Some Go projects do have a src folder, but it usually happens when the
devs came from the Java world where it’s a common pattern. If you can
help yourself try not to adopt this Java pattern. You really don’t want
your Go code or Go projects to look like Java :-)
</p>

 <p>
Don’t confuse the project level  <code>/src</code> directory with the  <code>/src</code>
directory Go uses for its workspaces as described in How to Write Go
Code. The  <code>$GOPATH</code> environment variable points to your (current)
workspace (by default it points to  <code>$HOME/go</code> on non-windows systems).
This workspace includes the top level  <code>/pkg</code>,  <code>/bin</code> and  <code>/src</code>
directories. Your actual project ends up being a sub-directory under
 <code>/src</code>, so if you have the  <code>/src</code> directory in your project the project
path will look like this:
 <code>/some/path/to/workspace/src/your_project/src/your_code.go</code>. Note that
with Go 1.11 it’s possible to have your project outside of your
 <code>GOPATH</code>, but it still doesn’t mean it’s a good idea to use this layout
pattern.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/german-naming-convention/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">German naming convention</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">How I write HTTP services</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/">Opinionated Style Guide</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/project-structure/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/project-structure/index.html</guid>
  <pubDate>Tue, 28 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>German naming convention</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <div id="table-of-contents" role="doc-toc">
 <h2>Table of Contents</h2>
 <div id="text-table-of-contents" role="doc-toc">
 <ul> <li> <a href="#expect-the-violent-psychopath">Expect the Violent Psychopath</a></li>
 <li> <a href="#naming-tropes">Naming Tropes</a></li>
 <li> <a href="#its-all-greek-to-me">It’s All Greek To Me</a></li>
 <li> <a href="#german-dutch-naming-convention">German / Dutch Naming Convention</a></li>
 <li> <a href="#isomorphic-naming">Isomorphic Naming</a></li>
</ul></div>
</div>
 <p>
There’s one thing that could make our life as software engineers much
easier: better naming convention.
</p>
 <h2>Expect the Violent Psychopath  <a id="expect-the-violent-psychopath" class="anchor" href="#expect-the-violent-psychopath" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-expect-the-violent-psychopath">
 <p>
You’re trying to tell a story with your code. Your code should tell that
story clearly, not cryptically, for an audience besides yourself. A good
yardstick for deciding what kind of audience you are writing for is to
imagine someone who has a familiarity with your domain but not your
program’s take on the domain. I think programmers forget that, as they
are authors, they have readers.
</p>

 <p>
A famous and regularly quoted piece of advice, from the mailing list
comp.lang.c in 1991, John F. Woods wrote:
</p>

 <blockquote>
 <p>
Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live. Code for readability.
</p>
</blockquote>

 <p>
It’s hard to put it better than that.
</p>
</div>
 <h2>Naming Tropes  <a id="naming-tropes" class="anchor" href="#naming-tropes" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-naming-tropes">
 <p>
There are some common naming conventions which are departures from plain
English, usually in the interest of brevity:
</p>

 <ul class="org-ul"> <li>Abbreviations: when words are abbreviated such as  <code>fct</code> for
“function”,  <code>dfn</code> for “definition”,  <code>ctx</code> for “context.”</li>
 <li>It’s All Greek To Me: using simply  <code>a</code>,  <code>x</code>, etc. as in mathematics.</li>
 <li>“Hungarian” notation: any prefix or suffix notation in which a single
letter is used to refer to a type or property of the variable, as in
sigils like  <code>$foo</code> (“scalar foo”),  <code>lpszFoo</code> (“long pointer string
zero-terminated”), or  <code>fooL</code> (list of foo).</li>
 <li>Acronyms: using initial letters to refer to concepts:  <code>throwVE</code>
(“throw validation error”).</li>
</ul> <p>
Most of these are unnecessary and/or harmful.
</p>
</div>
 <h2>It’s All Greek To Me  <a id="its-all-greek-to-me" class="anchor" href="#its-all-greek-to-me" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-its-all-greek-to-me">
 <p>
A word on this convention. Single letter naming comes from mathematical
tradition; it means “there isn’t a good noun for this because it’s
general”. A person of X height. In some cases, this is actually
reasonable. Consider:
</p>

 <p>
 <code>identity x = x</code>
</p>

 <p>
The identity function isn’t enhanced by calling its parameter thing; it
literally doesn’t matter what it is, especially in some typed languages.
In fact, one could argue that it’s harmful to try to using a meaningful
English name.
</p>

 <p>
However, anywhere that your variables have some meaning, by using “Greek
convention”, you’re throwing away information that could help someone to
digest your code better. You’re not trying to fit your code on a napkin.
</p>
</div>
 <h2>German / Dutch Naming Convention  <a id="german-dutch-naming-convention" class="anchor" href="#german-dutch-naming-convention" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-german-dutch-naming-convention">
 <p>
This is what I consider good naming convention. I discovered this
convention while working with a German colleague, who, I’d always joked,
uses long variable names, and almost never abbreviates anything.
However, the more I read his code, the more I realised I was able to
read the story he was trying to tell, and appreciated it a lot: Using as
many words as necessary to clearly name something. Everything.
</p>

 <p>
I called this “German” naming convention although same applies for
Dutch, as a reference to the fact that the German language is known for
its compound words, which can become comically long and specific at
times. Some examples include, Betäubungsmittelverschreibungsverordnung
(“regulation requiring a prescription for an anaesthetic”),
Rechtsschutzversicherungsgesellschaften (“legal protection insurance
companies”), and the 1999 German “Word of the Year”:
Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz (“beef
labelling regulation and delegation of supervision law”).
</p>

 <p>
Don’t write  <code>fopen</code> when you can write  <code>openFile</code>. Write
 <code>throwValidationError</code> and not  <code>throwVE</code>. Call that name  <code>function</code> and
not  <code>fct</code>. That’s German naming convention. Do this and your readers
will appreciate it.
</p>
</div>
 <h2>Isomorphic Naming  <a id="isomorphic-naming" class="anchor" href="#isomorphic-naming" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-isomorphic-naming">
 <p>
This convention complements German naming convention completely.
</p>

 <p>
Isomorphic naming is to say that the name of the variable is the same
form of the name of the type. A simple heuristic, in other words: just
use the name of the type.
</p>

 <p>
Here’s a real sample where better naming convention would make this
easier to read without being a cryptographer:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">updateColExp</span>
   <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">QualifiedTable</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">RenameField</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">ColExp</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">IO</span>  <span class="org-haskell-type">ColExp</span>
 <span class="org-haskell-definition">updateColExp</span> qt rf ( <span class="org-haskell-constructor">ColExp</span> fld val)  <span class="org-haskell-operator">=</span>
   <span class="org-haskell-constructor">ColExp</span> updatedFld  <span class="org-haskell-operator">&lt;$&gt;</span> updatedVal
   <span class="org-haskell-operator">...</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Look at this naming convention. This may be appropriate if you’re in
some kind of code golfing competition, but I can’t even pronounce these
names. Applying the type-based naming heuristic, we get:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">updateColumnExpression</span>
   <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">QualifiedTable</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">RenameField</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">ColumnExpression</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">IO</span>  <span class="org-haskell-type">ColumnExpression</span>
 <span class="org-haskell-definition">updateColumnExpression</span> qualifiedTable renameField ( <span class="org-haskell-constructor">ColumnExpression</span> field value)  <span class="org-haskell-operator">=</span>
   <span class="org-haskell-constructor">ColumnExpression</span> updatedField  <span class="org-haskell-operator">&lt;$&gt;</span> updatedValue
   <span class="org-haskell-operator">...</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Look, it’s readable, plain English! Isn’t this a huge improvement? Any
maintainer reading this code can read each variable and know what it is.
I can even pronounce the names out loud.
</p>

 <p>
Note that this convention only works well when your types are well-named
too, by German naming convention.
</p>

 <p>
Original post can be found at
 <a href="https://chrisdone.com/posts/german-naming-convention/">Chris Done’s
site</a>.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">pkg or ports ?</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/project-structure/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Project Structure</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/german-naming-convention/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/german-naming-convention/index.html</guid>
  <pubDate>Wed, 22 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>pkg or ports ?</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <div id="table-of-contents" role="doc-toc">
 <h2>Table of Contents</h2>
 <div id="text-table-of-contents" role="doc-toc">
 <ul> <li> <a href="#what-i-prefer">What I prefer</a></li>
 <li> <a href="#package-pkg-benefits">Package (pkg) Benefits</a></li>
 <li> <a href="#port-benefits">Port Benefits</a></li>
</ul></div>
</div>
 <p>
FreeBSD is bundled with a rich collection of system tools as part of the
base system. In addition, FreeBSD provides two complementary
technologies for installing third-party software:
</p>

 <ul class="org-ul"> <li>the FreeBSD Ports Collection, for installing from source</li>

 <li>packages, for installing from pre-built binaries.</li>
</ul> <p>
Either method may be used to install software from local media or from
the network.
</p>

 <p>
For more detailed information you can refer to
 <a href="https://docs.freebsd.org/en/books/handbook/ports/">Chapter 4.
Installing Applications: Packages and Ports</a>
</p>

 <p>
While the two technologies are similar, packages and ports each have
their own strengths. You should select the technology that meets your
requirements for installing a particular application.
</p>
 <h2>What I prefer  <a id="what-i-prefer" class="anchor" href="#what-i-prefer" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-what-i-prefer">
 <p>
My policy is to use pre-compiled binaries as much as possible to:
</p>

 <ul class="org-ul"> <li>avoid the need of tinkering with foreign source code and compiler
options</li>

 <li>have easily reproducible build</li>

 <li>update more easily</li>

 <li>use more reliable and stable versions.</li>
</ul></div>
 <h2>Package (pkg) Benefits  <a id="package-pkg-benefits" class="anchor" href="#package-pkg-benefits" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-package-pkg-benefits">
 <ul class="org-ul"> <li>A compressed package tarball is typically smaller than the compressed
tarball containing the source code for the application.</li>

 <li>Packages do not require compilation time. For large applications, such
as Mozilla, KDE, or GNOME, this can be important on a slow system.</li>

 <li>Packages do not require any understanding of the process involved in
compiling software on FreeBSD.</li>
</ul></div>
 <h2>Port Benefits  <a id="port-benefits" class="anchor" href="#port-benefits" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-port-benefits">
 <ul class="org-ul"> <li>Packages are normally compiled with conservative options because they
have to run on the maximum number of systems. By compiling from the
port, one can change the compilation options.</li>

 <li>Some applications have compile-time options relating to which features
are installed. For example, Apache can be configured with a wide
variety of different built-in options.</li>

 <li>In some cases, multiple packages will exist for the same application
to specify certain settings. For example, Ghostscript is available as
a ghostscript package and a ghostscript-nox11 package, depending on
whether or not Xorg is installed. Creating multiple packages rapidly
becomes impossible if an application has more than one or two
different compile-time options.</li>

 <li>The licensing conditions of some software forbid binary distribution.
Such software must be distributed as source code which must be
compiled by the end-user.</li>

 <li>Some people do not trust binary distributions or prefer to read
through source code in order to look for potential problems.</li>

 <li>Source code is needed in order to apply custom patches.</li>
</ul></div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">SQL transactions</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/german-naming-convention/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">German naming convention</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/">Updating FreeBSD in iocage</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/index.html</guid>
  <pubDate>Sat, 18 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>SQL transactions</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
There are several advantages into using prepared statements and
transactions in SQL, in my case mostly with MariaDB. I will explain some
of the advantages, some of the caveats and handy tips to manage them,
specifically with Go.
</p>
 <h2>Why SQL Transactions ?  <a id="why-sql-transactions" class="anchor" href="#why-sql-transactions" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-why-sql-transactions">
 <p>
We want our unit of work to be reliable and consistent, even in case of
system failure.
</p>

 <p>
We want to provide isolation between programs that access the database
concurrently.
</p>

 <p>
When you start an explicit transaction and issue a DML (Data
Manipulation Language) statement, the resources being locked by the
statement remain locked, and the results of statement are not visible
from outside the transaction until you manually commit or rollback it.
</p>

 <p>
This is what you may or may not need.
</p>

 <p>
The InnoDB storage engine, which is my default go-to database storage
engine and the one you should be going to for relational data, supports
ACID-compliant transactions. SQL transactions are also a great way to
avoid data races in the database engines, and to run queries against a
cluster of databases, while preserving data consistency and integrity, a
performant way to do batch operations, a way to avoid SQL injections
into the database, and more. ACID properties
</p>

 <p>
In order to achieve these 2 goals, a database transaction must satisfy
the ACID properties, where:
</p>

 <ul class="org-ul"> <li>A is Atomicity, which means either all operations of the transaction
complete successfully, or the whole transaction fails, and everything
is rolled back, the database is unchanged.</li>

 <li>C is Consistency, which means the database state should remains valid
after the transaction is executed. More precisely, all data written to
the database must be valid according to predefined rules, including
constraints, cascades, and triggers.</li>

 <li>I is Isolation, meaning all transactions that run concurrently should
not affect each other. There are several levels of isolation that
defines when the changes made by 1 transaction can be visible to
others.</li>

 <li>D is Durability. It basically means that all data written by a
successful transaction must stay in a persistent storage and cannot be
lost, even in case of system failure.</li>
</ul> <p>
How to run a SQL DB transaction from a SQL shell or Navicat / DataGrip?
</p>

 <p>
It’s pretty simple:
</p>

 <ul class="org-ul"> <li>We start a transaction with the  <code>BEGIN</code> statement.</li>

 <li>Then we write a series of normal SQL queries (or operations).</li>

 <li>If all of them are successful, We  <code>COMMIT</code> the transaction to make it
permanent, the database will be changed to a new state.</li>

 <li>Otherwise, if any query fails, we  <code>ROLLBACK</code> the transaction, thus all
changes made by previous queries of the transaction will be gone, and
the database stays the same as it was before the transaction.</li>
</ul></div>
 <h2>Using Transactions with Go  <a id="using-transactions-with-go" class="anchor" href="#using-transactions-with-go" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-using-transactions-with-go">
 <p>
There are several reasons why you should prefer using the  <code>COMMIT</code>,
 <code>ROLLBACK</code> and others in programmatic and type safe Go.
</p>

 <p>
This gives you the opportunity to create prepared statements, execute
them in a loop and then commit. If you were to not use transactions, and
had to do 1000  <code>INSERT</code> statements, you would need 1000 database
connections opening and closing one after the other, for single  <code>EXEC</code>
queries, while with prepared statements you would leave an open tunnel
for communication from your application and the database. This obviously
is much faster and brings less load on all services.
</p>

 <p>
We always recommend you do prepared statements.
</p>

 <p>
We always recommend you use prepared statements in a SQL transaction
when executing more than one  <code>INSERT</code> /  <code>UPDATE</code> /  <code>DELETE</code> statement to
the database.
</p>
</div>
 <h2>Rules of thumb  <a id="rules-of-thumb" class="anchor" href="#rules-of-thumb" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-rules-of-thumb">
 <ul class="org-ul"> <li>Always remember to defer  <code>stmt.Close()</code> - assuming your prepared
statement is called  <code>stmt</code> - as soon as possible.</li>

 <li>If you have started a transaction and you need to stop execution or
return from the function,  <b>ALWAYS</b> make sure to  <code>tx.Rollback()</code>
otherwise the resources allocated for the transaction will never be
de-allocated.</li>

 <li>Leaving transactions open without committing or rolling back exhausts
the database connection and you might get an unresponsive database.
This has already occurred and caused several issue. Make sure you
always either rollback or commit.</li>

 <li>Assuming you called your transaction variable that resulted from
 <code>db.Begin()</code> as  <code>tx</code>, you should only skip issuing a  <code>tx.Rollback()</code>
if you are certain that the  <code>tx.Commit()</code> has been executed
successfully.</li>

 <li>Always make sure to defer  <code>rows.Close()</code> if working with rows as soon
as possible.</li>
</ul></div>
 <h2>Real life transaction in Go  <a id="real-life-transaction-in-go" class="anchor" href="#real-life-transaction-in-go" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-real-life-transaction-in-go">
 <p>
Here you can see some production transactions that I have slightly
altered for this purpose.
</p>

 <div class="jfw-code"> <pre>// AddressBulkInsertion will perform a transaction to insert addresses in bulk
func AddressBulkInsertion(db *sql.DB, addresses []Address) error{
  tx, err := db.Begin()
  if err != nil {
    _ = tx.Rollback()
    return err
  }

  // here should be your SQL, never mind the naming here
  insertStmt, err := tx.Prepare(`
  INSERT INTO addresses (uid, address_data, created_at, updated_at)
  VALUES (?, ?, ?, ?) ON DUPLICATE KEY
      UPDATE address_data = ?, updated_at = ?;
  `)
  if err != nil {
    _ = tx.Rollback()
    return err
  }

  defer insertStmt.Close()

  for i := range payload {
    now := time.Now().Unix()

    if _, errr := insertStmt.Exec(
      uuid.NewString(),
      address.addressData,
      now,
      now,
    ); errr != nil {
      // you might be interested in continuing the loop
      // even when some error occurs, perhaps due to
      // bad data or inconsistencies and you try to do as good as possible
      log.Println(errr.Error())
      continue

      // otherwise simply rollback and return
      // if you want the entire bulk job to stop
      _ = tx.Rollback()
      return errr
    }
  }

  return tx.Commit()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Useful Resouces  <a id="useful-resouces" class="anchor" href="#useful-resouces" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-useful-resouces">
 <p>
 <a href="https://mariadb.com/kb/en/transactions/">More information about
transactions specifically for MariaDB.</a>
</p>

 <p>
 <a href="https://dev.mysql.com/doc/refman/8.0/en/commit.html">More information
about transactions</a>
</p>

 <p>
 <a href="https://pkg.go.dev/database/sql">Official SQL package for working with
Go</a>
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Practical rc.d scripting and Go</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">pkg or ports ?</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/">Opinionated Style Guide</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/sql-transactions/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/sql-transactions/index.html</guid>
  <pubDate>Fri, 17 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Practical rc.d scripting and Go</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
FreeBSD uses the init system, and system services must be made as rc.d
scripts.
</p>

 <p>
You can find more detailed information and examples in the handbook:
 <a href="https://docs.freebsd.org/en/articles/rc-scripting/">Practical rc.d
scripting</a>.
</p>
 <h2>CLI options choice for daemons  <a id="cli-options-choice-for-daemons" class="anchor" href="#cli-options-choice-for-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-cli-options-choice-for-daemons">
 <p>
Find below the options we normally use for any  <code>/etc/rc.d</code> script as
daemon. See more options by in the terminal issuing: man daemon
</p>

 <p>
 <code>-f</code>: Redirect standard input, standard output and standard error to
 <code>/dev/null</code>. When this option is used together with any of the options
related to file or  <code>syslog</code> output, the standard file descriptors are
first redirected to  <code>/dev/null</code>, then  <code>stdout</code> and/or  <code>stderr</code> is
redirected to a file or to  <code>syslog</code> as specified by the other options.
</p>

 <p>
 <code>-S</code>: Enable  <code>syslog</code> output. This is implicitly applied if other
 <code>syslog</code> parameters are provided. The default values are  <code>daemon</code>,
 <code>notice</code>, and  <code>daemon</code> for facility, priority, and tag, respectively.
</p>

 <p>
 <code>-P</code> : Write the ID of the daemon process into the file with given name
using the  <code>pidfile</code> functionality. The program is executed in a spawned
child process while the daemon waits until it terminates to keep the
 <code>supervisor_pidfile</code> locked and removes it after the process exits. The
 <code>supervisor_pidfile</code> owner is the user who runs the daemon regardless of
whether the  <code>-u</code> option is used or not.
</p>

 <p>
 <code>-r</code>: Supervise and restart the program after a one-second delay if it
has been terminated. Connecting a script to the rc.d framework
</p>

 <p>
In a nutshell,  <code>rcorder</code> takes a set of files, examines their contents,
and prints a dependency-ordered list of files from the set to stdout.
The point is to keep dependency information inside the files so that
each file can speak for itself only. A file can specify the following
information:
</p>

 <ul class="org-ul"> <li>the names of the “conditions” (which means services to us) it provides
with  <code># KEYWORD</code>:</li>

 <li>the names of the “conditions” it requires with  <code># REQUIRE</code>:</li>

 <li>the names of the “conditions” this file should run before with
 <code># BEFORE</code>:</li>

 <li>additional keywords that can be used to select a subset from the whole
set of files ( <code>rcorder</code> can be instructed via options to include or
omit the files having particular keywords listed.) with # KEYWORD:</li>
</ul> <p>
As a rule of thumb, every custom made rc.d script should provide 1
daemon, and require  <code>DAEMON</code> and  <code>networking</code> to be initialized. Thus
the first lines of your rc.d script will generally look something like:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span> <span class="org-comment-delimiter">#</span> <span class="org-comment">
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: &lt;name of this rc.d script&gt;
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Daemon load order  <a id="daemon-load-order" class="anchor" href="#daemon-load-order" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-daemon-load-order">
 <p>
The order in which the daemons load is highly important. For this
example, our  <code>my_service</code> rc.d script should run as a daemon and should
be able to access the network.
</p>

 <p>
This means that it should only load after  <code>DAEMON</code> and  <code>networking</code> are
loaded and running.
</p>

 <p>
You can verify the load order with:
</p>

 <div class="jfw-code"> <pre>service -e</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The correct load order in this case then would be:
</p>

 <div class="jfw-code"> <pre>service -e

/etc/rc.d/cleanvar
/etc/rc.d/ip6addrctl
/etc/rc.d/netif
/etc/rc.d/virecover
/etc/rc.d/motd
/etc/rc.d/os-release
/etc/rc.d/newsyslog
/etc/rc.d/syslogd
/etc/rc.d/my_service
/etc/rc.d/cron</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Go applications as daemons  <a id="go-applications-as-daemons" class="anchor" href="#go-applications-as-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-go-applications-as-daemons">
 <p>
In the case of Go binaries, I will use the daemon in a straightforward
manner. See the example below for one of my Go applications, running as
a compiled binary. I assume
 <code>/root/internalApplications/my-service-folder</code> is the folder where the
service is located and should be running from:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span> <span class="org-comment-delimiter">#</span> <span class="org-comment">
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: my_service
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:
</span>
 <span class="org-builtin">.</span> /etc/rc.subr

 <span class="org-variable-name">name</span>= <span class="org-string">&quot;my_service&quot;</span>
 <span class="org-variable-name">rcvar</span>= <span class="org-string">&quot;my_service_enable&quot;</span>
 <span class="org-variable-name">my_service_chdir</span>= <span class="org-string">&quot;/root/internalApplications/my-service-folder&quot;</span>
 <span class="org-variable-name">my_service_user</span>= <span class="org-string">&quot;root&quot;</span>
 <span class="org-variable-name">my_service_command</span>= <span class="org-string">&quot;/root/internalApplications/my-service-folder/app&quot;</span>
 <span class="org-variable-name">pidfile</span>= <span class="org-string">&quot;/var/run/${name}.pid&quot;</span>
 <span class="org-variable-name">command</span>= <span class="org-string">&quot;/usr/sbin/daemon&quot;</span>
 <span class="org-variable-name">command_args</span>= <span class="org-string">&quot;-P ${pidfile} -r -f -S ${my_service_command}&quot;</span>

load_rc_config $ <span class="org-variable-name">name</span>
: ${ <span class="org-variable-name">my_service_enable</span>:=no}

run_rc_command  <span class="org-string">&quot;$1&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Shell scripts as daemons  <a id="shell-scripts-as-daemons" class="anchor" href="#shell-scripts-as-daemons" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-shell-scripts-as-daemons">
 <p>
Shell scripts that run utilities can also be daemonized. See the example
below I use for Jaeger:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">sh</span> <span class="org-comment">
</span>
 <span class="org-comment-delimiter"># </span> <span class="org-comment">PROVIDE: jaeger_tracer
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">REQUIRE: DAEMON networking
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">KEYWORD:
</span> <span class="org-builtin">.</span> /etc/rc.subr

 <span class="org-variable-name">name</span>= <span class="org-string">&quot;jaeger_tracer&quot;</span>
 <span class="org-variable-name">rcvar</span>= <span class="org-string">&quot;jaeger_tracer_enable&quot;</span>
 <span class="org-variable-name">jaeger_tracer_user</span>= <span class="org-string">&quot;root&quot;</span>
 <span class="org-variable-name">pidfile</span>= <span class="org-string">&quot;/var/run/${name}.pid&quot;</span>
 <span class="org-variable-name">jaeger_tracer_command</span>= <span class="org-string">&quot;/root/internalApplications/run-jaeger.sh&quot;</span>
 <span class="org-variable-name">command</span>= <span class="org-string">&quot;/usr/sbin/daemon&quot;</span>
 <span class="org-variable-name">command_args</span>= <span class="org-string">&quot;-P ${pidfile} -r -f -S ${jaeger_tracer_command}&quot;</span>

load_rc_config $ <span class="org-variable-name">name</span>
: ${ <span class="org-variable-name">jaeger_tracer_enable</span>:=no}

run_rc_command  <span class="org-string">&quot;$1&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Conclusion  <a id="conclusion" class="anchor" href="#conclusion" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-conclusion">
 <p>
Once the rc.d script is created then you should make it executable with
</p>

 <div class="jfw-code"> <pre>chmod +x /etc/rc.d/my_service</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
and you can then use it as a system service whose output is in
 <code>/var/log/messages</code>.
</p>

 <div class="jfw-code"> <pre>service my_service status
service my_service enable
service my_service start
service my_service restart
service my_service stop</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Updating FreeBSD in iocage</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">SQL transactions</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/">Updating FreeBSD in iocage</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/index.html</guid>
  <pubDate>Wed, 01 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Updating FreeBSD in iocage</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In this document we will explain how to migrate to a newer FreeBSD
version both on hosts and on jails.
</p>

 <p>
You can always refer to
 <a href="https://docs.freebsd.org/en/books/handbook/cutting-edge/">Chapter 24:
Updating and Upgrading FreeBSD</a> for more detailed information.
</p>
 <h2>Updating the host  <a id="updating-the-host" class="anchor" href="#updating-the-host" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-updating-the-host">
 <p>
FreeBSD is known for being reliable and to be painlessly upgradeable,
even with custom setups, like I do, with manual partitioning, ZFS on
root, FreeBSD can handle this easily.
</p>

 <p>
We should start by evaluating the current version we have installed,
with:
</p>

 <div class="jfw-code"> <pre>uname -mrs</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
which in my case renders  <code>FreeBSD 12.2-RELEASE amd64</code>.
</p>

 <p>
We should make sure you apply all existing pending updates for FreeBSD
12.x:
</p>

 <div class="jfw-code"> <pre>sudo freebsd-update fetch
sudo freebsd-update install
sudo pkg update
sudo pkg upgrade</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Make sure to have a snapshot of the machine or VMWare snapshot for a VM.
</p>

 <p>
Once all updates are installed, we can then proceed to do the upgrade
(in this case to  <code>13.0-RELEASE</code>):
</p>

 <div class="jfw-code"> <pre>sudo freebsd-update -r 13.0-RELEASE upgrade</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
After that process is done, which may take a while, you will get
prompted
</p>

 <pre class="example" id="orgd673b3d">
To install the downloaded upgrades, run &quot;/usr/sbin/freebsd-update install&quot;
</pre>

 <p>
You should thus run:
</p>

 <div class="jfw-code"> <pre>sudo /usr/sbin/freebsd-update install</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then reboot the machine, then run again:
</p>

 <div class="jfw-code"> <pre>sudo /usr/sbin/freebsd-update install</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then you should perform a second reboot and you will have a system with
the new OS but old packages.
</p>

 <p>
Your  <code>/etc/resolv.conf</code> might be overriden during the update. Make sure
to check this.
</p>

 <p>
The next logical step to follow, after the last reboot, is to upgrade
all packages of the system, once again with:
</p>

 <div class="jfw-code"> <pre>sudo pkg update
sudo pkg upgrade</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Once all software is up-to-date, run again:
</p>

 <div class="jfw-code"> <pre>sudo /usr/sbin/freebsd-update install</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
and another reboot is recommended.
</p>
</div>
 <h2>Updating jails  <a id="updating-jails" class="anchor" href="#updating-jails" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-updating-jails">
 <p>
Even though this is a low-risk process, for production systems that
cannot allow any downtime it is recommended to simply create a new jail
with the new release, and switch traffic to the new jail. This requires
more work, but will be safer, and is a benefit of having a jailed
environment.
</p>

 <p>
Upon a successful update of your host’s system, any of your existing
jails will still be using the release where you created them. Ideally
you should always keep your jails to the same major release as your
host.
</p>

 <p>
You can get an overview of your jails with:
</p>

 <div class="jfw-code"> <pre>sudo iocage list</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You should pre-fetch the wanted release files, which will then be
available for all upgrades and for any new jails you might want to
create with said version.
</p>

 <pre class="example" id="orga85b846">
sudo iocage fetch -r 13.0-RELEASE
</pre>

 <p>
If the machine you are working on contains many jails, you should likely
open several SSH sessions and upgrade the jails in parallel, of course
at the cost of CPU &amp; RAM usage.
</p>

 <p>
In order to upgrade a jail’s FreeBSD version you should run:
</p>

 <div class="jfw-code"> <pre>sudo iocage upgrade &lt;name of your jail&gt; -r 13.0-RELEASE</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
then we must update all packages within the jail:
</p>

 <div class="jfw-code"> <pre>sudo iocage pkg &lt;name of your jail&gt; update
sudo iocage pkg &lt;name of your jail&gt; upgrade -y</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
it is recommendable to restart the jail after the procedure:
</p>

 <div class="jfw-code"> <pre>sudo iocage restart &lt;name of your jail&gt;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Cleaning up  <a id="cleaning-up" class="anchor" href="#cleaning-up" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-cleaning-up">
 <p>
It is highly recommendable to cleanup your system after verifying
everything is stable and in order. Several files, backups and rollbacks
can then be deleted, often saving 8GB+ of space. There are several handy
tricks to be able to clean a FreeBSD machine and shave some disk GB.
</p>

 <p>
You can do some cleanup by removing the fetched pkg files, both on your
host
</p>

 <div class="jfw-code"> <pre>sudo pkg clean</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
and on your jails:
</p>

 <div class="jfw-code"> <pre>sudo iocage pkg &lt;your jail&gt; clean -y</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can check the current allocated size for zpools by running:
</p>

 <pre class="example" id="orgb09f34b">
zpool list

NAME     SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
iocage  19.5G  13.5G  5.97G        -         -    66%    69%  1.00x    ONLINE  -
zroot   17.5G  3.72G  13.8G        -         -    23%    21%  1.00x    ONLINE  -
</pre>

 <p>
You can check which zfs file systems are currently taking more space
with:
</p>

 <pre class="example" id="org50b5e1b">
zfs list

NAME                                       USED  AVAIL     REFER  MOUNTPOINT
iocage                                    13.5G  5.38G       24K  /iocage
iocage/iocage                             13.5G  5.38G     29.5K  /iocage/iocage
iocage/iocage/download                     803M  5.38G       24K  /iocage/iocage/download
iocage/iocage/download/12.2-RELEASE        402M  5.38G      402M  /iocage/iocage/download/12.2-RELEASE
iocage/iocage/download/13.0-RELEASE        401M  5.38G      401M  /iocage/iocage/download/13.0-RELEASE
iocage/iocage/images                        24K  5.38G       24K  /iocage/iocage/images
iocage/iocage/jails                       10.5G  5.38G       24K  /iocage/iocage/jails
iocage/iocage/jails/elk-d                 4.19G  5.38G     25.5K  /iocage/iocage/jails/elk-d
iocage/iocage/jails/elk-d/root            4.19G  5.38G     4.51G  /iocage/iocage/jails/elk-d/root
iocage/iocage/jails/jaeger-d              4.00G  5.38G     25.5K  /iocage/iocage/jails/jaeger-d
iocage/iocage/jails/jaeger-d/root         4.00G  5.38G     4.32G  /iocage/iocage/jails/jaeger-d/root
iocage/iocage/jails/web-server-d          2.26G  5.38G     25.5K  /iocage/iocage/jails/web-server-d
iocage/iocage/jails/web-server-d/root     2.26G  5.38G     2.57G  /iocage/iocage/jails/web-server-d/root
iocage/iocage/log                           28K  5.38G       28K  /iocage/iocage/log
iocage/iocage/releases                    2.26G  5.38G       24K  /iocage/iocage/releases
iocage/iocage/releases/12.2-RELEASE       1.20G  5.38G       24K  /iocage/iocage/releases/12.2-RELEASE
iocage/iocage/releases/12.2-RELEASE/root  1.20G  5.38G     1.20G  /iocage/iocage/releases/12.2-RELEASE/root
iocage/iocage/releases/13.0-RELEASE       1.06G  5.38G       24K  /iocage/iocage/releases/13.0-RELEASE
iocage/iocage/releases/13.0-RELEASE/root  1.06G  5.38G     1.06G  /iocage/iocage/releases/13.0-RELEASE/root
iocage/iocage/templates                     24K  5.38G       24K  /iocage/iocage/templates
zroot                                     3.72G  13.2G       24K  /zroot
zroot/ROOT                                3.23G  13.2G       24K  none
zroot/ROOT/default                        3.23G  13.2G     3.23G  /
zroot/tmp                                 26.5K  13.2G     26.5K  /tmp
zroot/usr                                  497M  13.2G       24K  /usr
zroot/usr/home                            3.50M  13.2G     3.50M  /usr/home
zroot/usr/obj                               24K  13.2G       24K  /usr/obj
zroot/usr/ports                             72K  13.2G       24K  /usr/ports
zroot/usr/ports/distfiles                   24K  13.2G       24K  /usr/ports/distfiles
zroot/usr/ports/packages                    24K  13.2G       24K  /usr/ports/packages
zroot/usr/src                              493M  13.2G      493M  /usr/src
zroot/var                                  259K  13.2G       24K  /var
zroot/var/audit                             24K  13.2G       24K  /var/audit
zroot/var/crash                             24K  13.2G       24K  /var/crash
zroot/var/log                              135K  13.2G      135K  /var/log
zroot/var/mail                              28K  13.2G       28K  /var/mail
zroot/var/tmp                               24K  13.2G       24K  /var/tmp
</pre>

 <p>
By looking at the above output you can see we have both the 12.2-RELEASE
and 13.0-RELEASE versions of FreeBSD saved in our machine. In our case,
we have successfully upgraded to 13.0-RELEASE and thus can remove all
files stored related to 12.2-RELEASE. We can do this by simply removing
the zfs dataset containing the 12.2-RELEASE download:
</p>

 <div class="jfw-code"> <pre>sudo zfs destroy -r iocage/iocage/download/12.2-RELEASE</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Be extremely wary when running this command and ask someone more
experienced if you are doubting!
</p>

 <p>
We also can then clean the freebsd-update remaining files by removing
the rollback and creating a new empty folder:
</p>

 <div class="jfw-code"> <pre>sudo rm -rf /var/db/freebsd-update/files
sudo mkdir /var/db/freebsd-update/files
sudo chmod 755 /var/db/freebsd-update/files</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This should also be done in the jails if you upgraded them:
</p>

 <div class="jfw-code"> <pre>sudo iocage exec &lt;your jail&gt; rm -rf /var/db/freebsd-update/files
sudo iocage exec &lt;your jail&gt; mkdir /var/db/freebsd-update/files
sudo iocage exec &lt;your jail&gt; chmod 755 /var/db/freebsd-update/files</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
When you update to a new major version you might end up keeping old
datasets lying around. These can be seen like above in the output of zfs
list.
</p>

 <p>
Very likely at  <code>iocage/iocage/releases/12.2-RELEASE</code> and
 <code>iocage/iocage/releases/12.2-RELEASE/root</code>.
</p>

 <p>
We must first find the “cloned” datasets with:
</p>

 <div class="jfw-code"> <pre>sudo zfs list -t snapshot -o name,clones</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
which outputs something like:
</p>

 <pre class="example" id="orgc71e28d">
NAME                                                  CLONES
iocage/iocage/releases/12.2-RELEASE/root@database     iocage/iocage/jails/database/root
iocage/iocage/releases/12.2-RELEASE/root@cache-store  iocage/iocage/jails/cache-store/root
</pre>

 <p>
and then we can promote the clones to be the primary datasets for that
jail:
</p>

 <div class="jfw-code"> <pre>sudo zfs promote iocage/iocage/jails/database/root
sudo zfs promote iocage/iocage/jails/cache-store/root</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The clones can be removed with:
</p>

 <div class="jfw-code"> <pre>sudo zfs destroy iocage/iocage/releases/12.2-RELEASE/root
sudo zfs destroy iocage/iocage/releases/12.2-RELEASE</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
After all the cleanup it is recommended to restart the machine and
verify it all works as expected.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/breaking-free-of-javascript/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Breaking free of Javascript</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Practical rc.d scripting and Go</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/index.html</guid>
  <pubDate>Wed, 01 Sep 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Breaking free of Javascript</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1">
 <div id="org000c70f" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_hTGEAKTrOdt_vRzNUCcgRA_qgtbyc.png"></img></p>
</div>

 <p>
Javascript has a stranglehold on all Front End Development. If you write
code for the browser, then it’s most likely written directly in
Javascript or its very close cousin TypeScript. The problem is that
Javascript is a terrible language.
</p>

 <p>
TLDR: You should break free from Javascript by learning PureScript which
compiles to Javascript.
</p>

 <p>
Typescript and other attempts to curtail Javascript are about as
effective as a band-aid on a puncture wound. One might argue that it’s
better than nothing but eventually, you’re still going to bleed out.
</p>

 <p>
The language has undergone many changes since its initial development,
which consisted of a whopping 10 days, but all of these changes are just
polishing a turd.
</p>

 <p>
Javascript is a veritable Smorgasbord of languages paradigms. It has
some Object Oriented, Functional and Procedural features all mixed
together in an unpalatable Schizophrenic Goulash (mixed metaphor
intended).
</p>

 <p>
There are more bad parts of Javascript than good parts and anyone
working in Javascript on a daily basis will attest to the fact that
being a good Javascript Developer is more about knowing what NOT to do.
</p>

 <p>
Seasoned Javascript Developers have a litany of language constructs that
they routinely avoid like the plague lest they fall victim to the
plethora of runtime exceptions that are routinely encountered in
production, e.g. the dreaded “undefined is not a function”.
</p>

 <p>
Javascript’s reign is supreme thanks to its monopolistic hold on the
Browser. All previous attempts to extricate the Browser from the tyranny
of Javascript have long since failed leaving most leery of attempting
yet another failed coup d’état.
</p>
 <h2>Freedom or Death  <a id="freedom-or-death" class="anchor" href="#freedom-or-death" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-freedom-or-death">

 <div id="orgb5989c1" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_0xnuE8J8c0Ivwe_ud5i5xA_qk6ehg.jpg"></img></p>
</div>

 <p>
What options do we have?
</p>

 <p>
We could decide not to develop applications for the Browser. I like to
think that we should develop mostly on the server-side by default,
unless the situation requires very advanced client-side features and
state. I would personally recommend Go and Haskell as strong candidates
for server side applications. This of course could be done in a number
of different languages.
</p>

 <p>
We could create an Open Source Browser that would allow for other
languages or perhaps it could have a built-in language that’s “better”
than Javascript.
</p>

 <p>
But our Browser would be completely incompatible with every single web
site on the planet. This may appear to be Freedom at first but it most
definitely is Death. No one but the most fervent would adopt this.
</p>

 <p>
We could develop a Browser Extension that allows for a better developer
experience. This too has been tried before and since we’re reaching a
near monopoly in Browser development by only the largest of companies,
our initial taste of Freedom could, on a whim of a corporate giant, be
transformed into sudden Death.
</p>

 <p>
Most affected by an oppressive environment are too busy trying to
survive in the current climate than to overturn it.
</p>

 <p>
Revolutions are rare, dangerous and costly but subversion isn’t.
</p>
</div>
 <h2>If you can’t beat ’em, join ’em (sort of)  <a id="if-you-cant-beat-em-join-em-sort-of" class="anchor" href="#if-you-cant-beat-em-join-em-sort-of" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-if-you-cant-beat-em-join-em-sort-of">
 <p>
Javascript’s stranglehold on the Browser isn’t a new phenomenon. We’ve
seen this very thing before. In fact, it’s rampant in the hardware
world.
</p>

 <p>
A Microprocessor has a single instruction set that can never be
superseded by any other. Not without completely replacing the hardware.
</p>

 <p>
Yet, we don’t call for revolution but instead work to insulate ourselves
from the deficiencies of such a system. We did this over half a century
ago when we created high-level languages.
</p>

 <p>
Any flaws or complexities in the underlying architecture are squelched
by an abstraction layer that frees us from having to regularly consider
the pitfalls.
</p>

 <p>
By writing a compiler, we freed ourselves from the tyranny of a single
platform and by using this same approach, we can free ourselves from our
current dilemma.
</p>
</div>
 <h2>A Horse of a Different Color  <a id="a-horse-of-a-different-color" class="anchor" href="#a-horse-of-a-different-color" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-a-horse-of-a-different-color">

 <div id="orga451117" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_g4vok0cblQYGTiK5_k_Nmg_hyftb6.jpg"></img></p>
</div>

 <p>
What we want is a way to write Javascript without having to write
Javascript. To do that, we’re going to need a Transpiler.
</p>

 <p>
A Transpiler will compile code in one language and produce code in
another. Technically, CoffeeScript, TypeScript and Babel are Transpilers
but they start with nearly Javascript and produce Javascript.
</p>

 <p>
These solutions do not give us the benefits that we’re hoping for. This
is the equivalent of writing in Assembly Language instead of Machine
Code.
</p>

 <p>
What we want is a whole new language. One that avoids all of the
terrible design decisions of Javascript. There are many languages that
transpile to Javascript that are far superior to Javascript.
</p>

 <p>
I’m going to concentrate on Functional Programming Languages only
because it’s becoming very clear that Functional Programming is the
future of our industry.
</p>

 <p>
This is evident by the mass adoption of Functional Features in today’s
most popular languages. This is historically what’s been seen right
before a major paradigm shift is about to occur in the software
industry.
</p>

 <p>
For the curious, Richard Feldman does a wonderful job of making this
argument in this entertaining and illuminating talk The Next Paradigm
Shift in Programming.
</p>
</div>
 <h3>Go  <a id="go" class="anchor" href="#go" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-go">
 <p>
GopherJS is an honourable mention and could be exactly what you search
if you are into Go:  <a href="https://github.com/gopherjs/gopherjs">see GopherJS
on GitHub</a>
</p>
</div>
 <h3>Elm  <a id="elm" class="anchor" href="#elm" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-elm">

 <div id="orgb2e7225" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_yok_lg3cm73w-eeJttUY2A_xzgznt.png"></img></p>
</div>

 <p>
Elm is a great beginner language for Functional Programming. The
ecosystem is mature and I have personally been responsible for a team
that put over 160K lines of Elm code into production without a single
line of Elm code producing a Runtime Error.
</p>

 <p>
Elm is a dialect of ML and a very small subset of Haskell.
</p>

 <p>
If you want to dip your toe into the Statically Typed, Purely Functional
Programming world, then Elm can be a great starting point
( <a href="https://elm-lang.org/">https://elm-lang.org/</a>).
</p>

 <p>
Unfortunately, Elm’s lack of power quickly shows as your application
becomes complex and the resources for learning are somewhat limited. The
go-to book for learning Elm is Elm in Action.
</p>
</div>
 <h3>ReasonML  <a id="reasonml" class="anchor" href="#reasonml" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-reasonml">
 <p>
Facebook uses Functional Programming Languages, one of which is Haskell,
the granddaddy of them all. The other notable language is the one they
developed called ReasonML. It’s a dialect of OCaml, which is a dialect
of ML.
</p>

 <p>
It touts safety and interoperability with both Javascript and OCaml
ecosystems ( <a href="https://reasonml.github.io/">https://reasonml.github.io/</a>).
</p>

 <p>
Unfortunately, Reason isn’t a Pure Functional Language and so it suffers
from many of the problems that Imperative Languages do. It’s a
compromise the way that TypeScript is a compromise.
</p>

 <p>
There are a few books on Reason, Web Development with ReasonML:
Type-Safe, Functional Programming for JavaScript Developers and ReasonML
Quick Start Guide: Build fast and type-safe React applications that
leverage the JavaScript and OCaml ecosystems
</p>
</div>
 <h3>Fable  <a id="fable" class="anchor" href="#fable" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-fable">
 <p>
For those married to the .NET ecosystem, there’s Fable, a language that
lets you write in Microsoft’s Functional Programming Language, F#, and
compiler to Javascript.
</p>

 <p>
Fable supports most of the F# core library and most of the commonly used
.NET APIs ( <a href="https://fable.io/">https://fable.io/</a>).
</p>

 <p>
Unfortunately, like ReasonML, Fable is not a Pure Functional Programming
language either.
</p>

 <p>
I couldn’t seem to find any books on it but here’s a free online “book”,
The Elmish Book. The use of the word “Elm” in the title seems to be
coincidental and has nothing to do with the Elm language.
</p>
</div>
 <h3>PureScript  <a id="purescript" class="anchor" href="#purescript" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-purescript">

 <div id="org3d804cb" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_w0WBjtEDr_ESj8FdDApaOw_jimozj.png"></img></p>
</div>

 <p>
PureScript was developed by Haskell developers who stole as much as they
could from Haskell while making some great improvements along the way.
</p>

 <p>
This language is my personal favorite. All new projects at my company
will be developed in this language. It has all of the expressive power
of Haskell yet it runs beautifully in the Browser producing clean
readable Javascript ( <a href="https://www.purescript.org/">https://www.purescript.org/</a>).
</p>

 <p>
It’s a Pure Functional Language (hence its name) just like Haskell. It
is the most powerful of all the languages listed here but unfortunately
has a big downside.
</p>

 <p>
The learning curve is pretty steep. That’s what motivated me to write my
book to make that process as painless as possible. Once you put in the
work to learn PureScript, it will pay you back ten fold in dividends.
</p>

 <p>
There are 2 books I know of. The free one, which is great if you already
know Haskell, PureScript by Example.
</p>

 <p>
If you’ve never seen a Functional Language or if you have no idea what
Functional Programming is and you’re interested in the most powerful of
all of the aforementioned languages, then I’d suggest you consider my
book, Functional Programming Made Easier: A Step-by-Step Guide.
</p>

 <p>
It’s a complete Functional Programming course for Imperative Programmers
of any language. It starts from the very beginning of Functional
Programming and by the end, you’ve developed a web-server and front-end
single page application in PureScript.
</p>
</div>
 <h2>Too Good to be True?  <a id="too-good-to-be-true" class="anchor" href="#too-good-to-be-true" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-too-good-to-be-true">

 <div id="org818579a" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1630256482/jjba-site/blog/breaking-free-from-js/1_Hgvz80kAKCqSaMojl5oP1g_iipeq9.png"></img></p>
</div>

 <p>
All of these languages are very different from Javascript. They can be
downright scary. It’s not like going from Java to C# or from Java to
Javascript.
</p>

 <p>
These are Functional Programming Languages. You might be thinking that
what you’d really like is Java, C# or Python but in the Browser.
</p>

 <p>
But the biggest gains in program safety and developer productivity is
only possible from a Functional Programming Language.
</p>

 <p>
That’s a pretty bold claim and for the unconvinced, I invite them to ask
programmers who routinely program in a Functional Language in their
professional work and ask them if they miss their old Imperative
Programming Languages.
</p>

 <p>
I’d be willing to bet that 99 out of 100 would say that they’d never go
back to the old way of programming. Then ask them how much effort it
took to learn these new fangled beasts.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/haskell/haskell-in-production-at-foxdown-systems/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Haskell in Production at Foxdown Systems</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Updating FreeBSD in iocage</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/breaking-free-of-javascript/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/breaking-free-of-javascript/index.html</guid>
  <pubDate>Mon, 30 Aug 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Haskell in Production at Foxdown Systems</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Haskell is the first programming language we reach for when we build production software systems. This likely seems unusual to anyone who only has a passing familiarity with the language. Haskell has a reputation for being an advanced language with a steep learning curve. It is also often thought of as a research language with limited practical utility.
</p>

 <p>
While Haskell does have a very large surface area, with many concepts and a syntax that will feel unfamiliar to programmers coming from most other languages, it is unrivaled in the combination of developer productivity, code maintainability, software reliability, and performance that it offers. In this post I will cover some of the defining features of Haskell that make it an excellent, industrial-strength language that is well-suited for building commercial software, and why it is usually the first tool we consider using for new projects. Haskell has a strong static type system that prevents errors and reduces cognitive load
</p>

 <p>
Haskell has a very powerful static type system which serves as a programmer aid that catches and prevents many errors before code ever even runs. Many programmers encounter statically typed languages like Java or C++ and find that the compiler feels like an annoyance. By contrast, Haskell’s static type system, in conjunction with compile-time type checking, acts as an invaluable pair-programming buddy that gives instantaneous feedback during development.
</p>

 <p>
There’s a far smaller cognitive load that needs to be maintained when writing Haskell than when writing in languages like Python, JavaScript, or PHP. Many concerns can be completely offloaded to the compiler rather than needing to be remembered by the programmer. For example, when writing Haskell, there’s no need to preemptively ask questions like:
</p>

 <ul class="org-ul"> <li>Do I need to check whether this field is null?</li>
 <li>What if fields are missing from the request payload?</li>
 <li>Has this string already been decoded to an integer?</li>
 <li>What if this string can’t be decoded to an integer?</li>
 <li>Will this operator implicitly convert this integer to a string?</li>
 <li>Are these two values comparable?</li>
</ul> <p>
This is not to say that these are questions that never need answering in Haskell; it’s to say that the compiler will throw an error when you need to address one of these issues. For example, it’s possible that a Haskell program needs to handle values that are sometimes not present, but instead of setting any value to NULL, a Haskell programmer must use a Maybe type, which indicates that the value may not be there, and the compiler forces the programmer to explicitly handle the Nothing value; the case where the value is not present.
</p>

 <p>
Haskell’s static type system also leads to other benefits. Haskell code uses type signatures that precede its functions and describe the types of each parameter and return value. For example, a signature like Int -&gt; Int -&gt; Bool indicates that a function takes two integers and returns a boolean value. Since these type signatures are checked and enforced by the compiler, this allows a programmer reading Haskell code to look only at type signatures when getting a sense of what a certain piece of code does. For example, one would not use the type signature above when looking for a function that manipulates strings, decodes JSON, or queries a database.
</p>

 <p>
Type signatures can even be used to search through the entire corpus of Haskell code for a relevant function. Using Hoogle, Haskell’s API search, we can search for a type signature based off of functionality we know that we need. For example, if we need to convert an Int to a Float, we can search Hoogle for Int -&gt; Float (search results), which will point us to the aptly named int2Float function.
</p>

 <p>
Haskell also lets us create polymorphic type signatures through the use of type variables, represented by lowercase type names. For example, a signature of a -&gt; b -&gt; a tells us that that the function takes two parameters of two arbitrary types, and returns a value that whose type is the same as the first parameter. Suppose we want to check whether an element is in a list. We’re looking for a function that takes an item to search for, a list of items, and returns a boolean. We don’t care about the type of the item, so long as the search item and the items in the list are of the same type. So we can search Hoogle for a -&gt; [a] -&gt; Bool (search results), which will point us to the elem function. Parametric types are an extremely powerful feature in Haskell and are what enable writing reusable code. Haskell enables writing code that is composable, testable, and has predictable side-effects
</p>

 <p>
In addition to being statically typed, Haskell is a pure functional programming language. This is one of Haskell’s defining features and what the language is well known for, even amongst programmers that have only heard of Haskell but never used it. Writing in a pure functional style has many benefits, and is conducive to a well-organized code base.
</p>

 <p>
The word “pure” in “pure functional programming” is significant. Purity in this sense means that the code we write is pure, or free of side-effects. Another term that describes this is referential transparency, or the property where any expression (e.g. a function call with a given list of parameters) can be replaced with its return value without changing the functionality of the code. This is only possible when such pure functions do not have side effects, such as creating files on the host system, running database queries, or making HTTP requests. Haskell’s type system imposes this sort of purity.
</p>

 <p>
So does being pure mean that Haskell programs cannot have side effects? Certainly not—but it does mean that effects are pushed to the edge of our system. Any functions that perform I/O actions (such as querying a database or receiving HTTP requests) must have a return type that captures this. This means that type signatures like the ones we saw in the previous section (e.g.  <code>Int -&gt; Float</code> or  <code>a -&gt; [a] -&gt; Bool</code>) are indicators that the corresponding functions do not produce side effects, since  <code>Float</code> and  <code>Bool</code> are just primitive return types. For a contrasting example that includes a side effect, a function signature of  <code>FilePath -&gt; IO String</code> indicates that the function takes a file path and performs an I/O action that returns a string (which is exactly what the  <code>readFile</code> function does).
</p>

 <p>
Another feature of a pure functional programming paradigm is higher-order functions, which are functions that take functions as parameters. One of the most commonly used higher-order functions is  <code>fmap</code>, which applies a function to each value in a container (such as a list). For example, we can apply a function named square, which takes an integer and returns that integer multiplied by itself, to a list of integers to turn it into a list of squared integers: 
</p>
 <div class="jfw-code"> <pre> <span class="org-haskell-definition">square</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Int</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">Int</span>
 <span class="org-haskell-definition">square</span> x  <span class="org-haskell-operator">=</span> x  <span class="org-haskell-operator">*</span> x

 <span class="org-haskell-definition">fmap</span> square [1,2,3,4,5]  <span class="org-comment-delimiter">-- </span> <span class="org-comment">returns [1,4,9,16,25]</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Code written in this style tends to be both composable and testable. This above example is trivial, but there are many applications of higher-order functions. For example, we can write a function like renderPost which takes a record of post data and returns the version of the post rendered in HTML. If we have a list of posts, we can run fmap renderPost postList to produce a list of rendered posts. Our renderPost function can be used in both the single case and the multi-post case without any changes, because composing it with fmap changes how we can apply it. We can also write tests for the renderPost function and compose it with fmap in our tests when validating the behavior for a list of posts. Haskell facilitates rapid development, worry-free refactoring, and excellent maintainability
</p>

 <p>
Through the combination of the aforementioned static types and pure functional style that Haskell has, developing software in Haskell tends to be very fast. One of the common development workflows we employ is relies on a tool called ghcid, a simple command line tool that relies on the Haskell REPL to automatically watch code for changes and incrementally recompile. This allows us to see any compiler errors in our code immediately after saving changes to a file. It’s not uncommon for us to open only a terminal with a text editor in one pane and ghcid in another while developing applications in Haskell.
</p>

 <p>
While manually validating the results of our code is eventually necessary, such as by refreshing a page in a browser or using a tool to validate a JSON endpoint, a lot of this can be deferred until the end of a programming session. Many of the runtime errors that a programmer would encounter when writing a web service in a language like Python or PHP are caught immediately and displayed as compiler errors by ghcid. This is a far cry from the need to switch to a browser window and refresh the page after making a change to some code; a development workflow that everyone who has worked on a web application is intimately familiar with.
</p>

 <p>
Beyond the tight feedback loop during development, Haskell code is easy to refactor and modify. Like real world code written in any other language, such code written in Haskell is not write-only. It will eventually need to be maintained, updated, and extended, often by developers that are not the original authors of the code. With the aid of compile-time checking, many code refactors in Haskell become easy; a common refactoring workflow is to make a desired change in one location and then fix one compiler error at a time until the program compiles again. This is far easier than the equivalent changes in dynamically typed languages that offer no such assistance to the programmer.
</p>

 <p>
Proponents of dynamically typed languages will often argue that automated tests supplant the need for compile-time type checking, and can help prevent errors as well. However, tests are not as powerful as type constraints. For tests to be effective, they must:
</p>

 <ul class="org-ul"> <li>Actually be written, yet many real world code bases have limited
testing.</li>
 <li>Make correct assertions.</li>
 <li>Be comprehensive (test a variety of inputs) and provide good coverage
(test a large portion of the code base).</li>
 <li>Be easy to run and finish quickly, otherwise they will not become part
of the development workflow.</li>
 <li>Be updated and maintained in tandem with the code they test.</li>
</ul> <p>
Haskell’s type system has none of the above issues. The type system is a fixture in the language and the compiler always validates that the types are correct. The type system is inherently comprehensive, providing full coverage of every piece of Haskell code, and there are no changes to make to it as the underlying code changes. All this is not to say that the type system can replace every type of test. But what it does do is provide assurances that are more comprehensive than tests, and are present in every code base, even when no tests exist. Haskell programs have stellar performance, leading to faster applications and lower hardware costs
</p>

 <p>
GHC, the most commonly used Haskell compiler, produces extremely fast executables, especially when compared against other languages commonly used for application development, such as PHP or Python. This improved performance leads to both a more responsive application and lower hardware costs.
</p>

 <p>
It’s common to hear proponents of other languages be dismissive when their language is described as slow, as hardware is a relatively small cost compared to the cost of hiring programmers. This may be true, but we have found that the difference between Haskell and other languages used for web development is staggering.
</p>

 <p>
On one project we worked on in the past, we began implementing new API endpoints in a Haskell web service instead of the incumbent PHP. After around a year of building features and adding endpoints in Haskell, both the PHP and Haskell web services were dealing with a similar average workload in terms of request count and type, and performed similar CRUD actions backed by the same SQL database. The infrastructure was hosted on AWS, and the breakdown of the infrastructure used for each web service is below.
</p>

 <pre class="example" id="org176f1bf">
Web Service Language    EC2 Instance Type   CPU     RAM     Monthly Cost Per Instance   Number of Instances Used    Total Monthly Cost
PHP     c5.xlarge   4 Dedicated CPU cores   8 GB    $122    2   $244
Haskell     t3.nano     2 Flex CPU cores (limited to 20% use)   0.5 GB  $3.75   4   $15
</pre>

 <p>
In this application, each of the Haskell and PHP web services handled a
similar number of requests, handled a similar workload, and had similar
traffic spikes throughout the day, all while querying the same database.
Both the PHP and Haskell web services used Nginx as a reverse proxy. In
the end, the cost of operating the Haskell infrastructure was roughly
1/16th (or 6%) of what the PHP infrastructure was. Examining our AWS
usage metrics, the CPU on our Haskell machines never even hit 5%. The
Haskell endpoints consistently had response times of 100ms or less,
slightly outperforming the PHP endpoints.
</p>

 <p>
Ultimately, we had two web services, one written in Haskell and the
other written in PHP, that had similar performance but the former had a
cost of $200/year and the latter had a cost of $3,000/year. It’s worth
noting that the user base of this application was relatively small, with
under 25,000 monthly active users (MAUs). This difference in cost would
scale as the size of the user base, number of MAUs, and underlying
infrastructure increased.
</p>

 <p>
It’s certainly possible to criticize this comparison, and I do not claim
that it is in any way scientific. But it’s clear to me that based off of
our past experience running production workloads, Haskell outperforms
PHP by at least an order of magnitude (and PHP 7.0+ performs remarkably
well compared to many other similar languages). The cost reduction that
comes with operating Haskell over other web languages is not by any
means insignificant. Haskell is great for domain modeling and preventing
errors in domain logic
</p>

 <p>
Another benefit of Haskell’s type system beyond simple compile time
type-checking is that it enables modeling a problem domain through the
use of custom data types within an application. This allows a programmer
to create a description of business logic rules that are enforced by the
type system. Haskell has what are referred to as algebraic data types
(ADTs), consisting of both records (product types) and tagged unions
(sum types). Records are similar to dictionaries or JSON objects, and
commonly available in many languages. Tagged unions, however, are not
available in many languages, but are what enable a significant amount of
flexibility in domain modeling.
</p>

 <p>
The power of ADTs is best illustrated through an example. Suppose we are
creating an invoicing system that must keep track of customer invoices.
Each invoice must contain a list of line items that the invoice is for
and have an invoice status that indicates whether the order has been
paid or canceled. The types we would use to model this might look like
the following:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">type</span>  <span class="org-haskell-type">Dollars</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-type">Int</span>

 <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">CustomerInvoice</span>  <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">CustomerInvoice</span>
    { invoiceNumber  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Int</span>
    , amountDue      <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Dollars</span>
    , tax            <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Dollars</span>
    , billableItems  <span class="org-haskell-operator">::</span> [ <span class="org-haskell-type">String</span>]
    , status         <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">InvoiceStatus</span>
    , createdAt      <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">UTCTime</span>
    , dueDate        <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">Day</span>
    }

 <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">InvoiceStatus</span>
     <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Issued</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Paid</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Canceled</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Modeling domain rules in the type system like this (e.g. the status of
an invoice is either Issued, Paid, or Canceled) results in these rules
getting enforced at compile time, as described in the earlier section on
static typing. This is a much stronger set of guarantees than encoding
similar rules in class methods, as one might do in an object oriented
language that does not have sum types. With the type above, it becomes
impossible to define CustomerInvoice that doesn’t have an amount due,
for example. It’s also impossible to define an InvoiceStatus that is
anything other than one of the three aforementioned values.
</p>

 <p>
One application of the above types may be a function that creates a
notification message based on the status of the invoice. This function
would take a CustomerInvoice as a parameter and return a string
representing the content of the notification.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-definition">createCustomerNotification</span>  <span class="org-haskell-operator">::</span>  <span class="org-haskell-type">CustomerInvoice</span>  <span class="org-haskell-operator">-&gt;</span>  <span class="org-haskell-type">String</span>
 <span class="org-haskell-definition">createCustomerNotification</span> invoice  <span class="org-haskell-operator">=</span>
     <span class="org-haskell-keyword">case</span> status invoice  <span class="org-haskell-keyword">of</span>
         <span class="org-haskell-constructor">Issued</span>  <span class="org-haskell-operator">-&gt;</span>
             <span class="org-string">&quot;Invoice #&quot;</span>  <span class="org-haskell-operator">++</span> show (invoiceNumber invoice)  <span class="org-haskell-operator">++</span>  <span class="org-string">&quot; due on &quot;</span>  <span class="org-haskell-operator">++</span> show (dueDate invoice)

         <span class="org-haskell-constructor">Paid</span>  <span class="org-haskell-operator">-&gt;</span>
             <span class="org-string">&quot;Successfully paid invoice #&quot;</span>  <span class="org-haskell-operator">++</span> show (invoiceNumber invoice)

         <span class="org-haskell-constructor">Canceled</span>  <span class="org-haskell-operator">-&gt;</span>
             <span class="org-string">&quot;Invoice #&quot;</span>  <span class="org-haskell-operator">++</span> show (invoiceNumber invoice)  <span class="org-haskell-operator">++</span>  <span class="org-string">&quot; has been cancelled&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The above function uses pattern matching, another feature in the
language, to handle every possible InvoiceStatus value. The case
statement allows us to handle the different possible values of the
status field.
</p>

 <p>
The type system can protect us from making mistakes when changing the
rules of our domain. Suppose that after this application is live for a
while, we get feedback from our users that we need to be able to refund
invoices. To facilitate this, we’ll update our InvoiceStatus type to
include a Refunded value constructor:
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-keyword">data</span>  <span class="org-haskell-type">InvoiceStatus</span>
     <span class="org-haskell-operator">=</span>  <span class="org-haskell-constructor">Issued</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Paid</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Canceled</span>
     <span class="org-haskell-operator">|</span>  <span class="org-haskell-constructor">Refunded</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If this is the only code we change, then upon compilation, we get the
following error:
</p>

 <pre class="example" id="org0ce717d">
CustomerInvoice.hs:(15,5)-(20,35): error: [-Wincomplete-patterns, -Werror=incomplete-patterns]
    Pattern match(es) are non-exhaustive
    In a case alternative: Patterns not matched: Refunded
   |
15 |     case status invoice of
   |     ^^^^^^^^^^^^^^^^^^^^^^...
</pre>

 <p>
Whoops! Looks like we forgot to update the createCustomerNotification
function to handle this new status value. The compiler is throwing an
error and telling us that the case statement does not handle the
Refunded value as part of its pattern matches.
</p>

 <p>
By modeling our domain in our types, the compiler assists us in ensuring
that all of our domain logic can handle every possible value in the
domain*. This protects us from the very common mistake of an unhandled
value when writing in dynamically typed languages. Automated tests are
not a replacement for types in this situation, because the introduction
of new possible values often requires updating tests to assert whether
the new values can be handled, which doesn’t help us avoid the
problem—it’s just as easy to forget to update tests for the business
logic as it is to forget to update the business logic.
</p>

 <ul class="org-ul"> <li>By default, GHC (the Haskell compiler) will not throw an error in the
case of an unhandled value, but it’s standard practice for production
Haskell projects to use the -Wall and -Werror flags, which turn on
nearly every available warning and turn all warnings into errors.</li>
</ul> <p>
Haskell has a large number of mature, high-quality libraries
</p>

 <p>
The Haskell community has a published a large number of high quality,
production grade packages, many of which have been maintained for for a
decade or longer. The Haskell community has general consensus as to
which packages are good options in each functional category
(e.g. decoding/encoding JSON, parsing XML, decoding CSVs, working with
SQL databases, HTML templating, websockets, using Redis, etc). In some
categories there is a single, best option that is the de facto standard.
In other categories, there are several comparable options to choose
from, depending on what design decisions or trade offs a developer is
willing to make.
</p>

 <p>
Haskell has over 21,000 packages available in its package repository,
Hackage, and many more published in various places such as GitHub that
build tools can depend on. However, this number is dwarfed by the number
of packages available in the repositories of many other languages. As of
this post’s publication date, Ruby has 164,000 gems published. There are
282,000 Python packages on PyPI. There were over 1.3 million JavaScript
packages on npm as of April 2020.
</p>

 <p>
This discrepancy leads to one of the reservations I have heard expressed
about using Haskell in production: there aren’t as many Haskell packages
available as there are in other languages. My response to this is that
when building production systems, the total number of packages available
for a given language is largely irrelevant.
</p>

 <p>
When building a production system, the decision of which packages to use
is never based off of the total number of packages available, but which
individual packages have a good reputation, widespread use, and other
factors such as good documentation and whether a given package is still
being maintained. To put it simply, it’s quality and not quantity that
matters, and to that end, the Haskell community does an excellent job at
curating the packages necessary for real world use cases I described
earlier. Haskell makes it easy to write concurrent programs
</p>

 <p>
One feature of being a pure functional language is that, by default,
values in Haskell are immutable. This is not to say that values never
change, but state is not changed in-place. For example, when a function
appends an element to a list, a new list is returned and the memory used
by the old list will be freed by the garbage collector. A benefit of
such of immutability is that it simplifies concurrent programming. In a
language with mutable values, multiple threads accessing the same value
can lead to issues such as race conditions and deadlocks.
</p>

 <p>
Since values in Haskell are immutable, there is no risk of these types
of issues even when a program is running on multiple threads and
accessing shared memory. This also results in a simpler mental model
surrounding concurrent programming. Concurrent code can often be written
in the same style as single-threaded code, with functions that run the
underlying workload on a new thread simply wrapping the single-threaded
implementation.
</p>

 <p>
Concurrency is a useful tool in the Haskell programmer’s toolbox. On
projects we have worked on in the past, we have done everything from
implemented websocket servers that run as part of the same executable
that serves an HTTP API, to created a multi-threaded worker system that
required far less overhead than managing individual Linux processes
necessary for workers written in languages with limited concurrency
support. Haskell enables domain-specific languages, which foster
expressiveness and reduce boilerplate
</p>

 <p>
Haskell’s type system and language features make it a common choice for
writing compilers. One offshoot of this is that Haskell libraries
sometimes employ domain-specific languages (DSLs) to improve their
usability. A DSL, in contrast to a general purpose language, is a small
language designed to be well-suited for expressing the rules of a
specific application or problem domain.
</p>

 <p>
One of the most well known and widely used DSLs is SQL, which is the
language used to query data stored in relational database systems.
Unlike most languages, SQL is declarative rather than imperative. This
means that a SQL program tends to describe what the outcome of its
execution should be rather than how that outcome should be achieved. Any
developer familiar with SQL can imagine how writing code to retrieve
data stored in tables as a series of rows in an imperative style would
be very cumbersome.
</p>

 <p>
One of the features in Haskell that facilitates DSLs is called Template
Haskell. This is commonly employed by library authors to allow consumers
of the library to use what is an expressive syntax to avoid a lot of
boilerplate. One example of this is in the Persistent library, one of
the most popular SQL libraries. Persistent exposes a DSL that uses what
is referred to as Persistent Entity Syntax that allows the user of the
library to define their database schema. An example of this syntax is
below.
</p>

 <div class="jfw-code"> <pre> <span class="org-haskell-constructor">Person</span>
    name  <span class="org-haskell-constructor">Text</span>
    age  <span class="org-haskell-constructor">Int</span>  <span class="org-haskell-constructor">Maybe</span>
 <span class="org-haskell-constructor">BlogPost</span>
    title  <span class="org-haskell-constructor">Text</span>
    authorId  <span class="org-haskell-constructor">PersonId</span>
    publicationDate  <span class="org-haskell-constructor">UTCTime</span>
 <span class="org-haskell-constructor">BlogPostTag</span>
    label  <span class="org-haskell-constructor">Text</span>
    blogPostId  <span class="org-haskell-constructor">BlogPostId</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The code above is not Haskell, and if you have never used Haskell’s
Persistent library, odds are you have never seen this syntax. Yet it is
apparent what it does—it defines three tables (Person, BlogPost, and
BlogPostTag) and the columns within them. This code gets consumed by a
Haskell program and supplants the need to write approximately 150 lines
of Haskell code to define all of the data types and accessor functions
for working with the data from these three tables.
</p>

 <p>
The above is only one example of an external DSL, which is a DSL that
uses its own syntax. Other libraries that expose DSLs include ones for
webserver route definitions and for HTML templating. Some library
authors opt to create embedded domain-specific languages (eDSLs), which
are written in Haskell syntax. This results in a series of types and
functions that are specialized to a particular domain. Esqueleto is an
example of a widely-used library that exposes an eDSL for writing
type-safe SQL queries. Haskell has a large community filled with smart
and friendly people
</p>

 <p>
One of the most important facets of using a programming language is the
community. Haskell’s community is large and includes a wide variety of
people coming from many different technical backgrounds. This includes
programming language researchers, some of whom have been working on
Haskell since its inception in 1990, creators of other programming
languages whose compilers are written in Haskell, self-taught Haskell
enthusiasts, professional Haskell programmers using Haskell commercially
(we at Foxhound Systems fall into this category), as well as
eager-to-learn students, amongst many others.
</p>

 <p>
The Haskell community is very welcoming to beginners. While the language
has a learning curve that is steeper than that of many others due to its
depth and breadth, it’s easy to ask questions and find help any number
of people that sincerely want to help others learn the language.
</p>

 <p>
Some of the forms of communication we like to use to engage with the
Haskell community are:
</p>

 <ul class="org-ul"> <li>The Haskell subreddit, which has over 60,000 readers and is one of the
largest programming language communities on reddit.</li>
 <li>The Functional Programming Slack, which has a number of channels
dedicated to Haskell (including #haskell, #haskell-beginners,
#haskell-jobs, and #haskell-adoption).</li>
 <li>The Haskell mailing lists, such as haskell-cafe, which have a variety
of content from library announcements, to Q&amp;A about the language, to
volunteer opportunities</li>
 <li>The #haskell channel on the Freenode IRC network often has over 1,000
people connected to it, and is a great alternative to the Slack
channels.</li>
 <li>The Haskell Weekly Newsletter, which is a weekly newsletter that
highlights blog posts and other announcements from the preceding week.</li>
 <li>Although not conventional community, the haskell tag on StackOverflow
has over 46,000 questions associated with it. It’s not uncommon to
find excellent answers that give a great overview of a specific topic
or issue related to the language.</li>
</ul> <p>
This is not an exhaustive list, and participation through every forum is
not necessary. But when someone is looking for help or generally
learning about the language, it’s worth using any of the forums above.
Conclusion
</p>

 <p>
There are many reasons for why Haskell is our first choice of
programming language for building production software systems. To recap
the whole list covered in this post:
</p>

 <ul class="org-ul"> <li>Haskell has a strong static type system that prevents errors and
reduces cognitive load.</li>
 <li>Haskell enables writing code that is composable, testable, and has
predictable side-effects.</li>
 <li>Haskell facilitates rapid development, worry-free refactoring, and
excellent maintainability.</li>
 <li>Haskell programs have stellar performance, leading to faster
applications and lower hardware costs.</li>
 <li>Haskell is great for domain modeling and preventing errors in domain
logic.</li>
 <li>Haskell has a large number of mature, high-quality libraries.</li>
 <li>Haskell makes it easy to write concurrent programs.</li>
 <li>Haskell enables domain-specific languages, which foster expressiveness
and reduce boilerplate.</li>
 <li>Haskell has a large community filled with smart and friendly people.</li>
</ul> <p>
It is the sum of these reasons that makes Haskell such a compelling
choice. Haskell enables rapid development, worry-free refactoring, easy
maintainability, provides excellent performance, and has a mature
ecosystem. These facets among many others make it an excellent choice
for building production applications.
</p>

 <p>
Original post
 <a href="https://www.foxhound.systems/blog/why-haskell-for-production/">here</a>
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/sql-select-all/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Why SQL SELECT * is often a bad idea</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/breaking-free-of-javascript/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Breaking free of Javascript</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/">Free à la Carte</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/">Running Hoogle locally</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/">Type safety back and forth</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/haskell-in-production-at-foxdown-systems/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/haskell-in-production-at-foxdown-systems/index.html</guid>
  <pubDate>Sun, 22 Aug 2021 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Why SQL SELECT * is often a bad idea</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
There are some anti-patterns one should avoid when writing SQL queries. Sometimes these may seem like a shortcut, but in reality this can lead to bugs, problems, and brittle applications.
</p>

 <p>
It’s almost always better to use the explicit column list in the SELECT query than a * (star) wildcard. It not only improves the performance but also makes your code more explicit. It also helps you create maintainable code, which will not break when you add/remove columns from your table, especially if you have views that refer to the original table.
</p>
 <h2>SELECT *  <a id="select-" class="anchor" href="#select-" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgcda90f8">
 <p>
Doing a  <code>SELECT *</code> may seem like a time-saver, but it’s actually setting you up for problems in the long run, specially when database schema changes.
</p>
</div>
 <h3>Breaks Views While Adding New Columns to a Table  <a id="breaks-views-while-adding-new-columns-to-a-table" class="anchor" href="#breaks-views-while-adding-new-columns-to-a-table" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org1e474b5">
 <p>
When you use SELECT * in views, then you create subtle bugs if a new column has been added ro an old one is removed from the table. Why? Because your view might break, or start returning an incorrect result.
</p>
</div>
 <h3>Dependency on Order of Columns on ResultSet  <a id="dependency-on-order-of-columns-on-resultset" class="anchor" href="#dependency-on-order-of-columns-on-resultset" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3fb5e38">
 <p>
When you use the SELECT * query in your application and have any dependency on order of column, which you should not, the ordering of the result set will change if you add a new column or change the order of columns.
</p>
</div>
 <h3>Conflicts in a JOIN Query  <a id="conflicts-in-a-join-query" class="anchor" href="#conflicts-in-a-join-query" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org9efb3be">
 <p>
When you use SELECT * in JOIN query, you can introduce complications when multiple tables have columns with the same name e.g. status, active, name, etc.
</p>
</div>
 <h3>More Application Memory  <a id="more-application-memory" class="anchor" href="#more-application-memory" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3c1b561">
 <p>
Due to this increase in data, your application may require more memory just to hold unnecessary data that it will not be using
</p>
</div>
 <h3>Increased Network Traffic  <a id="increased-network-traffic" class="anchor" href="#increased-network-traffic" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org8e00d0e">
 <p>
SELECT * obviously returns more data than required to the client, which, in turn, will use more network bandwidth.
</p>
</div>
 <h3>Unnecessary I/O (Input Output)  <a id="unnecessary-io-input-output" class="anchor" href="#unnecessary-io-input-output" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-org3f6c9a2">
 <p>
By using SELECT *, you can be returning unnecessary data that will just be ignored, but fetching that data is not free of cost.
</p>
</div>
 <h2>COUNT(*)  <a id="count" class="anchor" href="#count" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org1b67488">
 <p>
One should default to using  <code>COUNT</code> clauses with column names, such as  <code>COUNT(id)</code>, since this will count values which are non-NULL.
</p>

 <p>
If NULL is explicitly wanted then one can choose for  <code>COUNT(1)</code> or  <code>COUNT(*)</code>.
There is a negligible performance difference, at least in PostgreSQL between 1 and * , so use at your discretion.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/ssr-wins-over-javascript/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">SSR wins over Javascript</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/haskell/haskell-in-production-at-foxdown-systems/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Haskell in Production at Foxdown Systems</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/sql-select-all/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/sql-select-all/index.html</guid>
  <pubDate>Sun, 28 Feb 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>SSR wins over Javascript</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In this day and age, server side rendering proves it is stable and more
effective than the JavaScript bloat we are growing used to. Any simple
page, with perhaps at most 3 KB of actual text content will download
over 2 MB of JavaScript in order to simply function.
</p>

 <p>
Besides that fact, SPA and API situations, where you have a decoupled
frontend from the backend, still do not justify the fact of using
JavaScript, or even worse, any of its frameworks. That paradigm can
easily be, in most cases, fulfilled by server side rendering in the
backend language of your choice, which will spit out a digested HTML for
your clients.
</p>

 <p>
In specific, if you keep the same programming language, in my case Go,
across your applications, you can share a lot of logic, data models, and
you get a consistent developer experience, and an easier to maintain
system.
</p>

 <p>
Not to mention the fact that the JavaScript ecosystem goes with the
wind, is the most unstable place I have ever seen, and most of the times
I need to look into some source code written in that language, of some
external package dependency, I start questioning the author’s sanity,
and mine, and also my career choices.
</p>

 <p>
Going further, with the bloated state management tools, and broken
concurrency model of JavaScript, as well as the insane “features” of the
language, and then seeing TypeScript, a “sub-set” of the language, which
also brings its own horrors and pre-compilation, I have no doubt that
the show must come to a stop, and for my professional needs, as a
software engineer at an e-commerce platform, I have decided to throw
away all the SPA code (3 attempts) that has previously been in
production, and go in a totally oposite direction.
</p>

 <p>
This direction may seem unorthodox, but it has many reasons that make it
a success, and a joy to work with, and extend.
</p>

 <p>
To give some background, the previous SPA I helped create and worked
with, that consumed my API’s data, was created using Vue.js 2, SCSS with
scoped styles (horror!), VueX, and TypeScript.
</p>

 <p>
This combination has quickly lead to spaghetti code of terrible quality,
and lots of it. To make matters worse, there was a transition of API v1
to v2, where some data models changed, and the developer decided to
refuse that change, and write his own mappers, to convert those v2 data
models to v1, and vice-versa, in order to comply with my API, which he
was interfacing with.
</p>

 <p>
As you can imagine, this has lead to an unmaintainable project, that no
one dares to touch.
</p>

 <p>
So I decided to follow my beloved KISS principle, and to go ahead and
get started on writing a SOLID coded Go application, that will act as
the API consumer, and spit out processed HTML for the client’s browser.
</p>

 <p>
I also followed the principle of “graceful degradation”, which in basic
terms, means that the website should function perfectly without
JavaScript, and it should only be used to enhance the user experience,
like in heavy animations, sliders, etc. By no means should JavaScript be
the center of the application, due to all the negative aspects it
brings, and due to the superior language that Go is.
</p>

 <p>
I have been met with much success with this application, and can really
say confidently that my future endeavours will always go the same route,
unless really necessary to code a more client-side application, in which
case I will most likely turn to GopherJS or such, or perhaps some Go to
WebAssembly, so I don’t need to write any more JavaScript ever.
</p>

 <p>
I want to list some of the advantages that I have found, and am sure
anyone will find when doing things more in an “old but gold” old-school
approach of building websites, server side rendered:
</p>

 <ul class="org-ul"> <li>In my case, one language for the whole platform 😀 Go !</li>
 <li>Native browser features, like remembering how far in the list of the
previous page you were when you go back.</li>
 <li>SEO is greatly improved, and you don’t even need to think about it as
much. Search engines will easily crawl your site, and will read
correctly formed HTML.</li>
 <li>Security improvements, due to not exposing application code, or API
calls in the client’s browser.</li>
 <li>Simpler front-end applications, no mapping, no state management, no
problems. API data directly to HTML.</li>
 <li>Go is a well designed, compiled, statically typed and concurrent
language. Why not use it for client-facing applications?</li>
 <li>The ecosystem around Go is much more stable and reliable than
JavaScript’s.</li>
 <li>The standard library of Go is great, and can power most of your needs
without additional thrid-party dependencies.</li>
 <li>High-concurrency and asynchronous process capabilities in the
client-facing applications.</li>
 <li>Accessibility is greatly improved due to the HTML being delivered as
already rendered, and we can care more about writing semantically
correct HTML, instead of caring so much about the newest JS framework.</li>
 <li>Supporting security conscious people and organizations: let’s face it
there’s bad people doing heinous things with JavaScript, so the
easiest solution is to get rid of JavaScript.</li>
 <li>Mobile devices, web-views, and embedded devices are better supported,
without inconsistencies.</li>
 <li>Search engine spiders only follow real links - JavaScript confuses
them.</li>
 <li>Cross site scripting attacks risk is greatly reduced.</li>
 <li>Hacking/Defacement through DOM manipulation is no longer possible.</li>
 <li>Severe speed improvements, both on first, and on subsequent loads.</li>
</ul> <p>
I really have no intentions to be part of the spaghetti mess that
JavaScript easily becomes, I want a consistent and predictible language,
that compiles to binary code and can easily beat any out there.
</p>

 <p>
As for the SPA fans out there, I know it has its use cases, but let’s
face it, JS is doing so much more than it should since React and buddies
came along, this has gotten way out of hand and it is time to stop.
</p>

 <p>
Thanks for your attention, and I look forward to seeing comments.
</p>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Opinionated Style Guide</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/sql-select-all/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Why SQL SELECT * is often a bad idea</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/ssr-wins-over-javascript/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/ssr-wins-over-javascript/index.html</guid>
  <pubDate>Mon, 01 Feb 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Opinionated Style Guide</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
This serves as a supplement to
 <a href="https://golang.org/doc/effective_go.html">Effective Go</a>, based on
years of experience and inspiration/ideas from conference talks.
</p>
 <h2>Add context to errors  <a id="add-context-to-errors" class="anchor" href="#add-context-to-errors" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-add-context-to-errors">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>file, err := os.Open(&quot;foo.txt&quot;)
if err != nil {
    return err
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Using the approach above can lead to unclear error messages because of
missing context.
</p>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>file, err := os.Open(&quot;foo.txt&quot;)
if err != nil {
    return fmt.Errorf(&quot;open foo.txt failed: %w&quot;, err)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Wrapping errors with a custom message provides context as it gets
propagated up the stack. This does not always make sense. If you’re
unsure if the context of a returned error is at all times sufficient,
wrap it.
</p>
</div>
 <h2>Dependency management  <a id="dependency-management" class="anchor" href="#dependency-management" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-dependency-management">
</div>
 <h3>Use modules  <a id="use-modules" class="anchor" href="#use-modules" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-modules">
 <p>
Use  <a href="https://github.com/golang/go/wiki/Modules">modules</a>, since it is
the built-in go dependency management tooling and will be widely
supported (available with Go 1.11+).
</p>
</div>
 <h3>Use Semantic Versioning  <a id="use-semantic-versioning" class="anchor" href="#use-semantic-versioning" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-semantic-versioning">
 <p>
Tag your packages using  <a href="http://semver.org">Semantic Versioning</a>,
check the
 <a href="https://github.com/golang/go/wiki/Modules#how-to-prepare-for-a-release">modules
wiki</a> for more information about best practices regarding releases. The
git tag for your go package should have the format
 <code>v&lt;major&gt;.&lt;minor&gt;.&lt;patch&gt;</code>, e.g.,  <code>v1.0.1</code>.
</p>
</div>
 <h2>Structured logging  <a id="structured-logging" class="anchor" href="#structured-logging" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-structured-logging">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>log.Printf(&quot;Listening on :%d&quot;, port)
http.ListenAndServe(fmt.Sprintf(&quot;:%d&quot;, port), nil)
// 2017/07/29 13:05:50 Listening on :80</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>import &quot;github.com/sirupsen/logrus&quot;
// ...

logger.WithField(&quot;port&quot;, port).Info(&quot;Server is listening&quot;)
http.ListenAndServe(fmt.Sprintf(&quot;:%d&quot;, port), nil)
// {&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;Server is listening&quot;,&quot;port&quot;:&quot;7000&quot;,&quot;time&quot;:&quot;2017-12-24T13:25:31+01:00&quot;}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This is a harmless example, but using structured logging makes debugging
and log parsing easier.
</p>
</div>
 <h2>Avoid global variables  <a id="avoid-global-variables" class="anchor" href="#avoid-global-variables" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-avoid-global-variables">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>var db *sql.DB

func main() {
    db = // ...
    http.HandleFunc(&quot;/drop&quot;, DropHandler)
    // ...
}

func DropHandler(w http.ResponseWriter, r *http.Request) {
    db.Exec(&quot;DROP DATABASE prod&quot;)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Global variables make testing and readability hard and every method has
access to them (even those, that don’t need it).
</p>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func main() {
    db := // ...
    handlers := Handlers{DB: db}
    http.HandleFunc(&quot;/drop&quot;, handlers.DropHandler)
    // ...
}

type Handlers struct {
    DB *sql.DB
}

func (h *Handlers) DropHandler(w http.ResponseWriter, r *http.Request) {
    h.DB.Exec(&quot;DROP DATABASE prod&quot;)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Use structs to encapsulate the variables and make them available only to
those functions that actually need them by making them methods
implemented for that struct.
</p>

 <p>
Alternatively, higher-order functions can be used to inject dependencies
via closures.
</p>

 <div class="jfw-code"> <pre>func main() {
    db := // ...
    http.HandleFunc(&quot;/drop&quot;, DropHandler(db))
    // ...
}

func DropHandler(db *sql.DB) http.HandleFunc {
    return func (w http.ResponseWriter, r *http.Request) {
        db.Exec(&quot;DROP DATABASE prod&quot;)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If you really need global variables or constants, e.g., for defining
errors or string constants, put them at the top of your file.
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>import &quot;xyz&quot;

func someFunc() {
    //...
}

const route = &quot;/some-route&quot;

func someOtherFunc() {
    // usage of route
}

var NotFoundErr = errors.New(&quot;not found&quot;)

func yetAnotherFunc() {
    // usage of NotFoundErr
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>import &quot;xyz&quot;

const route = &quot;/some-route&quot;

var NotFoundErr = errors.New(&quot;not found&quot;)

func someFunc() {
    //...
}

func someOtherFunc() {
    // usage of route
}

func yetAnotherFunc() {
    // usage of NotFoundErr
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Keep the happy path left  <a id="keep-the-happy-path-left" class="anchor" href="#keep-the-happy-path-left" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-keep-the-happy-path-left">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>if item, ok := someMap[someKey]; ok {
    return item
}
return ErrKeyNotFound</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>item, ok := someMap[someKey]
if !ok {
    return ErrKeyNotFound
}
return item</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This helps to keep your code clear and readable. Not doing it
accumulates in larger functions and leads to the happy path being buried
in a lot of if/for/… statements.
</p>
</div>
 <h2>Testing  <a id="testing" class="anchor" href="#testing" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-testing">
</div>
 <h3>Use an assert libary  <a id="use-an-assert-libary" class="anchor" href="#use-an-assert-libary" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-an-assert-libary">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func TestAdd(t *testing.T) {
    actual := 2 + 2
    expected := 4
    if (actual != expected) {
        t.Errorf(&quot;Expected %d, but got %d&quot;, expected, actual)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>import &quot;github.com/stretchr/testify/assert&quot;

func TestAdd(t *testing.T) {
    actual := 2 + 2
    expected := 4
    assert.Equal(t, expected, actual)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Using assert libraries makes your tests more readable, requires less
code and provides consistent error output.
</p>
</div>
 <h3>Use sub-tests to structure functional tests  <a id="use-sub-tests-to-structure-functional-tests" class="anchor" href="#use-sub-tests-to-structure-functional-tests" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-sub-tests-to-structure-functional-tests">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func TestSomeFunctionSuccess(t *testing.T) {
    // ...
}

func TestSomeFunctionWrongInput(t *testing.T) {
    // ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func TestSomeFunction(t *testing.T) {
    t.Run(&quot;success&quot;, func(t *testing.T){
        //...
    })

    t.Run(&quot;wrong input&quot;, func(t *testing.T){
        //...
    })
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Use table driven tests  <a id="use-table-driven-tests" class="anchor" href="#use-table-driven-tests" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-table-driven-tests">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func TestAdd(t *testing.T) {
    assert.Equal(t, 1+1, 2)
    assert.Equal(t, 1+-1, 0)
    assert.Equal(t, 1, 0, 1)
    assert.Equal(t, 0, 0, 0)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The above approach looks simpler, but it’s much harder to find a failing
case, especially when having hundreds of cases.
</p>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func TestAdd(t *testing.T) {
    cases := []struct {
        A, B, Expected int
    }{
        {1, 1, 2},
        {1, -1, 0},
        {1, 0, 1},
        {0, 0, 0},
    }

    for _, tc := range cases {
        t.Run(fmt.Sprintf(&quot;%d + %d&quot;, tc.A, tc.B), func(t *testing.T) {
            t.Parallel()
            assert.Equal(t, t.Expected, tc.A+tc.B)
        })
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Using table-driven tests in combination with subtests gives you direct
insight about which case is failing and which cases are tested. –
 <a href="https://youtu.be/8hQG7QlcLBk?t=7m34s">Mitchell Hashimoto at GopherCon
2017</a>
</p>

 <p>
Running subtests in parallel allow you to have a lot more test cases and
still get those awesomely fast go build times. –
 <a href="https://blog.golang.org/subtests">The Go Blog</a>
</p>
</div>
 <h3>Avoid mocks  <a id="avoid-mocks" class="anchor" href="#avoid-mocks" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-avoid-mocks">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func TestRun(t *testing.T) {
    mockConn := new(MockConn)
    run(mockConn)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func TestRun(t *testing.T) {
    ln, err := net.Listen(&quot;tcp&quot;, &quot;127.0.0.1:0&quot;)
    t.AssertNil(t, err)

    var server net.Conn
    go func() {
        defer ln.Close()
        server, err := ln.Accept()
        t.AssertNil(t, err)
    }()

    client, err := net.Dial(&quot;tcp&quot;, ln.Addr().String())
    t.AssertNil(err)

    run(client)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Only use mocks if not otherwise possible, favor real implementations. –
 <a href="https://youtu.be/8hQG7QlcLBk?t=26m51s">Mitchell Hashimoto at GopherCon
2017</a>
</p>
</div>
 <h3>Avoid DeepEqual  <a id="avoid-deepequal" class="anchor" href="#avoid-deepequal" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-avoid-deepequal">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>type myType struct {
    id         int
    name       string
    irrelevant []byte
}

func TestSomething(t *testing.T) {
    actual := &amp;myType{/* ... */}
    expected := &amp;myType{/* ... */}
    assert.True(t, reflect.DeepEqual(expected, actual))
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>type myType struct {
    id         int
    name       string
    irrelevant []byte
}

func (m *myType) testString() string {
    return fmt.Sprintf(&quot;%d.%s&quot;, m.id, m.name)
}

func TestSomething(t *testing.T) {
    actual := &amp;myType{/* ... */}
    expected := &amp;myType{/* ... */}
    if actual.testString() != expected.testString() {
        t.Errorf(&quot;Expected '%s', got '%s'&quot;, expected.testString(), actual.testString())
    }
    // or assert.Equal(t, actual.testString(), expected.testString())
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Using  <code>testString()</code> for comparing structs helps on complex structs with
many fields that are not relevant for the equality check. This approach
only makes sense for very big or tree-like structs. –
 <a href="https://youtu.be/8hQG7QlcLBk?t=30m45s">Mitchell Hashimoto at GopherCon
2017</a>
</p>

 <p>
Google open sourced their  <a href="http://github.com/google/go-cmp">go-cmp</a>
package as a more powerful and safer alternative to  <code>reflect.DeepEqual</code>.
–  <a href="https://twitter.com/francesc/status/885630175668346880">Joe Tsai</a>.
</p>
</div>
 <h3>Add examples to your test files to demonstrate usage  <a id="add-examples-to-your-test-files-to-demonstrate-usage" class="anchor" href="#add-examples-to-your-test-files-to-demonstrate-usage" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-add-examples-to-your-test-files-to-demonstrate-usage">
 <div class="jfw-code"> <pre>func ExamleSomeInterface_SomeMethod(){
    instance := New()
    result, err := instance.SomeMethod()
    fmt.Println(result, err)
    // Output: someResult, &lt;nil&gt;
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Use linters  <a id="use-linters" class="anchor" href="#use-linters" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-linters">
 <p>
Use all the linters included in
 <a href="https://github.com/golangci/golangci-lint">golangci-lint</a> to lint
your projects before committing.
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">Installation - replace vX.X.X with the version you want to use
</span> <span class="org-variable-name">GO111MODULE</span>=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@vX.X.X
 <span class="org-comment-delimiter"># </span> <span class="org-comment">traditional way without go module
</span>go get -u github.com/golangci/golangci-lint/cmd/golangci-lint


 <span class="org-comment-delimiter"># </span> <span class="org-comment">Usage in the project workspace
</span>golangci-lint run</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
For detailed usage and the ci-pipeline installation guide visit
 <a href="https://github.com/golangci/golangci-lint">golangci-lint</a>.
</p>
</div>
 <h2>Use goimports  <a id="use-goimports" class="anchor" href="#use-goimports" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-goimports">
 <p>
Only commit gofmt’d files. Use  <code>goimports</code> for this to format/update the
import statements as well.
</p>
</div>
 <h2>Use meaningful variable names  <a id="use-meaningful-variable-names" class="anchor" href="#use-meaningful-variable-names" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-meaningful-variable-names">
 <p>
Avoid single-letter variable names. They may seem more readable to you
at the moment of writing but they make the code hard to understand for
your colleagues and your future self.
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func findMax(l []int) int {
    m := l[0]
    for _, n := range l {
        if n &gt; m {
            m = n
        }
    }
    return m
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func findMax(inputs []int) int {
    max := inputs[0]
    for _, value := range inputs {
        if value &gt; max {
            max = value
        }
    }
    return max
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Single-letter variable names are fine in the following cases. * They are
absolut standard like … *  <code>t</code> in tests *  <code>r</code> and  <code>w</code> in http request
handlers *  <code>i</code> for the index in a loop * They name the receiver of a
method, e.g.,  <code>func (s *someStruct) myFunction(){}</code>
</p>

 <p>
Of course also too long variables names like
 <code>createInstanceOfMyStructFromString</code> should be avoided.
</p>
</div>
 <h2>Avoid side-effects  <a id="avoid-side-effects" class="anchor" href="#avoid-side-effects" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-avoid-side-effects">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func init() {
    someStruct.Load()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Side effects are only okay in special cases (e.g. parsing flags in a
cmd). If you find no other way, rethink and refactor.
</p>
</div>
 <h2>Favour pure functions  <a id="favour-pure-functions" class="anchor" href="#favour-pure-functions" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-favour-pure-functions">
 <blockquote>
 <p>
In computer programming, a function may be considered a pure function if
both of the following statements about the function hold: 1. The
function always evaluates the same result value given the same argument
value(s). The function result value cannot depend on any hidden
information or state that may change while program execution proceeds or
between different executions of the program, nor can it depend on any
external input from I/O devices. 2. Evaluation of the result does not
cause any semantically observable side effect or output, such as
mutation of mutable objects or output to I/O devices.
</p>
</blockquote>

 <p>
–  <a href="https://en.wikipedia.org/wiki/Pure_function">Wikipedia</a>
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func MarshalAndWrite(some *Thing) error {
    b, err := json.Marshal(some)
    if err != nil {
        return err
    }

    return ioutil.WriteFile(&quot;some.thing&quot;, b, 0644)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>// Marshal is a pure func (even though useless)
func Marshal(some *Thing) ([]bytes, error) {
    return json.Marshal(some)
}

// ...</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This is obviously not possible at all times, but trying to make every
possible func pure makes code more understandable and improves
debugging.
</p>
</div>
 <h2>Don’t over-interface  <a id="dont-over-interface" class="anchor" href="#dont-over-interface" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-dont-over-interface">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>type Server interface {
    Serve() error
    Some() int
    Fields() float64
    That() string
    Are([]byte) error
    Not() []string
    Necessary() error
}

func debug(srv Server) {
    fmt.Println(srv.String())
}

func run(srv Server) {
    srv.Serve()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>type Server interface {
    Serve() error
}

func debug(v fmt.Stringer) {
    fmt.Println(v.String())
}

func run(srv Server) {
    srv.Serve()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Favour small interfaces and only expect the interfaces you need in your
funcs.
</p>
</div>
 <h2>Don’t under-package  <a id="dont-under-package" class="anchor" href="#dont-under-package" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-dont-under-package">
 <p>
Deleting or merging packages is far easier than splitting big ones up.
When unsure if a package can be split, do it.
</p>
</div>
 <h2>Handle signals  <a id="handle-signals" class="anchor" href="#handle-signals" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-handle-signals">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func main() {
    for {
        time.Sleep(1 * time.Second)
        ioutil.WriteFile(&quot;foo&quot;, []byte(&quot;bar&quot;), 0644)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func main() {
    logger := // ...
    sc := make(chan os.Signal, 1)
    done := make(chan bool)

    go func() {
        for {
            select {
            case s := &lt;-sc:
                logger.Info(&quot;Received signal, stopping application&quot;,
                    zap.String(&quot;signal&quot;, s.String()))
                done &lt;- true
                return
            default:
                time.Sleep(1 * time.Second)
                ioutil.WriteFile(&quot;foo&quot;, []byte(&quot;bar&quot;), 0644)
            }
        }
    }()

    signal.Notify(sc, os.Interrupt, os.Kill)
    &lt;-done // Wait for go-routine
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Handling signals allows us to gracefully stop our server, close open
files and connections and therefore prevent file corruption among other
things.
</p>
</div>
 <h2>Divide imports  <a id="divide-imports" class="anchor" href="#divide-imports" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-divide-imports">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>import (
    &quot;encoding/json&quot;
    &quot;github.com/some/external/pkg&quot;
    &quot;fmt&quot;
    &quot;github.com/this-project/pkg/some-lib&quot;
    &quot;os&quot;
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>import (
    &quot;encoding/json&quot;
    &quot;fmt&quot;
    &quot;os&quot;

    &quot;github.com/bahlo/this-project/pkg/some-lib&quot;

    &quot;github.com/bahlo/another-project/pkg/some-lib&quot;
    &quot;github.com/bahlo/yet-another-project/pkg/some-lib&quot;

    &quot;github.com/some/external/pkg&quot;
    &quot;github.com/some-other/external/pkg&quot;
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Divide imports into four groups sorted from internal to external for
readability: 1. Standard library 2. Project internal packages 3. Company
internal packages 4. External packages
</p>
</div>
 <h2>Avoid unadorned return  <a id="avoid-unadorned-return" class="anchor" href="#avoid-unadorned-return" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-avoid-unadorned-return">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func run() (n int, err error) {
    // ...
    return
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>func run() (n int, err error) {
    // ...
    return n, err
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Named returns are good for documentation, unadorned returns are bad for
readability and error-prone.
</p>
</div>
 <h2>Use canonical import path  <a id="use-canonical-import-path" class="anchor" href="#use-canonical-import-path" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-canonical-import-path">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>package sub</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>package sub // import &quot;github.com/my-package/pkg/sth/else/sub&quot;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Adding the canonical import path adds context to the package and makes
importing easy.
</p>
</div>
 <h2>Avoid empty interface  <a id="avoid-empty-interface" class="anchor" href="#avoid-empty-interface" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-avoid-empty-interface">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>func run(foo interface{}) {
    // ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Empty interfaces make code more complex and unclear, avoid them where
you can.
</p>
</div>
 <h2>Main first  <a id="main-first" class="anchor" href="#main-first" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-main-first">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>package main // import &quot;github.com/me/my-project&quot;

func someHelper() int {
    // ...
}

func someOtherHelper() string {
    // ...
}

func Handler(w http.ResponseWriter, r *http.Reqeust) {
    // ...
}

func main() {
    // ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>package main // import &quot;github.com/me/my-project&quot;

func main() {
    // ...
}

func Handler(w http.ResponseWriter, r *http.Reqeust) {
    // ...
}

func someHelper() int {
    // ...
}

func someOtherHelper() string {
    // ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Putting  <code>main()</code> first makes reading the file a lot easier. Only the
 <code>init()</code> function should be above it.
</p>
</div>
 <h2>Use internal packages  <a id="use-internal-packages" class="anchor" href="#use-internal-packages" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-internal-packages">
 <p>
If you’re creating a cmd, consider moving libraries to  <code>internal/</code> to
prevent import of unstable, changing packages.
</p>
</div>
 <h2>Avoid helper/util  <a id="avoid-helperutil" class="anchor" href="#avoid-helperutil" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-avoid-helperutil">
 <p>
Use clear names and try to avoid creating a  <code>helper.go</code>,  <code>utils.go</code> or
even package.
</p>
</div>
 <h2>Embed binary data  <a id="embed-binary-data" class="anchor" href="#embed-binary-data" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-embed-binary-data">
 <p>
To enable single-binary deployments, use tools to add templates and
other static assets to your binary
(e.g.  <a href="https://github.com/gobuffalo/packr">github.com/gobuffalo/packr</a>).
</p>
</div>
 <h2>Use  <code>io.WriteString</code>  <a id="use-io.writestring" class="anchor" href="#use-io.writestring" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-io.writestring">
 <p>
A number of important types that satisfy  <code>io.Writer</code> also have a
 <code>WriteString</code> method, including  <code>*bytes.Buffer</code>,  <code>*os.File</code> and
 <code>*bufio.Writer</code>.  <code>WriteString</code> is behavioral contract with implicit
assent that passed string will be written in efficient way, without a
temporary allocation. Therefore using  <code>io.WriteString</code> may improve
performance at most, and at least string will be written in any way.
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>var w io.Writer = new(bytes.Buffer)
str := &quot;some string&quot;
w.Write([]byte(str))</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>var w io.Writer = new(bytes.Buffer)
str := &quot;some string&quot;
io.WriteString(w, str)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Use functional options  <a id="use-functional-options" class="anchor" href="#use-functional-options" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-use-functional-options">
 <div class="jfw-code"> <pre>func main() {
    // ...
    startServer(
        WithPort(8080),
        WithTimeout(1 * time.Second),
    )
}

type Config struct {
    port    int
    timeout time.Duration
}

type ServerOpt func(*Config)

func WithPort(port int) ServerOpt {
    return func(cfg *Config) {
        cfg.port = port
    }
}

func WithTimeout(timeout time.Duration) ServerOpt {
    return func(cfg *Config) {
        cfg.timeout = timeout
    }
}

func startServer(opts ...ServerOpt) {
    cfg := new(Config)
    for _, fn := range opts {
        fn(cfg)
    }

    // ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Structs  <a id="structs" class="anchor" href="#structs" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-structs">
</div>
 <h3>Use named structs  <a id="use-named-structs" class="anchor" href="#use-named-structs" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-use-named-structs">
 <p>
If a struct has more than one field, include field names when
instantiating it.
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>params := myStruct{
    1,
    true,
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>params := myStruct{
    Foo: 1,
    Bar: true,
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>Avoid new keyword  <a id="avoid-new-keyword" class="anchor" href="#avoid-new-keyword" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-avoid-new-keyword">
 <p>
Using the normal syntax instead of the  <code>new</code> keyword makes it more clear
what is happening: a new instance of the struct is created  <code>MyStruct{}</code>
and we get the pointer for it with  <code>&amp;</code>.
</p>

 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>s := new(MyStruct)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>s := &amp;MyStruct{}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Consistent header naming  <a id="consistent-header-naming" class="anchor" href="#consistent-header-naming" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-consistent-header-naming">
 <p>
 <b>Don’t:</b>
</p>

 <div class="jfw-code"> <pre>r.Header.Get(&quot;authorization&quot;)
w.Header.Set(&quot;Content-type&quot;)
w.Header.Set(&quot;content-type&quot;)
w.Header.Set(&quot;content-Type&quot;)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>Do:</b>
</p>

 <div class="jfw-code"> <pre>r.Header.Get(&quot;Authorization&quot;)
w.Header.Set(&quot;Content-Type&quot;)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/ci/shared-libraries-with-jenkins/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Shared Libraries with Jenkins</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/ssr-wins-over-javascript/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">SSR wins over Javascript</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/opinionated-style-guide/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/opinionated-style-guide/index.html</guid>
  <pubDate>Wed, 27 Jan 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Shared Libraries with Jenkins</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>Writing a Jenkins Shared Library pipeline  <a id="writing-a-jenkins-shared-library-pipeline" class="anchor" href="#writing-a-jenkins-shared-library-pipeline" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-writing-a-jenkins-shared-library-pipeline">
 <p>
A good read to get started understanding about why and how we are doing
this, is the
 <a href="https://www.jenkins.io/doc/book/pipeline/shared-libraries/">Jenkins
official documentation</a>, which gives a good explanation about this, but
quite incomplete when it comes an actual example implementation.
</p>

 <p>
I have taken most of the ideas and the article from
 <a href="https://dev.to/kuperadrian">Adrian Kuper</a>, thank him and me for this
tutorial.
</p>

 <p>
In this blog post I will try to explain how to setup and develop a
shared pipeline library for Jenkins, that is easy to work on and can be
unit tested with JUnit5 and Mockito.
</p>

 <p>
This blog post is kinda long and touches many topics without explaining
them in full detail.
</p>

 <p>
In order to be able to develop deployment pipelines, in the form of
shared library, we will need to set up a Java &amp; Groovy development
environment.
</p>

 <p>
For that purpose we will need the IntelliJ IDEA IDE that properly
supports Java and Groovy and has Gradle support.
</p>

 <p>
You should begin by downloading OpenJDK 8 and installing to your
machine, from
 <a href="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html">here</a> .
After having installed the package, verify your Java version with the
javac -version command, which should display something like:
</p>

 <div class="jfw-code"> <pre>$ javac -version

javac 1.8.0_231</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Following that you should download the Groovy language SDK from
 <a href="https://groovy.apache.org/download.html">here</a> and unzip it into your
SDKs folder. Then you should set an environment variable for
 <code>GROOVY_HOME</code> in your shell, for me ZSH:
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">export</span>  <span class="org-variable-name">GROOVY_HOME</span>= <span class="org-string">&quot;/Users/joe/Development/SDKs/groovy-3.0.7&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
and augment your path with the groovy bin folder:
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">export</span>  <span class="org-variable-name">PATH</span>= <span class="org-string">&quot;/Users/joe/Development/SDKs/groovy-3.0.7/bin:$PATH&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You then have a setup that will be able to run Java and Groovy code
without problems.
</p>

 <p>
Then let’s create a new IntelliJ IDEA project. I suggest using the
IntelliJ IDEA Ultimate for Jenkins shared pipeline development, because
it is the only IDE I know of, that properly supports Java and Groovy and
has Gradle support, and has excellent plugins, auto-complete and other
amazing features. So, if you don’t have it installed it yet, go ahead
and get a license.
</p>

 <p>
Then you can open up the IDE and create a new project, select Gradle and
make sure to set the checkbox on Groovy.
</p>


 <div id="orgb9fad0e" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1610803588/jjba-site/blog/shared-library-jenkins/mvf2arsz0dmpi721uc6l_xdxosk.png"></img></p>
 <p> <span class="figure-number">Figure 1: </span>New Project</p>
</div>

 <p>
Next up, enter a GroupId and an ArtifactId.
</p>


 <div id="org54d6e31" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1610803587/jjba-site/blog/shared-library-jenkins/6jgw5g2khn8nt9rrc0tp_az9ijw.png"></img></p>
 <p> <span class="figure-number">Figure 2: </span>New Project Settings</p>
</div>

 <p>
Ignore the next window (the defaults are fine), click “Next”, enter a
project name and click “Finish”.
</p>


 <div id="org1ba98f0" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1610803664/jjba-site/blog/shared-library-jenkins/Screenshot-2019-01-04-at-12.14.52_aevfeu.png"></img></p>
 <p> <span class="figure-number">Figure 3: </span>Set defaults</p>
</div>

 <p>
IntelliJ should boot up with your new project. The folder structure in
your project should be something like the following.
</p>


 <div id="org863f24d" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1610803663/jjba-site/blog/shared-library-jenkins/Screenshot-2019-01-04-at-12.24.01_qak7rp.png"></img></p>
 <p> <span class="figure-number">Figure 4: </span>Initial Structure</p>
</div>

 <p>
This is cool for usual Java/Groovy projects, but for our purpose we have
to change things up a bit since Jenkins demands a project structure like
this:
</p>

 <pre class="example" id="orgd099766">
├── build           # Gradle compilation results
├── build.gradle    # Gradle config for this project
├── gradle          # Gradle runtime libraries and JAR files
├── gradlew         # UNIX wrapper to run cradle, generated by the IDE
├── reports         # Custom folder where our test coverage reports will go
├── resources       # Necessary resources to run your pipelines, think JSON files, necessary config files
├── settings.gradle # Advanced Gradle setttings
├── src             # Library code will reside here, this is the source code root, organised as a usual Java project
│   └── org
│       └── company
│
│
├── test            # Unit tests for the library code, the contents of this folder will mimic the src folder structure
│
│
└── vars            # Globally accessible (from Jenkins) scripts and methods, when loading the library
    └── pipeline.gdsl
</pre>

 <p>
Make sure to add to your  <code>.gitignore</code> the  <code>.gradle</code>,  <code>build</code>,  <code>reports</code>,
 <code>.idea</code> folders.
</p>

 <p>
You might be wondering where does  <code>pipeline.gdsl</code> come from, well that
comes from your Jenkins instance, and depending on the plugins and
features you have installed on it, the file will contain different
content. This can be obtained from the pipeline syntax menu as seen in
the picture below. This file will ensure that your IDE understands
scripted pipeline steps. A message should pop up after having added the
contents to this file, with the text:
 <code>DSL descriptor file has been change and isn’t currently executed</code> to
which you should respond  <code>Activate Back</code>.
</p>


 <div id="orgece61bf" class="figure">
 <p> <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1611316353/jjba-site/blog/shared-library-jenkins/GDSL-link_m5b98g.png"></img></p>
 <p> <span class="figure-number">Figure 5: </span>Jenkins IntelliJ Pipeline GDSL</p>
</div>

 <p>
Once you are setup with the project structure like above, edit your
 <code>build.gradle</code> so that it resembles:
</p>

 <div class="jfw-code"> <pre>buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.eriwen:gradle-cobertura-plugin:1.1.1'
    }
}

group 'org.company'
version '1.0-SNAPSHOT'


apply plugin: 'groovy'
apply plugin: 'cobertura'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url 'https://repo.jenkins-ci.org/releases'
    }
    maven {
        url 'https://repo.jenkins-ci.org/public'
    }
}


dependencies {
    implementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.85'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.41', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-support', version: '2.16', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins', name: 'script-security', version: '1.34', ext: 'jar'

    implementation 'org.codehaus.groovy:groovy-all:3.0.7'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testImplementation 'org.mockito:mockito-core:2.+'
}

test {
    jvmArgs '-noverify'
    useJUnitPlatform()
}

sourceSets {
    main {
        groovy {
            // all code files will be in either of the folders
            srcDirs = ['src', 'vars']
        }
    }
    test {
        groovy {
            srcDirs = ['test']
        }
    }
}

cobertura {
    format = 'html'
    includes = ['**/*.groovy']
    excludes = ['*_build.groovy']
    reportsDir = file(&quot;./reports&quot;)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
At this point we should have a nice folder structure and enough
dependencies to use to get to our goal. Cool, it’s time to implement our
shared library!
</p>
</div>
 <h2>The General Approach  <a id="the-general-approach" class="anchor" href="#the-general-approach" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-the-general-approach">
 <p>
First a quick run-down on how we build our library and on why we do it
that way:
</p>

 <p>
We will keep the “custom” steps inside var as simple as possible and
without any real logic. Instead, we create classes (inside src) that do
all the work.
</p>

 <p>
We create an interface, which declares methods for all required Jenkins
steps (sh, bat, error, etc.). The classes call steps only through this
interface.
</p>

 <p>
We write unit tests for your classes like you normally would with JUnit
and Mockito. This way we are able to:
</p>

 <ul class="org-ul"> <li>Compile and execute our library/unit tests without Jenkins</li>
 <li>Test that our classes work as intended</li>
 <li>Test that Jenkins steps are called with the right parameters</li>
 <li>Test the behaviour of our code when a Jenkins step fails</li>
 <li>Build, test, run metrics and deploy your Jenkins Pipeline Library
through Jenkins itself</li>
</ul> <p>
Now let’s get really going.
</p>
</div>
 <h2>The Interface For Step Access  <a id="the-interface-for-step-access" class="anchor" href="#the-interface-for-step-access" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-the-interface-for-step-access">
 <p>
First, we will create the interface inside  <code>org.somecompany</code> that will
be used by all classes to access the regular Jenkins steps like  <code>sh</code> or
 <code>error</code>. We will start with a simple example, and then I will provide a
more advanced one.
</p>

 <div class="jfw-code"> <pre>package org.somecompany

interface IStepExecutor {
    int sh(String command)
    void error(String message)
    // add more methods for respective steps if needed
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This interface is neat, because it can be mocked inside our unit tests.
That way our classes become independent to Jenkins itself. For now,
let’s add an implementation that will be used in our vars Groovy
scripts:
</p>

 <div class="jfw-code"> <pre>package org.somecompany

class StepExecutor implements IStepExecutor {
    // this will be provided by the vars script and
    // let's us access Jenkins steps
    private steps

    StepExecutor(steps) {
        this.steps = steps
    }

    @Override
    int sh(String command) {
        this.steps.sh returnStatus: true, script: &quot;${command}&quot;
    }

    @Override
    void error(String message) {
        this.steps.error(message)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Here is a more complex example, with more available methods. You can
expand on this by looking at the  <code>pipeline.gdsl</code> file and taking
abstractions from there, both for methods, and properties.
</p>

 <div class="jfw-code"> <pre>import org.jenkinsci.plugins.workflow.cps.EnvActionImpl
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

interface IStepExecutor {
    /**
     * Current build environment variables
     */
    public EnvActionImpl env

    /**
     * Current build details
     */
    public RunWrapper currentBuild

    /**
     * Current build parameters
     */
    public Map params

    /**
     * Shell Script
     * @param command
     * @return
     */
    int sh(String command)

    /**
     * Shell Script
     * @param label
     * @param command
     * @return
     */
    int sh(String label, String command)

    /**
     * Error signal
     * @param message
     */
    void error(String message)

    /**
     * Stage of a Jenkins build
     * @param name
     * @param body
     */
    void stage(String name, Closure body)

    /**
     * Execute closures in parallel
     * @param closures
     */
    void parallel(Map closures)

    /**
     * Recursively delete the current directory from the workspace
     */
    void deleteDir()

    /**
     * Update the commit status in GitHub
     * @param name
     * @param status
     */
    void updateGitlabCommitStatus(String name, String status)

    /**
     * Send Slack Message
     * @param channel
     * @param color
     * @param iconEmoji
     * @param message
     */
    void slackSend(String channel, String color, String iconEmoji, String message)

    /**
     * Accept GitHub Merge Request
     * @param useMRDescription
     * @param removeSourceBranch
     */
    void acceptGitHubMR(Boolean useMRDescription, Boolean removeSourceBranch)

    /**
     * Archive JUnit-formatted test results
     * @param location
     */
    void junit(String location)

    /**
     * Stash some files to be used later in the build
     * @param name
     * @param includes
     */
    void stash(String name, String includes)

    /**
     * Restore files previously stashed
     * @param name
     */
    void unstash(String name)

    /**
     * PowerShell Script
     * @param command
     * @return
     */
    int powershell(String command)

    /**
     * PowerShell Script
     * @param label
     * @param command
     * @return
     */
    int powershell(String label, String command)

    /**
     * Change current directory
     * @param directory
     * @param body
     */
    void dir(String directory, Closure body)

    /**
     * Allocate node. Change execution of build to said agent
     * @param name
     * @param body
     */
    void node(String name, Closure body)

    /**
     * Catch error and set build result to failure
     * @param params
     * @param body
     */
    void catchError(Map params, Closure body)

    /**
     * Add Cobertura coverage report result
     * @param location
     */
    void cobertura(String location)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
And the implementation:
</p>

 <div class="jfw-code"> <pre>import org.jenkinsci.plugins.workflow.cps.EnvActionImpl
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

final class StepExecutor implements IStepExecutor {
    // this will be provided by the vars script and
    // let's us access Jenkins steps
    private steps

    public EnvActionImpl env
    public RunWrapper currentBuild
    public Map params

    StepExecutor(steps) {
        this.steps = steps
        this.env = this.steps.env
        this.currentBuild = this.steps.currentBuild
        this.params = Collections.unmodifiableMap(this.steps.params)
    }

    @Override
    int sh(String command) {
        this.steps.sh returnStatus: true, script: &quot;${command}&quot;
    }

    @Override
    int sh(String description, String command) {
        this.steps.sh returnStatus: true, label: &quot;${description}&quot;, script: &quot;${command}&quot;
    }

    @Override
    int powershell(String command) {
        this.steps.powershell returnStatus: true, script: &quot;${command}&quot;
    }

    @Override
    int powershell(String description, String command) {
        this.steps.powershell returnStatus: true, label: &quot;${description}&quot;, script: &quot;${command}&quot;
    }

    @Override
    void error(String message) {
        this.steps.currentBuild.setResult(JobStatus.Failure)
        this.steps.error(message)
    }

    @Override
    void stage(String name, Closure body) {
        this.steps.stage(name, body)
    }

    @Override
    void parallel(Map closures) {
        this.steps.parallel(closures)
    }

    @Override
    void deleteDir() {
        this.steps.deleteDir()
    }

    @Override
    void updateGitlabCommitStatus(String name, String status) {
        this.steps.updateGitlabCommitStatus name: &quot;${name}&quot;, status: &quot;${status}&quot;
    }

    @Override
    void slackSend(String channel, String color, String iconEmoji, String message) {
        this.steps.slackSend baseUrl: &quot;https://hooks.slack.com/services/&quot;, botUser: true,
                channel: &quot;${channel}&quot;, color: &quot;${color}&quot;, iconEmoji: &quot;${iconEmoji}&quot;,
                message: &quot;${message}&quot;, teamDomain: &quot;teamDomain&quot;,
                tokenCredentialId: &quot;token&quot;, username: &quot;webhookbot&quot;
    }

    @Override
    void acceptGitHubMR(Boolean useMRDescription, Boolean removeSourceBranch) {
        this.steps.acceptGitHubMR useMRDescription: useMRDescription, removeSourceBranch: removeSourceBranch
    }

    @Override
    void stash(String name, String includes) {
        this.steps.stash name: &quot;${name}&quot;, includes: &quot;${includes}&quot;
    }

    @Override
    void unstash(String name) {
        this.steps.unstash name: &quot;${name}&quot;
    }

    @Override
    void dir(String directory, Closure body) {
        this.steps.dir(directory, body)
    }

    @Override
    void node(String name, Closure body) {
        this.steps.node(name, body)
    }

    @Override
    void catchError(Map params, Closure body) {
        this.steps.catchError buildResult: params.buildResult,
                catchInterruptions: params.catchInterruptions,
                message: params.message,
                stageResult: params.stageResult,
                body: body
    }

    @Override
    void junit(String location) {
        this.steps.junit testResults: &quot;${location}&quot;, allowEmptyResults: false
    }

    @Override
    void cobertura(String location) {
        this.steps.cobertura autoUpdateHealth: false,
                autoUpdateStability: false,
                coberturaReportFile: &quot;${location}&quot;,
                conditionalCoverageTargets: '70, 0, 0',
                failUnhealthy: false,
                failUnstable: false,
                lineCoverageTargets: '80, 0, 0',
                maxNumberOfBuilds: 0,
                methodCoverageTargets: '80, 0, 0',
                onlyStable: false,
                sourceEncoding: 'ASCII',
                zoomCoverageChart: false
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Adding Basic Dependency Injection  <a id="adding-basic-dependency-injection" class="anchor" href="#adding-basic-dependency-injection" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-adding-basic-dependency-injection">
 <p>
Because we don’t want to use the above implementation in our unit tests,
we will setup some basic dependency injection in order to swap the above
implementation with a mock during unit tests. If you are not familiar
with dependency injection, you should probably read up about it, since
explaining it here would be out-of-scope, but you might be fine with
just copy-pasting the code in this chapter and follow along.
</p>

 <p>
So, first we create the org.somecompany.ioc package and add an IContext
interface:
</p>

 <div class="jfw-code"> <pre>package org.somecompany.ioc

import org.somecompany.IStepExecutor

interface IContext {
    IStepExecutor getStepExecutor()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Again, this interface will be mocked for our unit tests. But for regular
execution of our library we still need an default implementation:
</p>

 <div class="jfw-code"> <pre>package org.somecompany.ioc

import org.somecompany.IStepExecutor
import org.somecompany.StepExecutor

class DefaultContext implements IContext, Serializable {
    // the same as in the StepExecutor class
    private steps

    DefaultContext(steps) {
        this.steps = steps
    }

    @Override
    IStepExecutor getStepExecutor() {
        return new StepExecutor(this.steps)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
To finish up our basic dependency injection setup, let’s add a “context
registry” that is used to store the current context (DefaultContext
during normal execution and a Mockito mock of IContext during unit
tests):
</p>

 <div class="jfw-code"> <pre>package org.somecompany.ioc

class ContextRegistry implements Serializable {
    private static IContext context

    static void registerContext(IContext context) {
        context = context
    }

    static void registerDefaultContext(Object steps) {
        context = new DefaultContext(steps)
    }

    static IContext getContext() {
        return context
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
That’s it! Now we are free to code testable Jenkins steps inside  <code>vars</code>.
</p>
</div>
 <h2>Coding A Custom Jenkins Step  <a id="coding-a-custom-jenkins-step" class="anchor" href="#coding-a-custom-jenkins-step" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-coding-a-custom-jenkins-step">
 <p>
Let’s imagine for our example here, that we want to add a step to our
library that calls the some class that performs some data seeding to a
database. To do this we first add a groovy script  <code>example_build.groovy</code>
to the  <code>vars</code> folder that is called like our custom step we want to
implement. Since our script is called  <code>example_build.groovy</code> our step
will later be callable with  <code>example_build</code> in our  <code>Jenkinsfile</code>. Add
the following content to the script for now:
</p>

 <div class="jfw-code"> <pre>void call(
        String environment,
        String envFile,
        String dataSeederBranch,
        String deploymentScriptsBranch
) {
    // TODO
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
According to our general idea we want to keep our example_build script
as simple as possible and do all the work inside a unit-testable class.
So let’s create a new class  <code>DataSeederJob</code> in a new package
org.somecompany.jobs:
</p>

 <div class="jfw-code"> <pre>package org.somecompany.jobs

final class DataSeederJob implements Serializable {
    private String workspace
    private String environment
    private String envFile
    private String dataSeederBranch
    private String deploymentScriptsBranch
    private String seedingEnvironment
    private String seedingMode
    private ArrayList&lt;TargetRepository&gt; repositories

    DataSeederJob(
            String workspace,
            String environment,
            String envFile,
            String dataSeederBranch,
            String deploymentScriptsBranch,
            String seedingEnvironment,
            String seedingMode
    ) {
        this.workspace = workspace
        this.environment = environment
        this.envFile = envFile
        this.dataSeederBranch = dataSeederBranch
        this.deploymentScriptsBranch = deploymentScriptsBranch
        this.seedingEnvironment = seedingEnvironment
        this.seedingMode = seedingMode

        this.repositories = [
                new TargetRepository(
                        &quot;repo1&quot;,
                        this.deploymentScriptsBranch,
                        &quot;deploymentscripts&quot;
                ),
                new TargetRepository(
                        &quot;repo2&quot;,
                        this.dataSeederBranch,
                        &quot;dataseeder&quot;
                )
        ]
    }

    void build() {
        IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()

        steps.deleteDir()

        steps.stage(&quot;Cloning new content&quot;, {
            SourceControlUtils.parallelCheckoutCode(steps, this.repositories)
        })

        steps.stage(&quot;Preparing application environment&quot;, {
            int status = steps.sh(&quot;&quot;&quot;
                 /bin/cp deploymentscripts/${this.environment}/DataSeeder/${this.envFile} dataseeder/dist/config.toml
            &quot;&quot;&quot;)
            if (status != 0) {
                steps.error(&quot;Job failed! Copying env file exited with a non-zero status!&quot;)
            }
        })

        steps.stage(&quot;Running DataSeeder&quot;, {
            int status = steps.sh(&quot;&quot;&quot;
                cd dataseeder/dist
                ./goseeders-linux-x86 -env=${this.seedingEnvironment} -mode=${this.seedingMode}
            &quot;&quot;&quot;)
            if (status != 0) {
                steps.error(&quot;Job failed! Application exited with a non-zero status!&quot;)
            }
        })
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
As you can see, we use both the sh, deleteDir, stage and error steps in
our class, but instead of using them directly, we use the
ContextRegistry to get an instance of IStepExecutor to call Jenkins
steps with that. This way, we can swap out the context when we want to
unit test the build() method later.
</p>

 <p>
Now we can finish our script in  <code>vars</code> folder, which in this case will
also send a Slack message on failure:
</p>

 <div class="jfw-code"> <pre>void call(
        String environment,
        String envFile,
        String dataSeederBranch,
        String deploymentScriptsBranch
) {
    ContextRegistry.registerDefaultContext(this)
    IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()

    try {
        DataSeederJob buildExecutor = new DataSeederJob(
                steps.env.getProperty(EnvironmentVariables.workspace),
                environment,
                envFile,
                dataSeederBranch,
                deploymentScriptsBranch,
                steps.params[&quot;SeedingEnvironment&quot;] as String,
                steps.params[&quot;SeedingMode&quot;] as String
        )
        buildExecutor.build()
    } catch (e) {
        steps.currentBuild.setResult(JobStatus.Failure)
        throw e
    } finally {
        String result = JobStatus.Success
        if (steps.currentBuild.getResult() != null) {
            result = steps.currentBuild.getResult()
        }

        switch (result) {
            case JobStatus.Failure:
                steps.slackSend(
                        SlackChannels.monitoringChannel,
                        SlackColors.failure,
                        SlackEmojis.failure,
                        String.format(&quot;&quot;&quot;
                        %s - TEST PIPELINE FRAMEWORK
                        PARAMETERS: %s
                        &quot;&quot;&quot;,
                                steps.currentBuild.getFullDisplayName(),
                                steps.params.toString(),
                        ),
                )
                break
            default:
                break
        }
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
First, we set the context with the context registry. Since we are not in
a unit test, we use the default context. The  <code>this</code> that gets passed
into  <code>registerDefaultContext()</code> will be saved by the  <code>DefaultContext</code>
inside its private  <code>steps</code> variable and is used to access Jenkins steps.
After registering the context, we are free to instantiate our MsBuild
class and call the  <code>build()</code> method doing all the work.
</p>

 <p>
Nice, our  <code>vars</code> script is finished. Now we only have to write some unit
tests for our  <code>Job</code> class.
</p>
</div>
 <h2>Adding Unit Tests  <a id="adding-unit-tests" class="anchor" href="#adding-unit-tests" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-adding-unit-tests">
 <p>
At this point writing unit tests should be business as usual. We create
a new test class  <code>JobTest</code> inside the test folder with package
 <code>org.somecompany.jobs</code>. Before every test, we use Mockito to mock the
 <code>IContext</code> and  <code>IStepExecutor</code> interfaces and register the mocked
context. Then we can simply create a new  <code>Job</code> instance in our test and
verify the behaviour of our  <code>build()</code> method.
</p>

 <p>
Here is the data seeder test class:
</p>

 <div class="jfw-code"> <pre>import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

import static org.mockito.ArgumentMatchers.any
import static org.mockito.ArgumentMatchers.anyString
import static org.mockito.Mockito.times
import static org.mockito.Mockito.verify

final class DataSeederJobTest {
    private DataSeederJob sut

    protected IContext context
    protected IStepExecutor steps

    @BeforeEach
    void setup() {
        context = mock(IContext.class)
        steps = mock(IStepExecutor.class)

        when(context.getStepExecutor()).thenReturn(steps)

        ContextRegistry.registerContext(context)
    }

    @BeforeEach
    void setupJob() {
        String workspace = &quot;workspace&quot;
        String environment = &quot;environment&quot;
        String envFile = &quot;envFile&quot;
        String dataSeederBranch = &quot;dataSeederBranch&quot;
        String deploymentScriptsBranch = &quot;deploymentScriptsBranch&quot;
        String seedingEnvironment = &quot;seedingEnvironment&quot;
        String seedingMode = &quot;seedingMode&quot;

        this.sut = new DataSeederJob(
                workspace,
                environment,
                envFile,
                dataSeederBranch,
                deploymentScriptsBranch,
                seedingEnvironment,
                seedingMode
        )
    }

    @Test
    void jobBuildCallsDeleteDirStep() {
        this.sut.build()

        verify(steps).deleteDir()
    }

    @Test
    void jobBuildCallsStageSteps() {
        this.sut.build()

        verify(steps, times(3)).stage(anyString(), any(Closure))
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Another test class with several example tests, but unrelated to the data
seeder:
</p>

 <div class="jfw-code"> <pre>package org.somecompany.jobs

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

import static org.mockito.ArgumentMatchers.any
import static org.mockito.ArgumentMatchers.anyString
import static org.mockito.Mockito.*
import org.junit.jupiter.api.BeforeEach
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when


final class GenericGoJobTest {
    private GenericGoJob sut

    private String workspace = &quot;workspace&quot;
    private String appName = &quot;appName&quot;
    private String releaseDir = &quot;releaseDir&quot;
    private String repoName = &quot;repoName&quot;
    private String serviceName = &quot;serviceName&quot;
    private Boolean shouldUnitTest = false
    private Boolean deployToDifferentAgents = false
    private ArrayList&lt;String&gt; destinationAgents = [&quot;destinationAgent&quot;]
    private String mainGoFileLocation = &quot;mainGoFileLocation&quot;

    protected IContext context
    protected IStepExecutor steps

    @BeforeEach
    void setup() {
        context = mock(IContext.class)
        steps = mock(IStepExecutor.class)

        when(context.getStepExecutor()).thenReturn(steps)

        ContextRegistry.registerContext(context)
    }


    @BeforeEach
    void setupJob() {
        this.sut = new GenericGoJob(
                this.workspace,
                this.appName,
                this.releaseDir,
                this.repoName,
                this.serviceName,
                this.mainGoFileLocation,
                this.shouldUnitTest,
                this.deployToDifferentAgents,
                this.destinationAgents,
        )
    }

    @Test
    void verifyJobCallsDeleteDir() {
        this.sut.build()

        verify(steps).deleteDir()
    }

    @Test
    void verifyJobCallsStagesCorrectAmountOfTimes() {
        this.sut.build()

        verify(steps, times(5)).stage(anyString(), any(Closure))
    }

    @Test
    void verifyJobCallsStagesCorrectAmountOfTimesWithDifferentAgentOption() {
        this.deployToDifferentAgents = true
        this.setupJob()
        this.sut.build()

        verify(steps, times(4)).stage(anyString(), any(Closure))
    }

    @Test
    void verifyJobDoesNotCallNode() {
        this.sut.build()

        verify(steps, times(0)).node(anyString(), any(Closure))
    }

    @Test
    void verifyJobCallsNodeWithDifferentAgentOption() {
        this.deployToDifferentAgents = true
        this.setupJob()
        this.sut.build()

        verify(steps, times(1)).node(anyString(), any(Closure))
    }

    @Test
    void verifyJobCallsStageOneMoreTimeWithUnitTests() {
        this.shouldUnitTest = true
        this.setupJob()
        this.sut.build()

        verify(steps, times(6)).stage(anyString(), any(Closure))
    }

    @Test
    void verifyJobCallsNodeMultipleTimesWithDifferentAgentOption() {
        this.deployToDifferentAgents = true
        this.destinationAgents = [
                &quot;test1&quot;,
                &quot;test2&quot;,
                &quot;test3&quot;,
                &quot;test4&quot;,
                &quot;test5&quot;,
        ]

        this.setupJob()
        this.sut.build()

        verify(steps, times(5)).node(anyString(), any(Closure))
    }

    @Test
    void verifyDeployGoSystemServiceCallsDir() {
        this.sut.deployGoSystemService(steps)

        verify(steps, times(1)).dir(anyString(), any(Closure))
    }

    @Test
    void verifyBuildGoApplicationCallsSh() {
        this.sut.buildGoApplication(steps)

        verify(steps, times(1)).sh(anyString())
    }

    @Test
    void verifyBuildGoApplicationCallsError() {
        when(steps.sh(anyString())).thenReturn(-1)

        this.sut.buildGoApplication(steps)

        verify(steps).error(anyString())
    }

    @Test
    void verifyUnitTestApplicationCallsStage() {
        this.sut.unitTestApplication(steps)

        verify(steps, times(1)).stage(anyString(), any(Closure))
    }

    @Test
    void verifyDeployBuildCallsNodeCorrectly() {
        this.deployToDifferentAgents = true
        this.destinationAgents = [
                &quot;test1&quot;,
                &quot;test2&quot;,
                &quot;test3&quot;,
                &quot;test4&quot;,
                &quot;test5&quot;,
        ]
        this.setupJob()
        this.sut.deployBuild(steps)

        verify(steps, times(5)).node(anyString(), any(Closure))
    }


    @Test
    void verifyDeployBuildCallsStageCorrect() {
        this.sut.deployBuild(steps)

        verify(steps, times(1)).stage(anyString(), any(Closure))
    }


    @Test
    void verifyPrepareStashContentCallsSh() {
        this.sut.prepareStashContent(steps)

        verify(steps, times(2)).sh(anyString())
    }

    @Test
    void verifyPrepareStashCallsError() {
        when(steps.sh(anyString())).thenReturn(-1)

        this.sut.prepareStashContent(steps)

        verify(steps, times(2)).error(anyString())
    }

    @Test
    void verifyStashBuildCallsSh() {
        this.sut.stashBuild(steps)

        verify(steps, times(1)).sh(anyString())
    }

    @Test
    void verifyStashBuildCallsError() {
        when(steps.sh(anyString())).thenReturn(-1)

        this.sut.stashBuild(steps)

        verify(steps).error(anyString())
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can use the green play buttons on left of the IntelliJ code editor
to run the tests, which hopefully turn green.
</p>
</div>
 <h2>Wrapping Things Up  <a id="wrapping-things-up" class="anchor" href="#wrapping-things-up" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-wrapping-things-up">
 <p>
That’s basically it. Now it’s time to setup your library with Jenkins,
create a new job and run a  <code>Jenkinsfile</code> to test your new custom
example_build step. A simple test  <code>Jenkinsfile</code> could look like this:
</p>

 <div class="jfw-code"> <pre>node('master') {
    // Load your library
    library('pipeline-framework@master')

    // call the script with parameters
    // if your call function does not require any params
    // you could simply do example_build.call(), which I prefer,
    // or simply example_build

    example_build.call(
            'Acceptance',
            'config.toml',
            'master',
            'stable'
    )
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then you can decide either to add this to a Pipeline job immediately on
the script box, or checkout this small script from SCM, that is up to
you.
</p>

 <p>
Obviously there is still a lot more I could have talked about (things
like unit tests, dependency injection, Gradle, Jenkins configuration,
build and testing the library with Jenkins itself etc.), but I wanted to
keep this already very long blog post somewhat concise. I do hope
however, that the general idea and approach became clear and helps you
in creating a unit-testable shared library, that is more robust and
easier to work on than it normally would be.
</p>

 <p>
One last piece of advice: The unit tests and Gradle setup are pretty
nice and help a ton in easing the development of robust shared
pipelines, but unfortunately there is still quite a bit that can go
wrong inside your pipelines even though the library tests are green.
Things like the following, that mostly happen because of Jenkins’ Groovy
and sandbox weirdness:
</p>

 <ul class="org-ul"> <li>A class that does not implement Serializable which is necessary,
because “pipelines must survive Jenkins restarts”</li>
 <li>Using classes like java.io.File inside your library, which is
prohibited</li>
 <li>Syntax and spelling errors in your  <code>Jenkinsfile</code></li>
</ul> <p>
Therefore, it might be a good idea to have Jenkins instance solely for
integration testing, where new and modified  <code>vars</code> scripts can be tested
before going “live”.
</p>

 <p>
Again, feel free to write any kind of questions or feedback in the
comments, or contact me directly.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/jails-with-a-loopback-ip/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Jails with a loopback IP</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Opinionated Style Guide</span></a>
</nav></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/ci/shared-libraries-with-jenkins/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/ci/shared-libraries-with-jenkins/index.html</guid>
  <pubDate>Sun, 17 Jan 2021 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Jails with a loopback IP</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
In order to keep all of the jails behind a single public IP address,
you’ll need to set up a loopback interface and direct the incoming and
outgoing traffic of your Jails with a proper firewall like  <code>pf</code>. Learn
how to get started on an amazing setup.
</p>

 <p>
There are multiple ways to manage your jails, but iocage is one of the
more popular ones. In terms of jail managers it’s a fairly new player in
the game of jail management and is being very actively developed. It has
a full rewrite in Python, and while the code in the background might be
different, the actual user interface has stayed very similar.
</p>

 <p>
Iocage makes use of ZFS clones in order to create base jails, which
allow for sharing of one set of system packages between multiple jails,
reducing the amount of resources necessary. Alternatively, jails can be
completely independent of each other; however, using a base jail makes
it easier to update multiple jails as well.
</p>

 <p>
You can install it from a binary package:
</p>

 <div class="jfw-code"> <pre>pkg install -y py37-iocage</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
 <h2>Setting up the zpool  <a id="setting-up-the-zpool" class="anchor" href="#setting-up-the-zpool" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-setting-up-the-zpool">
 <p>
It is a great idea to separate the jails storage device from the host
system’s storage. Ideally in a separate physical device, but a separate
partition will also do.
</p>

 <p>
This means that you would be in a situation where your  <code>zroot</code> is
already setup, and you have a free device/partition where you can create
a second  <code>zpool</code> to be used specifically for the Jails.
</p>

 <p>
Doing a  <code>gpart show</code> in my machine reveals the following setup:
</p>

 <div class="jfw-code"> <pre>=&gt;      40  41942960  da0  GPT  (20G)
            40      1024    1  freebsd-boot  (512K)
          1064       984       - free -  (492K)
          2048   4194304    2  freebsd-swap  (2.0G)
       4196352  20971520    3  freebsd-zfs  (10G)
      25167872  16773120    4  freebsd-zfs  (8.0G)
      41940992      2008       - free -  (1.0M)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This means I want to create a new pool on  <code>da0p4</code> with the name  <code>iocage</code>
since my system has been installed on  <code>da0p3</code>.
</p>

 <p>
This can be achieved very simply with the command:
</p>

 <div class="jfw-code"> <pre>zpool create iocage da0p4</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
With the pool created, you can now activate  <code>iocage</code> to use the wanted
pool:
</p>

 <div class="jfw-code"> <pre>iocage activate iocage</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then fetch the latest FreeBSD release (or the one you prefer) to be used
to setup jails:
</p>

 <div class="jfw-code"> <pre>iocage fetch</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Add the following new line to your  <code>/etc/fstab</code> file to improve the jail
performance:
</p>

 <div class="jfw-code"> <pre>fdescfs /dev/fd fdescfs rw 0 0</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Setting up the network  <a id="setting-up-the-network" class="anchor" href="#setting-up-the-network" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-setting-up-the-network">
 <p>
You could go ahead and create your jail right off, but the networking
will not work out of the box. Take a minute and do some basic network
configuration before creating your first jail.
</p>
</div>
 <h3>Virtual Interface  <a id="virtual-interface" class="anchor" href="#virtual-interface" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-virtual-interface">
 <p>
For our internal network, we create a cloned loopback device called
 <code>lo1</code>. Therefore we need to customize the  <code>/etc/rc.conf</code> file, adding
the following two lines:
</p>

 <p>
In order to keep all of the jails behind a single public IP address,
you’ll need to set up a new network interface. This new interface will
be a clone of the loopback interface which will have an IP address
assigned to it. You can use any RFC 1918 address space. In this
tutorial,  <code>192.168.0.1</code> will be used. Add the following to
 <code>/etc/rc.conf</code> to get the new interface set up:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">/etc/rc.conf
</span> <span class="org-comment-delimiter"># </span> <span class="org-comment">Setup the interface that all jails will use
</span> <span class="org-variable-name">cloned_interfaces</span>= <span class="org-string">&quot;lo1&quot;</span>
 <span class="org-variable-name">ipv4_addrs_lo1</span>= <span class="org-string">&quot;192.168.0.1/24&quot;</span>

 <span class="org-variable-name">gateway_enable</span>= <span class="org-string">&quot;YES&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Enable port forwarding and packet filtering
</span> <span class="org-variable-name">pf_enable</span>= <span class="org-string">&quot;YES&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Enable iocage at startup
</span> <span class="org-variable-name">iocage_enable</span>= <span class="org-string">&quot;YES&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This defines a  <code>/24</code> network, offering IP addresses for a maximum of 254
jails:
</p>

 <div class="jfw-code"> <pre>joe@devjails &gt; ipcalc 192.168.0.1/24

Address:   192.168.0.1          11000000.10101000.00000000. 00000001
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=&gt;
Network:   192.168.0.0/24       11000000.10101000.00000000. 00000000
HostMin:   192.168.0.1          11000000.10101000.00000000. 00000001
HostMax:   192.168.0.254        11000000.10101000.00000000. 11111110
Broadcast: 192.168.0.255        11000000.10101000.00000000. 11111111
Hosts/Net: 254                   Class C, Private Internet</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then we need to restart the network. Please be aware of currently active
SSH sessions as they will be dropped during restart. It’s a good moment
to ensure you have KVM or physical access to that server ;-)
</p>

 <p>
With those entries in  <code>/etc/rc.conf</code> the interfaces will all be created
and configured at boot time, so give the machine a nice reboot
</p>

 <p>
After booting, an  <code>ifconfig</code> should now show a new interface:
</p>

 <div class="jfw-code"> <pre>lo1:  <span class="org-variable-name">flags</span>=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; metric 0 mtu 16384
     <span class="org-variable-name">options</span>=680003&lt;RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6&gt;
    inet 192.168.0.1 netmask 0xffffff00
    groups: lo
    nd6  <span class="org-variable-name">options</span>=29&lt;PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL&gt;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h3>NAT for packet forwarding  <a id="nat-for-packet-forwarding" class="anchor" href="#nat-for-packet-forwarding" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-nat-for-packet-forwarding">
 <p>
Now that you have an interface to use with your jails, you’ll need to
get some packet forwarding set up. Edit  <code>/etc/pf.conf</code> (which will be
empty by default) according to the following
</p>

 <div class="jfw-code"> <pre> <span class="org-variable-name">ext_if</span>= <span class="org-string">&quot;em0&quot;</span>
 <span class="org-variable-name">jail_if</span>= <span class="org-string">&quot;lo1&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Public IP address
</span> <span class="org-variable-name">ip_pub</span>= <span class="org-string">&quot;192.168.178.40&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Packet normalization
</span>scrub <span class="org-keyword"> in</span> all

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Skip packet filtering on loopback interfaces
</span> <span class="org-builtin">set</span> skip on lo0
 <span class="org-builtin">set</span> skip on lo1

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Allow outbound connections from within the jails
</span>nat pass on $ <span class="org-variable-name">ext_if</span> from 192.168.0.0/24 to any -&gt; $ <span class="org-variable-name">ip_pub</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The first 3 lines define a couple of useful variables – called macros
in PF parlance. The nat line instructs PF to mask outbound traffic from
the jails (all of them) behind the IP address of the external interface.
In short, all of your outbound jail traffic will come from the IP
address of your droplet.
</p>

 <p>
With that in place, you can enable and start PF:
</p>

 <div class="jfw-code"> <pre>service pf enable
service pf start</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Before you load the firewall ruleset, test the config file to ensure
that all is well:
</p>

 <div class="jfw-code"> <pre>pfctl -nvf /etc/pf.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
That command will cause PF to parse the rules in /etc/pf.conf, and print
them back out to the console. If there are syntax errors, they will be
called out.
</p>

 <p>
Your output should be very similar to:
</p>

 <div class="jfw-code"> <pre>ext_if =  <span class="org-string">&quot;em0&quot;</span>
jail_if =  <span class="org-string">&quot;lo1&quot;</span>
IP_PUB =  <span class="org-string">&quot;192.168.178.40&quot;</span>
 <span class="org-builtin">set</span> skip on { lo0 }
 <span class="org-builtin">set</span> skip on { lo1 }
scrub <span class="org-keyword"> in</span> all fragment reassemble
nat pass on em0 inet from 192.168.0.0/24 to any -&gt; 192.168.178.40</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then reload the firewall rules with:
</p>

 <div class="jfw-code"> <pre>pfctl -F all -f /etc/pf.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Creating the first jail  <a id="creating-the-first-jail" class="anchor" href="#creating-the-first-jail" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-creating-the-first-jail">
 <p>
It’s time to create &amp; start a jail:
</p>

 <div class="jfw-code"> <pre>iocage create -n  <span class="org-string">&quot;mydb&quot;</span> -r 12.2-RELEASE  <span class="org-variable-name">ip4_addr</span>= <span class="org-string">&quot;lo1|192.168.0.2&quot;</span>
iocage start mydb</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Those commands will have a lot of output, and may end with a warning.
You can safely ignore the warnings. The jail needs to be told how to do
DNS lookups. The simple way to solve this is to copy the hosts
/etc/resolv.conf into the jail. Assuming your zpool was setup to point
to /iocage:
</p>

 <div class="jfw-code"> <pre>mkdir /iocage/iocage/jails/mydb/etc
cp /etc/resolv.conf /iocage/iocage/jails/mydb/etc/resolv.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then start the machine and enter the console:
</p>

 <div class="jfw-code"> <pre>iocage start mydb
iocage console mydb</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
There will be a lot of stuff on the console – very similar to what you
should have seen when you first connected to your Droplet.
</p>

 <p>
Notice that your prompt has changed. Congratulations, you are inside
your jail! It’s probably a good idea to test your connectivity to the
outside world, but by default, and for security reasons, FreeBSD jails
are not allowed to ping. To test connectivity, you can use telnet:
</p>

 <div class="jfw-code"> <pre>telnet www.digitalocean.com 80</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
That command will open up a very basic connection to a webserver at
Digital Ocean. You can get out of it pressing Control-] to close the
connection, followed by quit to close telnet.
</p>

 <div class="jfw-code"> <pre>Trying 104.16.24.4...
Connected to www.digitalocean.com.
Escape character is  <span class="org-string">'^]'</span>.
^]
telnet&gt; quit
Connection closed.</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now you are ready to install your desired software and set up the wanted
services in the jail. It is a good idea to get familiar with  <code>iocage</code>
since it has many handy commands to manage the jails.
</p>

 <p>
In my case, I installed MariaDB on this jail, and for that purpose,
opened up a port redirection in the firewall, so that traffic from the
public-facing interface will be redirected to the internal jail’s port.
You can do this by adding this line to the end of  <code>/etc/pf.conf</code>, with
 <code>192.168.0.4</code> being the internal IP I have assigned to this jail:
</p>

 <div class="jfw-code"> <pre>rdr on $ <span class="org-variable-name">ext_if</span> proto tcp from any to $ <span class="org-variable-name">ip_pub</span> port 3306 -&gt; 192.168.0.4 port 3306</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then reload the firewall rules with:
</p>

 <div class="jfw-code"> <pre>pfctl -F all -f /etc/pf.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Locking down the firewall  <a id="locking-down-the-firewall" class="anchor" href="#locking-down-the-firewall" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-locking-down-the-firewall">
 <p>
The way things stand right now, your jail is working, but the host
system is pretty wide-open. If you edit your  <code>/etc/pf.conf</code> once more,
we can restrict all inbound traffic that is not destined for a jail
except for SSH.
</p>

 <p>
Edit your file to look like:
</p>

 <div class="jfw-code"> <pre> <span class="org-variable-name">ext_if</span>= <span class="org-string">&quot;em0&quot;</span>
 <span class="org-variable-name">jail_if</span>= <span class="org-string">&quot;lo1&quot;</span>
 <span class="org-variable-name">jail_net</span>= $ <span class="org-variable-name">jail_if</span>:network

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Public IP address
</span> <span class="org-variable-name">ip_pub</span>= <span class="org-string">&quot;192.168.178.40&quot;</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Packet normalization
</span>scrub <span class="org-keyword"> in</span> all

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Skip packet filtering on loopback interfaces
</span> <span class="org-builtin">set</span> skip on lo0
 <span class="org-builtin">set</span> skip on lo1

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Allow outbound connections from within the jails
</span>nat pass on $ <span class="org-variable-name">ext_if</span> from 192.168.0.0/24 to any -&gt; $ <span class="org-variable-name">ip_pub</span>

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Port redirect for MariaDB
</span>rdr pass on $ <span class="org-variable-name">ext_if</span> proto tcp to port 3306 -&gt; 192.168.0.4

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Set the default: block everything
</span>block all

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Allow the jail traffic to be translated
</span>pass from { lo0, $ <span class="org-variable-name">jail_net</span> } to any keep state

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Allow SSH in to the host
</span>pass <span class="org-keyword"> in</span> inet proto tcp to $ <span class="org-variable-name">ext_if</span> port ssh

 <span class="org-comment-delimiter"># </span> <span class="org-comment">Allow OB traffic
</span>pass out all keep state</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now you have a secure machine, that only takes traffic from the wanted
ports. This starts feeling production ready!
</p>
</div>
 <h2>Jail tweaks  <a id="jail-tweaks" class="anchor" href="#jail-tweaks" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-jail-tweaks">
 <p>
Jump back into your jail with  <code>iocage console -f mydb</code> and add the
following 2 lines to  <code>/etc/rc.conf</code>:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">Disable the RPC daemon
</span> <span class="org-variable-name">rpcbind_enable</span>= <span class="org-string">&quot;NO&quot;</span>
 <span class="org-comment-delimiter"># </span> <span class="org-comment">Clear /tmp at startup
</span> <span class="org-variable-name">clear_tmp_enable</span>= <span class="org-string">&quot;YES&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Go on now, create your universe of inter-connected systems, welcome to
the world of  <b>FreeBSD</b> jails!
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/root-on-zfs-with-partitions/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Root on ZFS with partitions</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/ci/shared-libraries-with-jenkins/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Shared Libraries with Jenkins</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/jails-with-a-loopback-ip/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/jails-with-a-loopback-ip/index.html</guid>
  <pubDate>Fri, 20 Nov 2020 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Root on ZFS with partitions</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
It is important to have a clean separation of concerns, both in your
code, as in your machine’s setup. If you are looking for information on
how to get a ZFS FreeBSD setup on one hard-drive with multiple
partitions, this is what you want.
</p>

 <p>
This guide assumes you want to install FreeBSD and manually create the
ZFS pool, to change default settings, or to not use the entire disk.
</p>

 <p>
If you just want to setup ZFS on the entire disk, use the ’ZFS’ option
in the bsdinstall partitioning menu.
</p>

 <ol class="org-ol"> <li>Boot FreeBSD install DVD or USB Memstick</li>
 <li>Select Install, and answer questions such as keyboard layout and
hostname</li>
 <li>When prompted to partition the disk, choose the  <code>shell</code> option. In
this mode you are expected to create a root file system mounted under
 <code>/mnt</code> that the installer will install the operating system into.</li>
</ol> <p>
Now to the installation steps, start by determining which disks you wish
to use:
</p>

 <div class="jfw-code"> <pre>camcontrol devlist
 <span class="org-comment-delimiter"># </span> <span class="org-comment">or alternatively
</span>geom disk list</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
That should return something like
 <code>TOSHIBA HDWN180 GX2M at scbus7 target 0 lun 0 (ada0,pass1)</code>
</p>

 <p>
SATA disks usually start with ada, followed by a number. SAS and USB
disks start with da, followed by a number. The rest of this page assumes
the disk is  <code>ada0</code>, replace it with your disk devices name in all
commands below.
</p>

 <p>
Proceed to create a fresh partition table, erasing ALL data on the
disk!:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">The first command is not needed if you are working on an empty new disk
</span>gpart destroy ada0
gpart create -s gpt ada0</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then create the boot code partition:
</p>

 <p>
for Legacy Boot:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">Confirmed working on FreeBSD 13
</span>gpart add -a 4k -s 512K -t freebsd-boot ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
for UEFI Boot we will need more space and some more manual steps:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">Confirmed working on FreeBSD 13
</span>gpart add -t efi -s 40M ada0
newfs_msdos -F 32 -c 1 /dev/ada0p1
mount -t msdosfs /dev/ada0p1 /mnt
mkdir -p /mnt/EFI/BOOT
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
umount /mnt</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We will now be creating the needed partitions to setup the system as we
wish. I will be working with a 20GB hard drive, which I want to split in
3 partitions. 2GB for Swap, 10 GB for the FreeBSD installation and the
remaining (8GB) for the Jails storage, in a secondary pool which will
later be created.
</p>

 <p>
Note that while a ZFS Swap Volume can be used instead of the
freebsd-swap partition, it is not recommended, and crash dumps can’t be
saved to the ZFS Swap Volume.
</p>

 <p>
Some of the  <code>gpart</code> options explained: *  <code>-a {number}</code>: controls
alignment. *  <code>-s {size}</code>: sets the size of the partition, if not set, it
will default to the remaining space on the disk. *  <code>-l {name}</code>: sets the
label for the partition
</p>

 <div class="jfw-code"> <pre>gpart add -a 1m -s 4G -t freebsd-swap -l swap0 ada0
gpart add -a 1m -s 10G -t freebsd-zfs -l disk0 ada0
gpart add -a 1m -t freebsd-zfs -l disk1 ada0</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Find the device for the freebsd-zfs partition created above with
 <code>gpart show -p ada0</code>
</p>

 <div class="jfw-code"> <pre>=&gt;      40  41942960  ada0  GPT  (20G)
        40      1024    1  freebsd-boot  (512K)
        1064       984       - free -  (492K)
        2048   4194304    2  freebsd-swap  (2.0G)
        4196352  20971520    3  freebsd-zfs  (10G)
        25167872  16773120    4  freebsd-zfs  (8.0G)
        41940992      2008       - free -  (1.0M)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Our FreeBSD installation will be on  <code>ada0p3</code>.
</p>

 <p>
For proceeding with the install we will mount a  <code>tmpfs</code> filesystem to
 <code>/mnt</code> with:
</p>

 <div class="jfw-code"> <pre>mount -t tmpfs tmpfs /mnt</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We will assume zroot as the name of the ystem’s  <code>zpool</code>, it could be
anything (i.e. tank, data, mypool), and to create it we do:
</p>

 <div class="jfw-code"> <pre>zpool create -o  <span class="org-variable-name">altroot</span>=/mnt zroot ada0p3</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We will use the lz4 compression algorithm, since it is fast enough to be
used by default, even for uncompressible data. It can be enabled with:
</p>

 <div class="jfw-code"> <pre>zfs set  <span class="org-variable-name">compress</span>=on zroot</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We will then create a Boot Environment hierarchy with:
</p>

 <div class="jfw-code"> <pre>zfs create -o  <span class="org-variable-name">mountpoint</span>=none zroot/ROOT
zfs create -o  <span class="org-variable-name">mountpoint</span>=/ -o  <span class="org-variable-name">canmount</span>=noauto zroot/ROOT/default
mount -t zfs zroot/ROOT/default /mnt</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
and then proceed to create the rest of filesystems required for FreeBSD
to be installed to this ZFS Pool:
</p>

 <div class="jfw-code"> <pre>zfs create -o  <span class="org-variable-name">mountpoint</span>=/tmp -o  <span class="org-variable-name">exec</span>=on -o  <span class="org-variable-name">setuid</span>=off zroot/tmp
zfs create -o  <span class="org-variable-name">canmount</span>=off -o  <span class="org-variable-name">mountpoint</span>=/usr zroot/usr
zfs create zroot/usr/home
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/usr/src
zfs create zroot/usr/obj
zfs create -o  <span class="org-variable-name">mountpoint</span>=/usr/ports -o  <span class="org-variable-name">setuid</span>=off zroot/usr/ports
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/usr/ports/distfiles
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/usr/ports/packages
zfs create -o  <span class="org-variable-name">canmount</span>=off -o  <span class="org-variable-name">mountpoint</span>=/var zroot/var
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/var/audit
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/var/crash
zfs create -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/var/log
zfs create -o  <span class="org-variable-name">atime</span>=on -o  <span class="org-variable-name">exec</span>=off -o  <span class="org-variable-name">setuid</span>=off zroot/var/mail
zfs create -o  <span class="org-variable-name">exec</span>=on -o  <span class="org-variable-name">setuid</span>=off zroot/var/tmp</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
then we will set a symlink to home, and set the correct permissions
with:
</p>

 <div class="jfw-code"> <pre>ln -s /usr/home /mnt/home
chmod 1777 /mnt/var/tmp
chmod 1777 /mnt/tmp</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We can then finalize the zpool creation, by setting the boot environment
configuration:
</p>

 <div class="jfw-code"> <pre>zpool set  <span class="org-variable-name">bootfs</span>=zroot/ROOT/default zroot</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
To finish the installation, we will create a new entry in the  <code>fstab</code> of
the installer, which later will be stored in our system. Now is your
opportunity to attach other devices if needed as well, but for this
tutorial, simply adding the swap is enough:
</p>

 <div class="jfw-code"> <pre>cat &lt;&lt; EOF &gt; /tmp/bsdinstall_etc/fstab <span class="org-sh-heredoc">
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/swap0 none swap sw 0 0
EOF</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We can then  <code>exit</code> the shell Partitioning mode, at which point
bsdinstall will continue and complete the installation.
</p>

 <p>
In the post installation step, when asked if you would like to drop into
the installed system, choose yes, and execute the following:
</p>

 <div class="jfw-code"> <pre>sysrc  <span class="org-variable-name">zfs_enable</span>= <span class="org-string">&quot;YES&quot;</span>
 <span class="org-builtin">echo</span>  <span class="org-variable-name">zfs_load</span>= <span class="org-string">&quot;YES&quot;</span> &gt;&gt; /boot/loader.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You are now ready to reboot into your newly installed FreeBSD system.
Simply type  <code>exit</code> at the current prompt, and eject the installation
media, when the machine restarts.
</p>
 <h2>Welcome to the magical world of FreeBSD!  <a id="welcome-to-the-magical-world-of-freebsd" class="anchor" href="#welcome-to-the-magical-world-of-freebsd" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-welcome-to-the-magical-world-of-freebsd">
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/file-descriptors-and-go/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">File Descriptors and Go</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/jails-with-a-loopback-ip/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Jails with a loopback IP</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/root-on-zfs-with-partitions/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/root-on-zfs-with-partitions/index.html</guid>
  <pubDate>Fri, 20 Nov 2020 00:00:00 +0100</pubDate>
</item>
<item>
  <title>File Descriptors and Go</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Ever heard of  <i>dangling pointers</i>? Have you ever left your database connections without closing them properly?
</p>

 <p>
One must pay special attention to this specially when dealing with lower
level languages like Go, C, and C++.
</p>

 <p>
Resource leaks really are a do or die in many applications, something
very often and very easily overlooked. I personally have had
applications catastrophically crash due to this. Read this to understand
useful patterns and practices avoiding these problems in Go…
</p>
 <h2>A true story!  <a id="a-true-story" class="anchor" href="#a-true-story" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-a-true-story">
 <p>
Last week I saw one of my beloved Go applications crash catastrophically
with such an error:
</p>

 <div class="jfw-code"> <pre>server.go:3095: http: Accept error: accept tcp [::]:7002: accept4: too many open files; retrying <span class="org-keyword"> in</span> 5ms</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This error kept repeating for a good few minutes, until I luckily
spotted the issue, and temporarily fixed it by restarting the
application (Go binary as system service).
</p>

 <p>
The application in question deals with a lot of incoming and outgoing
HTTP requests, acting as a Facade between several services.
</p>

 <p>
Due to the nature of this application, many requests of all kinds are
sent, and sometimes I do not care about the response body of a performed
request, only about the returned status code, or not even that.
</p>

 <p>
This lead to a situation where I performed several requests ignoring the
response body with the  <code>_</code> variable.
</p>

 <p>
So please follow my advice, always, ALWAYS, close the response body of a
request.
</p>

 <p>
 <b>BAD</b>
</p>

 <div class="jfw-code"> <pre>_, err := client.Do(request)
if err != nil {
  log.Println(err.Error())
  return nil
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>GOOD</b>
</p>

 <div class="jfw-code"> <pre>resp, err := client.Do(request)
if err != nil {
  log.Println(err.Error())
  return nil
}

defer resp.Body.Close()</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If you do not close the response body, or for that matter defer its
closing, the resources allocated for that will never be released, and
thus your application will keep it indefinitely reserved, in Unix
systems, in a file descriptor.
</p>

 <p>
Keep in mind, that the default limit per application is of 1024 file
descriptors. this can be manipulated, but in my opinion really should
not be done for web services, unless there is an actual necessity. Keep
it in the back of your head, if you need to increase this, you most
certainly have a leak in your program.
</p>

 <p>
The bad news is that not only HTTP requests will cause this issue.
Database connections, Redis connections, Buffered readers, Actual File
I/O operations…
</p>

 <p>
A solid example, is indeed the database connection:
</p>

 <p>
 <b>BAD</b>
</p>

 <div class="jfw-code"> <pre>db, err := sql.Open(databaseType, connection)
if err != nil {
  log.Println(err.Error())
  panic(err.Error())
}

// If you do not defer close to the connection
// you will dangerously forget about doing so.</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
 <b>GOOD</b>
</p>

 <div class="jfw-code"> <pre>db, err := sql.Open(databaseType, connection)
if err != nil {
  log.Println(err.Error())
  panic(err.Error())
}

defer db.Close()
// Use db here, no risk of forgetting to close the db connection</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Anything that you have opened and forgot to close, will hog the system
and bring the file descriptor count upwards, and will come back to haunt
you. For that reason, you should check your system services file
descriptor count sometimes. This can easily be achieved with a couple
commands. Log in as root user in your Unix server and do a  <code>ps aux</code>.
</p>

 <p>
You might be wondering, Go is a Garbage Collected (GC) language, why
doesn’t it simply destroy these unused connections/handles/response
bodies?
</p>

 <p>
This simply is not the case since for the GC these handles are still
“referenced” and thus are not eligible for garbage collection. They are
basically dangling around, and you can avoid this bad situation with a
simple  <code>defer</code> statement.
</p>

 <p>
Imagining your application is called  <code>my-application</code> and is located at
 <code>/internalApplications/my-application/app</code>, you should filter the
=ps aux=output to find:
</p>

 <div class="jfw-code"> <pre>root     531  0.0  0.1 1323436 8000 ?        Ssl  Nov12   0:35 /internalApplications/my-application/app</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
What we are intereseted in here, is the 2nd column and 11th column,
which contain respectively the PID of the process and the name of the
process.
</p>

 <p>
To get a file descriptor count per PID, do  <code>ls /proc/{pid}/fd | wc -l</code>,
in this case you would need to do,  <code>ls /proc/531/fd | wc -l</code>
</p>

 <p>
You can take this script I made, that finds all services that are
located in the  <code>/internalApplications</code> folder and modify it, to suit
your needs:
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter">#</span> <span class="org-comment">!/bin/</span> <span class="org-keyword">bash</span> <span class="org-comment">
</span> <span class="org-variable-name">pid</span>=( $( <span class="org-sh-quoted-exec">ps aux | grep /internalApplications/ | grep -v &quot;grep&quot; | awk '{print $2}'</span>) )
 <span class="org-variable-name">processName</span>=( $( <span class="org-sh-quoted-exec">ps aux | grep /internalApplications/ | grep -v &quot;grep&quot; | awk '{print $11}'</span>) )

 <span class="org-keyword">for</span> index <span class="org-keyword"> in</span> ${ <span class="org-variable-name">!</span>pid[*]};   <span class="org-keyword">do</span>
     <span class="org-builtin">printf</span>  <span class="org-string">&quot;%s --&gt; %s --&gt; %s\n&quot;</span>  <span class="org-string">&quot;${pid[$index]}&quot;</span>  <span class="org-string">&quot;$(</span> <span class="org-sh-quoted-exec"> ls /proc/${pid[$index]}/fd | wc -l </span> <span class="org-string">)&quot;</span>   <span class="org-string">&quot;${processName[$index]}&quot;</span>
 <span class="org-keyword">done</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Other good tips to avoid file descriptors being hogged are more related
to HTTP requests. If your application is exposed to other HTTP services,
ensure you follow the below tips.
</p>

 <p>
Always add a request close, unless you plan to have  <code>keep-alive</code>
connections. This can easily be done:
</p>

 <div class="jfw-code"> <pre>req, err := http.NewRequestWithContext(
  context.Background(),
  &quot;POST&quot;,
  &quot;www.example.com&quot;,
  bytes.NewBuffer([]byte(`{&quot;test&quot;: &quot;example&quot;}`)),
)
if err != nil {
  log.Println(err.Error())
  return nil, err
}

req.Header.Add(&quot;Content-Type&quot;, &quot;application/json&quot;)
req.Header.Add(&quot;Charset&quot;, &quot;utf-8&quot;)
// This will add a Connection: close header to the request
req.Close = true
// alternatively
req.Header.Add(&quot;Connection&quot;, &quot;close&quot;)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Set a default timeout for HTTP requests, to avoid hanging requests, or
malicious attempts:
</p>

 <div class="jfw-code"> <pre>// Do this at the beggining of your application, in your `main.go`
http.DefaultClient.Timeout = 30 * time.Second</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If you use  <code>http.Server</code> directly then make sure to set some sensible
timeouts:
</p>

 <div class="jfw-code"> <pre>srv := &amp;http.Server{
  ReadTimeout:  10 * time.Second,
  WriteTimeout: 30 * time.Second,
  IdleTimeout:  100 * time.Second,
}

// optional disable keep alives
srv.SetKeepAlivesEnabled(false)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
If you use  <code>http.Client</code> directly then also make sure to set a sensible
timeout:
</p>

 <div class="jfw-code"> <pre>client := &amp;http.Client{Timeout: 30 * time.Second}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
In conclusion, you should always take special care with closing
resources properly so as to not have stale sockets, and file descriptors
in your application.
</p>

 <p>
Always cleanup after yourself, and if possible, do a
 <code>defer whatever.Close()</code> as close to the declarations as possible, so as
to not forget to do it further down the code. This also avoids resources
not being closed due to early returns.
</p>

 <p>
With great power, such as what Go gives developers, comes great
responsability.
</p>

 <p>
I will keep expanding this article as I find more useful tips for this,
stay tuned!
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/zen-of-go/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Zen of Go</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/root-on-zfs-with-partitions/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Root on ZFS with partitions</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/file-descriptors-and-go/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/file-descriptors-and-go/index.html</guid>
  <pubDate>Sat, 14 Nov 2020 00:00:00 +0100</pubDate>
</item>
<item>
  <title>Zen of Go</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Something that I’ve been thinking about a lot recently, when reflecting
on the body of my own work, is a common subtitle, how should I write
good code? Given nobody actively seeks to write bad code, this leads to
the question; how do you know when you’ve written good Go code? If
there’s a continuum between good and bad, how to do we know what the
good parts are? What are its properties, its attributes, its hallmarks,
its patterns, and its idioms?
</p>
 <h3>Maintainability counts  <a id="maintainability-counts" class="anchor" href="#maintainability-counts" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-maintainability-counts">
 <p>
Clarity, readability, simplicity, are all aspects of maintainability.
Can the thing you worked hard to build be maintained after you’re gone?
What can you do today to make it easier for those that come after you?
</p>
</div>
 <h3>Each package fulfils a single purpose  <a id="each-package-fulfils-a-single-purpose" class="anchor" href="#each-package-fulfils-a-single-purpose" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-each-package-fulfils-a-single-purpose">
 <p>
A well designed Go package provides a single idea, a set of related
behaviours. A good Go package starts by choosing a good name. Package
names should always be lowercase and not contain any underscores or
dashes. Think of your package’s name as an elevator pitch to describe
what it provides, using just one word. Common examples,  <code>controllers</code>,
 <code>jobs</code>,  <code>services</code>,  <code>utils</code>.
</p>
</div>
 <h3>Handle errors explicitly  <a id="handle-errors-explicitly" class="anchor" href="#handle-errors-explicitly" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-handle-errors-explicitly">
 <p>
Robust programs are composed from pieces that handle the failure cases
before they pat themselves on the back. The verbosity of
 <code>if err !</code> nil { return err }=is outweighed by the value of deliberately
handling each failure condition at the point at which they occur. Panic
and recover are not exceptions, they aren’t intended to be used that
way. Ensure you always use  <code>log.Printf(err.Error())</code> in order to log
those errors to the application log for monitoring or debugging.
</p>
</div>
 <h3>Return early rather than nesting deeply  <a id="return-early-rather-than-nesting-deeply" class="anchor" href="#return-early-rather-than-nesting-deeply" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-return-early-rather-than-nesting-deeply">
 <p>
Every time you indent you add another precondition to the programmer’s
stack consuming one of the 7 ±2 slots in their short term memory. Avoid
control flow that requires deep indentation. Rather than nesting deeply,
keep the success path to the left using guard clauses.
</p>
</div>
 <h3>Leave concurrency to the caller  <a id="leave-concurrency-to-the-caller" class="anchor" href="#leave-concurrency-to-the-caller" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-leave-concurrency-to-the-caller">
 <p>
Let the caller choose if they want to run your library or function
asynchronously, don’t force it on them. If your library uses concurrency
it should do so transparently.
</p>
</div>
 <h3>Before you launch a goroutine, know when it will stop  <a id="before-you-launch-a-goroutine-know-when-it-will-stop" class="anchor" href="#before-you-launch-a-goroutine-know-when-it-will-stop" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-before-you-launch-a-goroutine-know-when-it-will-stop">
 <p>
Goroutines own resources; locks, variables, memory, etc. The sure fire
way to free those resources is to stop the owning goroutine.
</p>
</div>
 <h3>Avoid package level state  <a id="avoid-package-level-state" class="anchor" href="#avoid-package-level-state" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-avoid-package-level-state">
 <p>
Seek to be explicit, reduce coupling, and spooky action at a distance by
providing the dependencies a type needs as fields on that type rather
than using package variables. Exceptions to this rule are a global
singleton for the application config, and a database pool connection.
</p>
</div>
 <h3>Simplicity matters  <a id="simplicity-matters" class="anchor" href="#simplicity-matters" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-simplicity-matters">
 <p>
Simplicity is not a synonym for unsophisticated. Simple doesn’t mean
crude, it means  <b> <i>readable</i></b> and  <b> <i>maintainable</i></b>. When it is possible
to choose, defer to the simpler solution.
</p>
</div>
 <h3>Write tests to lock in the behaviour of your package  <a id="write-tests-to-lock-in-the-behaviour-of-your-package" class="anchor" href="#write-tests-to-lock-in-the-behaviour-of-your-package" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-write-tests-to-lock-in-the-behaviour-of-your-package">
 <p>
Test first or test later, if you shoot for 100% test coverage or are
happy with less, regardless, your package’s API is your contract with
its users. Tests are the guarantees that those contracts are written in.
Make sure you test for the behaviour that users can observe and rely on.
</p>
</div>
 <h3>If you think it’s slow, first prove it with a benchmark  <a id="if-you-think-its-slow-first-prove-it-with-a-benchmark" class="anchor" href="#if-you-think-its-slow-first-prove-it-with-a-benchmark" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-if-you-think-its-slow-first-prove-it-with-a-benchmark">
 <p>
So many crimes against maintainability are committed in the name of
performance. Optimisation tears down abstractions, exposes internals,
and couples tightly. If you’re choosing to shoulder that cost, ensure it
is done for good reason.
</p>
</div>
 <h3>Moderation is a virtue  <a id="moderation-is-a-virtue" class="anchor" href="#moderation-is-a-virtue" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-moderation-is-a-virtue">
 <p>
Use goroutines, channels, locks, interfaces, embedding, in moderation.
</p>
</div>
 <h2>Personal choices  <a id="personal-choices" class="anchor" href="#personal-choices" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-personal-choices">
</div>
 <h3>Never use anything other than camelCase  <a id="never-use-anything-other-than-camelcase" class="anchor" href="#never-use-anything-other-than-camelcase" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-never-use-anything-other-than-camelcase">
 <p>
My convention is using camelCase for all purposes, including JSON
responses, and in Go, if you would like to have a member (function,
variable, struct var) exported (public) you must do it with
UpperCamelCase. I avoid snake_case at all costs, since I mostly use it
for database fields.
</p>
</div>
 <h3>Short variable names only on short functions  <a id="short-variable-names-only-on-short-functions" class="anchor" href="#short-variable-names-only-on-short-functions" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-short-variable-names-only-on-short-functions">
 <p>
Only use one letter variables when the scope of them is so reduced and
when it does not affect the readability and maintainability of the code
they are lodged in.
</p>
</div>
 <h3>Comments  <a id="comments" class="anchor" href="#comments" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-comments">
 <p>
Comments should only be written using  <i>/. The multi-line comment /* *</i>
is left for disabling large pieces of code. Function comments should not
include any type annotations or similar habits. GoDoc is not PHPDoc or
JavaDoc. Every package should include a Doc.go file which serves as
introduction to the package’s purpose, such as below. Document why, not
how.
</p>
</div>
 <h3>Slice allocation  <a id="slice-allocation" class="anchor" href="#slice-allocation" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-slice-allocation">
 <p>
If you happen to know the exact size that a slice will take, always
allocate that. Only use append in the case where you may be filtering
out items, and/or are not sure of the size the list will be. This is
more clear and more efficient.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/tips-for-clean-code-with-go/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Tips for clean code with Go</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/file-descriptors-and-go/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">File Descriptors and Go</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/zen-of-go/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/zen-of-go/index.html</guid>
  <pubDate>Mon, 05 Oct 2020 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Tips for clean code with Go</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <h2>Why Write Clean Code?  <a id="why-write-clean-code" class="anchor" href="#why-write-clean-code" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-why-write-clean-code">
 <p>
This document is a reference for the Go community that aims to help
developers write cleaner code. Whether you’re working on a personal
project or as part of a larger team, writing clean code is an important
skill to have. Establishing good paradigms and consistent, accessible
standards for writing clean code can help prevent developers from
wasting many meaningless hours on trying to understand their own (or
others’) work.
</p>

 <blockquote>
 <p>
We don’t read code, we decode it – Peter Seibel
</p>
</blockquote>

 <p>
As developers, we’re sometimes tempted to write code in a way that’s
convenient for the time being without regard for best practices; this
makes code reviews and testing more difficult. In a sense, we’re
encoding—and, in doing so, making it more difficult for others to
decode our work. But we want our code to be usable, readable, and
maintainable. And that requires coding the right way, not the easy way.
</p>

 <p>
This document begins with a simple and short introduction to the
fundamentals of writing clean code. Later, we’ll discuss concrete
refactoring examples specific to Go.
</p>

 <p>
 <b>About  <code>gofmt</code></b>
</p>

 <p>
I’d like to take a few sentences to clarify my stance on =gofmt=because
there are plenty of things I disagree with when it comes to this tool.
This tool allows us to have a common standard for writing Go code, and
that’s a great thing. As a developer myself, I can certainly appreciate
that Go programmers may feel somewhat restricted by gofmt, especially if
they disagree with some of its rules. But in my opinion, homogeneous
code is more important than having complete expressive freedom.
</p>
</div>
 <h2>Introduction to Clean Code  <a id="introduction-to-clean-code" class="anchor" href="#introduction-to-clean-code" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-introduction-to-clean-code">
 <p>
Clean code is the pragmatic concept of promoting readable and
maintainable software. Clean code establishes trust in the codebase and
helps minimize the chances of careless bugs being introduced. It also
helps developers maintain their agility, which typically plummets as the
codebase expands due to the increased risk of introducing bugs.
</p>
</div>
 <h3>Test-Driven Development  <a id="test-driven-development" class="anchor" href="#test-driven-development" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-test-driven-development">
 <p>
Test-driven development is the practice of testing your code frequently
throughout short development cycles or sprints. It ultimately
contributes to code cleanliness by inviting developers to question the
functionality and purpose of their code. To make testing easier,
developers are encouraged to write short functions that only do one
thing. For example, it’s arguably much easier to test (and understand) a
function that’s only 4 lines long than one that’s 40.
</p>

 <p>
Test-driven development consists of the following cycle:
</p>

 <ol class="org-ol"> <li>Write (or execute) a test</li>
 <li>If the test fails, make it pass</li>
 <li>Refactor your code accordingly</li>
 <li>Repeat</li>
</ol> <p>
Testing and refactoring are intertwined in this process. As you refactor
your code to make it more understandable or maintainable, you need to
test your changes thoroughly to ensure that you haven’t altered the
behavior of your functions. This can be incredibly useful as the
codebase grows.
</p>
</div>
 <h3>Naming Conventions  <a id="naming-conventions" class="anchor" href="#naming-conventions" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-naming-conventions">
</div>
 <h4>Comments  <a id="comments" class="anchor" href="#comments" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-comments">
 <p>
I’d like to first address the topic of commenting code, which is an
essential practice but tends to be misapplied. Unnecessary comments can
indicate problems with the underlying code, such as the use of poor
naming conventions. However, whether or not a particular comment is
“necessary” is somewhat subjective and depends on how legibly the code
was written. For example, the logic of well-written code may still be so
complex that it requires a comment to clarify what is going on. In that
case, one might argue that the comment is helpful and therefore
necessary.
</p>

 <p>
In Go, according to gofmt, all public variables and functions should be
annotated. I think this is absolutely fine, as it gives us consistent
rules for documenting our code. However, I always want to distinguish
between comments that enable auto-generated documentation and all other
comments. Annotation comments, for documentation, should be written like
documentation—they should be at a high level of abstraction and
concern the logical implementation of the code as little as possible.
</p>

 <p>
I say this because there are other ways to explain code and ensure that
it’s being written comprehensibly and expressively. If the code is
neither of those, some people find it acceptable to introduce a comment
explaining the convoluted logic. Unfortunately, that doesn’t really
help. For one, most people simply won’t read comments, as they tend to
be very intrusive to the experience of reviewing code. Additionally, as
you can imagine, a developer won’t be too happy if they’re forced to
review unclear code that’s been slathered with comments. The less that
people have to read to understand what your code is doing, the better
off they’ll be.
</p>

 <p>
Let’s take a step back and look at some concrete examples. Here’s how
you shouldn’t comment your code:
</p>

 <div class="jfw-code"> <pre>// iterate over the range 0 to 9
// and invoke the doSomething function
// for each iteration
for i := 0; i &lt; 10; i++ {
  doSomething(i)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This is what I like to call a tutorial comment; it’s fairly common in
tutorials, which often explain the low-level functionality of a language
(or programming in general). While these comments may be helpful for
beginners, they’re absolutely useless in production code. Hopefully, we
aren’t collaborating with programmers who don’t understand something as
simple as a looping construct by the time they’ve begun working on a
development team. As programmers, we shouldn’t have to read the comment
to understand what’s going on—we know that we’re iterating over the
range 0 to 9 because we can simply read the code. Hence the proverb:
</p>

 <blockquote>
 <p>
Document why, not how. – Venkat Subramaniam
</p>
</blockquote>

 <p>
Following this logic, we can now change our comment to explain why we
are iterating from the range 0 to 9:
</p>

 <div class="jfw-code"> <pre>// instatiate 10 threads to handle upcoming work load
for i := 0; i &lt; 10; i++ {
  doSomething(i)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now we understand why we have a loop and can tell what we’re doing by
simply reading the code… Sort of.
</p>

 <p>
This still isn’t what I’d consider clean code. The comment is worrying
because it probably should not be necessary to express such an
explanation in prose, assuming the code is well written (which it
isn’t). Technically, we’re still saying what we’re doing, not why we’re
doing it. We can easily express this “what” directly in our code by
using more meaningful names:
</p>

 <div class="jfw-code"> <pre>for workerID := 0; workerID &lt; 10; workerID++ {
  instantiateThread(workerID)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
With just a few changes to our variable and function names, we’ve
managed to explain what we’re doing directly in our code. This is much
clearer for the reader because they won’t have to read the comment and
then map the prose to the code. Instead, they can simply read the code
to understand what it’s doing.
</p>

 <p>
Of course, this was a relatively trivial example. Writing clear and
expressive code is unfortunately not always so easy; it can become
increasingly difficult as the codebase itself grows in complexity. The
more you practice writing comments in this mindset and avoid explaining
what you’re doing, the cleaner your code will become.
</p>
</div>
 <h4>Function Naming  <a id="function-naming" class="anchor" href="#function-naming" aria-label="Link to this section">#</a></h4> <div class="outline-text-4" id="text-function-naming">
 <p>
Let’s now move on to function naming conventions. The general rule here
is really simple: the more specific the function, the more general its
name. In other words, we want to start with a very broad and short
function name, such as  <code>Run</code> or  <code>Parse</code>, that describes the general
functionality. Let’s imagine that we are creating a configuration
parser. Following this naming convention, our top level of abstraction
might look something like the following:
</p>

 <div class="jfw-code"> <pre>func main() {
    configpath := flag.String(&quot;config-path&quot;, &quot;&quot;, &quot;configuration file path&quot;)
    flag.Parse()

    config, err := configuration.Parse(*configpath)
    ...
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We’ll focus on the naming of the  <code>Parse</code> function. Despite this
function’s very short and general name, it’s actually quite clear what
it attempts to achieve.
</p>

 <p>
When we go one layer deeper, our function naming will become slightly
more specific:
</p>

 <div class="jfw-code"> <pre>func Parse(filepath string) (Config, error) {
    switch fileExtension(filepath) {
    case &quot;json&quot;:
        return parseJSON(filepath)
    case &quot;yaml&quot;:
        return parseYAML(filepath)
    case &quot;toml&quot;:
        return parseTOML(filepath)
    default:
        return Config{}, ErrUnknownFileExtension
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Here, we’ve clearly distinguished the nested function calls from their
parent without being overly specific. This allows each nested function
call to make sense on its own as well as within the context of the
parent. On the other hand, if we had named the  <code>parseJSON</code> function
 <code>json</code> instead, it couldn’t possibly stand on its own. The functionality
would become lost in the name, and we would no longer be able to tell
whether this function is parsing, creating, or marshalling JSON.
</p>

 <p>
Notice that  <code>fileExtension</code> is actually a little more specific. However,
this is because its functionality is in fact quite specific in nature:
</p>

 <div class="jfw-code"> <pre>func fileExtension(filepath string) string {
    segments := strings.Split(filepath, &quot;.&quot;)
    return segments[len(segments)-1]
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This kind of logical progression in our function names—from a high
level of abstraction to a lower, more specific one—makes the code
easier to follow and read. Consider the alternative: If our highest
level of abstraction is too specific, then we’ll end up with a name that
attempts to cover all bases, like
 <code>DetermineFileExtensionAndParseConfigurationFile</code>. This is horrendously
difficult to read; we are trying to be too specific too soon and end up
confusing the reader, despite trying to be clear!
</p>
</div>
 <ul> <li>Variable Naming <div class="outline-text-5" id="text-variable-naming">
 <p>
Rather interestingly, the opposite is true for variables. Unlike
functions, our variables should be named from more to less specific the
deeper we go into nested scopes.
</p>

 <blockquote>
 <p>
You shouldn’t name your variables after their types for the same reason
you wouldn’t name your pets ’dog’ or ’cat’. – Dave Cheney
</p>
</blockquote>

 <p>
Why should our variable names become less specific as we travel deeper
into a function’s scope? Simply put, as a variable’s scope becomes
smaller, it becomes increasingly clear for the reader what that variable
represents, thereby eliminating the need for specific naming. In the
example of the previous function  <code>fileExtension</code>, we could even shorten
the name of the variable  <code>segments</code> to  <code>s</code> if we wanted to. The context
of the variable is so clear that it’s unnecessary to explain it any
further with longer variable names. Another good example of this is in
nested for loops:
</p>

 <div class="jfw-code"> <pre>func PrintBrandsInList(brands []BeerBrand) {
    for _, b := range brands {
      fmt.Println(b)
    }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
In the above example, the scope of the variable b is so small that we
don’t need to spend any additional brain power on remembering what
exactly it represents. However, because the scope of brands is slightly
larger, it helps for it to be more specific. When expanding the variable
scope in the function below, this distinction becomes even more
apparent:
</p>

 <div class="jfw-code"> <pre>func BeerBrandListToBeerList(beerBrands []BeerBrand) []Beer {
    var beerList []Beer
    for _, brand := range beerBrands {
        for _, beer := range brand {
            beerList = append(beerList, beer)
        }
    }
    return beerList
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Great! This function is easy to read. Now, let’s apply the opposite
(i.e., wrong) logic when naming our variables:
</p>

 <div class="jfw-code"> <pre>func BeerBrandListToBeerList(b []BeerBrand) []Beer {
    var bl []Beer
    for _, beerBrand := range b {
        for _, beerBrandBeerName := range beerBrand {
            bl = append(bl, beerBrandBeerName)
        }
    }
    return bl
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Even though it’s possible to figure out what this function is doing, the
excessive brevity of the variable names makes it difficult to follow the
logic as we travel deeper. This could very well spiral into full-blown
confusion because we’re mixing short and long variable names
inconsistently.
</p>
</div>
</li></ul> <h3>Cleaning Functions  <a id="cleaning-functions" class="anchor" href="#cleaning-functions" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-cleaning-functions">
 <p>
Now that we know some best practices for naming our variables and
functions, as well as clarifying our code with comments, let’s dive into
some specifics of how we can refactor functions to make them cleaner.
</p>
</div>
 <ul> <li>Function Length <div class="outline-text-5" id="text-function-length">
 <blockquote>
 <p>
How small should a function be? Smaller than that! – Robert C. Martin
</p>
</blockquote>

 <p>
When writing clean code, our primary goal is to make our code easily
digestible. The most effective way to do this is to make our functions
as short as possible. It’s important to understand that we don’t
necessarily do this to avoid code duplication. The more important reason
is to improve  <i>code comprehension</i>.
</p>

 <p>
It can help to look at a function’s description at a very high level to
understand this better:
</p>

 <div class="jfw-code"> <pre>fn GetItem:
  - parse json input for order id
  - get user from context
  - check user has appropriate role
  - get order from database</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
By writing short functions (which are typically 5–8 lines in Go), we
can create code that reads almost as naturally as our description above:
</p>

 <div class="jfw-code"> <pre>var (
    NullItem = Item{}
    ErrInsufficientPrivileges = errors.New(&quot;user does not have sufficient privileges&quot;)
)

func GetItem(ctx context.Context, json []bytes) (Item, error) {
    order, err := NewItemFromJSON(json)
    if err != nil {
        return NullItem, err
    }
    if !GetUserFromContext(ctx).IsAdmin() {
          return NullItem, ErrInsufficientPrivileges
    }
    return db.GetItem(order.ItemID)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Using smaller functions also eliminates another horrible habit of
writing code:  <b>indentation hell</b>. This typically occurs when a chain of
 <code>if</code> statements are carelessly nested in a function. This makes it very
difficult for human beings to parse the code and should be eliminated
whenever spotted. Indentation hell is particularly common when working
with  <code>interface{}</code> and using type casting:
</p>

 <div class="jfw-code"> <pre>func GetItem(extension string) (Item, error) {
    if refIface, ok := db.ReferenceCache.Get(extension); ok {
        if ref, ok := refIface.(string); ok {
            if itemIface, ok := db.ItemCache.Get(ref); ok {
                if item, ok := itemIface.(Item); ok {
                    if item.Active {
                        return Item, nil
                    } else {
                      return EmptyItem, errors.New(&quot;no active item found in cache&quot;)
                    }
                } else {
                  return EmptyItem, errors.New(&quot;could not cast cache interface to Item&quot;)
                }
            } else {
              return EmptyItem, errors.New(&quot;extension was not found in cache reference&quot;)
            }
        } else {
          return EmptyItem, errors.New(&quot;could not cast cache reference interface to Item&quot;)
        }
    }
    return EmptyItem, errors.New(&quot;reference not found in cache&quot;)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
First, indentation hell makes it difficult for other developers to
understand the flow of your code. Second, if the logic in our if
statements expands, it’ll become exponentially more difficult to figure
out which statement returns what (and to ensure that all paths return
some value).
</p>

 <p>
Yet another problem is that this deep nesting of conditional statements
forces the reader to frequently scroll and keep track of many logical
states in their head. It also makes it more difficult to test the code
and catch bugs because there are so many different nested possibilities
that you have to account for.
</p>

 <p>
Indentation hell can result in reader fatigue if a developer has to
constantly parse unwieldy code like the sample above. Naturally, this is
something we want to avoid at all costs.
</p>

 <p>
So, how do we clean this function? Fortunately, it’s actually quite
simple. On our first iteration, we will try to ensure that we are
returning an error as soon as possible. Instead of nesting the  <code>if</code> and
 <code>else</code> statements, we want to “push our code to the left,” so to speak.
Take a look:
</p>

 <div class="jfw-code"> <pre>func GetItem(extension string) (Item, error) {
    refIface, ok := db.ReferenceCache.Get(extension)
    if !ok {
        return EmptyItem, errors.New(&quot;reference not found in cache&quot;)
    }

    ref, ok := refIface.(string)
    if !ok {
        // return cast error on reference
    }

    itemIface, ok := db.ItemCache.Get(ref)
    if !ok {
        // return no item found in cache by reference
    }

    item, ok := itemIface.(Item)
    if !ok {
        // return cast error on item interface
    }

    if !item.Active {
        // return no item active
    }

    return Item, nil
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Once we’re done with our first attempt at refactoring the function, we
can proceed to split up the function into smaller functions. Here’s a
good rule of thumb: If the  <code>value, err :=</code> pattern is repeated more than
once in a function, this is an indication that we can split the logic of
our code into smaller pieces:
</p>

 <div class="jfw-code"> <pre>func GetItem(extension string) (Item, error) {
    ref, ok := getReference(extension)
    if !ok {
        return EmptyItem, ErrReferenceNotFound
    }
    return getItemByReference(ref)
}

func getReference(extension string) (string, bool) {
    refIface, ok := db.ReferenceCache.Get(extension)
    if !ok {
        return EmptyItem, false
    }
    return refIface.(string)
}

func getItemByReference(reference string) (Item, error) {
    item, ok := getItemFromCache(reference)
    if !item.Active || !ok {
        return EmptyItem, ErrItemNotFound
    }
    return Item, nil
}

func getItemFromCache(reference string) (Item, bool) {
    if itemIface, ok := db.ItemCache.Get(ref); ok {
        return EmptyItem, false
    }
    return itemIface.(Item), true
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
As mentioned previously, indentation hell can make it difficult to test
our code. When we split up our  <code>GetItem</code> function into several helpers,
we make it easier to track down bugs when testing our code. Unlike the
original version, which consisted of several  <code>if</code> statements in the same
scope, the refactored version of  <code>GetItem</code> has just two branching paths
that we must consider. The helper functions are also short and
digestible, making them easier to read.
</p>

 <blockquote>
 <p>
Note: For production code, one should elaborate on the code even further
by returning errors instead of bool values. This makes it much easier to
understand where the error is originating from. However, as these are
just example functions, returning bool values will suffice for now.
Examples of returning errors more explicitly will be explained in more
detail later.
</p>
</blockquote>

 <p>
Notice that cleaning the  <code>GetItem</code> function resulted in more lines of
code overall. However, the code itself is now much easier to read. It’s
layered in an onion-style fashion, where we can ignore “layers” that we
aren’t interested in and simply peel back the ones that we do want to
examine. This makes it easier to understand low-level functionality
because we only have to read maybe 3–5 lines at a time.
</p>

 <p>
This example illustrates that we cannot measure the cleanliness of our
code by the number of lines it uses. The first version of the code was
certainly much shorter. However, it was  <i>artificially</i> short and very
difficult to read. In most cases, cleaning code will initially expand
the existing codebase in terms of the number of lines. But this is
highly preferable to the alternative of having messy, convoluted logic.
If you’re ever in doubt about this, just consider how you feel about the
following function, which does exactly the same thing as our code but
only uses two lines:
</p>

 <div class="jfw-code"> <pre>func GetItemIfActive(extension string) (Item, error) {
    if refIface,ok := db.ReferenceCache.Get(extension); ok {if ref,ok := refIface.(string); ok { if itemIface,ok := db.ItemCache.Get(ref); ok { if item,ok := itemIface.(Item); ok { if item.Active { return Item,nil }}}}} return EmptyItem, errors.New(&quot;reference not found in cache&quot;)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
</li>
 <li>Function Signatures <div class="outline-text-5" id="text-function-signatures">
 <p>
Creating a good function naming structure makes it easier to read and
understand the intent of the code. As we saw above, making our functions
shorter helps us understand the function’s logic. The last part of
cleaning our functions involves understanding the context of the
function input. With this comes another easy-to-follow rule:  <b>Function
signatures should only contain one or two input parameters</b>. In certain
exceptional cases, three can be acceptable, but this is where we should
start considering a refactor. Much like the rule that our functions
should only be 5–8 lines long, this can seem quite extreme at first.
However, I feel that this rule is much easier to justify.
</p>

 <p>
Take the following function from
 <a href="https://www.rabbitmq.com/tutorials/tutorial-one-go.html">RabbitMQ’s
introduction tutorial to its Go library</a>:
</p>

 <div class="jfw-code"> <pre>q, err := ch.QueueDeclare(
  &quot;hello&quot;, // name
  false,   // durable
  false,   // delete when unused
  false,   // exclusive
  false,   // no-wait
  nil,     // arguments
)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The function  <code>QueueDeclare</code> takes six input parameters, which is quite a
lot. With some effort, it’s possible to understand what this code does
thanks to the comments. However, the comments are actually part of the
problem—as mentioned earlier, they should be substituted with
descriptive code whenever possible. After all, there’s nothing
preventing us from invoking the QueueDeclare function without comments:
</p>

 <div class="jfw-code"> <pre>q, err := ch.QueueDeclare(&quot;hello&quot;, false, false, false, false, nil)</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now, without looking at the commented version, try to remember what the
fourth and fifth  <code>false</code> arguments represent. It’s impossible, right?
You will inevitably forget at some point. This can lead to costly
mistakes and bugs that are difficult to correct. The mistakes might even
occur through incorrect comments—imagine labeling the wrong input
parameter. Correcting this mistake will be unbearably difficult to
correct, especially when familiarity with the code has deteriorated over
time or was low to begin with. Therefore, it is recommended to replace
these input parameters with an ’Options’  <code>struct</code> instead:
</p>

 <div class="jfw-code"> <pre>type QueueOptions struct {
    Name string
    Durable bool
    DeleteOnExit bool
    Exclusive bool
    NoWait bool
    Arguments []interface{}
}

q, err := ch.QueueDeclare(QueueOptions{
    Name: &quot;hello&quot;,
    Durable: false,
    DeleteOnExit: false,
    Exclusive: false,
    NoWait: false,
    Arguments: nil,
})</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This solves two problems: misusing comments, and accidentally labeling
the variables incorrectly. Of course, we can still confuse properties
with the wrong value, but in these cases, it will be much easier to
determine where our mistake lies within the code. The ordering of the
properties also doesn’t matter anymore, so incorrectly ordering the
input values is no longer a concern.
</p>

 <p>
The last added bonus of this technique is that we can use our
QueueOptions struct to infer the default values of our function’s input
parameters. When structures in Go are declared, all properties are
initialised to their default value. This means that our  <code>QueueDeclare</code>
option can actually be invoked in the following way:
</p>

 <div class="jfw-code"> <pre>q, err := ch.QueueDeclare(QueueOptions{
    Name: &quot;hello&quot;,
})</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The rest of the values are initialised to their default value of  <code>false</code>
(except for  <code>Arguments</code>, which as an interface has a default value of
 <code>nil</code>). Not only are we much safer with this approach, but we are also
much clearer with our intentions. In this case, we could actually write
less code. This is an all-around win for everyone on the project.
</p>

 <p>
One final note on this: It’s not always possible to change a function’s
signature. In this case, for example, we don’t actually have control
over our =QueueDeclare=function signature because it’s from the RabbitMQ
library. It’s not our code, so we can’t change it. However, we can wrap
these functions to suit our purposes:
</p>

 <div class="jfw-code"> <pre>type RMQChannel struct {
    channel *amqp.Channel
}

func (rmqch *RMQChannel) QueueDeclare(opts QueueOptions) (Queue, error) {
    return rmqch.channel.QueueDeclare(
        opts.Name,
        opts.Durable,
        opts.DeleteOnExit,
        opts.Exclusive,
        opts.NoWait,
        opts.Arguments,
    )
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Basically, we create a new structure named  <code>RMQChannel</code> that contains
the  <code>amqp.Channel</code> type, which has the  <code>QueueDeclare</code> method. We then
create our own version of this method, which essentially just calls the
old version of the RabbitMQ library function. Our new method has all the
advantages described before, and we achieved this without actually
having to change any of the code in the RabbitMQ library.
</p>

 <p>
We’ll use this idea of wrapping functions to introduce more clean and
safe code later when discussing  <code>interface{}</code>.
</p>
</div>
</li>
 <li>Variable Scope <div class="outline-text-5" id="text-variable-scope">
 <p>
Now, let’s take a step back and revisit the idea of writing smaller
functions. This has another nice side effect that we didn’t cover in the
previous chapter: Writing smaller functions can typically eliminate
reliance on mutable variables that leak into the global scope.
</p>

 <p>
Global variables are problematic and don’t belong in clean code; they
make it very difficult for programmers to understand the current state
of a variable. If a variable is global and mutable, then by definition,
its value can be changed by any part of the codebase. At no point can
you guarantee that this variable is going to be a specific value… And
that’s a headache for everyone. This is yet another example of a trivial
problem that’s exacerbated when the codebase expands.
</p>

 <p>
Let’s look at a short example of how non-global variables with a large
scope can cause problems. These variables also introduce the issue of
variable shadowing.
</p>

 <div class="jfw-code"> <pre>func doComplex() (string, error) {
    return &quot;Success&quot;, nil
}

func main() {
    var val string
    num := 32

    switch num {
    case 16:
    // do nothing
    case 32:
        val, err := doComplex()
        if err != nil {
            panic(err)
        }
        if val == &quot;&quot; {
            // do something else
        }
    case 64:
        // do nothing
    }

    fmt.Println(val)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
What’s the problem with this code? From a quick skim, it seems the
 <code>var val string</code> value should be printed out as  <code>Success</code> by the end of
the main function. Unfortunately, this is not the case. The reason for
this lies in the following line:
</p>

 <div class="jfw-code"> <pre>val, err := doComplex()</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This declares a new variable  <code>val</code> in the switch’s  <code>case 32</code> scope and
has nothing to do with the variable declared in the first line of
 <code>main</code>. Of course, it can be argued that Go syntax is a little tricky,
which I don’t necessarily disagree with, but there is a much worse issue
at hand. The declaration of  <code>var val string</code> as a mutable, largely
scoped variable is completely unnecessary. If we do a very simple
refactor, we will no longer have this issue:
</p>

 <div class="jfw-code"> <pre>func getStringResult(num int) (string, error) {
    switch num {
    case 16:
    // do nothing
    case 32:
       return doComplex()
    case 64:
        // do nothing
    }
    return &quot;&quot;
}

func main() {
    val, err := getStringResult(32)
    if err != nil {
        panic(err)
    }
    if val == &quot;&quot; {
        // do something else
    }
    fmt.Println(val)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
After our refactor, val is no longer modified, and the scope has been
reduced. Again, keep in mind that these functions are very simple. Once
this kind of code style becomes a part of larger, more complex systems,
it can be impossible to figure out why errors are occurring. We don’t
want this to happen—not only because we generally dislike software
errors but also because it’s disrespectful to our colleagues, and
ourselves; we are potentially wasting each other’s time having to debug
this type of code. Developers need to take responsibility for their own
code rather than blaming these issues on the variable declaration syntax
of a particular language like Go.
</p>

 <p>
On a side note, if the  <code>// do something else</code> part is another attempt to
mutate the val variable, we should extract that logic out as its own
self-contained function, as well as the previous part of it. This way,
instead of expanding the mutable scope of our variables, we can just
return a new value:
</p>

 <div class="jfw-code"> <pre>func getVal(num int) (string, error) {
    val, err := getStringResult(32)
    if err != nil {
        return &quot;&quot;, err
    }
    if val == &quot;&quot; {
        return NewValue() // pretend function
    }
}

func main() {
    val, err := getVal(32)
    if err != nil {
        panic(err)
    }
    fmt.Println(val)
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
</li>
 <li>Variable Declaration <div class="outline-text-5" id="text-variable-declaration">
 <p>
Other than avoiding issues with variable scope and mutability, we can
also improve readability by declaring variables as close to their usage
as possible. In C programming, it’s common to see the following approach
to declaring variables:
</p>

 <div class="jfw-code"> <pre>func main() {
  var err error
  var items []Item
  var sender, receiver chan Item

  items = store.GetItems()
  sender = make(chan Item)
  receiver = make(chan Item)

  for _, item := range items {
    // ...
  }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
This suffers from the same symptom as described in our discussion of
variable scope. Even though these variables might not actually be
reassigned at any point, this kind of coding style keeps the readers on
their toes, in all the wrong ways. Much like computer memory, our
brain’s short-term memory has a limited capacity. Having to keep track
of which variables are mutable and whether or not a particular fragment
of code will mutate them makes it more difficult to understand what the
code is doing. Figuring out the eventually returned value can be a
nightmare. Therefore, to makes this easier for our readers (and our
future selves), it’s recommended that you declare variables as close to
their usage as possible:
</p>

 <div class="jfw-code"> <pre>func main() {
    var sender chan Item
    sender = make(chan Item)

    go func() {
        for {
            select {
            case item := &lt;-sender:
                // do something
            }
        }
    }()
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
However, we can do even better by invoking the function directly after
its declaration. This makes it much clearer that the function logic is
associated with the declared variable:
</p>

 <div class="jfw-code"> <pre>func main() {
  sender := func() chan Item {
    channel := make(chan Item)
    go func() {
      for {
        select { ... }
      }
    }()
    return channel
  }
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
And coming full circle, we can move the anonymous function to make it a
named function instead:
</p>

 <div class="jfw-code"> <pre>func main() {
  sender := NewSenderChannel()
}

func NewSenderChannel() chan Item {
  channel := make(chan Item)
  go func() {
    for {
      select { ... }
    }
  }()
  return channel
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
It is still clear that we are declaring a variable, and the logic
associated with the returned channel is simple, unlike in the first
example. This makes it easier to traverse the code and understand the
role of each variable.
</p>

 <p>
Of course, this doesn’t actually prevent us from mutating our  <code>sender</code>
variable. There is nothing that we can do about this, as there is no way
of declaring a  <code>const struct</code> or static variables in Go. This means that
we’ll have to restrain ourselves from modifying this variable at a later
point in the code.
</p>

 <blockquote>
 <p>
NOTE: The keyword const does exist but is limited in use to primitive
types only.
</p>
</blockquote>

 <p>
One way of getting around this can at least limit the mutability of a
variable to the package level. The trick involves creating a structure
with the variable as a private property. This private property is
thenceforth only accessible through other methods provided by this
wrapping structure. Expanding on our channel example, this would look
something like the following:
</p>

 <div class="jfw-code"> <pre>type Sender struct {
  sender chan Item
}

func NewSender() *Sender {
  return &amp;Sender{
    sender: NewSenderChannel(),
  }
}

func (s *Sender) Send(item Item) {
  s.sender &lt;- item
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
We have now ensured that the  <code>sender</code> property of our  <code>Sender</code> struct is
never mutated—at least not from outside of the package. As of writing
this document, this is the only way of creating publicly immutable
non-primitive variables. It’s a little verbose, but it’s truly worth the
effort to ensure that we don’t end up with strange bugs resulting from
accidental variable modification.
</p>

 <div class="jfw-code"> <pre>func main() {
  sender := NewSender()
  sender.Send(&amp;Item{})
}</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Looking at the example above, it’s clear how this also simplifies the
usage of our package. This way of hiding the implementation is
beneficial not only for the maintainers of the package but also for the
users. Now, when initialising and using the  <code>Sender</code> structure, there is
no concern over its implementation. This opens up for a much looser
architecture.
</p>

 <p>
Because our users aren’t concerned with the implementation, we are free
to change it at any point, since we have reduced the point of contact
that users have with the package. If we no longer wish to use a channel
implementation in our package, we can easily change this without
breaking the usage of the  <code>Send</code> method (as long as we adhere to its
current function signature).
</p>

 <blockquote>
 <p>
NOTE: There is a fantastic explanation of how to handle the abstraction
in client libraries, taken from the talk
 <a href="https://www.youtube.com/watch?v=kJq81Y7OEx4">AWS re:Invent 2017:
Embracing Change without Breaking the World (DEV319)</a>.
</p>
</blockquote>

 <p>
That is it for Part I of this document. Hope you have learned something
useful and that you are itching to get back to your codebase to apply
these principles.
</p>
</div>
</li></ul> <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/freebsd/running-postgresql-on-freebsd/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Running PostgreSQL on FreeBSD</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/zen-of-go/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Zen of Go</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/tips-for-clean-code-with-go/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/tips-for-clean-code-with-go/index.html</guid>
  <pubDate>Sat, 03 Oct 2020 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Running PostgreSQL on FreeBSD</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
PostgreSQL or Postgres is a powerful object-relational high-performance
database management system (ORDBMS) published under a flexible BSD-style
license. PostgreSQL is well suited for large databases and has many
advanced features.
</p>

 <p>
In this tutorial, I will show you how to install and configure a
PostgreSQL database server on FreeBSD. We will install the latest
version of PostgreSQL 11 on the FreeBSD 12.0 system.
</p>
 <h2>Prerequisites  <a id="prerequisites" class="anchor" href="#prerequisites" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-prerequisites">
 <p>
For this guide, we will use FreeBSD 12 with 2 GB of RAM memory and 2
CPUs. If you have a large deployment, you will need more than that. You
will also need the root privileges for package installation.
</p>
</div>
 <h2>Update and Upgrade Packages  <a id="update-and-upgrade-packages" class="anchor" href="#update-and-upgrade-packages" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-update-and-upgrade-packages">
 <p>
Firstly, we will update the packages repositories and upgrade all
packages to the latest version using the  <code>pkg</code> package management tool
for FreeBSD.
</p>

 <div class="jfw-code"> <pre>pkg update
pkg upgrade</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Install PostgreSQL 11  <a id="install-postgresql-11" class="anchor" href="#install-postgresql-11" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-install-postgresql-11">
 <p>
In this step, we’re going to install the latest stable version
PostgreSQL 11. By default, the FreeBSD repository provides multiple
versions of PostgreSQL package. You can use the following command to
check all available version of PostgreSQL packages.
</p>

 <div class="jfw-code"> <pre>pkg search postgresql</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You will get multiple versions of PostgreSQL database server.
</p>

 <p>
Now install the PostgreSQL 11 package using the command below.
</p>

 <div class="jfw-code"> <pre>pkg install postgresql11-server postgresql11-client</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Next, we need to add the PostgreSQL service to the system boot and
initialize the database before starting the service. Add the PostgreSQL
to the system boot using the command below.
</p>

 <div class="jfw-code"> <pre>sysrc  <span class="org-variable-name">postgresql_enable</span>=yes</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now initialize the PostgreSQL database, and then start the service,
using the following commands
</p>

 <div class="jfw-code"> <pre>/usr/local/etc/rc.d/postgresql initdb
service postgresql start
service postgresql status</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Verify the output of the last command gives a similar output:
</p>

 <div class="jfw-code"> <pre>root@bsdstation:/home/joe  <span class="org-comment-delimiter"># </span> <span class="org-comment">service postgresql status
</span>pg_ctl: server is running (PID: 1122)
/usr/local/bin/postgres  <span class="org-string">&quot;-D&quot;</span>  <span class="org-string">&quot;/var/db/postgres/data11&quot;</span></pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
The PostgreSQL service is up and running on FreeBSD 12.0. Additionally
you can check the system port used by the PostgreSQL service using the
sockstat command below. You should get the port  <code>5432</code> is used by the
PostgreSQL service.
</p>

 <div class="jfw-code"> <pre>sockstat -l4 -P tcp</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Configure PostgreSQL Authentication  <a id="configure-postgresql-authentication" class="anchor" href="#configure-postgresql-authentication" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-configure-postgresql-authentication">
 <p>
In this step, we’re going to set up the authentication method for
PostgreSQL. PostgreSQL supports different authentication methods such as
trust authentication (default), password-based authentication, Kerberos,
GSSAPI, LDAP, RADIUS, and PAM. For this guide, we’re going to set up the
password-based authentication using MD5. Go to the
 <code>/var/db/postgresql/data11</code> directory, edit the  <code>pg_hba.conf</code> file using
a text editor.
</p>

 <div class="jfw-code"> <pre> <span class="org-builtin">cd</span> /var/db/postgres/data11
vi pg_hba.conf</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now change the authentication method for all local connection to  <code>md5</code>
as below, and add a line to allow external access to the database if
needed.
</p>

 <div class="jfw-code"> <pre> <span class="org-comment-delimiter"># </span> <span class="org-comment">TYPE  DATABASE        USER            ADDRESS                 METHOD
</span>
 <span class="org-comment-delimiter"># </span> <span class="org-comment">&quot;local&quot; is for Unix domain socket connections only
</span> <span class="org-builtin">local</span>   all             all                                     trust
 <span class="org-comment-delimiter"># </span> <span class="org-comment">IPv4 local connections:
</span>host    all             all             127.0.0.1/32            md5
 <span class="org-comment-delimiter"># </span> <span class="org-comment">IPv6 local connections:
</span>host    all             all             ::1/128                 md5
 <span class="org-comment-delimiter"># </span> <span class="org-comment">External connections
</span>host    all             all             192.168.66.1/32         md5</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Save and close the file, and then restart the PostgreSQL service,
enabling the password-based authentication using  <code>md5</code> for the
PostgreSQL server.
</p>

 <div class="jfw-code"> <pre>service postgresql restart</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>
</div>
 <h2>Setup New User and Database  <a id="setup-new-user-and-database" class="anchor" href="#setup-new-user-and-database" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-setup-new-user-and-database">
 <p>
In this step, we’re going to set up a new user and database on
PostgreSQL. We’re going to create a new password for default user
 <code>postgres</code>, and create a new user and database. Log in to the ’postgres’
user using the command below.
</p>

 <div class="jfw-code"> <pre>su - postgres</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Now login to the interactive PostgreSQL shell  <code>psql</code>.
</p>

 <div class="jfw-code"> <pre>psql</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Then create a new password for the  <code>postgres</code> user.
</p>

 <div class="jfw-code"> <pre>\password postgres
TYPE THE PASSWORD</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Next, we will create a new user called  <code>joe</code> with the database  <code>joe_db</code>.
And the give privileges for the user to the database by running the
following queries.
</p>

 <div class="jfw-code"> <pre> <span class="org-keyword">CREATE</span> DATABASE joe_db;
 <span class="org-keyword">CREATE</span>  <span class="org-builtin">USER</span> joe  <span class="org-keyword">WITH</span> ENCRYPTED PASSWORD  <span class="org-string">'password123#'</span>;
 <span class="org-keyword">GRANT</span>  <span class="org-keyword">ALL</span>  <span class="org-keyword">PRIVILEGES</span>  <span class="org-keyword">ON</span> DATABASE joe_db  <span class="org-keyword">TO</span> joe;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
You can now exit from the PostgreSQL interactive shell with  <code>\q</code>. As a
result, the password for the default  <code>postgres</code> user has been created.
And the new user and database have been set up.
</p>
</div>
 <h2>Testing connection  <a id="testing-connection" class="anchor" href="#testing-connection" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-testing-connection">
 <p>
Log in to the  <code>postgres</code> user and then run the  <code>psql</code> command to get
into the PostgreSQL interactive shell.
</p>

 <div class="jfw-code"> <pre>su - postgres
psql</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Show list users and database on the PostgreSQL server using the
following queries. You will get the new user  <code>joe</code> and the database
 <code>joe_db</code> on the result.
</p>

 <div class="jfw-code"> <pre>\du
\l</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Type  <code>\q</code> to exit from the psql shell. Next, we will log in using the
created user  <code>joe</code> to the database  <code>joe_db</code> using the command below.
</p>

 <div class="jfw-code"> <pre>psql -U joe -d joe_db -W</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Type the  <code>joe</code> password to continue. Now we will proceed to create a new
table  <code>user_table</code> and insert some data into it.
</p>

 <div class="jfw-code"> <pre> <span class="org-keyword">CREATE</span>  <span class="org-keyword">TABLE</span>  <span class="org-function-name">user_table</span> (id  <span class="org-type">INT</span>,  <span class="org-keyword">name</span> TEXT, site TEXT);
 <span class="org-keyword">INSERT</span>  <span class="org-keyword">INTO</span> user_table (id,  <span class="org-keyword">name</span>, site)  <span class="org-keyword">VALUES</span> ( 1 ,  <span class="org-string">'Joe the Man'</span>,  <span class="org-string">'jjbigorra.netlify.app'</span>);</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Show content of tables using the following query.
</p>

 <div class="jfw-code"> <pre> <span class="org-keyword">SELECT</span> *  <span class="org-keyword">FROM</span> user_table;</pre> <button type="button" class="jfw-copy" aria-label="Copy this code block to the clipboard" title="Copy this code block to the clipboard">copy</button></div>

 <p>
Finally, the installation and configuration of PostgreSQL 11 on the
FreeBSD 12.0 system has been completed successfully.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/development/a-great-programmer/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">A Great Programmer</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/go/tips-for-clean-code-with-go/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Tips for clean code with Go</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/running-postgresql-on-freebsd/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/running-postgresql-on-freebsd/index.html</guid>
  <pubDate>Sun, 20 Sep 2020 01:00:00 +0200</pubDate>
</item>
<item>
  <title>A Great Programmer</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
If writing code were a science, all developers would pretty much be the
same. But it is not. And just like in art, no two developers have the
same thinking or perception while working towards the same outcome.
</p>

 <p>
While some struggle to produce the desired outcome, to a few, it comes
almost naturally, as if an epiphany hits them at the moment they start
writing code or solve a problem.
</p>

 <p>
Say no to artificial energy drinks.
 <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1600515371/jjba-site/blog/great-programmer/coffee_vsepjh.jpg"></img></p>

 <p>
And in a blog post, Steve McConnell, one of the experts in software
engineering talks about an original study which was carried in the late
1960s by Sackman, Erikson, and Grant. They found that the ratio of
initial coding time between the best and worst programmers was about 20
to 1.
</p>

 <p>
And the most interesting thing was that they found no relationship
between a programmer’s experience and code quality or productivity. In
simple words, writing good code is not the only factor that
differentiates a good programmer from a great one.
</p>

 <p>
Let us start with the good programmers first.
</p>
 <h2>Who is a good programmer?  <a id="who-is-a-good-programmer" class="anchor" href="#who-is-a-good-programmer" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-who-is-a-good-programmer">
 <p>
I would say it is someone with:
</p>

 <ul class="org-ul"> <li>Excellent technical skills and write clean, neat code.</li>
 <li>Solid knowledge of development techniques and problem-solving
expertise.</li>
 <li>Understanding programming best practices and when to employ them.</li>
 <li>An abiding passion for programming and strive to contribute to the
team.</li>
 <li>Respectable and likeable by other members of the team.</li>
</ul> <p>
So if you are a programmer and you have all the above traits,
Congratulations! You are a good programmer. Be proud of it.
</p>
</div>
 <h2>Now coming to the great ones.  <a id="now-coming-to-the-great-ones." class="anchor" href="#now-coming-to-the-great-ones." aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-now-coming-to-the-great-ones.">
 <ul class="org-ul"> <li>They are rare.</li>
 <li>Their productivity is 3 times that of a good programmer and 10 times
that of a bad programmer.</li>
 <li>They belong to the top 1% who don’t just write code but have a set of
intangible traits that keep them poles apart from other programmers.</li>
</ul></div>
 <h2>TLDR;  <a id="tldr" class="anchor" href="#tldr" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-tldr">
 <blockquote>
 <p>
Great programmer  <code>=</code> Good programmer + a set of intangible traits
</p>
</blockquote>

 <p>
While it’s not easy, if you’re dedicated enough, here are those
intangible traits which you can cultivate within yourself to transition
from being a good programmer to becoming a great programmer:
</p>
</div>
 <h2>Abrupt learning capability.  <a id="abrupt-learning-capability." class="anchor" href="#abrupt-learning-capability." aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-abrupt-learning-capability.">
 <p>
They are sharp-minded and that means they have the ability to learn new
technologies and aren’t browbeaten by new technologies. They have the
ability to integrate seemingly disparate bits of information and process
information on the fly.
</p>

 <p>
Every programmer will surely experience a situation where he or she
doesn’t know the answer. Great programmers will find different
resources, talk to the right people and find the solution no matter how
impossible it appears. The best skill anyone can possess is knowing how
to learn, and great programmers have mastered the skill of
self-learning.
</p>

 <p>
A great programmer doesn’t let his ego come in between his work and his
learning process. If he needs to know something, he will approach anyone
in the hierarchy; from the lowest to the highest.
</p>
</div>
 <h2>They balance pragmatism and perfectionism.  <a id="they-balance-pragmatism-and-perfectionism." class="anchor" href="#they-balance-pragmatism-and-perfectionism." aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-they-balance-pragmatism-and-perfectionism.">
 <p>
John Allspaw, Chief Technology Officer at Etsy makes a good point in his
post
 <a href="https://www.kitchensoap.com/2012/10/25/on-being-a-senior-engineer/"> <i>On
being a senior engineer</i></a>.
</p>

 <p>
He says that top-notch developers are healthy skeptics, which tend to
ask themselves and their peers’ questions while they work, such as:
</p>

 <blockquote>
 <p>
What could I be missing?
</p>

 <p>
How will this not work?
</p>

 <p>
Will you please shoot as many holes as possible into my thinking on
this?
</p>

 <p>
Even if it’s technically sound, is it understandable enough for the rest
of the organization to operate, troubleshoot, and extend it?
</p>
</blockquote>

 <p>
The idea behind these questions is that they perfectly understand the
importance of peer review and by a solid peer-review only, good design
decisions can be made. So they “beg” for the bad news.
</p>

 <p>
A great programmer will tend to not trust their own code until they’ve
tested it extensively. Having said that, they also have the ability to
understand market dynamics and the need to ship the product at the
earliest. So they have the ability to make both quick and dirty hacks
and elegant and refined solutions, and the wisdom to choose which is
appropriate for a given situation at hand.
</p>

 <p>
Some lesser programmers will lack the extreme attention to detail
necessary for some problems. Others are stuck in perfectionist mode.
Great programmers balance the two with perfect precision.
</p>
</div>
 <h2>They have great intuition.  <a id="they-have-great-intuition." class="anchor" href="#they-have-great-intuition." aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-they-have-great-intuition.">
 <p>
In the sixth book of  <i>The Nicomachean Ethics</i>, the famous philosopher
and statesman _Aristotle_discusses the fourth of five capabilities
people need to have for attaining true knowledge and thus becoming
successful in whatever they do: intuition.
</p>

 <p>
 <i>Aristotle</i>’s point is simple. Intuition is the way we start knowing
everything and knowledge gained by intuition must anchor all other
knowledge. In fact, this way of gaining knowledge is so foundational
that justification is impossible. That’s because knowledge by intuition
is not based on a series of facts or a line of reasoning to a
conclusion.
</p>

 <p>
Instead, we know intuitional truth simply by the process of
introspection and immediate awareness. From Steve Jobs to Richard
Branson to Warren Buffet, the intuitives are generally successful in
whatever they do, because they can see things more clearly and find the
best solutions to problems more quickly than others. No doubt, all these
individuals have a huge storage of expert knowledge and experience.
</p>

 <p>
But they also seem to have an abundance of intuition that comes
naturally to them and which enables them to grasp the essence of
complicated problems and find uncannily right solutions. Great
programmers typically display an intuitive understanding of algorithms,
technologies, and software architecture based on their extensive
experience and good development sense. They have the ability to
understand at a glance what tools in their arsenal best fit the problem
at hand.
</p>

 <p>
And their intuitive abilities extend well beyond development and coding.
This makes them highly versatile in articulating both technical and
non-technical problems with both a layman and a specialist audience.
</p>

 <p>
They are visionaries and they love challenges and will often seek to
break their own code (before others do) in their pursuit of excellence.
</p>
</div>
 <h2>They are master communicators.  <a id="they-are-master-communicators." class="anchor" href="#they-are-master-communicators." aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-they-are-master-communicators.">
 <p>
To get your ideas across, you need to make it simple and communicate as
unambiguously as possible. Sounds simple? Isn’t it? Damien Filiatrault
has rightly said:
</p>

 <blockquote>
 <p>
Good communication skills directly correlate with good development
skills.
</p>
</blockquote>

 <p>
But unfortunately, this lack of clarity is the root cause of all
troubles at work. And this is because of a phenomenon called the Curse
of Knowledge. In 1990, a Stanford University graduate student in
psychology named Elizabeth Newton illustrated the curse of knowledge by
studying a simple game in which she assigned people to one of two roles:
“tapper” or “listener.”
</p>

 <p>
Each tapper was asked to pick a well-known song, such as “Happy
Birthday” and tap out the rhythm on a table. The listener’s job was to
guess the song. Over the course of Newton’s experiment, 120 songs were
tapped out. Listeners guessed only three of the songs correctly: a
success ratio of 2.5%.
</p>

 <p>
But before they guessed, Newton asked the tappers to predict the
probability that listeners would guess correctly. They predicted 50%.
The tappers got their message across one time in 40, but they thought
they would get it across one time in 2.
</p>

 <p>
his favourite IDE and using a dark editor color scheme.
 <img loading="lazy" alt="" style="" src="https://res.cloudinary.com/dehs6irlh/image/upload/v1600515371/jjba-site/blog/great-programmer/software-developer_nevets.jpg"></img></p>

 <p>
Why did this happen? When a tapper taps, it is impossible for her to
avoid hearing the tune playing along to her taps. Meanwhile, all the
listener can hear is a kind of bizarre Morse code. Yet the tappers were
flabbergasted by how hard the listeners had to work to pick up the tune.
The problem is that once we know something — say, the melody of a song
— we find it hard to imagine not knowing it.
</p>

 <p>
Our knowledge has “cursed” us. We have difficulty sharing it with others
because we cannot readily re-create their state of mind. That is why
great programmers always confirm after communicating the message to the
team.
</p>

 <p>
They also can understand problems clearly, break them down into
hypotheses and propose solutions cohesively. They understand concepts
quickly or ask the right questions to understand, and above all, they
don’t need every small bit to be written down in a document.
</p>

 <p>
So if you want to become a great programmer, you need to make sure there
is effective communication between you and your team. This not only
keeps you at a higher plane of commitment but also shows your superiors
that you are genuinely interested and invested in delivering a quality
product.
</p>
</div>
 <h2>Last thoughts  <a id="last-thoughts" class="anchor" href="#last-thoughts" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-last-thoughts">
 <p>
So as you can see here, to be the best-of-class in your field, you don’t
need any fancy degrees or even money to invest. All you need is an
attitude to learn, be insanely curious and an intuitive ability to
connect things based on the knowledge gained by you over the years.
</p>

 <p>
Also important is the need to cultivate a healthy positive attitude,
ditching that ego and have a tolerance to take and act on feedback. Once
you do all this, I promise you will achieve greatness. As Bob Marley
stated:
</p>

 <blockquote>
 <p>
The greatness of a man is not in how much wealth he acquires, but in his
integrity and his ability to affect those around him positively.
</p>
</blockquote>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <a class="jfw-article-neighbour is-previous" href="/https/jointhefreeworld.org/blog/articles/go/make-or-new/" rel="prev"> <span class="jfw-article-neighbour-label">previous</span> <span class="jfw-article-neighbour-title">Make or New ?</span></a>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/freebsd/running-postgresql-on-freebsd/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">Running PostgreSQL on FreeBSD</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/a-great-programmer/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/a-great-programmer/index.html</guid>
  <pubDate>Sat, 19 Sep 2020 01:00:00 +0200</pubDate>
</item>
<item>
  <title>Make or New ?</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
This is a post about Go’s built in  <code>make</code> and  <code>new</code> functions.
</p>

 <p>
As Rob Pike noted at Gophercon on 2014, Go has many ways of initialising
variables. Among them is the ability to take the address of a struct
literal which leads to several ways to do the same thing.
</p>

 <pre class="example" id="org29c233a">
s := &amp;SomeStruct{}
v := SomeStruct{}
s := &amp;v              // identical
s := new(SomeStruct) // also identical
</pre>

 <p>
It is fair that people point out this redundancy in the language and
this sometimes leads them to search for other inconsistencies, most
notably the redundancy between  <code>make</code> and  <code>new</code>. On the surface it
appears that  <code>make</code> and  <code>new</code> do very similar things, so what is the
rationale for having both ?
</p>
 <h2>Why can’t we use make for everything ?  <a id="why-cant-we-use-make-for-everything" class="anchor" href="#why-cant-we-use-make-for-everything" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-why-cant-we-use-make-for-everything">
 <p>
Go does not have user defined generic types, but it does have several
built in types that can operate as generic lists, maps, sets, and
queues; slices, maps and channels.
</p>

 <p>
Because  <code>make</code> is designed to create these three built in generic types,
it must be provided by the runtime as there is no way to express the
function signature of  <code>make</code> directly in Go.
</p>

 <p>
Although  <code>make</code> creates generic slice, map, and channel values, they are
still just regular values;  <code>make</code> does not return pointer values.
</p>

 <p>
If  <code>new</code> was removed in favour  <code>make</code>, how would you construct a pointer
to an initialised value ?
</p>

 <pre class="example" id="orga251a08">
var x1 *int
var x2 = new(int)
</pre>

 <p>
x1 and x2 have the same type,  <code>*int</code>, x2 points to initialised memory
and may be safely de-referenced, the same is not true for x1.
</p>
</div>
 <h3>Why can’t we use new for everything ?  <a id="why-cant-we-use-new-for-everything" class="anchor" href="#why-cant-we-use-new-for-everything" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-why-cant-we-use-new-for-everything">
 <p>
Although the use of  <code>new</code> is rare, its behaviour is well specified.
</p>

 <p>
 <code>new(T)</code> always returns a  <code>*T</code> pointing to an initialised  <code>T</code>. As Go
doesn’t have constructors, the value will be initialised to T‘s zero
value.
</p>

 <p>
Using  <code>new</code> to construct a pointer to a slice, map, or channel zero
value works today and is consistent with the behaviour of  <code>new</code>.
</p>

 <pre class="example" id="org7cc5044">
s := new([]string)
fmt.Println(len(*s))  // 0
fmt.Println(*s == nil) // true

m := new(map[string]int)
fmt.Println(m == nil) // false
fmt.Println(*m == nil) // true

c := new(chan int)
fmt.Println(c == nil) // false
fmt.Println(*c == nil) // true
</pre>
</div>
 <h3>Sure, but these are just rules, we can change them, right ?  <a id="sure-but-these-are-just-rules-we-can-change-them-right" class="anchor" href="#sure-but-these-are-just-rules-we-can-change-them-right" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-sure-but-these-are-just-rules-we-can-change-them-right">
 <p>
For the confusion they may cause,  <code>make</code> and  <code>new</code> are consistent;
 <code>make</code> only makes slices, maps, and channels,  <code>new</code> only returns
pointers to initialised memory.
</p>

 <p>
Yes,  <code>new</code> could be extended to operate like  <code>make</code> for slices, maps and
channels, but that would introduce its own inconsistencies.
</p>

 <ol class="org-ol"> <li> <code>new</code> would have special behaviour if the type passed to  <code>new</code> was a
slice, map or channel. This is a rule that every Go programmer would
have to remember.</li>

 <li>For slices and channels,  <code>new</code> would have to become variadic, taking
a possible length, buffer size, or capacity, as required. Again more
special cases to have to remember, whereas before  <code>new</code> took exactly
one argument, the type.</li>

 <li> <p>
 <code>new</code> always returns a  <code>*T</code> for the  <code>T</code> passed to it. That would mean
code like
</p>

 <p>
func Read(buf []byte) []byte // assume new takes an optional length
buf := Read(new([]byte, length))
</p></li>
</ol> <p>
would no longer be possible, requiring more special cases in the grammar
to permit  <code>*new([]byte, length)</code>.
</p>
</div>
 <h3>In summary  <a id="in-summary" class="anchor" href="#in-summary" aria-label="Link to this section">#</a></h3> <div class="outline-text-3" id="text-in-summary">
 <p>
 <code>make</code> and  <code>new</code> do different things.
</p>

 <p>
If you are coming from another language, especially one that uses
constructors, it may appear that  <code>new</code> should be all you need, but Go is
not those languages, nor does it have constructors.
</p>

 <p>
My advice is to use  <code>new</code> sparingly, there are almost always easier or
cleaner ways to write your program without it.
</p>

 <p>
As a code reviewer, the use of  <code>new</code>, like the use of named return
arguments, is a signal that the code is trying to do something clever
and I need to pay special attention. It may be that code really is
clever, but more than likely, it can be rewritten to be clearer and more
idiomatic.
</p>
</div>
 <nav class="jfw-article-neighbours" aria-label="More articles"> <span></span>
 <a class="jfw-article-neighbour is-next" href="/https/jointhefreeworld.org/blog/articles/development/a-great-programmer/" rel="next"> <span class="jfw-article-neighbour-label">next</span> <span class="jfw-article-neighbour-title">A Great Programmer</span></a>
</nav> <section class="jfw-related" aria-label="Related reading"> <h2 class="jfw-related-title">related reading</h2>
 <ul class="jfw-related-list"> <li> <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a></li>
 <li> <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a></li>
</ul></section></div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/make-or-new/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/make-or-new/index.html</guid>
  <pubDate>Sat, 19 Sep 2020 01:00:00 +0200</pubDate>
</item>
<item>
  <title>CI / CD</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-01-16 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/ci/shared-libraries-with-jenkins/">Shared Libraries with Jenkins</a>
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/ci/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/ci/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Development</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-10-12 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/where-hexagonal-architecture-shines/">Where hexagonal architecture shines, and what to reach for instead</a> - Ports and adapters pays where the domain is the complicated part. Here is how it looks in Kotlin with Spring, in Guile Scheme and in Haskell, and when MVC, KISS and CQRS are the better answer.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-06-01 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/agile-manifesto/">Manifesto for Agile Software Development</a> - We are uncovering better ways of developing software by doing it and helping others do it. This document should help refresh you on what Agile truly is about.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-02-03 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/dont-reward-the-best-firefighter/">Don't Reward the Best Firefighter</a> - For every loud firefighter, there's an invisible fire preventer. This is the engineer who spends a month refactoring a messy legacy service that no one else wants to touch.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-12-05 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/most-technical-problems-are-people-problems/">Most Technical Problems are People Problems</a> - You cannot clean up technical debt without first addressing the people, process, and politics that created it.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/getting-rid-of-git-history/">Git Riddance</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/hexagon-of-doom/">Hexagon of Doom - The Cost of Over-Abstraction and Indirection</a> - Let me explain why I think Ports&amp;Adapter / Hexagonal architecture introduces net harm to software projects.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/tech-radar/">The FREE stack - My Tech Radar</a> - The FREE stack as a tech radar: what I adopt, trial, assess and deprecate across languages, frameworks, data, tools, platforms and practice.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-09-15 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/simple-markdown-cheatsheet/">Markdown Cheat-sheet for Beginners</a> - Markdown is a simple, lightweight markup language used for formatting plain text. It's designed to be easy to read and write, and it can be converted into HTML, PDF, LaTEX and many other formats.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-04-11 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/best-programmers/">The Best Programmers I Know</a> - I have met a lot of developers in my life. Lately, I asked myself: &quot;What does it take to be one of the best? What do they all have in common?&quot;
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-02-26 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/black-box-testing/">Black Box Testing in modern Software</a> - Testing software at a high level means freedom of implementation and refactoring, while maintaining guarantees of correctness.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-09-21 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/german-naming-convention/">German naming convention</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-08-29 Sun&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/breaking-free-of-javascript/">Breaking free of Javascript</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-02-27 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/sql-select-all/">Why SQL SELECT * is often a bad idea</a> - Doing a SELECT * may seem like a time-saver, but it's actually setting you up for problems in the long run, especially when the database schema changes.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-01-31 Sun&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/ssr-wins-over-javascript/">SSR wins over Javascript</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-09-18 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/development/a-great-programmer/">A Great Programmer</a>
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/development/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/development/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Emacs</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
Learn how to setup your favourite text editor, Emacs, as a super powerful and capable Scala IDE (integrated development environment) with the latest and most performant approach.
</p>

 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-10-23 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/">Emacs finally folds to my liking</a> - Emacs finally folds to my liking ... and understands what folds are in many languages and modes.. this really feels like absolute power and overview capability.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-07-20 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-eglot-scala-kotlin/">Emacs Eglot for Scala and Kotlin (JVM)</a> - Enjoy Emacs and its built-in language server (LSP) superpowers, for JVM languages. Let's walk through basic language setups, specialized workspace configuration handling, and dive deep into some advanced JSON-RPC and advice-based workarounds for Scala (Metals) and Kotlin that make development truly seamless from Emacs and liberate you from IntelliJ ☺️.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-06-30 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/build-emacs-from-source/">Hacking Freedom: Compiling GNU Emacs from Source</a> - By compiling GNU Emacs directly from the upstream Savannah repositories, you unlock the absolute bleeding edge of the extensible, self-documenting operating system disguised as a text editor.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-12-04 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/yaml-schemas-in-emacs-eglot/">YAML Schemas in Emacs with Eglot</a> - Are you editing YAML files and would like to use JSON schemas for YAML in Emacs?
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-08-13 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-registers/">Emacs registers - a god-send for your day job</a> - Ever had to work on very long files in projects you are not familiar with, and felt lost without an anchor point? Enter Emacs and its register system, which lets you &quot;bookmark&quot; locations in a file (buffer) and jump back to them, and much, much more!
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2023-04-28 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-for-absolute-begginners/">Emacs for absolute beginners</a> - In this article, I'm going to give you exactly what you need to get started using Emacs and understand the basic concepts and key bindings of the editor.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2023-04-26 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/emacs/emacs-and-scala-setup-with-eglot/">Emacs and Scala setup with Eglot</a>
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/emacs/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/emacs/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>FreeBSD</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-12-02 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/rcd-scripting/">rc.d scripting</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-09-17 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/pkg-or-ports/">pkg or ports ?</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-08-31 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/practical-rcd-scripting-and-go/">Practical rc.d scripting and Go</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-08-31 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/updating-freebsd-in-iocage/">Updating FreeBSD in iocage</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-11-19 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/jails-with-a-loopback-ip/">Jails with a loopback IP</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-11-19 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/root-on-zfs-with-partitions/">Root on ZFS with partitions</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-09-19 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/freebsd/running-postgresql-on-freebsd/">Running PostgreSQL on FreeBSD</a>
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/freebsd/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/freebsd/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>GNU/Linux</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-08-28 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/quest-for-eternal-dock/">Quest for the eternal Dock - lambdock</a> - How embedding a Lisp engine created an infinitely extensible program for your daily usage and workflow improvement, Guile Scheme + C + GTK4 built the dock Wayland was waiting for, after many failed prototypes and effort.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/increase-the-file-descriptor-limit-on-gnu-linux/">Increase the file descriptor count in GNU/Linux</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-03-04 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/sway-guix-fully-lisp-configuration/">Moving from Sway to Hyprland - Archived SwayFX config</a> - After using Sway as my daily Wayland compositor for quite some time, I recently made the switch to Hyprland. The decision wasn't made lightly, as Sway, especially with the SwayFX fork, served me well.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-02-17 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/conky-wayland-guix/">Building Conky with Wayland Support on GNU Guix</a> - Since I use GNU Guix and run a Wayland-based environment (Sway), I wanted to get Conky building with Wayland support.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-02-04 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/legendary-lisp-laptop/">Legendary Lisp Laptop - a modern Lisp machine with Framework laptop</a> - A modern Lisp machine built on a Framework laptop.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-12-09 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/podman-root-less-guix/">Podman root-less setup on GNU Guix</a> - By leveraging Podman, a daemonless container engine, we can achieve rootless containerization, enhancing security and flexibility with Guix.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2023-11-02 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-nixos-with-web-based-saml/">Open VPN 3 on NixOS with Web-based SAML</a> - Learn how to install and configure the OpenVPN 3 client on NixOS, in a reproducible way.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2023-08-25 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/windows-11-bootable-usb-from-gnu-linux/">Create a Windows 11 bootable USB from GNU Linux</a> - procedure for creating a bootable USB flash drive with Windows 11. The same process should also work with any HDD/SSD connected to your system.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2023-08-18 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/openvpn3-on-voidlinux/">Open VPN 3 on Void Linux</a> - Learn how to build OpenVPN 3 from source code and install it on Void Linux, for SAML VPN auth.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-12-21 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/arch-linux-uefi-encryption/">Arch Linux UEFI + Encryption</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-12-21 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/gnu-linux/gnu-guix-virtual-machine-image-aarch64/">GNU Guix VM aarch64</a> - The Guix ISO installer didn't work for me on aarch64. Making a qcow2 VM image or doing a manual install did work.
</p>
 <h2>🔗 Elsewhere  <a id="-elsewhere" class="anchor" href="#-elsewhere" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-orgf071a4b">
 <p>
Kept by hand, because this is not an article of this blog.
</p>

 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-12-03 Tue&gt;</span></span>  <a href="https://guix.gnu.org/blog/2018/multi-dimensional-transactions-and-rollbacks-oh-my/">How Guix enables multi-dimensional rollbacks and more reproducibility!</a>
</p>
</div>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/gnu-linux/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/gnu-linux/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Go</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-09-29 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/how-i-write-http-services/">How I write HTTP services</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-09-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/project-structure/">Project Structure</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-09-16 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/sql-transactions/">SQL transactions</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-01-26 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/opinionated-style-guide/">Opinionated Style Guide</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-11-13 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/file-descriptors-and-go/">File Descriptors and Go</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-10-04 Sun&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/zen-of-go/">Zen of Go</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-10-02 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/tips-for-clean-code-with-go/">Tips for clean code with Go</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2020-09-18 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/go/make-or-new/">Make or New ?</a>
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/go/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/go/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Haskell</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-04-20 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/haskell/free-alacarte/">Free à la Carte</a> - Modeling effects with free monads in a simple and composable way with Haskell. Checkout my custom library and how to use it.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2022-10-10 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/haskell/running-hoogle-locally/">Running Hoogle locally</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2022-09-12 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/haskell/type-safety-back-and-forth/">Type safety back and forth</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2022-09-10 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/haskell/why-haskell-is-important/">Why Haskell is important?</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2021-08-21 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/haskell/haskell-in-production-at-foxdown-systems/">Haskell in Production at Foxdown Systems</a> - Haskell is the first programming language Foxdown reaches for when we build production software systems.
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/haskell/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/haskell/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Lisps</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-12-02 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/">Sift: the Lisp formatter I kept trying to write (+lint +LSP)</a> - an idempotent formatter, a rule-based linter and a language server, for Scheme, Racket, Emacs Lisp and Common Lisp
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-10-23 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/orgwebalchemy-benchmarking-profiling-and-org-support/">OrgWebAlchemy: Benchmarking, Profiling, and the Long Road to Real Org Support</a> - OrgWebAlchemy now renders Markdown, understands figures, named elements and real table rows, and got up to 6x faster. This is the story of the profiling that found a quadratic collapse pass and a per-character scanner, what changed, and the numbers measured before and after.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-09-24 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/parsing-expression-grammar-lisp-org-convert-to-html/">Parsing Expression Grammar in Lisp: Converting Org to HTML with (ice-9 peg) in Guile</a> - Converting Org to HTML with (ice-9 peg) in Guile: OrgWebAlchemy
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-07-14 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/maak/">Maak: The power of Lisp that powers your trusty command runner and the enlightenments</a> - The infinitely extensible command runner, control plane and project automator à la Make (Guile Scheme - Lisp)
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-06-03 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/scriba-structured-logging-library-in-lisp/">Scriba v0.3.3 - Structured Logging in Lisp</a> - Scriba is a structured logging library for GNU Guile that prioritizes flexibility and observability. It provides modular log routing, formatting, and filtering, allowing developers to generate human-readable console logs during development and machine-readable JSON logs for production environments.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-04-28 Tue&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/">Why I Still Reach for Scheme and Lisp Instead of Haskell</a> - Scheme (and Lisp) lets you express complex systems and problem domains in simpler terms than any other language can. For all its brilliance, Haskell resists most of the attempts people make to just hack and write useful code quickly.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-04-10 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/functional-repository-pattern-in-scheme-with-macros/">Functional repository pattern in Scheme? Decoupling and abstracting the data layer in Lisp</a> - Decoupling and abstracting the data layer in Lisp. Implementing the Repository Pattern with Hygienic Macros in Scheme.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/embracing-the-eternal-sexp-wisdom-of-the-gnu/">Embracing the eternal Sexp wisdom with the GNU</a> - I have recently reached new heights in declarative configurations of operating systems, programs and my workflow ⚙️ and development.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-27 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/taming-complexity-with-scheme-the-byggsteg-story/">Taming Complexity with Scheme: The Byggsteg Story</a>
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-06-26 Thu&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisps-are-great-for-production/">Scheme and Lisps are Great for production</a> - &quot;Why bother with Scheme/Lisp?&quot; is a classic question, with countless valid answers. While I can't list them all exhaustively, I will try to explain my motivation.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-04-11 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/why-i-program-in-lisp/">Why I Program in Lisp?</a> - Why choose for this paren-heavy form of lambda calculus? Lisp is a language that was designed to be used as a tool for thinking about problems, and that is the fun part of programming.
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-12-18 Wed&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/lisps/scheme-and-lisp-style-guide/">Scheme &amp; Lisp Style Guide</a> - Riastradh's Lisp Style Rules for some really clean Scheme, Lisp and Guile code.
</p>
 <h2>🔗 Elsewhere  <a id="-elsewhere" class="anchor" href="#-elsewhere" aria-label="Link to this section">#</a></h2> <div class="outline-text-2" id="text-org4175f2c">
 <p>
Kept by hand, because this is not an article of this blog.
</p>

 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-12-02 Mon&gt;</span></span>  <a href="https://artanis.dev/blog/why-to-port-to-artanis.html">Why port web Scheme applications to the amazing GNU Artanis framework?</a>
</p>
</div>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/lisps/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/lisps/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Personal</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2026-06-20 Sat&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/personal/jointhefreeworld-documentation-style-guide/">jointhefreeworld - A Style Guide for Documentation</a> - This style guide will help you write better documentation, manuals, tutorials and READMEs
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-10-19 Sun&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/personal/josep-astrology-by-metsatron/">Mètsàtron's astral analysis of Joe's being</a> - My brother from another mother, ⁨Mètsàtron Sucurí Jibōia⁩ did some astral and digital readings about me (Joe).
</p>
 <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2024-06-17 Mon&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/personal/brief-aan-mijzelf/">Brief aan mijzelf</a> - Jij en ik weten dat levend zijn pieken en dalen betekent.
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/personal/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/personal/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
<item>
  <title>Rust</title>
  <description><![CDATA[<div id="content" class="content" tabindex="-1"> <p>
 <span class="timestamp-wrapper"> <span class="timestamp">&lt;2025-11-14 Fri&gt; </span></span>  <a href="/https/jointhefreeworld.org/blog/articles/rust/simple-guix-emacs-rust-development-environment/">Simple Rust Guix Emacs development environment</a> - A minimal, declarative setup for productive Rust hacking with Emacs and Guix.
</p>
</div>]]></description>
  <link>https://jointhefreeworld.org/blog/articles/rust/index.html</link>
  <guid isPermaLink="false">https://jointhefreeworld.org/blog/articles/rust/index.html</guid>
  <pubDate>Thu, 01 Jan 1970 01:00:00 +0100</pubDate>
</item>
</channel>
</rss>
