{"@attributes":{"version":"2.0"},"channel":{"title":"Matthias Endler","link":"https:\/\/endler.dev","description":"Consultant at corrode.dev. Likes just-in-time compilers and hot chocolate","generator":"Zola","language":"en","lastBuildDate":"Thu, 05 Nov 2026 00:00:00 +0000","item":[{"title":"Wrong Ways To Create Strings","pubDate":"Thu, 05 Nov 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/wrong-ways-to-create-strings\/","guid":"https:\/\/endler.dev\/2026\/wrong-ways-to-create-strings\/","description":"<p>I\u2019m on my way back from RustLab 2026, where I gave a lightning talk about all the ways to create a <code>String<\/code> in Rust that don\u2019t involve <code>String::new<\/code>.\nThe talks were not recorded, so I decided to write it up as a blog post.<\/p>\n<h2 id=\"collect-some-characters\"><a class=\"anchor\" href=\"#collect-some-characters\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Collect Some Characters<\/h2>\n<p>One of the most obvious ways to create a string without calling <code>String::new<\/code> is to collect some characters into a string:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-5 z-d-7\">f<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">e<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">s<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Alternatively, you can start with the UTF-8 bytes:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_utf8<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">102<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 101<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 114<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 114<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 105<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 115<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><h2 id=\"derive-debug\"><a class=\"anchor\" href=\"#derive-debug\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Derive Debug<\/h2>\n<p>If we derive <code>Debug<\/code> for an enum, we can format a variant as a string.\nNote that debug output isn\u2019t a stable serialization format, so this just happens to work for this particular string.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">allow<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">non_camel_case_types<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">derive<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Debug<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">enum<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Mascot<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    ferris<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:?<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Mascot<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>ferris<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><h2 id=\"use-a-cstring\"><a class=\"anchor\" href=\"#use-a-cstring\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Use a CString<\/h2>\n<p>This is another very obvious one: we can use <code>CString<\/code> to create a string with a NUL terminator, then convert it back to a <code>String<\/code>.\nConverting it back removes the terminator and checks that the remaining bytes are valid UTF-8.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ffi<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">CString<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><h2 id=\"use-unwrap-err\"><a class=\"anchor\" href=\"#use-unwrap-err\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Use <code>unwrap_err<\/code><\/h2>\n<p>If we supply an invalid string to <code>CString::new<\/code>, it will return an error instead of panicking.\nWe can abuse that fact and call <code>unwrap_err()<\/code> on the result to get the error, which <strong>gives us the rejected bytes back<\/strong>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> bytes<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ffi<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">CString<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">b<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-15 z-d-13\">\\<\/span><span class=\"z-l-15 z-d-13\">0<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_vec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap_err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_vec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>All we have to do now is remove the invalid NUL byte we added:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span>bytes<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">pop<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Now we can convert each byte back to a character.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> bytes<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">char<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>from<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p><code>char::from(u8)<\/code> is safe because every <code>u8<\/code> value (0\u2013255) corresponds to a valid Unicode character.\nIt does not decode UTF-8; it simply converts each byte into a Unicode code point.\nWhen collecting these characters into a <code>String<\/code>, Rust automatically encodes them as valid UTF-8.\nTherefore, the conversion cannot fail, but the resulting text may be incorrect if the original bytes represented multibyte UTF-8 characters.<\/p>\n<h2 id=\"statically-include-some-text-with-include-str\"><a class=\"anchor\" href=\"#statically-include-some-text-with-include-str\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Statically include some text with <code>include_str!<\/code><\/h2>\n<p>Create a file called <code>file.rs<\/code> containing exactly <code>ferris<\/code>, without a trailing\nnewline.\nIn another Rust file, we can include that text at compile time:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> include_str!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">file.rs<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_owned<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>The extension doesn\u2019t matter.\n<code>include_str!<\/code> embeds the file as UTF-8 text at compile time; it doesn\u2019t try to parse it as Rust.<\/p>\n<h2 id=\"thread-shenanigans\"><a class=\"anchor\" href=\"#thread-shenanigans\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Thread Shenanigans<\/h2>\n<p>Threads can have names, and we can read the name of the current thread.\nWe can abuse that to create a string by naming a thread and then reading its name from another thread.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> builder<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">thread<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Builder<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">name<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_owned<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Then let it read its own name and send it back:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> builder<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">spawn<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">thread<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">current<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">name<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_owned<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> handle creation errors<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">join<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> wait for the thread to finish<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> handle a panic in the thread<\/span><\/span><\/code><\/pre>\n<p>The name is borrowed from the thread handle; that\u2019s why we copy it into an owned string.<\/p>\n<h2 id=\"ask-another-process\"><a class=\"anchor\" href=\"#ask-another-process\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Ask Another Process<\/h2>\n<p>Instead of threads, you can also spawn a child process and read its output.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">process<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Command<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args_os<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">any<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>arg<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> arg<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">--child<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        return<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> child<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Command<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">current_exe<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">arg<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">--child<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">output<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    assert!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>child<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>status<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">success<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_utf8<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>child<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">stdout<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The child prints the string and exits.\nThe parent waits for it, checks its exit status, and converts the captured stdout into a <code>String<\/code>.<\/p>\n<h2 id=\"store-it-in-a-float\"><a class=\"anchor\" href=\"#store-it-in-a-float\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Store It in a Float<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> crab<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> f64<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_bits<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">0x0000_7369_7272_6566<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Those bits, read as little-endian bytes, are <code>['f', 'e', 'r', 'r', 'i', 's', 0, 0]<\/code>.\nWe can use <code>from_bits<\/code> to avoid the numeric conversion of these bytes.<\/p>\n<p>Now extract the characters and discard the two padding bytes:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span>f<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> e<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> r1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> r2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> i<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> s<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> ..<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> crab<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_bits<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_le_bytes<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">char<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>from<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">f<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">e<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">r1<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">r2<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">s<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Note how I use <code>r1<\/code> and <code>r2<\/code> here.\nThat\u2019s because these are two separate variables, not characters.\nUsing <code>to_le_bytes()<\/code> makes this independent of the machine\u2019s byte order.<\/p>\n<p>All we have to do is format the variables back into a string.<\/p>\n<h2 id=\"assemble-a-string-from-raw-parts\"><a class=\"anchor\" href=\"#assemble-a-string-from-raw-parts\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Assemble a String From Raw Parts<\/h2>\n<p>A <code>String<\/code> in Rust is just a pointer to a heap allocation, along with a length and capacity.\nWe can manually create an instance of that type, but we have to be careful to get the layout, length, capacity, and UTF-8 validity right ourselves.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> crab<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span class=\"z-l-5 z-d-7\">b<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> pointer<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_raw<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>crab<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cast<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> unsafe<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_raw_parts<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>pointer<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 6<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 6<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p><code>Box::into_raw<\/code> gives up ownership without freeing the allocation.\nThe <code>String<\/code> takes over and will free it when dropped.<\/p>\n<h2 id=\"using-the-type-name\"><a class=\"anchor\" href=\"#using-the-type-name\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Using the Type Name<\/h2>\n<p>Every type in Rust has a name.\nWe can use <code>std::any::type_name<\/code> to get the name of a type as a string.\nSo if we create a type with the string we want, we can get that string back from the type name.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">allow<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">non_camel_case_types<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span> ferris<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> name<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">any<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">type_name<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>ferris<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>The name can include the module path, so we take the last component, then \u201cparse\u201d it as a string:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> result<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> name<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">rsplit<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">::<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">next<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">String<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Note that <code>type_name<\/code> does not have a stable naming API, so the exact output is unspecified.<\/p>\n<h2 id=\"deliver-it-through-a-panic\"><a class=\"anchor\" href=\"#deliver-it-through-a-panic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Deliver It Through a Panic<\/h2>\n<p>Maybe one of my favorite ways to create a string is to panic with it and catch the panic.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-13 z-d-15\">std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">panic<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">catch_unwind<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">    std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">panic<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">panic_any<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">ferris<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap_err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">downcast<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">String<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>That works because the panic carries an owned <code>String<\/code>.\nCatching it gives us the payload, downcasting gives us a <code>Box&lt;String&gt;<\/code>, and dereferencing moves the string out of the box.<\/p>\n<p>This requires <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/nomicon\/unwinding.html\">unwinding<\/a>.\nWith <code>panic = \"abort\"<\/code>, the process would just exit instead.<\/p>\n<h2 id=\"use-only-padding\"><a class=\"anchor\" href=\"#use-only-padding\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Use Only Padding<\/h2>\n<p><code>format!<\/code> is one of the most powerful macros in the Rust standard library.\nIt supports \u201cformat specifiers\u201d that let you control how the output is formatted in exactly the way you want.<\/p>\n<p>One feature is <code>&gt;<\/code>, which right-aligns the output and pads it with a fill character.\nThe character before <code>&gt;<\/code> in a format specifier is the fill character.\nThe number is the minimum width:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> hello<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">hello<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">assert_eq!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">hello:o&gt;10<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">ooooohello<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Knowing this, we can completely abuse specifiers to pad an empty string with each letter we need.\nArgument <code>0<\/code> lets us reuse the same empty string:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> ferris<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">0:f&gt;1<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">0:e&gt;1<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">0:r&gt;2<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">0:i&gt;1<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">0:s&gt;1<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>So we take an empty string and pad it with <code>f<\/code>, then <code>e<\/code>, then <code>r<\/code> twice, then <code>i<\/code>, then <code>s<\/code>.\nI like how we use <code>r&gt;2<\/code> to get two <code>r<\/code>s instead of writing <code>r&gt;1<\/code> twice like a peasant.<\/p>\n<h2 id=\"that-was-fun\"><a class=\"anchor\" href=\"#that-was-fun\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>That was fun!<\/h2>\n<p>This little exercise is not completely useless.\nTrying to solve a familiar problem in an unfamiliar way can teach you something new.<\/p>\n<p>One more way I didn\u2019t have the time to show in the talk is to use <code>rand<\/code> to extract random bytes from memory and hope they form the string you want.\nApart from that, did I forget an interesting way to create a string?\nLet me know on <a rel=\"external\" href=\"https:\/\/mastodon.social\/@mre\">Mastodon<\/a>.<\/p>\n<p>You might also like my 2023 RustLab lightning talk on <a href=\"\/2023\/cursed-rust\">Printing Things The Wrong Way<\/a>.<\/p>\n"},{"title":"Why I Still Believe in Mentorship","pubDate":"Sun, 13 Sep 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/why-i-still-believe-in-mentorship\/","guid":"https:\/\/endler.dev\/2026\/why-i-still-believe-in-mentorship\/","description":"<p>One of the best tips I ever got was from my table tennis coach.\nHe watched me play and said, \u201cYou are leaning forward with the wrong foot!\u201d\nI\u2019d been playing for years and thought I had a good stance.\nI\u2019m left-handed, and no one had told me that I should put my right foot forward.\nI had copied the stance of other players without noticing the problem.<\/p>\n<p>It was obvious once he pointed it out.\nBut until then, I hadn\u2019t thought to question it, and more practice hadn\u2019t helped me notice.\nThat single observation improved my game more than any amount of practice because it gave me better control over my forehand play.<\/p>\n<p>Note that I didn\u2019t actively seek out advice on my stance.\nSomeone had to watch me play, observe, and then point out the single most helpful thing that would set me on the right path.<\/p>\n<h2 id=\"mentorship-in-software\"><a class=\"anchor\" href=\"#mentorship-in-software\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Mentorship in Software<\/h2>\n<p>In software, we are often expected to struggle alone.\nWe\u2019re supposed to learn systems design, architecture, testing, and refactoring largely by sitting with the problems.\nThe times when I grew the most as a programmer were through thoughtful code reviews, but they are rare.\nBesides, the reviewer sees the end result but not the (sometimes flawed) reasoning that produced it.<\/p>\n<p>Pair programming gets closer.\nBut two equally inexperienced programmers can reinforce each other\u2019s bad habits.<\/p>\n<p>An agent can control the keyboard instead of helping you reason through a problem.\nIt may produce better code without making you much better at writing it.\nA session where a machine fixes everything is productive, but being productive and growing as a programmer are two different things entirely.<\/p>\n<p>This is part of why I still believe in mentorship, even now that an LLM can answer so many programming questions.<\/p>\n<h2 id=\"going-beyond-the-superficial-questions\"><a class=\"anchor\" href=\"#going-beyond-the-superficial-questions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Going beyond the Superficial Questions<\/h2>\n<p>I run a one-on-one <a rel=\"external\" href=\"https:\/\/corrode.dev\/mentorship\/\">Rust mentorship program<\/a>, so I have a personal stake in this.\nMost of my mentees come with a concrete question:<\/p>\n<ul>\n<li>Would you make this generic?<\/li>\n<li>Is it okay to clone here?<\/li>\n<li>How can I handle this error?<\/li>\n<\/ul>\n<p>Often, answering the concrete question is beside the point.\nWe have to look at the thought process that led to it.<\/p>\n<p>That\u2019s related to the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/XY_problem\">XY problem<\/a> where a person is asking for help with a proposed solution rather than the underlying problem.\nWe might discuss how to make something generic before asking whether it <em>needs to vary at all<\/em>.<\/p>\n<p>A mentor has enough distance from the problem to question its framing and enough experience to recognize familiar patterns.\nThey notice which details you leave out, which patterns you reach for, and which you ignore.\nYou may <em>sense<\/em> that something is wrong without having the words to describe it.<\/p>\n<p>LLMs can question assumptions, too!\nBut I\u2019ve found they usually work best when you already know what to ask.\n<strong>It\u2019s hard to ask about a blind spot you haven\u2019t noticed.<\/strong><\/p>\n<p>You can also use an LLM to examine a decision, or you can use it as an echo chamber to justify it.\nThe second use may feel more rewarding in the moment, but it leaves you where you started.<\/p>\n<h2 id=\"mentoring-in-other-fields\"><a class=\"anchor\" href=\"#mentoring-in-other-fields\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Mentoring in Other Fields<\/h2>\n<p>Nobody is surprised when a professional athlete has a coach.\nMusicians keep taking lessons after decades of playing.<\/p>\n<p>We don\u2019t take this as evidence that they haven\u2019t learned the basics.\nQuite the contrary: it\u2019s an indication that they are serious about improving and that they\u2019ve outgrown generic advice.\nIt requires introspection to recognize that you can benefit from someone who can observe you from the outside.\nAnd in some sense, you put yourself in a vulnerable position: the wrong mentor can set you back, while the right one can dramatically accelerate your growth.<\/p>\n<p>Experience doesn\u2019t remove the need for mentoring in software either.\nYou can become an experienced developer while still carrying counterproductive habits you\u2019ve never examined.\nIf those habits let you get the work done, you may have little reason to suspect them and the problem gets worse because bad habits get reinforced.\nI could play table tennis with the wrong stance, too, just worse.<\/p>\n<p>The people I mentor are <em>already<\/em> experienced software engineers.\nThey are perfectly capable of using LLMs in their work.\nMany are in leading positions as staff or principal engineers.\nAnd yet, they\u2019ve realized there\u2019s something missing that\u2019s holding them back.\nThey feel like they\u2019re not progressing as quickly as they could, and their companies haven\u2019t provided the mentorship they need.<\/p>\n<h2 id=\"friction-is-part-of-the-learning-process\"><a class=\"anchor\" href=\"#friction-is-part-of-the-learning-process\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Friction Is Part of the Learning Process<\/h2>\n<p>Another problem is that software gives us very uneven feedback.\nA syntax error gets your attention immediately because the code won\u2019t compile.\nBut a poor architectural decision can compile, pass the tests, get approved in review, and become a major problem months later when you lack the time to make changes.<\/p>\n<p>One way to learn architecture is to make bad decisions and sit with their consequences.\nThat\u2019s how I learned!\nThe trouble is that it takes years, and it\u2019s certainly not motivating.<\/p>\n<p>A mentor can streamline that process by asking questions you may not think to ask yet:<\/p>\n<ul>\n<li>Is this abstraction really necessary?<\/li>\n<li>How would an error propagate across the system?<\/li>\n<li>How can we test this?<\/li>\n<\/ul>\n<p>There is no single \u201ccorrect\u201d answer to these questions.\nThe answers depend on the constraints and the stage of the project.\nA mentor should help you examine those constraints and point out risks you\u2019ve missed, while leaving the decision to you.\nIf someone else chooses the design, you lose the practice of choosing it yourself.<\/p>\n<p>You also still have to write the code and live with all the consequences.\nBut you go in with a better understanding of what might go wrong.\nAnd if it does, you have someone to help you work out why.\nThat is how you develop judgment you can use on the next project.\nIt\u2019s a bit like climbing with a partner.<\/p>\n<h2 id=\"does-everyone-need-a-mentor\"><a class=\"anchor\" href=\"#does-everyone-need-a-mentor\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Does Everyone Need a Mentor?<\/h2>\n<p>If you\u2019re just starting out, a book, a course, or a friendly community might be better value.\nIf you need an answer to an isolated question, documentation or an LLM is faster and cheaper.\nIf mentorship were only about transferring information, it would be harder to make a case for it.<\/p>\n<p>Personal mentorship becomes valuable when the potential payoff is a multiple of the investment.\nThat is typically the case in a professional setting, where focused mentorship can help you land a better job or switch to a different team with a more interesting project.<\/p>\n<p>That doesn\u2019t mean personal mentorship is a guarantee of success.\nOur busy days leave little time for deliberate practice.\nWe have to carve out time for learning, which is hard, but the alternative is stagnation.<\/p>\n<p>As with going to the gym, paying for help doesn\u2019t spare you the exercise.\nOne hour of conversation cannot make up for a week without practice.\nYou have to try things between sessions if you want the next conversation to be different from the last.\nEasier access to answers hasn\u2019t changed any of this.<\/p>\n<p>What I want from mentorship is the kind of help my coach gave me: someone paying enough attention to notice what I couldn\u2019t see for myself.<\/p>\n<p>That\u2019s what I aim to offer in my <a rel=\"external\" href=\"https:\/\/corrode.dev\/mentorship\/\">Rust mentorship<\/a>, at least: we work through hard problems together, explore the design space, and make deliberate choices.\nIf I do a good job, my mentee will eventually surpass me, and I\u2019d be proud to help them get there.<\/p>\n"},{"title":"Advice to Young Developers","pubDate":"Mon, 24 Aug 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/advice-to-young-developers\/","guid":"https:\/\/endler.dev\/2026\/advice-to-young-developers\/","description":"<p>Someone recently asked me what advice I\u2019d give to a young developer today.\nMy answer had surprisingly little to do with code. Here\u2019s what I\u2019d focus on:<\/p>\n<h2 id=\"learn-how-to-build-products\"><a class=\"anchor\" href=\"#learn-how-to-build-products\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Learn How to Build Products<\/h2>\n<p>Even if LLMs write most of the code, there is still a need for problem solvers who can understand user needs, design solutions, and iterate based on feedback.\nNo matter the technology, this skill will always be valuable.<\/p>\n<h2 id=\"learn-how-to-learn\"><a class=\"anchor\" href=\"#learn-how-to-learn\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Learn How to Learn<\/h2>\n<p>If information is free, the ability to think critically and make decisions based on data is a superpower.\nYou can run circles around those who just memorize facts and rely on \u201cpattern matching\u201d without taking the time to understand the underlying principles.<\/p>\n<h2 id=\"learn-how-to-communicate\"><a class=\"anchor\" href=\"#learn-how-to-communicate\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Learn How to Communicate<\/h2>\n<p>Being able to explain ideas and inspire others gives you a head start.\nThat way, you can multiply your impact by getting others to work with you rather than being a lone wolf.<\/p>\n<h2 id=\"be-a-problem-solver\"><a class=\"anchor\" href=\"#be-a-problem-solver\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Be a Problem Solver<\/h2>\n<p>If everyone has access to the same tools, what sets you apart is your ability to fix problems quickly and effectively.\nPick a problem, learn the domain, and create a fast feedback loop to iterate on solutions.\nIf you can solve problems faster than anyone else, you will be in high demand.<\/p>\n<h2 id=\"have-more-than-one-skill\"><a class=\"anchor\" href=\"#have-more-than-one-skill\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Have More than One Skill<\/h2>\n<p>If all you know is how to code, you will be easily replaceable.\nTry to apply your knowledge in a domain that interests you.\nIf you\u2019re interested in fitness, for example, you could combine your coding skills with knowledge of health and wellness.\nThat narrows the field of people you compete with.\nPick a field you\u2019re naturally drawn to and would enjoy exploring, even in your free time.\nIt\u2019s better to be driven and curious than just smart and dedicated.\nYour curiosity will keep you motivated longer than sheer willpower.<\/p>\n<h2 id=\"nothing-has-fundamentally-changed\"><a class=\"anchor\" href=\"#nothing-has-fundamentally-changed\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Nothing Has Fundamentally Changed<\/h2>\n<p>Mine was the last generation that could get a job just by knowing how to code, but in reality, it was never only about coding.\n<a href=\"\/2025\/best-programmers\/\">The best developers I know<\/a> have always been the ones who could understand the bigger picture, communicate effectively, and solve problems.\nWhat has changed recently is that the tools can do more than just generate boilerplate.\nWith the right guidance, these tools are powerful enough to replace much of the work that used to be done by coders.\nThat means being a good coder is no longer enough to stand out.\nYou have to develop those other muscles.<\/p>\n"},{"title":"GitHub Was Never about the Source Code","pubDate":"Mon, 17 Aug 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/github-was-never-about-the-source-code\/","guid":"https:\/\/endler.dev\/2026\/github-was-never-about-the-source-code\/","description":"<p>With GitHub down once again, I decided to write this long-overdue blog post.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/github-was-never-about-the-source-code\/github-down.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/github-was-never-about-the-source-code\/github-down.jpg\" alt=\"GitHub's unicorn error page during an outage\" width=\"650\" height=\"494\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>This was the <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=49330987\">top comment on Hacker News<\/a> when I started writing this:<\/p>\n<blockquote>\n<p>For a variety of reasons, we had a centralized place where everyone of a\nparticular set of persuasions could connect, and this had outside benefits for\nthe community as a whole. That place is becoming untenable, and with the loss\nof goodwill and stability, the community\u2019s started to dissipate. [\u2026] But\nthose emergent features like <strong>a core community and default expectation of\nwhere you can find someone will fade<\/strong>.\nAnd that is a very real loss for all of us.<\/p>\n<\/blockquote>\n<p>That resonates sooo much with me. GitHub has never been about the source code. It\u2019s where I hang out with friends, see what they\u2019ve built, and discover all the cool projects they star. It\u2019s the only \u201cFacebook\u201d I still visit. There is no other place like it anymore.<\/p>\n<p>GitHub is on its way out, and the community around it is starting to crumble.\nMy feed basically consists of the same two people starring repos and being really \u201cactive.\u201d\nThe rest is just noise. (I wish I could show you a screenshot, but, well, GitHub is down.)<\/p>\n<p>\u201cAI\u201d has only accelerated this trend.\nThese days, you\u2019re lucky to get a pull request from a real human being.\nDiscussing changes is no longer fun when you\u2019re talking to a bot 90% of the time.<\/p>\n<p><strong>I hope someone builds a community for developers; we need one now more than ever.<\/strong><\/p>\n<p>The way I see it, our code could live anywhere. We could share stars, comments, and project updates through a common network, similar to <a rel=\"external\" href=\"https:\/\/keybase.io\/\">Keybase<\/a> or <a rel=\"external\" href=\"https:\/\/mastodon.social\">Mastodon<\/a>.<\/p>\n<p>Send me an email if you like the idea.<\/p>\n"},{"title":"How Other Link Checkers Do Recursion","pubDate":"Wed, 03 Jun 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/how-other-link-checkers-recurse\/","guid":"https:\/\/endler.dev\/2026\/how-other-link-checkers-recurse\/","description":"<p>After I published <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">Five Years of Trying to Add Recursion to lychee<\/a>, one reply I got was a very fair question:<\/p>\n<blockquote>\n<p>If recursion is so hard, how do <em>other<\/em> link checkers do it? Plenty of them already crawl websites!<\/p>\n<\/blockquote>\n<p>This sent me down a rabbit hole of reading the code of other link checkers.\nThe key takeaway is: <strong>they didn\u2019t find a clever trick we missed.<\/strong> They were built as crawlers from the very first commit, and I initially built lychee as a stream.<\/p>\n<p>I went and read the source of the recursive checkers we list in <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee#features\">lychee\u2019s README<\/a>: <a rel=\"external\" href=\"https:\/\/github.com\/raviqqe\/muffet\">muffet<\/a> (Go), <a rel=\"external\" href=\"https:\/\/github.com\/linkchecker\/linkchecker\">LinkChecker<\/a> (Python), <a rel=\"external\" href=\"https:\/\/github.com\/JustinBeckwith\/linkinator\">linkinator<\/a> (TypeScript), and <a rel=\"external\" href=\"https:\/\/github.com\/stevenvachon\/broken-link-checker\">broken-link-checker<\/a> (JavaScript). This post is a teardown of how each one actually handles recursion, what it costs them, and what it means for lychee.<\/p>\n<p>If you haven\u2019t read the <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">first post<\/a>, the summary is that lychee was architected as a one-shot, unidirectional pipeline (<code>inputs \u2192 extract \u2192 check \u2192 output<\/code>). Recursion needs a <em>cycle<\/em> (responses create new inputs), and cycles in an async, channel-based pipeline are where the <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">dragons live<\/a>. \ud83d\udc32 Five years and four attempts later, the pieces we\u2019ll need to do it properly only <em>just<\/em> landed.<\/p>\n<h2 id=\"dags-vs-cycles\"><a class=\"anchor\" href=\"#dags-vs-cycles\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>DAGs vs. Cycles<\/h2>\n<p>Every recursive checker I looked at is built from the same three parts:<\/p>\n<ol>\n<li>A mutable work queue (let\u2019s call it \u201cfrontier\u201d), not a fixed input stream. Discovered URLs go back into the same queue they came from.<\/li>\n<li>A visited set that\u2019s updated at enqueue time (before the request completes), so two pages discovering the same link can\u2019t both submit it.<\/li>\n<li>A primitive that answers \u201cis everything done?\u201d: a <code>WaitGroup<\/code>, a joinable-queue counter, an <code>onIdle()<\/code> promise, or a queue-drain event.<\/li>\n<\/ol>\n<p>Diagrammatically, lychee is different from the others:<\/p>\n<pre class=\"mermaid\">\ngraph TD\n    subgraph crawler[\"Everyone else: a cycle\"]\n        direction TB\n        CQ[Frontier queue] --> CW[Worker pool]\n        CW --> CP[Fetch and parse page]\n        CP -->|new links| CQ\n        CP --> CR[Results]\n    end\n    subgraph lychee[\"lychee: a DAG\"]\n        direction TB\n        LA[Inputs] --> LB[Extractor]\n        LB --> LC[Checker]\n        LC --> LD[Results]\n    end\n<\/pre>\n<p>Crawlers have a back-edge baked in. Our pipeline doesn\u2019t, and every one of my failed attempts was an effort to bend that back-edge into a graph that was never designed for it.<\/p>\n<p>Let\u2019s look at that graph design more closely:<\/p>\n<pre class=\"mermaid\">\ngraph TD\n    Seed[Seed URLs] --> Enq[\"Enqueue step: is URL in visited set?\"]\n    Enq -->|yes| Skip[Drop]\n    Enq -->|no| Mark[\"Mark visited, then push\"]\n    Mark --> Q[Frontier queue]\n    Q --> Pool[\"Worker pool, bounded concurrency\"]\n    Pool --> FP[Fetch page and extract links]\n    FP -->|discovered links| Enq\n    FP --> Rec[Results]\n    Q -.->|empty AND no worker busy| Stop[Terminate]\n<\/pre>\n<p>Note that the visited check happens in the <strong>enqueue<\/strong> step, atomically with the mark, before the worker ever touches the network. That ordering is the entire fix to the deduplication race that haunted lychee\u2019s attempts 1\u20134, where the cache was written <em>after<\/em> checking.<\/p>\n<p>Each tool uses a variation on it.<\/p>\n<h2 id=\"muffet-go-a-waitgroup-and-a-set\"><a class=\"anchor\" href=\"#muffet-go-a-waitgroup-and-a-set\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>muffet (Go): A WaitGroup and a Set<\/h2>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/raviqqe\/muffet\">muffet<\/a> is closest in spirit to lychee: a fast, single-binary, concurrent website checker.\nThe dedup + scheduling decision lives in one method (<code>page_checker.go<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">c <\/span><span class=\"z-l-2 z-d-5\">*<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">pageChecker<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> addPage<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">p<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> page<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span class=\"z-l-2 z-d-5\"> !<\/span><span>c<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>donePages<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>p<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">URL<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">String<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tc<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>daemonManager<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> c<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">checkPage<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>p<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p><code>donePages<\/code> is a <code>concurrentStringSet<\/code> (a mutex-guarded <code>map[string]struct{}<\/code>). <code>Add<\/code> returns whether the URL was already present, so a page is only scheduled the <em>first<\/em> time it\u2019s seen. Dedup happens at enqueue, synchronized by the set\u2019s mutex. This is basically a line-by-line translation of the diagram above.<\/p>\n<p>Checking a page fetches all of its links concurrently, and feeds qualifying ones back into <code>addPage<\/code>, the back-edge:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">go<\/span><span class=\"z-l-9 z-d-9\"> func<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">u<\/span><span class=\"z-l-9 z-d-9\"> string<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tdefer<\/span><span> w<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tstatus<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> p<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> err<\/span><span class=\"z-l-2 z-d-5\"> :=<\/span><span> c<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>fetcher<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Fetch<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>u<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\t\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span class=\"z-l-2 z-d-5\"> !<\/span><span>c<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>onePageOnly<\/span><span class=\"z-l-2 z-d-5\"> &amp;&amp;<\/span><span> p<\/span><span class=\"z-l-2 z-d-5\"> !=<\/span><span class=\"z-l-10 z-d-12\"> nil<\/span><span class=\"z-l-2 z-d-5\"> &amp;&amp;<\/span><span> c<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>linkValidator<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Validate<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>p<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">URL<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tc<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">addPage<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>p<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">   \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> recursion: discovered page re-enters the frontier<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>u<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre><h3 id=\"how-muffet-knows-it-s-done\"><a class=\"anchor\" href=\"#how-muffet-knows-it-s-done\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How muffet Knows It\u2019s Done<\/h3>\n<p>muffet\u2019s answer to termination is a little <code>daemonManager<\/code> built around a <code>sync.WaitGroup<\/code> (<code>daemon_manager.go<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">m <\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">daemonManager<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> Add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">f<\/span><span class=\"z-l-9 z-d-9\"> func<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tm<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>waitGroup<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tm<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>daemons<\/span><span class=\"z-l-2 z-d-5\"> &lt;-<\/span><span class=\"z-l-9 z-d-9\"> func<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\t\tf<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tm<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>waitGroup<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">m <\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">daemonManager<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> Run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tgo<\/span><span class=\"z-l-9 z-d-9\"> func<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\tfor<\/span><span> f<\/span><span class=\"z-l-2 z-d-5\"> :=<\/span><span class=\"z-l-9 z-d-9\"> range<\/span><span> m<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>daemons<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tgo<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> f<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tm<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>waitGroup<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Wait<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">   \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> &lt;- termination<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Every scheduled page increments the group; every completed page decrements it; <code>Wait()<\/code> returns when the count hits zero. The whole crawl bootstraps with a single <code>addPage<\/code> before <code>Run()<\/code>, so the counter is positive before anyone waits on it.<\/p>\n<p>This is the <em>same counter<\/em> I tried (and failed with) in <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">Attempt 1<\/a> and <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">Attempt 4<\/a>. The difference is the invariant: <code>waitGroup.Add(1)<\/code> is only ever called from inside an already-running daemon that holds the count above zero (or from the bootstrap). There is no window where the counter briefly reads zero while work is still pending. Go\u2019s <code>WaitGroup<\/code> enforces this invariant so naturally that it doesn\u2019t feel like distributed termination detection at all, but that\u2019s exactly what it is. It\u2019s the moral equivalent of the <code>WaitGroup<\/code> primitive <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/2046\">Kait contributed to lychee in 2026<\/a>.<\/p>\n<h3 id=\"where-the-tradeoffs-are\"><a class=\"anchor\" href=\"#where-the-tradeoffs-are\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where the Tradeoffs Are<\/h3>\n<ul>\n<li>Concurrency isn\u2019t bounded by the daemon manager. <code>Run()<\/code> does <code>go f()<\/code> for every task, spawning unbounded goroutines. The actual limiting happens downstream in a <code>semaphore<\/code> (a buffered-channel counting semaphore) and a per-host throttler pool. muffet <em>separates<\/em> \u201cthe frontier\u201d from \u201cthe rate limiter,\u201d which is exactly the separation lychee lacked when it tried to use one bounded channel as both in the past.<\/li>\n<li>Cheap goroutines do a lot of heavy lifting. Spawning a goroutine per link is \u201cfine\u201d in Go. The equivalent in Rust (<code>tokio::spawn<\/code> per link, each needing <code>Send + 'static<\/code> state) is what pushed me toward <code>Arc&lt;RwLock&lt;\u2026&gt;&gt;<\/code> and the ownership pain I <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#attempt-3-semaphores-february-2022\">wrote about<\/a>.<\/li>\n<li>On extensibility, muffet is a focused CLI, not a library. There\u2019s no plugin surface; you get what the flags give you. lychee deliberately ships <code>lychee-lib<\/code> as a reusable crate, which raises the bar, since every architectural choice has to uphold the standards of a public API.<\/li>\n<li>On scalability, unbounded goroutines plus an in-memory visited set scale comfortably to large sites, but there\u2019s no disk-backed frontier, so a truly enormous crawl is bounded by RAM. Same as lychee.<\/li>\n<\/ul>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways: muffet<\/p>\n    <ul>\n<li>muffet\u2019s termination is a <code>sync.WaitGroup<\/code>, full stop. It\u2019s the design lychee converged on after five years; muffet got it for free from Go\u2019s standard library on day one.<\/li>\n<li>The frontier and the concurrency limiter are separate things. A mutex-guarded set is the frontier; a semaphore plus host throttler bounds concurrency. Conflating them is what deadlocked lychee.<\/li>\n<li>Goroutines hide the cost that Rust makes you pay explicitly. The same per-task model that\u2019s trivial in Go is where Rust\u2019s <code>Send<\/code>\/ownership friction shows up.<\/li>\n<\/ul>\n<\/div>\n<h2 id=\"linkchecker-python-a-joinable-unbounded-queue\"><a class=\"anchor\" href=\"#linkchecker-python-a-joinable-unbounded-queue\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>LinkChecker (Python): A Joinable Unbounded Queue<\/h2>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/linkchecker\/linkchecker\">LinkChecker<\/a> has existed since the year 2000. It\u2019s a synchronous, thread-pool crawler.<\/p>\n<p>Its frontier is a hand-written <code>UrlQueue<\/code> (<code>cache\/urlqueue.py<\/code>), a clone of Python\u2019s <code>queue.Queue<\/code> with <code>task_done()<\/code>\/<code>join()<\/code>. Look at the very first design comment:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-1 z-l-i z-d-3 z-d-i\"> __init__<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> max_allowed_urls<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-16 z-d-16\">None<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Note: don&#39;t put a maximum size on the queue since it would<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> lead to deadlocks when all worker threads called put().<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>queue<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> collections<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">deque<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>unfinished_tasks<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><\/span><\/code><\/pre>\n<p>It\u2019s explicit about the exact deadlock that bit me.<\/p>\n<p>That comment is <em>our <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#attempt-4-gwenn-takes-a-swing-january-march-2025\">Attempt 4 backpressure deadlock<\/a><\/em>, called out and designed around. lychee tried to push discovered URLs into a <strong>bounded<\/strong> channel; when it filled, the response handler blocked, no responses drained, no slots freed. Deadlock. \ud83d\udca5<\/p>\n<p>LinkChecker\u2019s answer is brutalist in nature: the frontier is <strong>unbounded<\/strong>.\nBackpressure is enforced elsewhere (a fixed thread count and per-host throttling), never by blocking a producer that is also a consumer.<\/p>\n<h3 id=\"termination-by-counter-done-right\"><a class=\"anchor\" href=\"#termination-by-counter-done-right\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Termination by Counter, Done Right<\/h3>\n<p><code>join()<\/code> blocks until <code>unfinished_tasks<\/code> hits zero (<code>urlqueue.py<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> task_done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> url_data<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    with<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>all_tasks_done<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">        self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>finished_tasks<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">        self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>unfinished_tasks<\/span><span class=\"z-l-2 z-d-5\"> -=<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">        self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>in_progress<\/span><span class=\"z-l-2 z-d-5\"> -=<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        if<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>unfinished_tasks<\/span><span class=\"z-l-2 z-d-5\"> &lt;=<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">            self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>all_tasks_done<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">notify_all<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> join<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> timeout<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-16 z-d-16\">None<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    with<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>all_tasks_done<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        while<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>unfinished_tasks<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">            self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>all_tasks_done<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">wait<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>Again: a counter. But the increment in <code>_put<\/code> and the decrement in <code>task_done<\/code> are both inside the queue\u2019s <code>Condition<\/code> lock, and a worker calls <code>task_done<\/code> only after fully processing an item <em>including enqueuing its children<\/em>. So children are counted before the parent is marked done, with no premature zero. It\u2019s <code>WaitGroup<\/code> semantics implemented with a mutex and a condition variable.<\/p>\n<h3 id=\"deduplication-before-the-request\"><a class=\"anchor\" href=\"#deduplication-before-the-request\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Deduplication, before the Request<\/h3>\n<p>LinkChecker writes the URL into its result cache at <strong>enqueue<\/strong> time (<code>urlqueue.py<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> _put<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> url_data<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>    key<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> url_data<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>cache_url<\/span><\/span>\n<span class=\"giallo-l\"><span>    cache<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> url_data<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>aggregate<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>result_cache<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span> cache<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">has_result<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>key<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        return<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> already queued\/checked -&gt; skip<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>queue<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">append<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>url_data<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>unfinished_tasks<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> add a None placeholder so this URL is never queued twice<\/span><\/span>\n<span class=\"giallo-l\"><span>    cache<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">add_result<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>key<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> None<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>That <code>add_result(key, None)<\/code> sentinel is a \u201cfix\u201d that\u2019s missing in lychee\u2019s attempts. By the time any worker thread checks the URL, the cache already says \u201cmine,\u201d so concurrent discovery from another page is a no-op.<\/p>\n<h3 id=\"per-host-politeness-and-termination-guards\"><a class=\"anchor\" href=\"#per-host-politeness-and-termination-guards\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Per-Host Politeness and Termination Guards<\/h3>\n<p>The <code>Aggregate<\/code> (<code>director\/aggregator.py<\/code>) throttles per host:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">@<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">synchronized<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>_hosts_lock<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> wait_for_host<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> host<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>    t<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> time<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">time<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span> host<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>times<\/span><span class=\"z-l-9 z-d-9\"> and<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\"> self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">times<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">host<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span> t<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>        time<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">sleep<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">times<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">host<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> -<\/span><span> t<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> spread requests using maxrequestspersecond<\/span><\/span>\n<span class=\"giallo-l\"><span>    wait_time<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> random<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">uniform<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>wait_time_min<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> wait_time_max<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    self<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">times<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">host<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> time<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">time<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span> wait_time<\/span><\/span><\/code><\/pre>\n<p>and <code>abort()<\/code> calls <code>urlqueue.join(timeout=\u2026)<\/code> so a stuck crawl can\u2019t hang forever.<\/p>\n<h3 id=\"where-the-tradeoffs-are-1\"><a class=\"anchor\" href=\"#where-the-tradeoffs-are-1\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where the Tradeoffs Are<\/h3>\n<ul>\n<li>Blocking threads instead of async. Each of the (default 10\u2013100) <code>Checker<\/code> threads does blocking I\/O via <code>requests<\/code>. Simple and battle-tested, but the concurrency ceiling is the thread count, and each thread carries a full stack. lychee\u2019s Tokio model reaches thousands of concurrent in-flight requests on a handful of OS threads; LinkChecker can\u2019t, and doesn\u2019t try.<\/li>\n<li>The unbounded frontier trades a deadlock for unbounded memory. The explicit \u201cno max size\u201d decision means RAM growth on huge sites. There\u2019s a <code>max_allowed_urls<\/code> cap and a periodic <code>cleanup()<\/code> to mitigate it.<\/li>\n<li>Extensibility is excellent. LinkChecker has a real plugin system (<code>linkcheck\/plugins\/<\/code>: anchor checks, SSL, virus scanning, and more) and many output loggers. This is the most extensible of the bunch, and it pays for that with a large, mature, somewhat old-fashioned codebase.<\/li>\n<li>On scalability, it\u2019s GIL-bound and thread-limited, so raw throughput is the lowest here, but correctness and feature coverage are high.<\/li>\n<\/ul>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways: LinkChecker<\/p>\n    <ul>\n<li>The unbounded frontier is a deliberate anti-deadlock choice, documented in a one-line comment. It describes the exact problem we hit in lychee in attempt 4.<\/li>\n<li>Dedup at <code>put()<\/code> time (a <code>None<\/code> placeholder in the cache) is their synchronization mechanism. The cache must claim the URL <em>before<\/em> the request, not after.<\/li>\n<li>Threads buy simplicity at the cost of throughput. A blocking thread pool is the easiest correct model\u2026 and the slowest one.<\/li>\n<\/ul>\n<\/div>\n<h2 id=\"linkinator-typescript-single-threaded-queue-onidle\"><a class=\"anchor\" href=\"#linkinator-typescript-single-threaded-queue-onidle\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>linkinator (TypeScript): Single-Threaded <code>queue.onIdle()<\/code><\/h2>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/JustinBeckwith\/linkinator\">linkinator<\/a> is a Node.js checker, and it benefits from something neither Go nor Rust provides: a <strong>single-threaded event loop<\/strong>. Check-and-insert into the visited set is atomic <em>for free<\/em>, because no two callbacks run simultaneously.<\/p>\n<p>The frontier is a concurrency-limited <code>Queue<\/code> (a p-queue-style structure). Termination is one line in <code>check()<\/code> (<code>src\/index.ts<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"typescript\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span> queue<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-l-b z-d-9 z-d-b\"> new<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> Queue<\/span><span>(<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span> concurrency<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>concurrency<\/span><span class=\"z-l-2 z-d-5\"> ||<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ... seed the queue ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> resolve when nothing is queued or running:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">await<\/span><span> queue<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">onIdle<\/span><span>(<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span>  <\/span><\/span><\/code><\/pre>\n<p><code>onIdle()<\/code> is the library\u2019s termination detection: it resolves when the queue is empty <em>and<\/em> no task is in flight. Same idea as muffet\u2019s <code>WaitGroup<\/code> and LinkChecker\u2019s <code>join()<\/code>, just expressed as a promise and backed by a single-threaded runtime, so no Mutex is needed to protect the visited set.<\/p>\n<h3 id=\"the-back-edge-and-the-race-free-dedup\"><a class=\"anchor\" href=\"#the-back-edge-and-the-race-free-dedup\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Back-Edge and the Race-Free Dedup<\/h3>\n<p>When crawling, <code>crawl()<\/code> GETs the page, extracts links, and for each new URL re-enters the queue (<code>src\/index.ts<\/code>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"typescript\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span> inCache<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>cache<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">has<\/span><span>(<\/span><span>result<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>url<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>href<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">if<\/span><span> (<\/span><span class=\"z-l-2 z-d-5\">!<\/span><span>inCache<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Mark visited...<\/span><\/span>\n<span class=\"giallo-l\"><span>    options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>cache<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add<\/span><span>(<\/span><span>result<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>url<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>href<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Create the promise for this check<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    const<\/span><span> checkPromise<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> (<\/span><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        await<\/span><span class=\"z-l-10 z-d-12\"> this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">crawl<\/span><span>(<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span> url<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> result<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ... <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span>)<\/span><span>(<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Store the promise.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Another page discovering the same URL can wait on this promise<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> instead of enqueuing a duplicate check.<\/span><\/span>\n<span class=\"giallo-l\"><span>    options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>pendingChecks<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">set<\/span><span>(<\/span><span>result<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>url<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>href<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> checkPromise<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Enqueue...<\/span><\/span>\n<span class=\"giallo-l\"><span>    options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>queue<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add<\/span><span>(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span> checkPromise<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span>        <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Because JavaScript is single-threaded, the entire thing executes without interruption.\nIn Rust or Go, that\u2019s a critical section you must guard with a mutex (and get the ordering right); in Node it\u2019s just three statements. This is the single biggest reason recursion is <em>easier<\/em> in Node than in Rust.\nIt\u2019s just a language feature.<\/p>\n<p>linkinator also keeps a <code>relationshipCache<\/code> of <code>`${url}|${parent}`<\/code> keys, and a <code>pendingChecks<\/code> map so it can wait on an in-flight check and still report a <em>duplicate broken link<\/em> against every parent that references it. Those reuse-operations are themselves pushed onto the same queue, so <code>onIdle()<\/code> correctly waits for them too.<\/p>\n<h3 id=\"head-vs-get\"><a class=\"anchor\" href=\"#head-vs-get\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>HEAD vs GET<\/h3>\n<p>linkinator uses <code>HEAD<\/code> for leaf links but <code>GET<\/code> when it needs to crawl, because <strong>recursion needs the response body to find more links<\/strong>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"typescript\"><span class=\"giallo-l\"><span>response<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> await<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> makeRequest<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span>  options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>crawl<\/span><span class=\"z-l-2 z-d-5\"> ?<\/span><span class=\"z-l-5 z-d-7\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">GET<\/span><span class=\"z-l-5 z-d-7\">&#39;<\/span><span class=\"z-l-2 z-d-5\"> :<\/span><span class=\"z-l-5 z-d-7\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">HEAD<\/span><span class=\"z-l-5 z-d-7\">&#39;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>  options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>url<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>href<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ... <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>This is precisely <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#what-proper-recursion-could-look-like\">lychee\u2019s remaining open problem<\/a>: you can only recurse into pages you fetched with a body. linkinator just always GETs when crawling; lychee plans to reuse the body it already has in cache from the check it just performed.<\/p>\n<h3 id=\"where-the-tradeoffs-are-2\"><a class=\"anchor\" href=\"#where-the-tradeoffs-are-2\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where the Tradeoffs Are<\/h3>\n<ul>\n<li>Single-threaded is both a blessing and a ceiling. No data races, trivially correct dedup, but HTML parsing is CPU work that blocks the one event loop. For thousands of pages, you\u2019re bound by a single core. lychee\u2019s multi-threaded runtime parses and checks in parallel.<\/li>\n<li>It suffers from in-memory result inflation. The source explicitly comments on \u201cmassive result inflation for heavily interlinked sites\u201d: the <code>results<\/code> array, <code>cache<\/code>, and <code>relationshipCache<\/code> all grow with the crawl. Fine for a docs site, heavy for a giant one.<\/li>\n<li>Rate limiting is reactive, not proactive. There\u2019s a <code>delayCache<\/code> that backs off per host on a <code>429<\/code> with <code>Retry-After<\/code>, but no general per-host concurrency cap like lychee\u2019s <code>HostPool<\/code>. linkinator can hammer a host until it complains; lychee now paces <em>before<\/em> the complaint.<\/li>\n<li>For extensibility, it\u2019s an <code>EventEmitter<\/code> (<code>on('link')<\/code>, <code>on('pagestart')<\/code>, and so on), so it\u2019s embeddable and scriptable, which is nice. It\u2019s a library first, like lychee.<\/li>\n<\/ul>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways: linkinator<\/p>\n    <ul>\n<li><code>queue.onIdle()<\/code> is the termination mechanism. Simple and provided by the JS runtime.<\/li>\n<li>A single-threaded event loop makes request deduplication pretty much free. This is the biggest structural reason recursion is easier in that case.<\/li>\n<li>Reactive 429 backoff is not the same as proactive per-host pacing. lychee\u2019s <code>HostPool<\/code> aims higher, at the cost of more machinery.<\/li>\n<\/ul>\n<\/div>\n<h2 id=\"broken-link-checker-javascript-event-driven-using-two-queues\"><a class=\"anchor\" href=\"#broken-link-checker-javascript-event-driven-using-two-queues\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>broken-link-checker (JavaScript): Event-Driven, Using Two Queues<\/h2>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/stevenvachon\/broken-link-checker\">broken-link-checker<\/a> (BLC) takes the event-driven model furthest. It\u2019s built on <a rel=\"external\" href=\"https:\/\/github.com\/stevenvachon\/limited-request-queue\"><code>limited-request-queue<\/code><\/a>, a queue with <code>maxSockets<\/code> (concurrency) and <code>rateLimit<\/code>, and it nests <strong>two<\/strong> of them: a site-level queue feeding a page-level <code>HtmlUrlChecker<\/code>.<\/p>\n<p>The frontier and dedup live in <code>SiteChecker<\/code> (<code>lib\/public\/SiteChecker.js<\/code>). Visited pages are tracked in a <code>URLCache<\/code>, written at enqueue time:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"javascript\"><span class=\"giallo-l\"><span>#<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">enqueuePage<\/span><span>(<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> customData<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> auth<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Mark before crawl to avoid links to self within page. <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">    this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#sitePagesChecked<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">set<\/span><span>(<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> PAGE_WAS_CHECKED<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">    this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#htmlUrlChecker<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">enqueue<\/span><span>(<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> customData<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> auth<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Recursion is governed by a filter that decides whether a discovered link becomes a crawled page:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"javascript\"><span class=\"giallo-l\"><span>#<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">maybeEnqueuePage<\/span><span>(<\/span><span>link<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> customData<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> auth<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    const<\/span><span> tagGroup<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-10 z-d-12\"> this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>tags<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>recursive<\/span><span>[<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">      this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>filterLevel<\/span><\/span>\n<span class=\"giallo-l\"><span>    ]<\/span><span>[<\/span><span>link<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span>(<\/span><span>HTML_TAG_NAME<\/span><span>)<\/span><span>]<\/span><span class=\"z-l-2 z-d-5\"> ??<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    const<\/span><span> attrSupported<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> link<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span>(<\/span><span>HTML_ATTR_NAME<\/span><span>)<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> tagGroup<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span> (<\/span><span class=\"z-l-2 z-d-5\">!<\/span><span>attrSupported<\/span><span class=\"z-l-2 z-d-5\"> ||<\/span><\/span>\n<span class=\"giallo-l\"><span>        link<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span>(<\/span><span>IS_BROKEN<\/span><span>)<\/span><span class=\"z-l-2 z-d-5\"> ||<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        !<\/span><span>link<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span>(<\/span><span>IS_INTERNAL<\/span><span>)<\/span><span class=\"z-l-2 z-d-5\"> ||<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">        this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#sitePagesChecked<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">has<\/span><span>(<\/span><span>rebasedURL<\/span><span>)<\/span><span class=\"z-l-2 z-d-5\"> ||<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> dedup check<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        !<\/span><span class=\"z-l-10 z-d-12\">this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">#isAllowed<\/span><span>(<\/span><span>link<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> robots.txt<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">          \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> do nothing<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> (<\/span><span class=\"z-l-10 z-d-12\">this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#options<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">includePage<\/span><span>(<\/span><span>rebasedURL<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">        this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">#enqueuePage<\/span><span>(<\/span><span>rebasedURL<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> customData<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> auth<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><h3 id=\"termination-by-event-cascade\"><a class=\"anchor\" href=\"#termination-by-event-cascade\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Termination by Event Cascade<\/h3>\n<p>BLC has no counter and no <code>onIdle()<\/code>. It rides the queue\u2019s drain events. When the page-level queue empties it fires <code>END_EVENT<\/code>, which makes <code>SiteChecker<\/code> emit <code>SITE_EVENT<\/code> and call the site queue\u2019s <code>done<\/code> callback; when the <em>site<\/em> queue drains, it fires <code>REQUEST_QUEUE_END_EVENT<\/code>. That\u2019s the public <code>END_EVENT<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"javascript\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">on<\/span><span>(<\/span><span>END_EVENT<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> =&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">    this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">emit<\/span><span>(<\/span><span>SITE_EVENT<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#currentPageError<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#currentSiteURL<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>#currentCustomData<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">    this<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">#currentDone<\/span><span>(<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">   \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> tell the site queue this site is finished<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>That\u2019s their termination detection, expressed as \u201cthe request queue reported empty.\u201d<\/p>\n<p>And in classic Node.js fashion, the <code>done<\/code> callback is what actually tells the site queue to free up a slot for another site. So the termination of one site is what allows another to start, and the termination of the whole crawl is what allows the process to exit. It\u2019s a cascade of events that propagates from the page queue to the site queue to the process.<\/p>\n<h3 id=\"where-the-tradeoffs-are-3\"><a class=\"anchor\" href=\"#where-the-tradeoffs-are-3\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where the Tradeoffs Are<\/h3>\n<ul>\n<li>It\u2019s the best web citizen of the bunch. robots.txt is honored (<code>getRobotsTxt<\/code>, <code>isAllowed<\/code>), <code>rel=nofollow<\/code> is respected, and <code>rateLimit<\/code> plus <code>maxSockets<\/code> are first-class. This is a crawler that\u2019s polite by default.<\/li>\n<li>Event cascades are powerful but fiddly. Termination is spread across half a dozen event handlers and two nested queues. It works, but the control flow is much harder to follow than <code>await queue.onIdle()<\/code>. This is the JS cousin of the \u201cleaky abstraction\u201d problem I described, where recursion-awareness ends up sprinkled across many handlers.<\/li>\n<li>It\u2019s single-threaded, the same ceiling as linkinator, plus the in-memory <code>URLCache<\/code> per site.<\/li>\n<li>On maturity versus momentum, it\u2019s very widely used (it powers a lot of tooling), but development has slowed. The architecture is still sound and worth studying.<\/li>\n<\/ul>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways: broken-link-checker<\/p>\n    <ul>\n<li>Termination is a cascade of queue-drain events, not a counter. Same idea, different syntax.<\/li>\n<li>Politeness is built in. robots.txt, <code>rateLimit<\/code>, and <code>maxSockets<\/code> make it the most server-friendly recursive checker by default.<\/li>\n<li>Event-driven control flow is the cost. Distributing recursion logic across many handlers is exactly the kind of spread-out complexity that makes the feature hard to reason about.<\/li>\n<\/ul>\n<\/div>\n<h2 id=\"a-note-on-markdown-link-check-and-the-industrial-crawlers\"><a class=\"anchor\" href=\"#a-note-on-markdown-link-check-and-the-industrial-crawlers\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Note on markdown-link-check and the \u201cindustrial\u201d Crawlers<\/h2>\n<p>Our README marks <a rel=\"external\" href=\"https:\/\/github.com\/tcort\/markdown-link-check\">markdown-link-check<\/a> as supporting recursion, but there\u2019s some nuance there: it recurses over <em>Markdown files<\/em>, not by spidering a live website. There\u2019s no HTTP frontier and no termination problem in the sense above. Worth a mention so the comparison is honest, not worth a teardown.<\/p>\n<p>If you want to see the pattern at full industrial scale, look at <a rel=\"external\" href=\"https:\/\/www.scrapy.org\/\">Scrapy<\/a> (Python\/Twisted) or <a rel=\"external\" href=\"https:\/\/github.com\/gocolly\/colly\">Colly<\/a> (Go). Both use the same approach: a scheduler (frontier) with a pluggable, optionally disk-backed queue, a dupefilter (often a Bloom filter rather than a <code>HashSet<\/code>), a bounded downloader pool, and explicit \u201cengine idle \u2192 close spider\u201d termination. They solve exactly the problems lychee struggled with (<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Dijkstra%E2%80%93Scholten_algorithm\">distributed termination detection<\/a>, backpressure, dedup), just with years of dedicated crawler engineering behind them. The takeaway isn\u2019t \u201clychee should be Scrapy\u201d: it\u2019s that crawling is a well-trodden architecture, and lychee is simply standing on a different one right now.<\/p>\n<h2 id=\"side-by-side\"><a class=\"anchor\" href=\"#side-by-side\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Side-by-Side<\/h2>\n<div class=\"wide-table\">\n<table><thead><tr><th>Tool<\/th><th>Lang \/ runtime<\/th><th>Concurrency model<\/th><th>Frontier<\/th><th>\u201cDone?\u201d signal<\/th><th>Dedup point<\/th><th>Per-host limiting<\/th><\/tr><\/thead><tbody>\n<tr><td><strong>muffet<\/strong><\/td><td>Go, goroutines<\/td><td>goroutine pool + semaphore + host throttler<\/td><td>mutex-guarded set + daemon channel<\/td><td><code>sync.WaitGroup<\/code><\/td><td>visited set at enqueue<\/td><td>host throttler pool<\/td><\/tr>\n<tr><td><strong>LinkChecker<\/strong><\/td><td>Python, threads<\/td><td>fixed blocking thread pool<\/td><td><strong>unbounded<\/strong> <code>UrlQueue<\/code><\/td><td>joinable-queue counter (<code>join()<\/code>)<\/td><td>result cache at <code>put()<\/code><\/td><td><code>wait_for_host<\/code> (req\/s)<\/td><\/tr>\n<tr><td><strong>linkinator<\/strong><\/td><td>Node, event loop<\/td><td>single-thread + p-queue (<code>concurrency<\/code>)<\/td><td>p-queue<\/td><td><code>queue.onIdle()<\/code><\/td><td><code>Set<\/code> at enqueue (race-free)<\/td><td>reactive <code>429<\/code> <code>delayCache<\/code><\/td><\/tr>\n<tr><td><strong>broken-link-checker<\/strong><\/td><td>Node, event loop<\/td><td><code>limited-request-queue<\/code> (<code>maxSockets<\/code>)<\/td><td>nested request queues<\/td><td>queue-drain events<\/td><td><code>URLCache<\/code> at enqueue<\/td><td><code>maxSockets<\/code> + <code>rateLimit<\/code><\/td><\/tr>\n<tr><td><strong>lychee (2026)<\/strong><\/td><td>Rust, Tokio<\/td><td>tasks + <code>HostPool<\/code><\/td><td>channels + <code>WaitGroup<\/code><\/td><td><code>WaitGroup<\/code><\/td><td><code>HostPool<\/code> <code>active_requests<\/code><\/td><td><code>HostPool<\/code> per-host pool<\/td><\/tr>\n<\/tbody><\/table>\n<\/div>\n<p>lychee in 2026 finally has a column-for-column match. The <code>WaitGroup<\/code> is muffet\u2019s <code>sync.WaitGroup<\/code> and LinkChecker\u2019s <code>join()<\/code>. The <code>HostPool<\/code> is BLC\u2019s <code>rateLimit<\/code>\/<code>maxSockets<\/code> and LinkChecker\u2019s <code>wait_for_host<\/code>. The per-URI <code>active_requests<\/code> mutex is everyone\u2019s enqueue-time dedup.<\/p>\n<h2 id=\"so-why-couldn-t-we-just-copy-them\"><a class=\"anchor\" href=\"#so-why-couldn-t-we-just-copy-them\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>So Why Couldn\u2019t We Just Copy Them?<\/h2>\n<p>Three reasons, in increasing order of how much they\u2019re actually lychee\u2019s fault.<\/p>\n<p><strong>They started as crawlers; lychee started as a stream.<\/strong><\/p>\n<p>Every tool above has a back-edge in its core data structure. lychee\u2019s core was a DAG optimized for the 99% case (a list of files\/URLs, checked once, fast). Retrofitting a cycle onto a pipeline is much harder than having one from the start. The problem is architectural in nature.<\/p>\n<p><strong>The frontier and the rate-limiter must be different objects.<\/strong><\/p>\n<p>muffet (set + semaphore), LinkChecker (unbounded queue + thread count), linkinator (p-queue + delayCache), BLC (request queue + maxSockets) all keep \u201cwhat to do next\u201d separate from \u201chow fast to go.\u201d lychee\u2019s early attempts tried to make one bounded channel serve both roles, and a cycle through a bounded channel deadlocks. The fix (lychee\u2019s <code>HostPool<\/code> plus a <code>WaitGroup<\/code> over an unbounded work source) is the same separation we\u2019re aiming for now.<\/p>\n<p><strong>Single-threaded runtimes get dedup for free.<\/strong><\/p>\n<p>Both Node tools dedup with a plain <code>Set<\/code> and zero locking, because the event loop serializes access. Go and Python pay a mutex. Rust pays a mutex <em>and<\/em> fights the borrow checker about who owns the shared state across <code>tokio::spawn<\/code>. That\u2019s the ~30% \u201cRust tax\u201d I <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#how-much-of-this-is-rust-s-fault\">estimated last time<\/a>: not the algorithm, but the friction of expressing shared mutable frontier state under <code>Send + 'static<\/code>.<\/p>\n<p>None of this is a knock on lychee\u2019s design. A unidirectional stream is <em>the right call<\/em> for the common, non-recursive case: it\u2019s why lychee is fast and why the 30% channel regression from <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/\">Attempt 2<\/a> was a dealbreaker. The other tools pay for their back-edge on every run, recursive or not. lychee refused to, and that principle is exactly why recursion took five years and why, when it lands, it won\u2019t slow down the path everyone actually uses.\nI believe that we can have our cake and eat it too: a crawler architecture that supports recursion without sacrificing the speed of a one-shot pipeline. But it\u2019s a harder problem than just \u201ccopy what they do,\u201d because most link checkers didn\u2019t start with uncompromising performance as their top goal.<\/p>\n<div class=\"info\">\n    <p class=\"info-title\">Key takeaways<\/p>\n    <ul>\n<li>There is no secret sauce. Every recursive checker is a worklist plus a visited set plus a quiescence detector. The \u201ctrick\u201d is being shaped like a crawler from commit one.<\/li>\n<li>Termination is always the same idea wearing different clothes: <code>sync.WaitGroup<\/code> (muffet), joinable-queue counter (LinkChecker), <code>queue.onIdle()<\/code> (linkinator), queue-drain events (BLC), <code>WaitGroup<\/code> (lychee 2026). All of them are distributed termination detection.<\/li>\n<li>Dedup belongs at enqueue, before the request. Marking a URL visited <em>after<\/em> checking it (what lychee did for four attempts) is the bug. Everyone else claims the URL the moment it enters the frontier.<\/li>\n<li>Separate the frontier from the rate limiter. A bounded channel that is both your queue <em>and<\/em> your backpressure will deadlock the instant you add a cycle.<\/li>\n<li>There is no free lunch. Node\u2019s single thread makes dedup trivial at the cost of performance; Go\u2019s goroutines and <code>WaitGroup<\/code> make termination trivial at the cost of a runtime; Rust gives you neither for free but hands you a compiler that refuses to let the races compile and you can get the network card to glow if you know exactly what you are doing.<\/li>\n<\/ul>\n<\/div>\n<p>So when someone asks \u201chow do other link checkers do recursion?\u201d, the real answer is: they made it a part of the architecture from the beginning, and they leaned on a runtime (providing conveniences like a <code>WaitGroup<\/code>, a joinable queue, an idle promise) that solved termination without solving \u201cdistributed termination detection.\u201d<\/p>\n<p>Thanks to the maintainers of muffet, LinkChecker, linkinator, and broken-link-checker: reading your source is the clearest way to learn about crawler architecture out there and we\u2019re all in this together, just with a different set of tradeoffs.<\/p>\n"},{"title":"Five Years of Trying to Add Recursion to lychee","pubDate":"Sun, 31 May 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/lychee-recursion\/","guid":"https:\/\/endler.dev\/2026\/lychee-recursion\/","description":"<p>Recursion has been <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\">lychee<\/a>\u2019s longest-standing open issue.\nIt\u2019s been sitting there, unresolved, for over five years now.<\/p>\n<p>If you haven\u2019t come across it before, lychee is a fast, async link checker written in Rust (BTW).\nYou point it at your website, your docs, your README, your Markdown files.<\/p>\n<p>I started it in 2020 because I got bored at home. By now, around 40k GitHub repositories depend on it.\nGoogle, AWS, Microsoft, Cloudflare, and many others use it to check links in their documentation.<\/p>\n<p>I gave <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=BIguvia6AvM\">talks<\/a> and <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=plEz4l7HwhY\">podcasts<\/a> about it, in case you\u2019d like to learn more.<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2026\/lychee-recursion\/screencast.svg\" alt=\"lychee goes weeeee...\" width=\"1192\" height=\"760\"\n    \/>\n    <figcaption>\n        lychee goes weeeee\u2026\n    <\/figcaption>\n<\/figure>\n<p>lychee got <a rel=\"external\" href=\"https:\/\/nlnet.nl\/\">funded by NLnet<\/a> through their <a rel=\"external\" href=\"https:\/\/nlnet.nl\/NGI0\/\">NGI Zero program<\/a> for open, trustworthy infrastructure.<\/p>\n<p>That funding allowed us to spend serious, focused time on the project instead of coding late at night.<sup class=\"footnote-reference\" id=\"fr-night-1\"><a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#fn-night\">[1]<\/a><\/sup>\nThe funding is now coming to an end, which feels like the right moment to write this post.<\/p>\n<p>And the most honest thing I can say is this: the single most requested feature, recursion, still isn\u2019t shipped. :,(\nBut there are good reasons! Of course, the gist is \u201cit\u2019s hard,\u201d but let\u2019s go deeper than that.<\/p>\n<h2 id=\"where-it-started\"><a class=\"anchor\" href=\"#where-it-started\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where It Started<\/h2>\n<p>On December 14, 2020, a user named <a rel=\"external\" href=\"https:\/\/github.com\/styfle\"><strong>@styfle<\/strong><\/a> opened <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/issues\/78\">issue #78<\/a>:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/lychee-recursion\/issue78.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/lychee-recursion\/issue78.jpg\" alt=\"The original recursion issue\" width=\"650\" height=\"222\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The original recursion issue\n    <\/figcaption>\n<\/figure>\n<p>Very reasonable! At that point, lychee was already a fast, concurrent link checker with a lot of features. Surely adding a little <code>--recursive<\/code> flag to follow links within a domain could be done in an honest day\u2019s work, no?<\/p>\n<p>But five years, four serious implementation attempts, and several abandoned pull requests later, recursion still isn\u2019t merged. The issue is tagged for the v1.0 milestone and we still want to ship it before that. But somewhere along the way it became lychee\u2019s white whale.<\/p>\n<h2 id=\"my-initial-architecture-made-it-hard\"><a class=\"anchor\" href=\"#my-initial-architecture-made-it-hard\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>My Initial Architecture Made It Hard<\/h2>\n<p>To understand why recursion is so difficult to add, you need to understand how lychee processes things.\nHere\u2019s the flow from back in late 2020:<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2026\/lychee-recursion\/initial-architecture.svg\" alt=\"lychee's initial architecture\" width=\"1280\" height=\"90\"\n    \/>\n    <figcaption>\n        lychee\u2019s initial architecture\n    <\/figcaption>\n<\/figure>\n<p>Basically one big pipeline, from input URLs over link extraction, to link checking, to output formatting.<\/p>\n<p>When @styfle opened the issue, I <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/issues\/78#issuecomment-744720356\">spotted the core problem almost immediately<\/a>:<\/p>\n<blockquote>\n<p>There is no connection back to the extractor.<\/p>\n<\/blockquote>\n<p>That missing feedback loop (from checked responses back to the input queue) is the whole problem in a nutshell. lychee\u2019s pipeline was designed as a one-shot, unidirectional flow: inputs go in one end, results come out the other, and the program stops when the input stream stops.\nRecursion needs a <em>cycle<\/em>: responses have to be able to create new inputs. And cycles in async, channel-based pipelines are where the dragons live. \ud83d\udc32<\/p>\n<p>I knew this on day one. I just badly underestimated how many ways we\u2019d find to get the cycle wrong.<\/p>\n<h2 id=\"attempt-1-a-simple-counter-february-december-2021\"><a class=\"anchor\" href=\"#attempt-1-a-simple-counter-february-december-2021\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Attempt 1: A Simple Counter (February - December 2021)<\/h2>\n<p>My <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/165\">first attempt<\/a> was deliberately small. I didn\u2019t want to rearchitect anything; I just wanted recursion to work!\nSo I added the handling directly in <code>main.rs<\/code>. The idea was:<\/p>\n<ol>\n<li>After receiving a response, extract links from it if it came from one of the original input domains.<\/li>\n<li>Push those new links back into the request channel.<\/li>\n<li>Keep a running count of total expected requests vs. completed requests.<\/li>\n<li>Stop when <code>completed == total<\/code>.<\/li>\n<\/ol>\n<p>I added a <code>recurse()<\/code> function that called <code>collector::collect_links()<\/code> on successful responses, spawned a task to send the new requests into the channel, and returned how many new requests it created. A plain <code>HashSet&lt;String&gt;<\/code> acted as a \u201cseen\u201d cache so I wouldn\u2019t re-check the same URL twice.<\/p>\n<p>On top of that:<\/p>\n<ul>\n<li>A <code>recursion_level<\/code> field on the <code>Request<\/code> and <code>Response<\/code> structs<\/li>\n<li>A <code>--recursive<\/code> \/ <code>-r<\/code> flag<\/li>\n<li>A <code>--depth<\/code> option for the maximum recursion depth<\/li>\n<li>Domain filtering to stay within the input domains<\/li>\n<\/ul>\n<p>Straightforward, right?<\/p>\n<h3 id=\"wrong\"><a class=\"anchor\" href=\"#wrong\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Wrong<\/h3>\n<p><strong>The program wouldn\u2019t terminate.<\/strong><\/p>\n<p>The termination logic was a <code>while curr &lt; total_requests<\/code> loop:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> curr<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">while<\/span><span> curr<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span> total_requests<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    curr<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> response<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> recv_resp<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">recv<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">context<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Receive channel closed<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ... process response, potentially incrementing total_requests<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>When responses arrive and generate new requests, <code>total_requests<\/code> goes up.\nSo far so good.  But extraction, sending, and receiving all happen <strong>concurrently<\/strong> across different tasks, so the count can get out of sync.<\/p>\n<p>I wasn\u2019t happy about it even at the time:<\/p>\n<blockquote>\n<p>TBH I\u2019m not super happy with the current impl anymore as I count the links in the queue and then close the channel after all links got checked. It can lead to subtle bugs I think. There must be a better way.<\/p>\n<\/blockquote>\n<p>Yes, Matthias from the past, the counter is fragile because:<\/p>\n<ul>\n<li>New links are discovered asynchronously, so <code>total_requests<\/code> can be bumped <em>after<\/em> the loop has already decided to exit.<\/li>\n<li>If the count is off by even one, you either hang forever (count too high) or quit too early (count too low).<\/li>\n<li>And to add insult to injury, every edge case made the counting logic gnarlier. Cached responses, failed responses, empty pages,\u2026<\/li>\n<\/ul>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/pawroman\"><strong>@pawroman<\/strong><\/a> gave me a genuinely thorough review here, including a careful analysis of memory usage for the <code>HashSet<\/code> cache (fine for up to millions of links), a suggestion to use signed depth values to express infinite recursion, and a nudge for integration tests. It was good feedback. It just couldn\u2019t fix the thing that was actually wrong, which was the whole approach to termination.<\/p>\n<h3 id=\"the-death-blow\"><a class=\"anchor\" href=\"#the-death-blow\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Death Blow<\/h3>\n<p>In September 2021 we decided to do a bigger rewrite: a stream-based architecture (<a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/330\">PR #330<\/a>) to improve concurrency. It changed <code>Collector::collect_links<\/code> from returning a <code>Vec<\/code> to returning a <code>Stream<\/code>, removed the <code>ClientPool<\/code> abstraction, and reshaped how tasks talked to each other. That was a great improvement as it meant that the collector was lazy and we wouldn\u2019t allocate big <code>Vec<\/code>s of requests anymore. But it also meant that the recursion branch was borked and got its rug pulled from underneath.<\/p>\n<blockquote>\n<p>Will put this on hold once again as we started implementing a stream-based approach in #330, which might supersede this branch soon. Sorry to everyone waiting on recursion support to land, but I\u2019d like to get this right instead of merging a buggy solution prematurely.<\/p>\n<\/blockquote>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/165\">PR #165<\/a> was closed in December 2021. The stream refactor landed and gave us a 35\u201350% speedup. Nice! Tradeoffs, I guess.<\/p>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways<\/p>\n    <ul>\n<li><strong>Counting outstanding work in an async pipeline is fragile.<\/strong> An off-by-one in distributed counting means a deadlock or an early exit.<\/li>\n<li><strong>Big refactors and feature branches don\u2019t get along.<\/strong> The stream rewrite made the recursion branch stale before it was ever ready.<\/li>\n<li><strong>Recursion touches almost every layer.<\/strong> This isn\u2019t something you bolt on.<\/li>\n<\/ul>\n<\/div>\n<p>And one honest aside on the language question, because I get asked it a lot: the counting problem here is <strong>not Rust\u2019s fault<\/strong>. A Go version with goroutines and channels, or a Python asyncio version, would hit the same off-by-one bugs. The race between \u201cresponse processed\u201d and \u201cnew requests discovered\u201d is inherent to any concurrent recursive crawler. Rust\u2019s <code>Stream<\/code> trait and the way it plays with ownership made a streaming architecture feel natural, and that\u2019s what invalidated the work. So that\u2019s perhaps a Rust-specific point.<\/p>\n<h2 id=\"attempt-2-feed-it-back-through-a-channel-january-july-2022\"><a class=\"anchor\" href=\"#attempt-2-feed-it-back-through-a-channel-january-july-2022\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Attempt 2: Feed It Back through a Channel (January - July 2022)<\/h2>\n<p>Now that the stream architecture was in place, I took another stab at it. This time, instead of counting requests by hand, I\u2019d <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/465\">feed discovered URLs back through a <em>channel<\/em> connected to the collector<\/a>.<\/p>\n<p>The collector would read from an input channel and turn what it received into a stream of requests.\nRecursion would just mean sending newly discovered URLs into that channel. (Look, a feedback loop!)\nThe stream would close naturally when the channel closed.<\/p>\n<p>I also played with unifying the input type so one method could take either a <code>Vec<\/code> or a <code>Stream<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> enum<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> InputType<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    Stream<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Pin<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Stream<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Item<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Input<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    Seq<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Input<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p><strong>It hung. Again.<\/strong> But for a completely different reason this time.<\/p>\n<p>The feedback loop created a circular dependency:<\/p>\n<ol>\n<li>The <strong>collector<\/strong> reads from an input channel and produces a stream of requests.<\/li>\n<li>The <strong>checker<\/strong> reads requests and produces responses.<\/li>\n<li>The <strong>recursion handler<\/strong> reads responses and sends new inputs back to the collector\u2019s channel.<\/li>\n<\/ol>\n<p>Do you see the problem?<\/p>\n<p>For the collector\u2019s stream to end, the input channel has to close.\nFor the channel to close, all senders have to be dropped.\nBut the recursion handler holds a sender; it needs one to push discovered URLs back.\nAnd the recursion handler only stops when there are no more responses, which only happens when there are no more requests, which only happens when the collector\u2019s stream ends.\nAnother circular dependency causing a deadlock.<\/p>\n<p>I said as much at the time:<\/p>\n<blockquote>\n<p>I had very little time to look at the issue so far, but it hangs because the input channel does not get dropped, leading to a dangling connection. I thought that the channel would be closed (and dropped) automatically once <code>futures::StreamExt::for_each_concurrent<\/code> finishes.<\/p>\n<\/blockquote>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/untitaker\"><strong>@untitaker<\/strong><\/a> confirmed it and could reproduce the deadlock in even trivial cases:<\/p>\n<blockquote>\n<p>You want to drop the <code>sender<\/code> once there\u2019s nothing to process anymore right? But won\u2019t <code>for_each_concurrent<\/code> hang forever because you didn\u2019t do that yet? (and can\u2019t, because you need the sender for more cloning)<\/p>\n<\/blockquote>\n<blockquote>\n<p>I can repro a deadlock even with <code>time lychee --offline -b . '**\/*.htm*' -T1<\/code> on an empty directory.<\/p>\n<\/blockquote>\n<p>This is the heart of using channels for cyclic data flow: <strong>channels use sender-drop as their termination signal, but in a cycle you can never drop all the senders, because each stage needs to hold one to keep the cycle alive.<\/strong><\/p>\n<p>I took the problem to the Tokio Discord, and the advice that came back was: \u201cStop using channels for this. Use semaphores with <code>tokio::spawn<\/code> instead.\u201d<\/p>\n<h3 id=\"the-performance-problem-too\"><a class=\"anchor\" href=\"#the-performance-problem-too\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Performance Problem Too<\/h3>\n<p>Even ignoring the deadlock, there was a second issue. The new <code>from_chan<\/code> method benchmarked roughly 30% slower than the existing <code>from<\/code> method. The extra channel indirection cost something, and it cost it even in the non-recursive case, which is the case basically everyone uses.<\/p>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways<\/p>\n    <ul>\n<li><strong>Channels are the wrong tool for cyclic pipelines.<\/strong> Their close-on-last-sender-drop semantics are fundamentally at odds with a feedback loop.<\/li>\n<li><strong><code>for_each_concurrent<\/code> looks perfect and isn\u2019t.<\/strong> It processes a stream concurrently but gives you no way to feed items back in.<\/li>\n<li><strong>The common path can\u2019t get slower.<\/strong> Recursion support is worthless if it taxes everyone who never uses it.<\/li>\n<\/ul>\n<\/div>\n<p>The channel-cycle deadlock is <strong>inherent to any channel-based system<\/strong>. Go channels have the same problem. Closing one means knowing nobody will send again, and a cycle makes that impossible. Erlang\/OTP sidesteps it with process monitoring instead of channel semantics. The 30% regression, though, has a Rust angle. Rust\u2019s zero-cost-abstraction culture means people (me included) expect to pay nothing for features they don\u2019t use. In a runtime-heavy language, a 30% regression on an unused path might slide. In Rust, \u201cyou don\u2019t pay for what you don\u2019t use\u201d is practically a moral position, and it made that regression a non-starter for me.<\/p>\n<h2 id=\"attempt-3-semaphores-february-2022\"><a class=\"anchor\" href=\"#attempt-3-semaphores-february-2022\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Attempt 3: Semaphores (February 2022)<\/h2>\n<h3 id=\"what-i-tried\"><a class=\"anchor\" href=\"#what-i-tried\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What I Tried<\/h3>\n<p>I dropped channels for the recursion loop entirely and reached for:<\/p>\n<ul>\n<li><code>Arc&lt;Semaphore&gt;<\/code> to cap concurrency (replacing the channel\u2019s natural backpressure)<\/li>\n<li><code>tokio::spawn<\/code> for each unit of work (replacing <code>for_each_concurrent<\/code>)<\/li>\n<li><code>OwnedSemaphorePermit<\/code> handed to each task, so work could be \u201ctransferred\u201d when spawning a recursive sub-task<\/li>\n<\/ul>\n<p>The <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/489\">prototype<\/a> was pretty clean, honestly:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> MAX_CONCURRENCY<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 10<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> recurse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">permit<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> OwnedSemaphorePermit<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> i<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> JoinHandle<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">    tokio<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">spawn<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> move<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        handle_input<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>permit<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> i<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> handle_input<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">permit<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> OwnedSemaphorePermit<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> i<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">got = <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span class=\"z-l-16 z-d-16\"> 9<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        recurse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>permit<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 10<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>But I guess you can tell what the problem with it was: <strong>it still locked up.<\/strong><\/p>\n<p>When I tried to bring this model into the real codebase, the ownership requirements got ugly fast. The link checker needs the client config, the cache, the progress bar, the stats, and a handful of other things. To share all of that across spawned tasks, it all wanted to be wrapped in <code>Arc&lt;RwLock&lt;State&gt;&gt;<\/code>.\nI tried this model on the branch, but it gets quite ugly because of ownership and <code>Send<\/code>.<\/p>\n<h3 id=\"semaphores-aren-t-enough\"><a class=\"anchor\" href=\"#semaphores-aren-t-enough\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Semaphores Aren\u2019t Enough<\/h3>\n<p>A semaphore solves the concurrency-limiting problem. It does nothing for the <em>termination<\/em> problem. With <code>tokio::spawn<\/code>, there\u2019s no built-in way to know when all spawned tasks \u2014 including the ones spawned recursively \u2014 have finished. You\u2019d need a separate coordination mechanism, which is to say: you\u2019d be reinventing the counter from Attempt 1, except now spread across an unbounded number of spawned tasks. We\u2019d come full circle to the very thing I was trying to escape.<\/p>\n<p>There\u2019s a subtlety with the permits, too. Swapping <code>for_each_concurrent<\/code> for raw <code>tokio::spawn<\/code> loses the bounded concurrency that channels gave us for free. The semaphore adds it back, but you have to manage permits carefully. If a task acquires a permit, spawns a child, and transfers the permit, the parent can\u2019t do more work. If it clones the permit, you can blow past your concurrency limit. Getting the permit lifecycle exactly right is fiddly.<\/p>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways<\/p>\n    <ul>\n<li><strong>Semaphores solve concurrency, not termination.<\/strong> You still need something to tell you \u201call the work is done.\u201d<\/li>\n<li><strong><code>Arc&lt;RwLock&lt;State&gt;&gt;<\/code> is a code smell in async Rust.<\/strong> When you start wrapping everything in locks, you\u2019re fighting the ownership model instead of working with it. That can leave a lot of performance on the table since every access is a lock acquisition across all threads.<\/li>\n<li><strong>The real question was never \u201chow do I recurse?\u201d<\/strong> It was \u201chow do I know when I\u2019m done recursing.\u201d<\/li>\n<\/ul>\n<\/div>\n<p>This was the most Rust-specific failure of the bunch.\nThe semaphore approach is idiomatic in Go. A <code>sync.WaitGroup<\/code> plus a semaphore channel, with state shared across goroutines via <code>sync.Mutex<\/code> is how you\u2019d do that in Golang because it has green threads and a runtime that manages goroutine lifecycles for you.<\/p>\n<p>But in Rust, the <code>Send + 'static<\/code> bounds on <code>tokio::spawn<\/code>, the borrow checker\u2019s aversion to shared mutable state, and the cost of <code>Arc&lt;RwLock&lt;T&gt;&gt;<\/code> get in the way. Rust made the \u201cjust wrap everything in Arc and Mutex\u201d escape hatch painful enough that it became a dead end.<\/p>\n<h2 id=\"2022-2024-sleeping\"><a class=\"anchor\" href=\"#2022-2024-sleeping\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2022\u20132024 \ud83d\ude34<\/h2>\n<p>For more than two years, the recursion issue kept collecting comments from people who wanted it.\nPeople suggested workarounds (piping sitemap URLs through <code>xargs<\/code> was a popular one). The person who originally filed it built <a rel=\"external\" href=\"https:\/\/github.com\/styfle\/links-awakening\">their own tool<\/a> and moved on, which I completely understood.<\/p>\n<p>Someone offered a \u20ac100 bounty. Others pointed to <a rel=\"external\" href=\"https:\/\/github.com\/raviqqe\/muffet\">muffet<\/a>, which already does recursive checking. lychee wasn\u2019t standing still during these years; a lot of work went into performance, caching, rate limiting, and other features. But recursion was the elephant in the room.<\/p>\n<h2 id=\"attempt-4-gwenn-takes-a-swing-january-march-2025\"><a class=\"anchor\" href=\"#attempt-4-gwenn-takes-a-swing-january-march-2025\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Attempt 4: Gwenn Takes a Swing (January \u2013 March 2025)<\/h2>\n<p>In late 2024, a community contributor, <a rel=\"external\" href=\"https:\/\/github.com\/gwennlbh\"><strong>@gwennlbh<\/strong><\/a>, <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/1603\">picked up the gauntlet<\/a>. Her plan went back to the channel-based model but with a twist: instead of trying to close channels for termination, she used an <code>Arc&lt;AtomicUsize&gt;<\/code> counter. Like Attempt 1, but atomic and shared across tasks!<\/p>\n<p>And it looked so elegant:<\/p>\n<ol>\n<li>Keep the two existing mpsc channels (requests and responses).<\/li>\n<li>After receiving a response, extract links from the body and send them as new requests.<\/li>\n<li>Use the <code>Arc&lt;AtomicUsize&gt;<\/code> to track remaining work \u2014 increment when new requests are sent (recursive ones included), decrement when a response is processed, and break out of the receive loop when it hits zero.<\/li>\n<li>Lean on the existing cache to avoid cycles (don\u2019t re-check URLs already seen).<\/li>\n<\/ol>\n<p>This was the most functional attempt yet. It <em>actually worked<\/em> on real websites:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lychee<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">R<\/span><span class=\"z-l-5 z-d-7\"> https:\/\/endler.dev<\/span><span class=\"z-l-15 z-d-13\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">       -<\/span><span class=\"z-l-5 z-d-7\">-recursed-domains<\/span><span class=\"z-l-5 z-d-7\"> endler.dev<\/span><\/span><\/code><\/pre>\n<p>I was really excited watching it come together, and I tried to give useful design guidance along the way:<\/p>\n<ul>\n<li>Default recursion depth of 5<\/li>\n<li>Strict domain matching (no subdomain checking)<\/li>\n<li>Rate limiting deferred to a separate PR<\/li>\n<li>Breaking changes to <code>lychee-lib<\/code>\u2019s public API accepted<\/li>\n<\/ul>\n<h3 id=\"where-it-broke\"><a class=\"anchor\" href=\"#where-it-broke\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where It Broke<\/h3>\n<p>And then it hit the same wall, from several directions at once.<\/p>\n<h4 id=\"1-channel-backpressure-deadlock\"><a class=\"anchor\" href=\"#1-channel-backpressure-deadlock\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>1. Channel Backpressure Deadlock<\/h4>\n<p>When recursion discovered a lot of links, the response handler tried to send new requests into the request channel. But if that channel was full (bounded by <code>max_concurrency<\/code>), the send blocked. A blocked response handler means no responses get processed, which means no request slots free up. <strong>Classic backpressure deadlock.<\/strong><\/p>\n<p>@gwennlbh worked around it by spawning the \u201csend new requests\u201d work in a separate <code>tokio::spawn<\/code>, decoupling response processing from request sending. It worked, but it meant there was no longer a limit on how many of these background tasks could pile up (and with that, use unbounded memory).<\/p>\n<h4 id=\"2-duplicate-requests\"><a class=\"anchor\" href=\"#2-duplicate-requests\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2. Duplicate Requests<\/h4>\n<p>Because requests are processed in parallel, the same URL could be discovered by multiple pages and sent into the channel before any of them got cached. The cache check happened too late: after the request was already in flight. There was no per-URL synchronization to stop concurrent duplicates:<\/p>\n<blockquote>\n<p>Because of the parallel nature of the request-to-response task, it seems to me that sending the same request twice to the channel is hard to prevent. I tried adding guards basically everywhere [\u2026] and I still seem to get duplicates.<\/p>\n<\/blockquote>\n<p>As a stopgap, a dedup check went into <code>Stats::insert<\/code>, but that only stopped duplicate <em>reporting<\/em>, not duplicate <em>checking<\/em>. The real fix would arrive much later, with the <code>HostPool<\/code>\u2019s per-URI <code>active_requests<\/code> mutex, but that machinery didn\u2019t exist yet.<\/p>\n<h4 id=\"3-the-counter-yet-again\"><a class=\"anchor\" href=\"#3-the-counter-yet-again\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>3. The Counter, Yet Again<\/h4>\n<p>The <code>Arc&lt;AtomicUsize&gt;<\/code> counter is, at heart, the same idea as Attempt 1 \u2014 and it brought the same fragility. With <code>Ordering::Relaxed<\/code> (the weakest memory ordering), increments and decrements across threads could be reordered, so the counter could briefly read zero before the work was actually done. On Wikipedia with <code>--max-depth=0<\/code>, it would lock up on the very last URL.<\/p>\n<h4 id=\"4-changes-everywhere\"><a class=\"anchor\" href=\"#4-changes-everywhere\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>4. Changes Everywhere<\/h4>\n<p>Adding <code>subsequent_uris<\/code> (the list of discovered links) to the <code>Response<\/code> type meant touching nearly every file that builds or consumes a <code>Response<\/code>. Every <code>Response::new()<\/code> call needed two new arguments (<code>vec![]<\/code> and <code>0<\/code> for the non-recursive case).<\/p>\n<h4 id=\"5-the-collector-got-bypassed\"><a class=\"anchor\" href=\"#5-the-collector-got-bypassed\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>5. The Collector Got Bypassed<\/h4>\n<p>To extract links from response bodies, the code built a fresh <code>Collector<\/code> inline in the checker, sidestepping the configured collector that respects user flags like <code>--exclude<\/code>, <code>--include<\/code>, and fragment checking.<\/p>\n<h3 id=\"the-end-of-that-road\"><a class=\"anchor\" href=\"#the-end-of-that-road\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The End of That Road<\/h3>\n<p>After a burst of energy in January 2025, things slowed. Merge conflicts piled up. CI linting rules changed underneath the branch. @gwennlbh switched to Windows and couldn\u2019t get the OpenSSL dependency to build. In March 2025 she wrote, honestly:<\/p>\n<blockquote>\n<p>even though I was kinda denying it, it\u2019s pretty clear that I\u2019ve lost motivation to keep working on this [\u2026] I\u2019m sorry T_T<\/p>\n<\/blockquote>\n<p>I didn\u2019t want her to apologize. She got further than anyone, on a hard feature, in a complex async codebase, as a volunteer. Instead, I\u2019m grateful for the time she invested to push things forward.<\/p>\n<div class=\"info\">\n    <p class=\"info-title\">Takeaways<\/p>\n    <ul>\n<li><strong>The atomic counter is a manual counter in a trenchcoat.<\/strong> It had the same failure modes.<\/li>\n<li>When you\u2019re adding <code>vec![]<\/code> and <code>0<\/code> to every <code>Response::new()<\/code> call, that\u2019s a leaky abstraction.<\/li>\n<li><strong>Outside contributors face extra friction.<\/strong> Build-environment differences, conflicts with a moving target, and the sheer cognitive load of a big async codebase make this an especially brutal feature to contribute.<\/li>\n<\/ul>\n<\/div>\n<p>How much of the issues were Rust-specific?\nI\u2019d say around half.\nThe backpressure is simply part of the problem space.\nAny concurrent crawler in any language meets that.\nThe <code>Ordering::Relaxed<\/code> trap is somewhat Rust-specific in that Rust makes you <em>choose<\/em> a memory ordering (Go\u2019s <code>sync\/atomic<\/code> does too, but most Go folks reach for <code>sync.WaitGroup<\/code> instead).<\/p>\n<h2 id=\"so-why-is-this-actually-hard\"><a class=\"anchor\" href=\"#so-why-is-this-actually-hard\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>So Why Is This Actually Hard?<\/h2>\n<p>Four attempts in five years.\nIf we take a step back, I think the difficulties can be grouped into a few categories:<\/p>\n<h3 id=\"knowing-when-you-re-done\"><a class=\"anchor\" href=\"#knowing-when-you-re-done\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Knowing When You\u2019re Done<\/h3>\n<p>Every implementation faced the same question: <strong>how do you know when you\u2019re finished?<\/strong><\/p>\n<p>In a non-recursive pipeline the answer is easy. You\u2019re done when the input stream is exhausted and the in-flight requests have completed.\nClose the channel sender, drain the receiver, and Bob\u2019s your uncle.<\/p>\n<p>In a recursive pipeline the input stream is never truly exhausted, because every response might create new inputs. You need a separate way to detect <em>quiescence<\/em>: the state where nothing is in progress and nothing new will be generated.<\/p>\n<p>Turns out, the problem has a name in distributed systems: \u2728 <strong>distributed termination detection<\/strong>. \u2728<\/p>\n<p>The classic solutions (<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Dijkstra%E2%80%93Scholten_algorithm\">Dijkstra\u2013Scholten<\/a>, <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Token_passing\">token passing<\/a>) just don\u2019t map well onto Tokio\u2019s channel-based world.<\/p>\n<h3 id=\"the-cycle\"><a class=\"anchor\" href=\"#the-cycle\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Cycle<\/h3>\n<p>lychee\u2019s architecture is fundamentally a DAG.\nInputs flow one direction through the stages.\nRecursion introduces a cycle.\nAnd cycles in channel-based systems deadlock, because channels use \u201call senders dropped\u201d as their done signal, and in a cycle that condition is never met on its own.<\/p>\n<h3 id=\"backpressure\"><a class=\"anchor\" href=\"#backpressure\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Backpressure<\/h3>\n<p>Bounded channels give you natural backpressure: if the checker is slow, the sender blocks until there\u2019s room.\nWhich is lovely, until you want recursion.\nNow the <em>response handler<\/em> needs to send into the <em>request channel<\/em>.\nIf that channel is full, the response handler blocks; if it blocks, no responses are consumed; if no responses are consumed, no request slots free up.<\/p>\n<h3 id=\"deduplication-races\"><a class=\"anchor\" href=\"#deduplication-races\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Deduplication Races<\/h3>\n<p>We check links concurrently, which means multiple pages can hold the same link.\nWithout synchronization, several tasks discover the same URL and submit it before any of them can mark it \u201cseen.\u201d\nThrough attempts 1\u20134 the cache didn\u2019t save us, because cache entries were written <em>after<\/em> checking, not before submission.<\/p>\n<h3 id=\"leaky-abstraction\"><a class=\"anchor\" href=\"#leaky-abstraction\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Leaky Abstraction<\/h3>\n<p>Recursion-awareness wants to live \u201ceverywhere.\u201d\nResponses need to carry discovered links, Requests need a depth, the collector needs to understand recursive inputs, stats and formatters need to handle duplicates.<\/p>\n<h3 id=\"how-much-of-this-is-rust-s-fault\"><a class=\"anchor\" href=\"#how-much-of-this-is-rust-s-fault\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How Much of This Is Rust\u2019s Fault?<\/h3>\n<p>I think this is the question people reading my blog really want answered, so let me be direct.\nMy honest estimate is\u2026 <strong>about 30%?<\/strong>\nThe termination problem, the cycle problem, and the backpressure problem are all just part of the problem space.\nAny concurrent recursive crawler, be it written in Go, Python, Java, or Erlang, has to solve that.\nAt some point, <a rel=\"external\" href=\"https:\/\/www.scrapy.org\/\">Scrapy<\/a>, <a rel=\"external\" href=\"https:\/\/github.com\/gocolly\/colly\">Colly<\/a>, and the other mature crawling frameworks all had to do distributed termination detection and backpressure management.<\/p>\n<p>What Rust adds is friction at the implementation level:<\/p>\n<ul>\n<li>Ownership and <code>Send<\/code> bounds make it harder to share state across spawned tasks. In Go you capture variables in a goroutine closure and move on. In Rust everything in async-land wants to be <code>Arc<\/code>-wrapped and <code>Send + 'static<\/code>.<\/li>\n<li>Explicit memory ordering on atomics forces you to think about concurrency correctness and also makes \u201ceh, just use relaxed\u201d a tempting but dangerous choice.<\/li>\n<li>Channel termination semantics in Tokio are stricter than in some other ecosystems. Go\u2019s <code>context.Context<\/code> gives you an orthogonal cancellation mechanism that Tokio channels don\u2019t natively have. (In Tokio, you\u2019d use a <a rel=\"external\" href=\"https:\/\/tokio.rs\/tokio\/topics\/shutdown\">CancellationToken<\/a> for that.)<\/li>\n<\/ul>\n<p>But on the other side, Rust also prevented a lot of issues:<\/p>\n<ul>\n<li>The compiler caught every unsafe attempt to share mutable state. In Go those would\u2019ve been subtle runtime bugs I\u2019d find in production or maybe with the race detector.<\/li>\n<li>Using the type system in our favor, we can make the right thing be the ergonomic thing.<\/li>\n<\/ul>\n<p>Put another way, Rust made the <em>wrong<\/em> approaches fail loudly and painfully e.g. with compiler errors (but also deadlocks in tests) and made the <em>right<\/em> approach more solid and ergonomic.<\/p>\n<h2 id=\"a-new-hope\"><a class=\"anchor\" href=\"#a-new-hope\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A New Hope<\/h2>\n<p>Despite all the failed attempts, the ground has quietly shifted under this problem in 2025\u20132026. A bunch of work, most of it not even about recursion, has made a real implementation finally look within reach.<\/p>\n<h3 id=\"per-host-rate-limiting-december-2025\"><a class=\"anchor\" href=\"#per-host-rate-limiting-december-2025\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Per-Host Rate Limiting (December 2025)<\/h3>\n<p>Recursion without rate limiting is dangerous.\nGwenn found that out firsthand by accidentally DDoS\u2019ing their own WiFi router while recursively checking Wikipedia. \ud83d\ude2c\nPer-host rate limiting, which got merged in <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/1929\">PR #1929<\/a>, makes recursive crawling respect server limits.\nI previously waved this off as \u201cout of scope\u201d but it\u2019s super important in practice.<\/p>\n<p>The underlying issue (<a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/issues\/1605\">#1605<\/a>) was one I opened on January 6, 2025 \u2014 the same week <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/1603\">PR #1603<\/a> (Attempt 4) opened. That timing was no accident. The moment we tried recursion for real, the lack of per-host rate limiting showed up as a glaring gap. It caused concurrent requests to the same host to throw 429s, the cache to be ineffective under high concurrency due to races (issue <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/issues\/1593\">#1593<\/a>), and global concurrency settings being too coarse for a workload spread across many hosts at once.<\/p>\n<p>The fix introduced a <code>HostPool<\/code>, which is a per-host request queue with configurable rate limits, delays, and concurrent-request caps.\nEach host gets its own bucket with its own settings, configurable via <code>lychee.toml<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"toml\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span>hosts<\/span><span>.<\/span><span>&quot;github<\/span><span>.<\/span><span>com&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span>max_concurrent_requests<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 10<\/span><\/span>\n<span class=\"giallo-l\"><span>request_delay<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">100ms<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>The <code>HostPool<\/code> would later become a central abstraction. It\u2019s the very same <code>HostPool<\/code> that <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/2100\">PR #2100<\/a> reused to unify input fetching with link checking, which means it\u2019s now the single entrypoint that all HTTP requests flow through.<\/p>\n<p>It\u2019s important for recursion because the <code>HostPool<\/code> gives us per-host rate limiting, deduplication (via each <code>Host<\/code>\u2019s per-URI <code>active_requests<\/code> mutex and <code>HostCache<\/code>), and caching at the right granularity, which lets recursive crawling stay a good web citizen (respecting rate-limit headers, backing off on 429s).<\/p>\n<h3 id=\"the-waitgroup-february-2026\"><a class=\"anchor\" href=\"#the-waitgroup-february-2026\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The WaitGroup (February 2026)<\/h3>\n<p>The single most important recent thing is the <code>WaitGroup<\/code> primitive, contributed by <a rel=\"external\" href=\"https:\/\/github.com\/katrinafyi\">Kait<\/a> and merged in <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/2046\">PR #2046<\/a>.\nIt is one step towards solving the termination problem.<\/p>\n<p><code>WaitGroup<\/code> is a mechanism for waiting on a dynamic set of tasks that can themselves spawn more tasks. It\u2019s two pieces:<\/p>\n<ul>\n<li><code>WaitGroup<\/code>, a single waiter that fires when all the work is done.<\/li>\n<li><code>WaitGuard<\/code>, a cloneable guard held by each task. When the last guard is dropped, the waiter completes.<\/li>\n<\/ul>\n<p>The key move is that a <code>WaitGuard<\/code> can be cloned. A task can spawn sub-tasks (recursion!) while preserving the invariant that the <code>WaitGroup<\/code> only completes once <em>every<\/em> guard \u2014 including the ones held by recursive sub-tasks \u2014 has been dropped.<\/p>\n<p>That cleanly solves the termination problem:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>waiter<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> guard<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> WaitGroup<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Each request carries a guard clone<\/span><\/span>\n<span class=\"giallo-l\"><span>send_req<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">send<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>guard<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> request<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> In the response handler, if recursing:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> the guard is cloned for each new request<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span> new_request<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> discovered_links<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    send_req<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">send<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>guard<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> new_request<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The original guard is dropped when the response is fully processed.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> When ALL guards are dropped (no more work), waiter.wait() returns.<\/span><\/span><\/code><\/pre>\n<p>It\u2019s already wired into lychee\u2019s main check loop. The <code>collect_responses<\/code> function uses <code>take_until(waiter.wait())<\/code> to stop receiving when the work is done. There\u2019s even a comment in the current code anticipating exactly this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> unused for now, but will be used for recursion eventually. by holding<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> an extra `send_req` endpoint, we prevent the natural termination when<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> each channel finishes and closes. instead, we rely on the WaitGroup to<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> break the cyclic channels.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> _<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> send_req<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>That\u2019s the missing piece that our previous attempts lacked.<\/p>\n<h3 id=\"unified-request-handling-pr-2100-merged-march-2026\"><a class=\"anchor\" href=\"#unified-request-handling-pr-2100-merged-march-2026\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Unified Request Handling (PR #2100, Merged March 2026)<\/h3>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/2100\">PR #2100<\/a> unified input URL fetching with the link checker\u2019s <code>HostPool<\/code>. Before this, CLI input URLs went through a separate <code>reqwest::Client<\/code> that didn\u2019t share config (user-agent, rate limiting, TLS settings) with the checker. That caused real bugs (Wikipedia returning 403 for input URLs because no user-agent was set).<\/p>\n<p>After it, input fetching and link checking go through the same pool. For recursion this matters because recursively discovered pages need to be fetched and parsed, and they should use the same client config as everything else.<\/p>\n<h3 id=\"sitemap-support-february-2026\"><a class=\"anchor\" href=\"#sitemap-support-february-2026\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Sitemap Support (February 2026)<\/h3>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\/pull\/2062\">Sitemap support<\/a> is a partial solution to a lot of recursion use cases. By parsing <code>sitemap.xml<\/code>, lychee can discover every page on a site without crawling recursively at all. It\u2019s not a replacement for true recursion (it doesn\u2019t help sites without sitemaps, and it won\u2019t find dynamically linked pages), but it unblocks a lot of use-cases.<\/p>\n<h2 id=\"what-proper-recursion-could-look-like\"><a class=\"anchor\" href=\"#what-proper-recursion-could-look-like\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What Proper Recursion <em>Could<\/em> Look Like<\/h2>\n<p>With all that in place, here\u2019s what\u2019s left. The striking part is how much of it is already done:<\/p>\n<ul>\n<li>Knowing when the crawl is done is solved by the <code>WaitGroup<\/code>.<\/li>\n<li>Deadlocks are avoided by spawning the follow-up work instead of blocking on a full channel.<\/li>\n<li>The per-host pool already paces requests, so we don\u2019t hammer a server.<\/li>\n<li>lychee already skips URLs it has seen, which matters when every page links to the same nav and footer.<\/li>\n<li><strong>Getting the page back is the one open problem.<\/strong> lychee throws the page away after checking it, but recursion needs the HTML to find more links. It\u2019s still in cache from the check that just happened, so we can grab it again for free. (Assuming the request method is GET, not a HEAD, which doesn\u2019t return a body.)<\/li>\n<\/ul>\n<p>Once those are in, the actual recursion is just a handful of lines. When a checked page is on an allowed domain and under the depth limit, grab its content from cache, pull out the links, and send them back through the same pipeline as fresh requests:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">if<\/span><span> recursive<\/span><span class=\"z-l-2 z-d-5\"> &amp;&amp;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> is_same_domain<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>response<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span>recursion_domains<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> &amp;&amp;<\/span><span> depth<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span> max_depth<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> content<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> resolver<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">url_contents<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>response<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">url<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> cache hit<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> links<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> extractor<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">extract<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>content<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span> req<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-13 z-d-15\"> request<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">create<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>links<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> ...<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        send_req<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">send<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>guard<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>req<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The hard parts (knowing when to stop, not deadlocking, not flooding a server) are already solved by work that was never about recursion in the first place.\nRecursion becomes a by-product of good architecture, not a special case bolted onto a pipeline that was never built for it.<\/p>\n<h2 id=\"so-did-we-fail\"><a class=\"anchor\" href=\"#so-did-we-fail\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>So, Did We Fail\u2026?<\/h2>\n<p>For a long time I told myself we\u2019d failed. Four attempts, five years, seemingly nothing shipped.<\/p>\n<p>But writing it all out changed how I see it.\nEvery attempt hit some mix of channel termination semantics, backpressure deadlocks, ownership ergonomics, and distributed termination detection.\nNone of those are lychee problems. They\u2019re hard concurrent-systems problems.\nWe just lacked the vocabulary to talk about them, and while I wasn\u2019t looking, those primitives got built.\nSometimes the most important code you write for a feature is the code that never mentions the feature at all.<\/p>\n<p>So no, I don\u2019t think we failed. We made progress by stumbling into the right direction.<\/p>\n<p>Thanks to NLnet for funding the work on lychee, and to everyone who contributed to the recursion effort over the years, whether in code, design feedback, or moral support. It\u2019s been a long road, but we\u2019re closer than ever to the finish line.<\/p>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n<li id=\"fn-night\">\n<p>Well, to be fair, I still code late at night. But that\u2019s just how I\u2019m wired. <a href=\"https:\/\/endler.dev\/2026\/lychee-recursion\/#fr-night-1\">\u21a9<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n"},{"title":"Hosting My Own Newsletter","pubDate":"Thu, 21 May 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/newsletter-setup\/","guid":"https:\/\/endler.dev\/2026\/newsletter-setup\/","description":"<p>I had a newsletter on this blog for years, but I didn\u2019t send a single email for a long time.\nThis is the story of how I finally got it back up and running, and what I learned along the way.<\/p>\n<p>A quick note up front, because this caused some confusion: by \u201chosting my own\u201d I mean I don\u2019t use a newsletter <em>platform<\/em>. The signup backend and the CLI I use to send issues are mine, and the issues themselves are just markdown files in a git repo. I still use <a rel=\"external\" href=\"https:\/\/www.useplunk.com\/\">Plunk<\/a> as the sending backend (so SES, bounces, suppression lists, and unsubscribe pages aren\u2019t my problem). Plunk <em>is<\/em> open source and I could self-host it, but the deliverability side has enough edge cases that I\u2019m happy to pay someone else to run it. \ud83d\ude43<\/p>\n<h2 id=\"the-tinyletter-years\"><a class=\"anchor\" href=\"#the-tinyletter-years\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Tinyletter Years<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-landing-page.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-landing-page.jpg\" alt=\"The old Tinyletter landing page, now a sad 404.\" width=\"650\" height=\"392\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The old Tinyletter landing page, now a sad 404.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20240229161126\/http:\/\/tinyletter.com\/\">Wayback Machine<\/a>\n    <\/figcaption>\n<\/figure>\n<p>For years my setup was a small form on the website pointing at <strong>Tinyletter<\/strong>, a small newsletter service that was focused on writers.\nWhat I liked about it was the simplicity.\nI never had to think about email deliverability, bounce rates, suppression lists, SPF, DKIM, DMARC, or any of that.\nI wrote a thing, hit send, people got it.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-compose-message.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-compose-message.jpg\" alt=\"The Tinyletter compose page, showing the simplicity of the interface.\" width=\"650\" height=\"378\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The Tinyletter compose page, showing the simplicity of the interface.\n    <\/figcaption>\n<\/figure>\n<p>It just worked. Then Tinyletter shut down.<\/p>\n<p>A bit of history: Tinyletter was built in 2010 by <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Philip_Kaplan\">Philip Kaplan<\/a>, reportedly coded <a rel=\"external\" href=\"https:\/\/techcrunch.com\/2010\/11\/12\/pud-revisits-his-past-launches-an-email-newsletter-platform-with-tinyletter\/\">on a single Sunday, the 31st of October, 2010<\/a>.<\/p>\n<p>It got acquired by Mailchimp one year later, and quietly became the de facto home for writers who wanted a personal newsletter without thinking about funnels, segments, or A\/B tests.<\/p>\n<p>Then in late 2023, Mailchimp (now part of Intuit) announced they\u2019d shut it down.\nThe official wording was that their \u201cbusiness priorities have evolved\u201d and that they were \u201claser focused on building tools to serve marketers and help small businesses grow.\u201d\n<a rel=\"external\" href=\"https:\/\/simonowens.substack.com\/p\/tinyletter-was-one-of-the-greatest\">Writers were never their core customers.<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-shutdown.png\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/newsletter-setup\/tinyletter-shutdown.png\" alt=\"Mailchimp's shutdown announcement, late 2023.\" width=\"1222\" height=\"1584\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Mailchimp\u2019s shutdown announcement, late 2023.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/emailoctopus.com\/blog\/alternative-to-tinyletter\">EmailOctopus<\/a>\n    <\/figcaption>\n<\/figure>\n<p>Just before Tinyletter went dark on February 29, 2024, I made a final backup of my subscriber list, but I didn\u2019t have a plan for what to do with it.<\/p>\n<h2 id=\"denial\"><a class=\"anchor\" href=\"#denial\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Denial<\/h2>\n<p>At this point, I became hostile to the idea of using a third-party service.\nThe same story could repeat itself again.<\/p>\n<p>I still looked at all options and bounced off all of them:<\/p>\n<ul>\n<li><strong>Too expensive!<\/strong> Most services price per contact and assume you\u2019re running a business funnel, not writing letters to people.<\/li>\n<li><strong>Too marketing-focused!<\/strong> Templates, drag-and-drop builders, A\/B tests, engagement scoring, tracking pixels. The whole vocabulary is wrong. I don\u2019t want to run <em>campaigns<\/em>; I want to send <em>email<\/em>!<\/li>\n<li><strong>Not hacker-friendly.<\/strong> No markdown, no CLI, no API I\u2019d actually enjoy using. Everything happens in a web dashboard built for a marketing team.<\/li>\n<li><strong>Not open source.<\/strong> If the next Tinyletter shuts down, I\u2019d like to keep going without having to migrate again.<\/li>\n<li><strong>Tracking by default!<\/strong> Open tracking, click tracking, pixels in every footer. I don\u2019t want to know who opened what. I want to write, you read it (or don\u2019t), the end.<\/li>\n<\/ul>\n<h2 id=\"migrating-to-fly-io\"><a class=\"anchor\" href=\"#migrating-to-fly-io\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Migrating to Fly.io<\/h2>\n<p>People kept asking me when the newsletter was coming back, so I cobbled something together on <a rel=\"external\" href=\"https:\/\/fly.io\/\">fly.io<\/a>.\nIt was a small Rust API, a CSV file with subscribers, and a way to subscribe through the website.\nThe idea was to deal with the sending later, but at least offer a way to sign up for now.<\/p>\n<p>Then the list just sat there.<\/p>\n<p>Turns out, a cold list is a problem all by itself.\nWhen you finally do send to a list of people who haven\u2019t heard from you in a long time, mail providers get suspicious and you can get flagged as spam.\nSuddenly your own newsletter can turn against you.<\/p>\n<h2 id=\"the-hunt-for-a-sending-service\"><a class=\"anchor\" href=\"#the-hunt-for-a-sending-service\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Hunt for a Sending Service<\/h2>\n<p>This was the hardest part by far.\nI looked into <a rel=\"external\" href=\"https:\/\/resend.com\/\">Resend<\/a>, <a rel=\"external\" href=\"https:\/\/postmarkapp.com\/\">Postmark<\/a>, <a rel=\"external\" href=\"https:\/\/sendgrid.com\/\">SendGrid<\/a>, <a rel=\"external\" href=\"https:\/\/www.mailgun.com\/\">Mailgun<\/a>, <a rel=\"external\" href=\"https:\/\/aws.amazon.com\/ses\/\">Amazon SES<\/a>, and many more.\nAll of them were either quite expensive for a small newsletter, had a terrible API, didn\u2019t comply\u00a0with GDPR regulations, or were way too complicated.<\/p>\n<p>I was about to give up when I found <a rel=\"external\" href=\"https:\/\/www.useplunk.com\/\">Plunk<\/a>.\nIt is open source, the pricing scales with your list size, and the API doesn\u2019t fight me.\nIt does the deliverability work I don\u2019t want to think about (<a rel=\"external\" href=\"https:\/\/aws.amazon.com\/ses\/\">SES integration<\/a>, <a rel=\"external\" href=\"https:\/\/debounce.com\/glossary\/bounce-handling\/\">bounce handling<\/a>, <a rel=\"external\" href=\"https:\/\/mailchimp.com\/resources\/email-suppression-list\/\">suppression list<\/a>, <a rel=\"external\" href=\"https:\/\/docs.useplunk.com\/concepts\/templates\">hosted unsubscribe pages<\/a>).\nI\u2019m a paying customer now.\nI\u2019m not affiliated, just a genuinely happy user.<\/p>\n<p>I even sent them a <a rel=\"external\" href=\"https:\/\/github.com\/useplunk\/plunk\/pull\/359\">small contribution<\/a> and they merged it in ten minutes.\nThis made me feel like I was actually part of a community.<\/p>\n<p>The first real newsletter issue went out to a thousand-plus contacts that hadn\u2019t heard from me in ages.\nI was bracing for a wave of bounces, but it went fine.\nBounce rate around 1%, only very few unsubscribes, and no deliverability issues.\nWow!<\/p>\n<p>I didn\u2019t do anything fancy: no batching, no slow warmup, no clever subject line.\nI sent it all at once and let Plunk (well, SES underneath) auto-prune obviously dead addresses via bounce handling.\nThe one thing I did do was lead the first issue with a short, frank reintroduction \u2013 something like <em>\u201chey, you signed up because you read a blog post of mine once, sorry for the silence\u201d<\/em> \u2013 which I think did most of the work in keeping unsubscribes low.<\/p>\n<p>Cost-wise, one send to the full list costs me roughly <strong>$1<\/strong>.\nFor a newsletter I send irregularly, that\u2019s nothing.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/newsletter-setup\/plunk-dashboard.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/newsletter-setup\/plunk-dashboard.jpg\" alt=\"The Plunk dashboard, showing the campaign overview and deliverability report. As you can see, I don't track who opens my emails.\" width=\"650\" height=\"140\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The Plunk dashboard, showing the campaign overview and deliverability report. As you can see, I don\u2019t track who opens my emails.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/www.useplunk.com\/\">Plunk<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"this-feels-like-home\"><a class=\"anchor\" href=\"#this-feels-like-home\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>This Feels like Home!<\/h2>\n<p>I realized I could write issues as plain markdown files in a folder, version-controlled, with a small CLI for everything else.\nThat\u2019s where I feel at home.\nJust me, a cup of hot chocolate, my editor, the terminal, and git.\nNo more web dashboard between me and the writing.<\/p>\n<p>The whole thing lives in a single repo:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">newsletter\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u251c\u2500\u2500<\/span><span class=\"z-l-5 z-d-7\"> issues\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">         #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> one .md per edition (1.md, 2.md, ...)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u251c\u2500\u2500<\/span><span class=\"z-l-5 z-d-7\"> send\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">           #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> the CLI I run locally<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u2514\u2500\u2500<\/span><span class=\"z-l-5 z-d-7\"> subscribe\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">      #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> tiny HTTP service behind the website signup form<\/span><\/span><\/code><\/pre>\n<p>The CLI is called <code>send<\/code>. Here\u2019s what it can do:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">$<\/span><span class=\"z-l-5 z-d-7\"> send<\/span><span class=\"z-l-5 z-d-7\"> help<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Usage:<\/span><span class=\"z-l-5 z-d-7\"> send<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span class=\"z-l-5 z-d-7\">COMMAN<\/span><span>D<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Commands:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  new<\/span><span class=\"z-l-5 z-d-7\">      Create<\/span><span class=\"z-l-5 z-d-7\"> a<\/span><span class=\"z-l-5 z-d-7\"> new<\/span><span class=\"z-l-5 z-d-7\"> issue<\/span><span class=\"z-l-5 z-d-7\"> file<\/span><span class=\"z-l-5 z-d-7\"> and<\/span><span class=\"z-l-5 z-d-7\"> open<\/span><span> $<\/span><span>EDITOR<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  list<\/span><span class=\"z-l-5 z-d-7\">     List<\/span><span class=\"z-l-5 z-d-7\"> local<\/span><span class=\"z-l-5 z-d-7\"> issues<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  lint<\/span><span class=\"z-l-5 z-d-7\">     Check<\/span><span class=\"z-l-5 z-d-7\"> links<\/span><span class=\"z-l-5 z-d-7\"> in<\/span><span class=\"z-l-5 z-d-7\"> an<\/span><span class=\"z-l-5 z-d-7\"> issue<\/span><span> (or<\/span><span class=\"z-l-5 z-d-7\"> all<\/span><span class=\"z-l-5 z-d-7\"> issues<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">  test<\/span><span class=\"z-l-5 z-d-7\">     Send<\/span><span class=\"z-l-5 z-d-7\"> a<\/span><span class=\"z-l-5 z-d-7\"> test<\/span><span class=\"z-l-5 z-d-7\"> email<\/span><span class=\"z-l-5 z-d-7\"> to<\/span><span class=\"z-l-5 z-d-7\"> myself<\/span><span> <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  publish<\/span><span class=\"z-l-5 z-d-7\">  Publish<\/span><span class=\"z-l-5 z-d-7\"> the<\/span><span class=\"z-l-5 z-d-7\"> issue<\/span><span class=\"z-l-5 z-d-7\"> to<\/span><span class=\"z-l-5 z-d-7\"> all<\/span><span class=\"z-l-5 z-d-7\"> subscribed<\/span><span class=\"z-l-5 z-d-7\"> contacts<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  status<\/span><span class=\"z-l-5 z-d-7\">   Show<\/span><span class=\"z-l-5 z-d-7\"> contact-list<\/span><span class=\"z-l-5 z-d-7\"> and<\/span><span class=\"z-l-5 z-d-7\"> deliverability<\/span><span class=\"z-l-5 z-d-7\"> report<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  prune<\/span><span class=\"z-l-5 z-d-7\">    Delete<\/span><span class=\"z-l-5 z-d-7\"> unsubscribed<\/span><span class=\"z-l-5 z-d-7\"> contacts<\/span><\/span><\/code><\/pre>\n<p><code>send publish 2<\/code> shows me a preview, the recipient count, and a <code>y\/N<\/code> prompt before it actually fires anything off.\nThe subject line gets built automatically as <code>corrode v0.N.0 # &lt;topic&gt;<\/code> \u2013 semver-styled, with the major version stuck at <code>0<\/code> forever as a small joke about projects that never quite reach 1.0.<\/p>\n<p><code>send status<\/code> shows me per-campaign deliverability with bounce-rate cells colour-coded against the SES thresholds, plus daily bounces and unsubscribes, so I can spot trouble early.<\/p>\n<p><code>send lint<\/code> runs every link in an issue through <a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\"><code>lychee<\/code><\/a> before I hit publish.\nI am a lychee maintainer, so dogfooding it here was an obvious choice and a nice quality-of-life improvement over the old Tinyletter web editor, which had no link checking at all.<\/p>\n<p>The signup form on the website POSTs to the tiny <code>subscribe<\/code> service, which runs on my server.\nIt validates the email, drops anything with the honeypot field filled in, and POSTs to Plunk with a <code>subscribe-requested<\/code> event.\nPlunk creates the contact in the <em>unsubscribed<\/em> state and fires off the transactional confirmation email through its Action workflow.\nOnly when the recipient clicks the link does Plunk flip them to <em>subscribed<\/em><sup class=\"footnote-reference\" id=\"fr-gdpr-1\"><a href=\"https:\/\/endler.dev\/2026\/newsletter-setup\/#fn-gdpr\">[1]<\/a><\/sup>.\nNo webhook back to my side, no callback, no JavaScript on the page.\nI just push to git, my server detects the change, builds and runs the server crate, and the new version is live.\nThe running service takes absolutely no CPU or memory.<\/p>\n<h2 id=\"a-little-dns-briefly\"><a class=\"anchor\" href=\"#a-little-dns-briefly\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Little DNS, Briefly<\/h2>\n<p>Plunk needs three things in DNS to send on my behalf: an <strong>SPF<\/strong> record (saying SES is allowed to send for the domain), a <strong>DKIM<\/strong> key (so SES can sign outgoing mail), and a return-path <strong>MX<\/strong> record (so bounces come back somewhere Plunk can read them).\nAll three live under a subdomain.\nDon\u2019t worry, Plunk tells you exactly how to set this up and you can copy-paste the records into your DNS provider\u2019s dashboard.<\/p>\n<p>The one thing worth not forgetting: do <em>not<\/em> add Plunk\u2019s optional inbound MX at the apex of your domain. That would steal mail away from whoever currently handles your inbox (mailbox.org in my case), and replies stop landing where you expect.<\/p>\n<h2 id=\"a-minor-hiccup\"><a class=\"anchor\" href=\"#a-minor-hiccup\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Minor Hiccup<\/h2>\n<p>I forgot that the <code>From:<\/code> address actually needs to be a real mailbox if you want replies to work.\nThe first issue went out as <code>newsletter@corrode.dev<\/code>, which didn\u2019t exist as a mailbox.\nA kind reader (hey Kevin!) replied to say hi, his message bounced, and he forwarded the bounce notice back to me to let me know.\nI created the alias on mailbox.org, and replies have landed in my inbox ever since.<\/p>\n<h2 id=\"one-list-not-two\"><a class=\"anchor\" href=\"#one-list-not-two\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>One List, Not Two<\/h2>\n<p>While I was at it, I also collapsed my older endler.dev newsletter and the <a rel=\"external\" href=\"https:\/\/corrode.dev\">corrode.dev<\/a> one into a single list.\nBoth were always written by me, and running two parallel setups never really made sense. Same person on the keyboard, mostly overlapping audience, twice the maintenance.<\/p>\n<p>The merge itself was uneventful: I had a CSV exported from Tinyletter (the original endler.dev list) and another from my fly.io service (the corrode.dev list I\u2019d started collecting when corrode.dev launched). Same format. Both went into Plunk and deduplication was a non-issue. In the first issue I made the framing explicit (one newsletter for all my writing) so nobody had to guess what they were now signed up for. <sup class=\"footnote-reference\" id=\"fr-backup-1\"><a href=\"https:\/\/endler.dev\/2026\/newsletter-setup\/#fn-backup\">[2]<\/a><\/sup><\/p>\n<p>Going forward, there\u2019s just one newsletter. If any of this isn\u2019t for you, you can always unsubscribe and never hear from me again. No hard feelings.<\/p>\n<h2 id=\"what-i-d-tell-you\"><a class=\"anchor\" href=\"#what-i-d-tell-you\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What I\u2019d Tell You<\/h2>\n<p>If you\u2019ve been thinking about doing this yourself: do it.\nSelf-hosting is genuinely easier than it used to be.\nThere are great open source services for almost every piece now.\nIn general, <a href=\"\/2025\/build-it-yourself\/\">building small things yourself<\/a> is one of the best ways to actually understand them and to keep owning the parts that matter.\nThat would be its own blog post, so let me know if you want me to write it.<\/p>\n<p>If you\u2019d like a peek at the (somewhat hacky) repo, send me a mail and I\u2019ll send you a link. It\u2019s really not that interesting, but if you\u2019re curious about how it works, I\u2019m happy to share.\nOr wait until I clean it up a bit and open source it properly, which will just take me another few years to get around to it.<\/p>\n<p>And the best part is that you can now test my setup by filling out the form below and subscribing to the newsletter!<\/p>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n<li id=\"fn-gdpr\">\n<p>The confirmation click matters to comply with GDPR regulations, and Plunk handles that for me. <a href=\"https:\/\/endler.dev\/2026\/newsletter-setup\/#fr-gdpr-1\">\u21a9<\/a><\/p>\n<\/li>\n<li id=\"fn-backup\">\n<p>As for backups: Plunk holds the canonical subscriber list, and I can export it to CSV any time. I think they also have an API for that, but I haven\u2019t tried it yet. <a href=\"https:\/\/endler.dev\/2026\/newsletter-setup\/#fr-backup-1\">\u21a9<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n"},{"title":"On Taste","pubDate":"Fri, 01 May 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/taste\/","guid":"https:\/\/endler.dev\/2026\/taste\/","description":"<p>I\u2019ve been refining this blog\u2019s design for two decades now.\nWith each new version, I get a little better at knowing what I want.<\/p>\n<p>Turns out, my designs tend to get <em>simpler<\/em> with time.\nAt this point, it\u2019s all typography and negative space.\nI got better at knowing what I value and what I can <em>take away<\/em>.<\/p>\n<p>Uncluttering brings joy.\nMaybe that\u2019s a deeply human thing?<\/p>\n<h2 id=\"screenshots-of-my-blog-s-design-over-the-years\"><a class=\"anchor\" href=\"#screenshots-of-my-blog-s-design-over-the-years\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Screenshots of My Blog\u2019s Design over the Years<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/taste\/2007.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/taste\/2007.jpg\" alt=\"2007\" width=\"650\" height=\"486\"\n    \/>\n    <\/picture>\n    <figcaption>\n        2007\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/taste\/2011.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/taste\/2011.jpg\" alt=\"2011\" width=\"650\" height=\"486\"\n    \/>\n    <\/picture>\n    <figcaption>\n        2011\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/taste\/2018.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/taste\/2018.jpg\" alt=\"2018\" width=\"650\" height=\"486\"\n    \/>\n    <\/picture>\n    <figcaption>\n        2018\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2026\/taste\/2026.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2026\/taste\/2026.jpg\" alt=\"2026\" width=\"650\" height=\"487\"\n    \/>\n    <\/picture>\n    <figcaption>\n        2026\n    <\/figcaption>\n<\/figure>\n<h2 id=\"obsession-and-preference\"><a class=\"anchor\" href=\"#obsession-and-preference\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Obsession and Preference<\/h2>\n<p>Spend enough time with anything, and you\u2019ll develop strong opinions about it.\nYou become obsessed with the details.\nAnd everything <em>is<\/em> somebody\u2019s obsession.<\/p>\n<p>Sneakers. Mechanical keyboards. Coffee.<\/p>\n<p>Watch enough movies and you might start analyzing Dutch angles and obsessing over color grading.\nYou start noticing subtle issues in pacing.\nYou\u2019ll <a rel=\"external\" href=\"https:\/\/www.imdb.com\/title\/tt3087298\/\">recognize the same actor in different roles<\/a>, even if they\u2019re just a random extra.<\/p>\n<p>Once you start seeing nuance, you can never unsee it.\nYou\u2019ve developed a strong personal preference.<\/p>\n<p>But at this stage, you\u2019re just a guy with an opinion.<\/p>\n<p>Having preferences isn\u2019t the same as having good taste.<\/p>\n<p>To develop good taste, you have to recognize quality <em>outside<\/em> your own preferences.\nIt\u2019s seeing how something expresses an idea through deliberate choice, and being able to tell when those choices are honest.<\/p>\n<p>Good taste is rooted in context.\nIt requires understanding the history and craftsmanship behind a thing.\nWithout that, quality flies right by you.<\/p>\n<h2 id=\"taste-and-expertise\"><a class=\"anchor\" href=\"#taste-and-expertise\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Taste and Expertise<\/h2>\n<p>Good taste and expertise are siblings.\nBoth come from caring deeply.\nBoth require knowing <em>why<\/em> things work.\nBoth demand awareness of the effect each decision has.<\/p>\n<p>But they\u2019re not the same.\nTaste is recognition. You can have taste in something you can\u2019t make yourself.\nExpertise is production. You can be an expert in something whether you have taste or not.<\/p>\n<p>What\u2019s interesting is how often one drags the other along.\nPeople with taste care so much about the details that they eventually start making the thing themselves.\nAnd experts who care about their craft tend to develop taste as a byproduct.<\/p>\n<h2 id=\"trigger\"><a class=\"anchor\" href=\"#trigger\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Trigger<\/h2>\n<p>Take Willie Nelson\u2019s guitar, <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=uhQuJTc5yFY\">Trigger<\/a>, a 1969 Martin N-20.\nOut of context, it\u2019s just a worn-down chunk of wood.\nIt could just as easily be a busker\u2019s guitar.\nBut after 10,000 performances, it has become a part of Willie Nelson.<\/p>\n<p>He could have bought a new guitar a hundred times over.\nHe didn\u2019t.\nHe developed such a strong taste for the sound he wanted that he refused to settle for anything less than Trigger.\nThe same repairman has maintained it since 1977.<\/p>\n<p>Willie demands <em>control<\/em> over his sound, because the details are what shape it.\nHe didn\u2019t do anything out of the ordinary. He just did the ordinary so well that it became extraordinary.<\/p>\n<p>Is it Willie who shaped the guitar, or the guitar that rounded Willie\u2019s sound?\nThey aged together. They\u2019ll die together.<\/p>\n<p>If you watch an artist like him perform, it looks effortless.\nThat\u2019s because he knows what matters and what doesn\u2019t.\nHe focuses on the details that make a difference and ignores the rest, which makes the task simpler for him.\nThat\u2019s the trick: good taste tells you what to look for,\nand expertise teaches you how to achieve it \u2014 what to emphasize and what to leave out.<\/p>\n<h2 id=\"apple\"><a class=\"anchor\" href=\"#apple\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Apple<\/h2>\n<p>Buying an Apple device doesn\u2019t mean you have good taste.\nMillions own them.\nFor many, it\u2019s just a status symbol.\nApple helps you think different in the same way that Air Jordans help you jump higher. (I do love the posters, though.)<\/p>\n<p>In fact, people with good taste often <em>avoid<\/em> brands.\nBrands are what kill great products.<\/p>\n<p>The cycle goes like this:<\/p>\n<ol>\n<li>A company builds something great.<\/li>\n<li>Early adopters rave about it.<\/li>\n<li>Popularity grows.<\/li>\n<li>The product gets adjusted for the mass market.<\/li>\n<li>Quality drops.<\/li>\n<li>Early adopters move on.<\/li>\n<\/ol>\n<p>Most products are built for the average customer, so most products settle for average quality.\nWe can\u2019t be experts in everything, so we trust what others say, then wonder why most things suck.<\/p>\n<p>We <em>sense<\/em> when something\u2019s sub-par, even if we can\u2019t put our finger on it.\nThat\u2019s a little tragic.<\/p>\n<p>Brands don\u2019t care about quality or being honest.\nThey care about money.<\/p>\n<h2 id=\"the-algorithm-problem\"><a class=\"anchor\" href=\"#the-algorithm-problem\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Algorithm Problem<\/h2>\n<p>It\u2019s harder to develop a unique taste today.\nWe\u2019re surrounded by feeds and algorithms that show us only what we already like.\nWithout exposure to things we <em>don\u2019t<\/em> like, we can\u2019t discover the things we <em>do<\/em>.<\/p>\n<p>If we get too comfortable, we stop developing taste at all.\nOur preferences become narrow and shallow.\nWe just like what everyone else likes, with no way to say why.<\/p>\n<p>The way out is to care about <em>something<\/em>. Anything!\nCare so much it becomes part of who you are.<\/p>\n<p>Everyone should have at least one thing they irrationally obsess over.\nSomething they know inside and out.\nIt makes for a more interesting personality. A richer life.<\/p>\n<p>Humans socialize over shared obsessions.\nWe bond over espresso grinders and motorbikes.\nSuddenly, you can connect with a stranger.<\/p>\n<p>When you create for others, your taste becomes visible.\nIt shows who you are and what you care about.\nThat\u2019s scary. But it\u2019s how you find your people.<\/p>\n<p>I don\u2019t think I will ever stop refining this blog\u2019s design.\nMaybe I\u2019m not an expert, just a guy with an opinion, but my blog is my zen garden. It brings me joy. Now go out and build your own.<\/p>\n"},{"title":"Now's the Time to Start That Blog","pubDate":"Mon, 26 Jan 2026 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2026\/personal-blog\/","guid":"https:\/\/endler.dev\/2026\/personal-blog\/","description":"<p>I was listening to a podcast recently where someone pointed out something curious: machines have been better at playing chess than humans for three decades now, and nobody cares.\nPeople still watch human chess players.\nIf anything, chess is experiencing a renaissance.<\/p>\n<p>I don\u2019t know anyone who wants to watch robots play chess.\nBut I know plenty of people who love watching humans play.\nI\u2019m not a big chess player myself (heck, I could hardly win any game), but I catch myself watching matches on YouTube.<\/p>\n<p>The reason is that the game is way more than moving pieces on a board.\nThere\u2019s a background story to every player and the match is a truly human experience where people don\u2019t only compete against an opponent but also against themselves.\nThat\u2019s what makes it so interesting, not the fact that there\u2019s an algorithm which has 3646 Elo.\nHumans can still contribute!<\/p>\n<p>And I think it\u2019s the same with writing.<\/p>\n<p>Everyone wants to read personal thoughts from real human beings, but no one writes them anymore.\nWhat we get instead is slop, and that\u2019s hardly a good read.\nThe moment I notice I\u2019m reading autogenerated text, I care less.<\/p>\n<p>That\u2019s why I keep writing.\nMy personal blog is a weird mix of ramblings about <a href=\"\/2025\/how-to-review-code\/\">reviewing code<\/a>, <a href=\"\/2025\/best-programmers\/\">the best programmers I know<\/a>, and random thoughts.<\/p>\n<p>But you know what? People are reading it and from time to time I get an email from someone who found one of my articles helpful.<\/p>\n<p>Time and again, when I talk to friends, they share the same experience.\nMy friend Thomas wrote his first article about his <a rel=\"external\" href=\"https:\/\/thomaszahner.ch\/posts\/atlassian-experience\/\">Experience with Atlassian<\/a> and many people found it helpful and reached out.\nAnd even if no one does, writing is a joyful hobby and it helps me clear my thoughts.<\/p>\n<p>I believe there has rarely been a better time to start writing.<\/p>\n"},{"title":"Building Up and Sanding Down","pubDate":"Fri, 31 Oct 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/","guid":"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/","description":"<p>Over the years, I\u2019ve gravitated toward two complementary ways to build robust software systems: building up and sanding down.<\/p>\n<p><strong>Building up<\/strong> means starting with a tiny core and gradually adding functionality.\n<strong>Sanding down<\/strong> means starting with a very rough idea and refining it over time.<\/p>\n<p>Neither approach is inherently better; it\u2019s almost a stylistic decision that depends on team dynamics and familiarity with the problem domain.\nOn top of that, my thoughts on the topic are not particularly novel, but I wanted to summarize what I\u2019ve learned over the years.<\/p>\n<h2 id=\"building-up\"><a class=\"anchor\" href=\"#building-up\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Building Up<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/stonework.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/stonework.jpg\" alt=\"Working on a solid stone block in ancient Egypt\" width=\"650\" height=\"500\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Working on a solid stone block in ancient Egypt\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:%C3%84gypten_Steinbearbeitung.png\">Wikimedia<\/a> Public Domain\n    <\/figcaption>\n<\/figure>\n<p>Building up focuses on creating a solid foundation first.\nI like to use it when working on systems I know well or when there is a clear specification I can refer to.\nFor example, I use it for implementing protocols or when emulating hardware such as for my <a rel=\"external\" href=\"https:\/\/github.com\/mre\/mos6502\">MOS 6502 emulator<\/a>.<\/p>\n<p>I prefer \u201cbuilding up\u201d over \u201cbottom-up\u201d as the former evokes construction and upward growth. \u201cBottom-up\u201d is more abstract and directional.\nAlso \u201cbottom-up\u201d always felt like jargon while \u201cbuilding up\u201d is more intuitive and very visual, so it could help communicate the idea to non-technical stakeholders.<\/p>\n<p>There are a few rules I try to follow when building up:<\/p>\n<ul>\n<li>Focus on atomic building blocks that are easily composable and testable.<\/li>\n<li>Build up powerful guarantees from simple, verifiable properties.<\/li>\n<li>Focus on correctness, not performance.<\/li>\n<li>Write the documentation along with the code to test your reasoning.<\/li>\n<li>Nail the abstractions before moving on to the next layer.<\/li>\n<\/ul>\n<p>When I collaborate with highly analytical people, this approach works well.\nPeople who have a background in formal methods or mathematics tend to think in terms of \u201cbuilding blocks\u201d and proofs.\nI also found that functional programmers tend to prefer this approach.<\/p>\n<p>In languages like Rust, the type system can help enforce invariants and make it easier to build up complex systems from simple components.\nAlso, Rust\u2019s trait system encourages composition, which aligns well with that line of thinking.<\/p>\n<p>The downside of the \u201cbuild up\u201d approach is that you end up spending a lot of time on the foundational layers before you can see any tangible results.\nIt can be slow to get to an MVP this way.\nSome people also find this approach too rigid and inflexible, as it can be hard to pivot or change direction once you\u2019ve committed to a certain architecture.<\/p>\n<p>For example, say you\u2019re building a web framework.\nThere are a ton of questions at the beginning of the project:<\/p>\n<ul>\n<li>Will it be synchronous or asynchronous?<\/li>\n<li>How will the request routing work?<\/li>\n<li>Will there be middleware? How?<\/li>\n<li>How will the response generation work?<\/li>\n<li>How will error handling be done?<\/li>\n<\/ul>\n<p>In a building-up approach, you would start by answering these questions and designing the core abstractions first.\nFoundational components like the request and response types, the router, and the middleware system are the backbone of the framework and have to be rock solid.<\/p>\n<p>Only after you\u2019ve pinned down the core data structures and their interactions would you move on to building the public API.\nThis can lead to a very robust and well-designed system, but it can also take a long time to get there.<\/p>\n<p>For instance, <a rel=\"external\" href=\"https:\/\/docs.rs\/http\/latest\/src\/http\/request.rs.html#158\">here<\/a> is the <code>Request<\/code> struct from the popular <code>http<\/code> crate:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">derive<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Clone<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Request<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    head<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Parts<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>    body<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> T<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Component parts of an HTTP `Request`<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The HTTP request head consists of a method, uri, version, and a set of<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> header fields.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">derive<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Clone<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Parts<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The request&#39;s method<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    pub<\/span><span> method<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Method<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The request&#39;s URI<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    pub<\/span><span> uri<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Uri<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The request&#39;s version<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    pub<\/span><span> version<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Version<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The request&#39;s headers<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    pub<\/span><span> headers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HeaderMap<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">HeaderValue<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> The request&#39;s extensions<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    pub<\/span><span> extensions<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Extensions<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>    _priv<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>There are quite a few clever design decisions in this short piece of code:<\/p>\n<ul>\n<li>The <code>Request<\/code> struct is generic over the body type <code>T<\/code>, allowing for flexibility in how the body is represented (e.g., as a byte stream, a string, etc.).<\/li>\n<li>The <code>Parts<\/code> struct is separated from the <code>Request<\/code> struct, allowing for easy access to the request metadata without needing to deal with the body.<\/li>\n<li><code>Extensions<\/code> can be used to store extra data derived from the underlying protocol.<\/li>\n<li>The <code>_priv: ()<\/code> field is a zero-sized type used to prevent external code from constructing <code>Parts<\/code> directly. It enforces the use of the provided constructors and ensures that the invariants of the <code>Parts<\/code> struct are maintained.<\/li>\n<\/ul>\n<p>With the exception of extensions, this design has stood the test of time.\nIt has remained largely unchanged since the <a rel=\"external\" href=\"https:\/\/github.com\/hyperium\/http\/commit\/0858e716984c95d2dd0c04f57a228e324ebc0f41\">very first version<\/a> in 2017.<\/p>\n<h2 id=\"sanding-down\"><a class=\"anchor\" href=\"#sanding-down\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Sanding Down<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/Rekhmire-tomb-drawing-furniture.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2025\/building-up-and-sanding-down\/Rekhmire-tomb-drawing-furniture.jpg\" alt=\"Drawing of the part of wall painting in the tomb of Rekhmire\" width=\"650\" height=\"314\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Drawing of the part of wall painting in the tomb of Rekhmire\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Rekhmire-tomb-drawing-furniture.jpg\">Wikimedia<\/a> Public Domain\n    <\/figcaption>\n<\/figure>\n<p>The alternative approach, which I found to work equally well, is \u201csanding down.\u201d\nIn this approach, you start with a rough prototype (or vertical slice) and refine it over time.\nYou \u201csand down\u201d the rough edges over and over again, until you are happy with the result.\nIt feels a bit like woodworking, where you start with a rough piece of wood and gradually refine it into a work of art.\n(Not that I have any idea what woodworking is like, but I imagine it\u2019s something like that.)<\/p>\n<p>Crucially, this is similar but not identical to prototyping.\nThe difference is that you don\u2019t plan on throwing away the code you write.\nInstead, you\u2019re trying to exploit the iterative nature of the problem and purposefully work on \u201cdrafts\u201d until you get to the final version.\nAt any point in time you can stop and ship the current version if needed.<\/p>\n<p>I find that this approach works well when working on creative projects which require experimentation and quick iteration.\nPeople with a background in game development or scripting languages tend to prefer this approach, as they are used to working in a more exploratory way.<\/p>\n<p>When using this approach, I try to follow these rules:<\/p>\n<ul>\n<li>Switch off your inner perfectionist.<\/li>\n<li>Don\u2019t edit while writing the first draft.<\/li>\n<li>Code duplication is strictly allowed.<\/li>\n<li>Refactor, refactor, refactor.<\/li>\n<li>Defer testing until after the first draft is done.<\/li>\n<li>Focus on the outermost API first; nail that, then polish the internals.<\/li>\n<\/ul>\n<p>This approach makes it easy to throw code away and try something new.\nI found that it can be frustrating for people who like to plan ahead and are very organized and methodical.\nThe \u201cchaos\u201d seems to be off-putting for some people.<\/p>\n<p>As an example, say you\u2019re writing a game in Rust.\nYou might want to tweak all aspects of the game and quickly iterate on the gameplay mechanics until they feel \u201cjust right.\u201d<\/p>\n<p>In order to do so, you might start with a skeleton of the game loop and nothing else.\nThen you add a player character that can move around the screen.\nYou tweak the jump height and movement speed until it <em>feels good<\/em>.\nThere is very little abstraction between you and the game logic at this point.\nYou might have a lot of duplicated code and hardcoded values, but that\u2019s okay for now.\nOnce the core gameplay mechanics are pinned down, you can start refactoring the code.<\/p>\n<p>I think Rust can get in the way if you use <a rel=\"external\" href=\"https:\/\/bevy.org\/\">Bevy<\/a> or other frameworks early on in the game design process.\nThe entity component system can feel quite heavy and hinder rapid iteration.\n(At least that\u2019s how I felt when I tried Bevy last time.)<\/p>\n<p>I had a much better experience creating my own window and rendering loop using <a rel=\"external\" href=\"https:\/\/macroquad.rs\/\">macroquad<\/a>.\nYes, the entire code was in one file and no, there were no tests.\nThere also wasn\u2019t any architecture to speak of.<\/p>\n<p>And yet\u2026 working on the game felt amazing!\nI knew that I could always refactor the code later, but I wanted to stay in the moment and get the gameplay right first.<\/p>\n<p>Here\u2019s <a rel=\"external\" href=\"https:\/\/github.com\/mre\/red\/blob\/4d798f88d2b9de18619c875bff6d5c75f4a4dcc3\/src\/main.rs#L285C1-L304C2\">my game loop<\/a>, which was extremely imperative and didn\u2019t require learning a big framework to get started:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">macroquad<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Game<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> input_handler<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> InputHandler<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    clear_background<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">BLACK<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    loop<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Get inputs - only once per frame<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> movement<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> input_handler<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get_movement<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> action<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> input_handler<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get_action<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Update player with both movement and action inputs<\/span><\/span>\n<span class=\"giallo-l\"><span>        player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">update<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>movement<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span>action<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get_frame_time<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Draw<\/span><\/span>\n<span class=\"giallo-l\"><span>        player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">draw<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        next_frame<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>You don\u2019t have to be a Rust expert to understand this code.<\/p>\n<p>In every loop iteration, I simply:<\/p>\n<ul>\n<li>get the inputs<\/li>\n<li>update the player state<\/li>\n<li>draw the player<\/li>\n<li>wait for the next frame<\/li>\n<\/ul>\n<p>It\u2019s a very typical design for that type of work.<\/p>\n<p>If I wanted to, I could now sand down the code and refactor it into a more modular design until it\u2019s production-ready.\nI could introduce a \u201clistener\/callback\u201d system to separate input handling from player logic or a scene graph to manage multiple game objects or an ontology system to manage game entities and their components.\nBut why bother?\nFor now, I care about the game mechanics, not the architecture.<\/p>\n<h2 id=\"finding-the-right-balance\"><a class=\"anchor\" href=\"#finding-the-right-balance\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Finding the Right Balance<\/h2>\n<p>Both variants can lead to correct, maintainable, and efficient systems.\nThere is no better or worse approach.<\/p>\n<p>I found that most people gravitate toward one approach or the other.\nHowever, it helps to be familiar with both approaches and know when to apply which mode.\nChoose wisely, because switching between the two approaches is quite tricky as you start from different ends of the problem.<\/p>\n"},{"title":"On Choosing Rust","pubDate":"Fri, 26 Sep 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/choosing-rust\/","guid":"https:\/\/endler.dev\/2025\/choosing-rust\/","description":"<p>Since my professional writing on Rust has moved to the <a rel=\"external\" href=\"https:\/\/corrode.dev\/blog\">corrode blog<\/a>, I can be a bit more casual on here and share some of my personal thoughts on the recent debate around using Rust in established software.<\/p>\n<p>The two projects in question are git (<a rel=\"external\" href=\"https:\/\/lore.kernel.org\/git\/20250904-b4-pks-rust-breaking-change-v1-0-3af1d25e0be9@pks.im\/\">kernel thread<\/a>, <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=45312696\">Hacker News Discussion<\/a>) and the recently rewritten <a rel=\"external\" href=\"https:\/\/github.com\/uutils\/coreutils\">coreutils in Rust<\/a>, which will <a rel=\"external\" href=\"https:\/\/discourse.ubuntu.com\/t\/carefully-but-purposefully-oxidising-ubuntu\/56995\">ship with Ubuntu 25.10 Quizzical Quokka<\/a>.<\/p>\n<p>What prompted me to write this post is a <a rel=\"external\" href=\"https:\/\/x.com\/nafonsopt\/status\/1968954376262652175\">discussion on Twitter<\/a> and a blog post titled <a rel=\"external\" href=\"https:\/\/dayvster.com\/blog\/are-we-chasing-language-hype-over-solving-real-problems\">\u201cAre We Chasing Language Hype Over Solving Real Problems?\u201d<\/a>.<\/p>\n<p>In both cases, the authors speculate about the motivations behind choosing Rust, and as someone who helps teams use Rust in production, I find those takes\u2026 hilarious.<\/p>\n<p>Back when I started corrode, people always mentioned that Rust wasn\u2019t used for anything serious.\nI knew about the production use cases from client work, but there was very little public information out there.\nAs a consequence, we started the <a rel=\"external\" href=\"https:\/\/corrode.dev\/podcast\/\">\u2018Rust in Production\u2019<\/a> podcast to show that companies indeed choose Rust for real-world applications.\nHowever, people don\u2019t like to be proven wrong, so that conspiracy theory has now morphed into \u201cBig Rust\u201d trying to take over the world. \ud83d\ude06<\/p>\n<p>Let\u2019s look at some of the claims made in the blog post and Twitter thread and see how these could be debunked pretty easily.<\/p>\n<blockquote>\n<p>\u201cGNU Core Utils has basically never had any major security vulnerabilities in its entire existence\u201d<\/p>\n<\/blockquote>\n<p>If only that were true.\nA <a rel=\"external\" href=\"https:\/\/www.cve.org\/CVERecord\/SearchResults?query=coreutils\">quick CVE search<\/a> shows multiple security issues over the decades, including buffer overflows and path traversal vulnerabilities. Just a few months ago, a <a rel=\"external\" href=\"https:\/\/nvd.nist.gov\/vuln\/detail\/CVE-2025-5278\">heap buffer under-read<\/a> was found in <code>sort<\/code>, which would cause a leak of sensitive data if an attacker sends a specially crafted input stream.<\/p>\n<p>The GNU coreutils are one of the most widely used software packages worldwide with billions of installations and hundreds (thousands?) of developers looking at the code.\nYes, vulnerabilities still happen.\nNo, it is not easy to write correct, secure C code.\nNo, not even if you\u2019re extra careful and disciplined.<\/p>\n<p><code>ls<\/code> is five thousand lines long. (Check out the <a rel=\"external\" href=\"https:\/\/github.com\/coreutils\/coreutils\/blob\/master\/src\/ls.c\">source code<\/a>). That\u2019s a lot of code for printing file names and metadata and a big attack surface!<\/p>\n<blockquote>\n<p>\u201cRust can only ever match C performance at best and is usually slower\u201d<\/p>\n<\/blockquote>\n<p>Work by <a rel=\"external\" href=\"https:\/\/trifectatech.org\/initiatives\/codegen\/\">Trifecta<\/a> shows that it is possible to write Rust code that is faster than C in some cases.\nEspecially in concurrent workloads and with memory safety guarantees.\nIf writing safe C code is too hard, try writing safe concurrent C code!<\/p>\n<p>That\u2019s where Rust shines.\nYou can achieve ridiculous levels of parallelization without worrying about security issues.\nAnd no, you don\u2019t need to litter your code with <code>unsafe<\/code> blocks.\nCheck out <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=q8qn0dyT3xc\">Steve Klabnik\u2019s recent talk about Oxide<\/a> where he shows that their bootloader and their preemptive multitasking OS, hubris \u2013 both pretty core systems code \u2013 only contain 5% of <code>unsafe<\/code> code each.\nYou can write large codebases in Rust with no unsafe code at all.<\/p>\n<p>As a trivial example, I sat down to rewrite <code>cat<\/code> in Rust one day.\nThe result was 3x faster than GNU <code>cat<\/code> on my machine.\nYou can read the <a href=\"\/2018\/fastcat\/\">post here<\/a>.\nAll I did was use <code>splice<\/code> to copy data, which saves one memory copy.\nPerformance is not only dependent on the language but on the algorithms and system calls you use.<\/p>\n<p>If you play into Rust\u2019s strengths, you can match C\u2019s performance.\nAt least there is no technical limitation that would prevent this.\nAnd I personally feel more willing to aggressively optimize my code in Rust, because I don\u2019t have to worry about introducing memory safety bugs.\nIt feels like <a rel=\"external\" href=\"https:\/\/steveklabnik.com\/writing\/is-rust-faster-than-c\/\">I\u2019m not alone<\/a>.<\/p>\n<blockquote>\n<p>\u201cWe reward novelty over necessity in the industry\u201d<\/p>\n<\/blockquote>\n<p>This ignores that most successful companies (Google, Meta, etc.) primarily use battle-tested tech stacks, not bleeding-edge languages.\nThese companies have massive codebases and cannot afford to rewrite everything in the latest trendy language.\nBut they see the value of using Rust for new components and gradually rewriting existing ones.\nThat\u2019s because <a rel=\"external\" href=\"https:\/\/corrode.dev\/blog\/why-rust\/#reasons-for-using-rust-in-production\">70% of security vulnerabilities are memory safety issues<\/a> and these issues are extremely costly to fix.\nIf these companies could avoid switching to a new language to do so, they would.<\/p>\n<p>Besides, Rust is not exactly <em>new<\/em> anymore.\nRust 1.0 was released 10+ years ago!\nThe industry is moving slowly, but not that slowly.\nYou\u2019d be surprised to find out how many established companies use Rust without even announcing it or thinking of it as \u201cnovelty\u201d.<\/p>\n<blockquote>\n<p>\u201c100% orchestrated\u201d<\/p>\n<\/blockquote>\n<p>Multiple people in the Twitter thread were convinced this is some coordinated master plan rather than developers choosing better tools,\nwhile the very maintainers of git and coreutils openly discussed their motivations in public forums for everyone to see.<\/p>\n<blockquote>\n<p>\u201cThey\u2019re trying to replace\/erase C. It\u2019s not going to happen\u201d<\/p>\n<\/blockquote>\n<p>They are right. C is not going away anytime soon.\nThere is just so much C\/C++ code out there in the wild, and rewriting everything in Rust is not feasible.\nThe good news is that you can incrementally rewrite C\/C++ code in Rust, one component at a time.\nThat\u2019s what the git maintainers are planning, by using Rust for new components.<\/p>\n<blockquote>\n<p>\u201cThey\u2019re rewriting software with a GNU license into software with an MIT license\u201d<\/p>\n<\/blockquote>\n<p>Even if you use Rust, you can still license your code under GPL or any other license you want.\nGit itself remains GPL, and many Rust projects use various licenses, not only MIT.\nThe license fear is often brought up by people who don\u2019t understand how open source licensing works or it might just be FUD.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/interoperable-europe.ec.europa.eu\/licence\/compatibility-check\/GPL-2.0%20\/MIT\">MIT code is still compatible with GPL code<\/a> and you can use both of them in the same project without issues.\nIt\u2019s just that the end product (the thing you deliver to your users, i.e. binary executables) is now covered by GPL because of its virality.<\/p>\n<blockquote>\n<p>\u201cIt\u2019s just developers being bored and wanting to work with shiny new languages\u201d<\/p>\n<\/blockquote>\n<p>The aging maintainers of C projects are retiring, and there are fewer new developers willing to pick up C just to maintain legacy code in their free time.\nC developers are essentially going extinct.\nNew developers want to work with modern languages and who can blame them?\nOr would you want to maintain a 40-year-old COBOL codebase or an old Perl script?\nWe have to move on.<\/p>\n<blockquote>\n<p>\u201cWhy not build something completely new instead of rewriting existing tools?\u201d<\/p>\n<\/blockquote>\n<p>It\u2019s not that easy.\nThe code is only part of the story.\nThe other part is the ecosystem, the tooling, the integrations, the documentation, and the user base.\nAll of that takes years to build.\nUsers don\u2019t want to change their workflows, so they want drop-in replacements.\nProven interfaces and APIs, no matter how crude and old-fashioned, have a lot of value.<\/p>\n<p>But yes, new tools are being built in Rust as well.<\/p>\n<blockquote>\n<p>\u201cThey don\u2019t know how to actually solve problems, just chase trends\u201d<\/p>\n<\/blockquote>\n<p>Talk about dismissing the technical expertise of maintainers who\u2019ve been working on these projects for years or decades and understand the pain points better than anyone.<\/p>\n<p>If they were just chasing trends, they wouldn\u2019t be maintaining these projects in the first place!\nThese people are some of the most experienced developers in the world, and yet people want to tell them how to do their jobs.<\/p>\n<blockquote>\n<p>\u201cIt\u2019s part of the woke mind virus infecting software\u201d<\/p>\n<\/blockquote>\n<p>Imagine thinking memory safety is a political conspiracy.\nApparently preventing buffer overflows is now an ideological stance.\nThe closest thing to this is the <a rel=\"external\" href=\"https:\/\/bidenwhitehouse.archives.gov\/oncd\/briefing-room\/2024\/02\/26\/press-release-technical-report\/\">White House\u2019s technical report<\/a> which recommends memory-safe languages for government software and mandating memory safety for software receiving federal funding is a pretty reasonable take.<\/p>\n<h2 id=\"conclusion\"><a class=\"anchor\" href=\"#conclusion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Conclusion<\/h2>\n<p>I could go on, but I think you get my point.<\/p>\n<p>People who give Rust an honest chance know that it offers advantages in terms of memory safety, concurrency, and maintainability.\nIt\u2019s not about chasing hype but about long-term investment in software quality.\nAs more companies successfully adopt Rust every day, it increasingly becomes the default choice for many new projects.<\/p>\n<p>If you\u2019re interested in learning more about using Rust in production, check out <a rel=\"external\" href=\"https:\/\/corrode.dev\/blog\">my other blog<\/a> or listen to the <a rel=\"external\" href=\"https:\/\/corrode.dev\/podcast\/\">Rust in Production podcast<\/a>.<\/p>\n<p>Oh, and if you know someone who posts such takes, stop arguing and send them a link to this post.<\/p>\n"},{"title":"How to Review Code","pubDate":"Wed, 06 Aug 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/how-to-review-code\/","guid":"https:\/\/endler.dev\/2025\/how-to-review-code\/","description":"<p>I\u2019ve been reviewing other people\u2019s code for a while now, more than two decades to be precise.\nNowadays, I spend around 50-70% of my time reviewing code in some form or another.\nIt\u2019s what I get paid to do, alongside systems design.<\/p>\n<p>Over time, I learned a thing or two about how to review code effectively.\nI focus on different things now than when I started.<\/p>\n<h2 id=\"think-about-the-big-picture\"><a class=\"anchor\" href=\"#think-about-the-big-picture\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Think about the Big Picture<\/h2>\n<p>Bad reviews are narrow in scope.\nThey focus on syntax, style, and minor issues instead of maintainability and extensibility.<\/p>\n<p>Good reviews look at not only the changes, but also what problems the changes solve, what future issues might arise, and how a change fits into the overall design of the system.<\/p>\n<p>I like to look at the lines that <em>weren\u2019t<\/em> changed. They often tell the true story.<\/p>\n<p>For example, often people forget to update a related section of the codebase or the docs.\nThis can lead to bugs, confusion, breaking changes, or security issues.<\/p>\n<p>Be thorough and look at all call-sites of the new code.\nHave they been correctly updated?\nAre the tests still testing the right thing?\nAre the changes in the right place?<\/p>\n<div class=\"info\">\n    <p>Here\u2019s a cheat sheet of questions I ask myself when reviewing code:<\/p>\n<ul>\n<li>How does this code fit into the rest of the system?<\/li>\n<li>What\u2019s its interaction with other parts of the codebase?<\/li>\n<li>How does it affect the overall architecture?<\/li>\n<li>Does it impact future planned work?<\/li>\n<\/ul>\n<\/div>\n<p>These questions have more to do with systems design than with the changes themselves.\nDon\u2019t neglect the bigger picture because systems become brittle if you accept bad changes.<\/p>\n<p>Code isn\u2019t written in isolation.\nThe role of more experienced developers is to reduce operational friction and handle risk management for the project.\nThe documentation, the tests, and the data types are equally as important as the code itself.<\/p>\n<p>Always keep an eye out for better abstractions as the code evolves.<\/p>\n<h2 id=\"naming-is-everything\"><a class=\"anchor\" href=\"#naming-is-everything\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Naming Is Everything<\/h2>\n<p>I spend a big chunk of my time thinking about good names when reviewing code.<\/p>\n<p>Naming things is hard, which is why it\u2019s so important to get it right.\nOften, it\u2019s the most important part of a code review.<\/p>\n<p>It\u2019s also the most subjective part, which makes it tedious because it\u2019s hard to distinguish between nitpicking and important naming decisions.<\/p>\n<p>Names encapsulate concepts and serve as \u201cbuilding blocks\u201d in your code.\nBad names are the code smell that hint at problems running deep.\nThey increase cognitive overhead by one or more orders of magnitude.<\/p>\n<p>For example, say we have a struct that represents a player\u2019s stats in a game:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    username<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>    score<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> i32<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>    level<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> i32<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>I often see code like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Bad: using temporary\/arbitrary names creates confusion<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> update_player_stats<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">player<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> bonus_points<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> i32<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> level_up<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> bool<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> usr<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>username<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">trim<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_lowercase<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> updated_score<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>score <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span> bonus_points<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> l<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> level_up<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>level <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>level <\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> l2<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> l<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> l<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Player<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        username<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> usr<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>        score<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> updated_score<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> <\/span><\/span>\n<span class=\"giallo-l\"><span>        level<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> l2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>This code is hard to read and understand.\nWhat is <code>usr<\/code>, <code>updated_score<\/code>, and <code>l2<\/code>? The purpose is not conveyed clearly.\nThis builds up cognitive load and make it harder to follow the logic.<\/p>\n<p>That\u2019s why I always think of the most fitting names for variables, even if it feels like I\u2019m being pedantic.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Good: meaningful names that describe the transformation at each step<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> update_player_stats<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">player<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> bonus_points<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> i32<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> level_up<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> bool<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Player<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Each variable name describes what the value represents<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> username<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>username<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">trim<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_lowercase<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> score<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>score <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span> bonus_points<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Use shadowed variables to clarify intent<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> level<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> level_up<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>level <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> player<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>level <\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> level<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> level<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> level<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> If done correctly, the final variable names<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> often match the struct&#39;s field names<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Player<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        username<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>        score<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>        level<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Good names become even more critical in larger codebases where values are declared far away from where they\u2019re used\nand where many developers have to have a shared understanding of the problem domain.<\/p>\n<h2 id=\"don-t-be-afraid-to-say-no\"><a class=\"anchor\" href=\"#don-t-be-afraid-to-say-no\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be Afraid to Say \u201cNo\u201d<\/h2>\n<p>I have to decline changes all the time and it\u2019s never easy.\nAfter all someone put in a lot of effort and they want to see their work accepted.<\/p>\n<p>Avoid sugarcoating your decision or trying to be nice.\nBe objective, explain your reasoning and provide better alternatives.\nDon\u2019t dwell on it, but focus on the next steps.<\/p>\n<p>It\u2019s better to say no than to accept something that isn\u2019t right and will cause problems down the road.\nIn the future it will get even harder to deny a change once you\u2019ve set a precedent.<\/p>\n<p>That\u2019s the purpose of the review process: there is no guarantee that the code will be accepted.<\/p>\n<p>In open source, many people will contribute code that doesn\u2019t meet your standards.\nThere needs to be someone who says \u201cno\u201d and this is a very unpopular job (ask any open source maintainer).\nHowever, great projects need gatekeepers because the alternative is subpar code and eventually unmaintainable projects.<\/p>\n<p>At times, people will say \u201clet\u2019s just merge this and fix it later.\u201d\nI think that\u2019s a slippery slope.\nIt can lead to tech debt and additional work later on.\nIt\u2019s hard to stand your ground, but it\u2019s important to do so.\nIf you see something that isn\u2019t right, speak up.<\/p>\n<p>When it gets hard, remember that you\u2019re not rejecting the person, you\u2019re rejecting the code.\nRemind people that you appreciate their effort and that you want to help them improve.<\/p>\n<p>Even though you\u2019ll develop an intuition for what to focus on in reviews, you should still back it up with facts.\nIf you find yourself saying \u201cno\u201d to the same thing over and over again, consider writing a style guide or a set of guidelines for your team.<\/p>\n<p>Be gracious but decisive; it\u2019s just code.<\/p>\n<h2 id=\"code-review-is-communication\"><a class=\"anchor\" href=\"#code-review-is-communication\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Code Review Is Communication<\/h2>\n<p>Code reviews aren\u2019t just about code; people matter too.\nBuilding a good relationship with your coworkers is important.<\/p>\n<p>I make it a point to do the first couple of reviews together in a pair programming session if possible.<\/p>\n<p>This way, you can learn from each other\u2019s communication style.\nBuilding trust and getting to know each other works well this way.\nYou should repeat that process later if you notice a communication breakdown or misunderstanding.<\/p>\n<h2 id=\"use-multiple-iterations-of-reviews\"><a class=\"anchor\" href=\"#use-multiple-iterations-of-reviews\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Use Multiple Iterations of Reviews<\/h2>\n<p>\u201cCan you take a quick look at this PR? I want to merge it today.\u201d\nThere often is an expectation that code reviews are a one-time thing.\nThat\u2019s not how it works.\nInstead, code reviews are an iterative process.\nMultiple iterations should be expected to get the code right.<\/p>\n<p>In my first iteration, I focus on the big picture and the overall design.\nOnce I\u2019m done with that, I go into the details.<\/p>\n<p>The goal shouldn\u2019t be to merge as quickly as possible, but to accept code that is of high quality.\nOtherwise, what\u2019s the point of a code review in the first place?\nThat\u2019s a mindset shift that\u2019s important to make.<\/p>\n<p>Reviews aren\u2019t <em>exclusively<\/em> about pointing out flaws, they\u2019re also about creating a shared understanding of the code within the team.\nI often learn the most about writing better code by reviewing other people\u2019s code.\nI\u2019ve also gotten excellent feedback on my own code from excellent engineers.<\/p>\n<p>These are invaluable \u201caha moments\u201d that help you grow as a developer.\nExperts spent their valuable time reviewing <em>my<\/em> code, and I learned a lot from it.\nI think everybody should experience that once in their career.<\/p>\n<h2 id=\"don-t-be-a-jerk\"><a class=\"anchor\" href=\"#don-t-be-a-jerk\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be a Jerk<\/h2>\n<p>From time to time, you\u2019ll disagree with the author.\nBeing respectful and constructive is important.\nAvoid personal attacks or condescending language.\nDon\u2019t say \u201cthis is wrong.\u201d\nInstead, say \u201cI would do it this way.\u201d\nIf people are hesitant, ask a few questions to understand their reasoning.<\/p>\n<ul>\n<li>\u201cWill this break existing workflows if we do it this way?\u201d<\/li>\n<li>\u201cWhich alternatives have you considered?\u201d<\/li>\n<li>\u201cWhat happens if you call this function with an empty array?\u201d<\/li>\n<li>\u201cIf I don\u2019t set this value, what will be the error message presented to the user?\u201d<\/li>\n<\/ul>\n<p>These <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Socratic_questioning\">\u201cSocratic questions\u201d<\/a><sup class=\"footnote-reference\" id=\"fr-lucca-1\"><a href=\"https:\/\/endler.dev\/2025\/how-to-review-code\/#fn-lucca\">[1]<\/a><\/sup> help the author think about their decisions and can lead to better designs.<\/p>\n<p>People should enjoy receiving your feedback.\nIf not, revisit your review style.\nOnly add comments that you yourself would be happy to receive.<\/p>\n<p>From time to time, I like to add positive comments like \u201cI like this\u201d or \u201cthis is a great idea.\u201d\nKeeping the author motivated and showing that you appreciate their work goes a long way.<\/p>\n<h2 id=\"if-possible-try-to-run-the-code\"><a class=\"anchor\" href=\"#if-possible-try-to-run-the-code\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>If Possible, Try to Run the Code<\/h2>\n<p>It\u2019s easy to miss subtle details when you look at code for too long.\nHaving a local copy of the code that I can play with helps me a lot.<\/p>\n<p>I try to run the code, the tests, and the linters if I can.\nChecking out the branch, moving things around, breaking things, and trying to understand how it works is part of my review process.<\/p>\n<p>User-facing changes like UI changes or error messages are often easier to spot when you run the code and try to break it.<\/p>\n<p>After that, I revert the changes and, if needed, write down my findings in a comment.\nBetter understanding can come from this approach.<\/p>\n<h2 id=\"be-upfront-about-your-availability\"><a class=\"anchor\" href=\"#be-upfront-about-your-availability\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Be Upfront about Your Availability<\/h2>\n<p>Code reviews are often a bottleneck in the development process, because they can\u2019t be fully automated:\nthere\u2019s a human in the loop who has to look at the code and provide feedback.<\/p>\n<p>But if you wait for your colleagues to review your code, that can lead to frustration.\nAvoid being that person.<\/p>\n<p>Sometimes you won\u2019t have time to review code and that is okay.\nIf you can\u2019t review the code in a reasonable time, let the author know.<\/p>\n<p>I\u2019m still working on this, but I try to be more proactive about my availability and set clear expectations.<\/p>\n<h2 id=\"never-stop-learning\"><a class=\"anchor\" href=\"#never-stop-learning\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Never Stop Learning<\/h2>\n<p>Code reviews are my favorite way to learn new things.\nI learn new techniques, patterns, new libraries, but most importantly, how other people approach problems.<\/p>\n<p>I try to learn one new thing with each review.\nIt\u2019s not wasted time, if it helps the team improve and grow as a whole.<\/p>\n<h2 id=\"don-t-be-nitpicky\"><a class=\"anchor\" href=\"#don-t-be-nitpicky\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be Nitpicky<\/h2>\n<p>Formatters exist for a reason: leave whitespace and formatting to the tools.\nSave your energy for issues that truly matter.<\/p>\n<p>Focus on logic, design, maintainability, and correctness. Avoid subjective preferences that don\u2019t impact code quality.<\/p>\n<p>Ask yourself: Does this affect functionality or would it confuse future developers? If not, let it go.<\/p>\n<h2 id=\"focus-on-the-why-not-the-how\"><a class=\"anchor\" href=\"#focus-on-the-why-not-the-how\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Focus on the Why, Not the How<\/h2>\n<p>When reviewing code, focus on the reasoning behind the changes.\nThis has a much better chance of success than pointing out flaws without any reasoning.<\/p>\n<p>Consider the following two code review comments.\nThe first one is unhelpful and dismissive.<\/p>\n<p><img src=\"https:\/\/endler.dev\/2025\/how-to-review-code\/bad-review-comment.png\" alt=\"A code review comment just saying: \u201cDon\u2019t do this.\u201d\" \/><\/p>\n<p>The second suggests an alternative, links to the documentation, and explains why the change could lead to problems down the road.<\/p>\n<p><img src=\"https:\/\/endler.dev\/2025\/how-to-review-code\/good-review-comment.png\" alt=\"A code review comment explaining the reasoning behind rejecting the change by providing a helpful alternative and a link to the docs\" \/><\/p>\n<p>Which one would you prefer to receive?<\/p>\n<p>I realize that this requires more time and effort, but it\u2019s worth it!\nMost of the time, the author will appreciate it and avoid making the same mistake in the future. There is a compound effect from helpful reviews over time.<\/p>\n<h2 id=\"don-t-be-afraid-to-ask-stupid-questions\"><a class=\"anchor\" href=\"#don-t-be-afraid-to-ask-stupid-questions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be Afraid to Ask Stupid Questions<\/h2>\n<p>Asking is better than assuming.\nIf you don\u2019t understand something, ask the author to explain it.\nChances are, you\u2019re not the only one who doesn\u2019t get it.<\/p>\n<p>Often, the author will be happy to explain their reasoning.\nBetter understanding of the code and the system as a whole can result from this.\nIt can also help the author see things from a different perspective.\nPerhaps they\u2019ll learn that their assumptions were wrong or that the system isn\u2019t self-explanatory.\nPerhaps there\u2019s missing documentation?<\/p>\n<p><a href=\"\/2024\/asking-better-questions\/\">Asking great questions is a superpower.<\/a><\/p>\n<h2 id=\"ask-for-feedback-on-your-reviewing-style\"><a class=\"anchor\" href=\"#ask-for-feedback-on-your-reviewing-style\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Ask for Feedback on Your Reviewing Style<\/h2>\n<p>From time to time, ask the author for feedback on your feedback:<\/p>\n<ul>\n<li>Have you been too harsh\/nitpicky\/slow\/sloppy?<\/li>\n<li>Did you point out the right things?<\/li>\n<li>Did your feedback help them?<\/li>\n<li>Do they have suggestions for improvement?<\/li>\n<\/ul>\n<p>Basically, you ask them to review your review process, heh.<\/p>\n<p>Learning how to review code is a skill that needs constant practice and refinement.\nGood luck finding your own style.<\/p>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n<li id=\"fn-lucca\">\n<p>Thanks for pointing out that term to me, Lucca! <a href=\"https:\/\/endler.dev\/2025\/how-to-review-code\/#fr-lucca-1\">\u21a9<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n"},{"title":"Repeat Yourself","pubDate":"Mon, 23 Jun 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/repeat-yourself\/","guid":"https:\/\/endler.dev\/2025\/repeat-yourself\/","description":"<p>One of the most repeated pieces of advice throughout my career in software has been \u201cdon\u2019t repeat yourself,\u201d also known as the DRY principle.\nFor the longest time, I took that at face value, never questioning its validity.<\/p>\n<p>That was until I saw actual experts write code: <strong>they copy code all the time<\/strong><sup class=\"footnote-reference\" id=\"fr-experts-1\"><a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fn-experts\">[1]<\/a><\/sup>.\nI realized that repeating yourself has a few great benefits.<\/p>\n<h2 id=\"why-people-love-dry\"><a class=\"anchor\" href=\"#why-people-love-dry\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why People Love DRY<\/h2>\n<p>The common wisdom is that if you repeat yourself, you have to fix the same bug in multiple places, but if you have a shared abstraction, you only have to fix it once.<\/p>\n<p>Another reason why we avoid repetition is that it makes us feel clever.\n\u201cLook, I know all of these smart ways to avoid repetition! I know how to use interfaces, generics, higher-order functions, and inheritance!\u201d<\/p>\n<p>Both reasons are misguided.\nThere are many benefits of repeating yourself that might get us closer to our goals in the long run.<\/p>\n<h2 id=\"keeping-up-the-momentum\"><a class=\"anchor\" href=\"#keeping-up-the-momentum\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Keeping Up the Momentum<\/h2>\n<p>When you\u2019re writing code, you want to keep the momentum going to get into a flow state.\nIf you constantly pause to design the perfect abstraction, it\u2019s easy to lose momentum.<\/p>\n<p>Instead, if you allow yourself to copy-paste code, you keep your train of thought going and work on the problem at hand.\nYou don\u2019t introduce another problem of trying to find the right abstraction at the same time.<\/p>\n<p>It\u2019s often easier to copy existing code and modify it until it becomes too much of a burden, at which point you can go and refactor it.<\/p>\n<p>I would argue that \u201cwriting mode\u201d and \u201crefactoring mode\u201d are two different modes of programming.\nDuring writing mode, you want to focus on getting the idea down and stop your inner critic, which keeps telling you that your code sucks.\nDuring refactoring mode, you take the opposite role: that of the critic.\nYou look for ways to improve the code by finding the right abstractions, removing duplication, and improving readability.<\/p>\n<p>Keep these two modes separate.\nDon\u2019t try to do both at the same time.<sup class=\"footnote-reference\" id=\"fr-1-1\"><a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fn-1\">[2]<\/a><\/sup><\/p>\n<h2 id=\"finding-the-right-abstraction-is-hard\"><a class=\"anchor\" href=\"#finding-the-right-abstraction-is-hard\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Finding the Right Abstraction Is Hard<\/h2>\n<p>When you start to write code, you don\u2019t know the right abstraction just yet.\nBut if you copy code, the right abstraction reveals itself; it\u2019s too tedious to copy the same code over and over again, at which point you start to look for ways to abstract it away.\nFor me, this typically happens after the first copy of the same code, but I try to resist the urge until the 2nd or 3rd copy.<\/p>\n<p>If you start too early, you might end up with a bad abstraction that doesn\u2019t fit the problem.\nYou know it\u2019s wrong because it <em>feels clunky<\/em>.\nSome typical symptoms include:<\/p>\n<ul>\n<li>Generic names that don\u2019t convey intent, e.g., <code>render_pdf_file<\/code> instead of <code>generate_invoice<\/code><\/li>\n<li>Difficult to understand without additional context<\/li>\n<li>The abstraction is only used in one or two places<\/li>\n<li>Tight coupling to implementation details<\/li>\n<\/ul>\n<h2 id=\"it-s-hard-to-get-rid-of-wrong-abstractions\"><a class=\"anchor\" href=\"#it-s-hard-to-get-rid-of-wrong-abstractions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>It\u2019s Hard to Get Rid of Wrong Abstractions<\/h2>\n<p>We easily settle for the first abstraction that comes to mind, but most often, it\u2019s not the right one.\nAnd removing the <em>wrong<\/em> abstraction is hard work, because now the data flow depends on it.<\/p>\n<p>We also tend to fall in love with our own abstractions because they took time and effort to create.\nThis makes us reluctant to discard them even when they no longer fit the problem\u2014it\u2019s a sunk cost fallacy.<\/p>\n<p>It gets worse when other programmers start to depend on it, too.\nThen you have to be careful about changing it, because it might break other parts of the codebase.\nOnce you introduce an abstraction, you have to work with it for a long time, sometimes forever.<\/p>\n<p>If you had a copy of the code instead, you could just change it in one place without worrying about breaking anything else.<\/p>\n<div>\n  <blockquote cite=\"https:\/\/sandimetz.com\/blog\/2016\/1\/20\/the-wrong-abstraction\">\n    <p>\n      Duplication is far cheaper than the wrong abstraction\n    <\/p>\n  <\/blockquote>\n  <p>\u2014Sandi Metz, <cite><a href=\"https:\/\/sandimetz.com\/blog\/2016\/1\/20\/the-wrong-abstraction\">The Wrong Abstraction<\/a><\/cite><\/p>\n<\/div>\n<p>Better to wait until the <em>last moment<\/em> to settle on the abstraction, when you have a solid understanding of the problem space.<sup class=\"footnote-reference\" id=\"fr-ooda-1\"><a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fn-ooda\">[3]<\/a><\/sup><\/p>\n<h2 id=\"the-mental-overhead-of-abstractions\"><a class=\"anchor\" href=\"#the-mental-overhead-of-abstractions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Mental Overhead of Abstractions<\/h2>\n<p>Abstraction reduces code duplication, but it comes at a cost.<\/p>\n<p>Abstractions can make code harder to read, understand, and maintain because you have to jump between multiple levels of indirection to understand what the code does.\nThe abstraction might live in different files, modules, or libraries.<\/p>\n<p>The cost of traversing these layers is high.\nAn expert programmer might be able to keep a few levels of abstraction in their head, but we all have a limited context window (which depends on familiarity with the codebase).<\/p>\n<p>When you copy code, you can keep all the logic in one place.\nYou can just read the whole thing and understand what it does.<\/p>\n<h2 id=\"resist-the-urge-of-premature-abstraction\"><a class=\"anchor\" href=\"#resist-the-urge-of-premature-abstraction\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Resist the Urge of Premature Abstraction<\/h2>\n<p>Sometimes, code <em>looks<\/em> similar but serves different purposes.<\/p>\n<p>For example, consider two pieces of code that calculate a sum by iterating over a collection of items.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span>total<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span> item<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> shopping_cart<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>    total<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>price<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>quantity<\/span><\/span><\/code><\/pre>\n<p>And elsewhere in the code, we have<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span>total<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span> item<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> package_items<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>    total<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>weight<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>rate<\/span><\/span><\/code><\/pre>\n<p>In both cases, we iterate over a collection and calculate a total.\nYou might be tempted to introduce a helper function, but the two calculations are very different.<\/p>\n<p>After a few iterations, these two pieces of code might evolve in different directions:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> calculate_total_price<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">shopping_cart<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-9 z-d-9\"> not<\/span><span> shopping_cart<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        raise<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> ValueError<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Shopping cart cannot be empty<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span>    total<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 0.0<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span> item<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> shopping_cart<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Round for financial precision<\/span><\/span>\n<span class=\"giallo-l\"><span>        total<\/span><span class=\"z-l-2 z-d-5\"> +=<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> round<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>price<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>quantity<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    return<\/span><span> total<\/span><\/span><\/code><\/pre>\n<p>In contrast, the shipping cost calculation might look like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> calculate_shipping_cost<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">package_items<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> destination_zone<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Use higher of actual weight vs dimensional weight<\/span><\/span>\n<span class=\"giallo-l\"><span>    total_weight<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> sum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>weight<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> item<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> package_items<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>    total_volume<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> sum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>length<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>width<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> item<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>height<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> item<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> package_items<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>    dimensional_weight<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> total_volume<\/span><span class=\"z-l-2 z-d-5\"> \/<\/span><span class=\"z-l-16 z-d-16\"> 5000<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> FedEx formula<\/span><\/span>\n<span class=\"giallo-l\"><span>    <\/span><\/span>\n<span class=\"giallo-l\"><span>    billable_weight<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> max<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>total_weight<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> dimensional_weight<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    return<\/span><span> billable_weight<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> shipping_rates<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">destination_zone<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span><\/code><\/pre>\n<p>Had we applied \u201cdon\u2019t repeat yourself\u201d too early, we would have lost the context and specific requirements of each calculation.<\/p>\n<h2 id=\"dry-can-introduce-complexity\"><a class=\"anchor\" href=\"#dry-can-introduce-complexity\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>DRY Can Introduce Complexity<\/h2>\n<p>The DRY principle is misinterpreted as a blanket rule to avoid any duplication at all costs, which can lead to complexity.<\/p>\n<p>When you try to avoid repetition by introducing abstractions, you have to deal with all the edge cases in a place far away from the actual business logic.\nYou end up adding redundant checks and conditions to the abstraction, just to make sure it works in all cases.\nLater on, you might forget the reasoning behind those checks, but you keep them around \u201cjust in case\u201d because you don\u2019t want to break any callers.\nThe result is dead code that adds complexity to the codebase; all because you wanted to avoid repeating yourself.<\/p>\n<p>The common wisdom is that if you repeat yourself, you have to fix the same bug in multiple places.\nBut the assumption is that the bug exists in all copies.\nIn reality, each copy might have evolved in different ways, and the bug might only exist in one of them.<\/p>\n<p>When you create a shared abstraction, a bug in that abstraction breaks <em>every<\/em> caller, breaking multiple features at once.\nWith duplicated code, a bug is isolated to just one specific use case.<\/p>\n<h2 id=\"clean-up-afterwards\"><a class=\"anchor\" href=\"#clean-up-afterwards\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Clean Up Afterwards<\/h2>\n<p>Knowing that you didn\u2019t break anything in a shared abstraction is much harder than checking a single copy of the code.\nOf course, if you have a lot of copies, there is a risk of forgetting to fix all of them.<\/p>\n<p>The key to making this work is to clean up afterwards.\nThis can happen before you commit the code or during a code review.<\/p>\n<p>At this stage, you can look at the code you copied and see if it makes sense to keep it as is or if you can see the right abstraction.\nI try to refactor code once I have a better understanding of the problem, but not earlier.<\/p>\n<p>A trick to undo a bad abstraction is to inline the code back into the places where it was used.\nFor a while, you end up \u201crepeating yourself\u201d again in the codebase, but that\u2019s okay.\nRethink the problem based on the new information you have.\nOften you\u2019ll find a better abstraction that fits the problem better.<\/p>\n<div>\n  <blockquote cite=\"https:\/\/sandimetz.com\/blog\/2016\/1\/20\/the-wrong-abstraction\">\n    <p>\n      When the abstraction is wrong, the fastest way forward is back.\n    <\/p>\n  <\/blockquote>\n  <p>\u2014Sandi Metz, <cite><a href=\"https:\/\/sandimetz.com\/blog\/2016\/1\/20\/the-wrong-abstraction\">The Wrong Abstraction<\/a><\/cite><\/p>\n<\/div>\n<h2 id=\"tl-dr\"><a class=\"anchor\" href=\"#tl-dr\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>TL;DR<\/h2>\n<p>It\u2019s fine to look for the right abstraction, but don\u2019t obsess over it.\nDon\u2019t be afraid to copy code when it helps you keep momentum and find the right abstraction.<\/p>\n<p><strong>It bears repeating: \u201cRepeat yourself.\u201d<\/strong><\/p>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n<li id=\"fn-experts\">\n<p>For some examples, see <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=ToOt-osLxNk\">Ferris working on Rustendo64<\/a> or <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=j79G5Be8Q4Y\">tokiospliff working on a C++ game engine<\/a>. <a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fr-experts-1\">\u21a9<\/a><\/p>\n<\/li>\n<li id=\"fn-1\">\n<p>This is also how I write prose: I first write a draft and block my inner critic, and then I play the role of the editor\/critic and \u201crefactor\u201d the text.\nThis way, I get the best of both worlds: a quick feedback loop which doesn\u2019t block my creativity, and a final product which is more polished and well-structured.\nOf course, I did not invent this approach. I recommend reading \u201cShitty first drafts\u201d from Anne Lamott\u2019s book <a rel=\"external\" href=\"https:\/\/canongate.co.uk\/books\/3055-bird-by-bird-instructions-on-writing-and-life\/\">Bird by Bird: Instructions on Writing and Life<\/a> if you want to learn more about this technique. <a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fr-1-1\">\u21a9<\/a><\/p>\n<\/li>\n<li id=\"fn-ooda\">\n<p>This is similar to the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/OODA_loop\">OODA loop<\/a> concept, which stands for \u201cObserve, Orient, Decide, Act.\u201d It was developed by military strategist John Boyd. Fighter pilots use it to wait until the last responsible moment to decide on a course of action, which allows them to make the best decision based on the current situation and available information. <a href=\"https:\/\/endler.dev\/2025\/repeat-yourself\/#fr-ooda-1\">\u21a9<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n"},{"title":"Watching Millionaires","pubDate":"Fri, 06 Jun 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/watching-millionaires\/","guid":"https:\/\/endler.dev\/2025\/watching-millionaires\/","description":"<p>I watched the Champions League final the other day when it struck me:\n<strong>I\u2019m basically watching millionaires all the time.<\/strong><\/p>\n<p>The players are millionaires, the coaches are millionaires, the club owners are millionaires. It\u2019s surreal.<\/p>\n<p>This week I watched John Wick Ballerina and, again, there\u2019s Keanu Reeves, who is a millionaire, and Ana de Armas, who is as well.<\/p>\n<p>Yesterday I heard about Trump and Musk fighting. They are not millionaires, they are billionaires!<\/p>\n<p>As I\u2019m writing this, I\u2019m watching the Rock am Ring live stream, a music festival in Germany. Weezer is playing. These guys are all millionaires.<\/p>\n<p>I don\u2019t know what to make of it.\nIt\u2019s a strange realization, but one that feels worth sharing.<\/p>\n<p>I could go down the road of how this fixation on elites distracts us from the people nearby, but that\u2019s not quite it.\nWhat interests me more is how normalized this has become.<\/p>\n<p>Maybe it\u2019s just the power law in action: a few rise to the top, and we amplify them by watching. But most people in every field aren\u2019t millionaires. We just don\u2019t <em>see<\/em> them.<\/p>\n<p>You\u2019re on a tiny blog by a tiny man and if you made it this far, I appreciate you. It looks as if you care about the little stories as well.<\/p>\n<p>If you\u2019re anything like me, you\u2019re not only enjoying the little stories, you\u2019re actively <em>seeking<\/em> them out \u2013 but there\u2019s so few of it nowadays. Yes, there are <a rel=\"external\" href=\"https:\/\/bearblog.dev\/discover\/\">still places<\/a> where people share their stories, but you need to know where to look.<\/p>\n<p>If anything, we all should share more. <a href=\"\/2024\/what-to-write\/\">Write about<\/a> the little things, the everyday moments, the people you meet, the things <em>you<\/em> care about. Don\u2019t live anybody else\u2019s life!<\/p>\n<p>Rivers Cuomo, Weezer\u2019s lead singer, once wrote:<\/p>\n<blockquote>\n<p>My motivation is much different now than it was then: then I was terribly discontent and dreaming of being a classical composer, a writer, or basically <strong>anything that I wasn\u2019t<\/strong>; now I just want to enjoy my life and do the responsible thing\u2014graduate.<\/p>\n<\/blockquote>\n<p>That\u2019s from his <a rel=\"external\" href=\"https:\/\/www.weezerpedia.com\/wiki\/Harvard\">Letter For Readmission To Harvard (2005)<\/a>.<\/p>\n<p>Nobody forced him to go back to Harvard after so many years.\nHe was a freaking millionaire rock star by then.<\/p>\n<p>And yet, he did.<\/p>\n<p>He stopped <em>pretending<\/em> and started <em>living<\/em>.<\/p>\n<p>We don\u2019t have to keep watching other people\u2019s lives.<\/p>\n<p>Live your own.<\/p>\n"},{"title":"Paolo the Plumber","pubDate":"Mon, 02 Jun 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/paolo\/","guid":"https:\/\/endler.dev\/2025\/paolo\/","description":"<p>Paolo was a plumber.<\/p>\n<p>People knew him as a reliable and thorough craftsman.\nHe fixed the pipes in his small town and made a good living doing so.<\/p>\n<p>One day, his friend Mario told him that he\u2019d bought a plumbing machine.\nPaolo was intrigued and asked how it worked.<\/p>\n<p>\u201cIt\u2019s magical!\u201d said Mario.\n\u201cI show it what\u2019s broken, and it fixes the problem in no time!\u201d\nPaolo asked if he could watch the machine work.<\/p>\n<p>The next day, Paolo and Mario took the machine to a house with a broken pipe.\nPaolo watched as Mario positioned the machine by the pipe.\n\u201cBeep boop,\u201d and the machine started working, and quickly.\nPaolo noticed the machine turned the wrench back and forth instead of steady pressure - something he could adapt for his own work.\nWithin minutes, the pipe was fixed.<\/p>\n<p>\u201cSoon no one will need plumbers anymore,\u201d said Mario.\n\u201cI can already do the work of ten plumbers with this machine!\u201d<\/p>\n<p>That night, Paolo couldn\u2019t sleep.\nHe thought about his job and how it might change.\nHe loved being a plumber and helping people.\nBut what if machines really took over?<\/p>\n<p>Within a few weeks, Paolo\u2019s phone stopped ringing.\nPeople were calling Mario instead because he did quicker, cheaper work.\nSome of Paolo\u2019s old customers told him he was \u201cold-fashioned\u201d and \u201cout of touch.\u201d<\/p>\n<p>In the past, none of his customers had ever complained about his work.\nHe always took time to do things right.\nHe would check every joint, seal every pipe, and make sure everything was perfect before leaving.\nSometimes he noticed other problems that needed fixing and he would offer to fix those too.<\/p>\n<p>Then one day, he got a call from an old customer.\nIt was an emergency.\nThe pipes in the restaurant were leaking and they needed help fast.\nPaolo rushed over and found a mess.\nHe got to work and fixed the problem.<\/p>\n<p>\u201cWe just got it fixed the other day!\u201d\nWhen Paolo asked who did the work, the owner said it was Mario.<\/p>\n<p>From that day on, more people called Paolo.\nThey all had problems after working with Mario and the machine.\nPaolo kept finding the same mistakes: pipes not properly sealed, joints not aligned correctly, leaks temporarily fixed with instant glue.\nSometimes the machine would add extra parts: pipes that ended nowhere, valves that didn\u2019t connect to anything.\nPaolo recognized these as signs of the machine at work.<\/p>\n<p>Paolo called Mario and told him what he\u2019d found.\nMario knew about the issues: \u201cI told it to fix it, but it didn\u2019t work right. Even when I asked multiple times and was very polite.\u201d\nAnd worse: \u201cOne time I looked away for a moment and the machine started remodeling the bathroom! It added a new sink that wasn\u2019t there before.\u201d<\/p>\n<p>Paolo asked why he didn\u2019t just fix it himself.\n\u201cI can\u2019t,\u201d Mario said.\n\u201cI don\u2019t know how to do it without the machine.\u201d<\/p>\n<p>Mario had been a reputable plumber before he got the machine.\nNow he was relying on a machine that didn\u2019t always work.\nWorse, Mario didn\u2019t own the machine but rented it from a company far away.\nThe rent was cheap in the beginning, but now it was getting more expensive.<\/p>\n<p>Paolo realized that Mario wasn\u2019t the only one.\nMany plumbers were using machines now, and new plumbers were learning machines instead of tools.\nIt wasn\u2019t just plumbers\u2014electricians, carpenters, other tradespeople were all relying on machines.\nThe machines caused problems, but the company promised they would fix everything and get better with time.\nThey kept updating the machines and gave them fancy names, but the problems remained.<\/p>\n<p>Paolo just kept working.\nHe fixed what the machines broke.\nHis customers called him back for more work.\nSoon his phone was ringing like before.<\/p>\n<p>A while later, a salesperson came to town with a new machine.\nPaolo heard Mario talking to him at the coffee shop.<\/p>\n"},{"title":"Reinvent the Wheel","pubDate":"Sat, 24 May 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/reinvent-the-wheel\/","guid":"https:\/\/endler.dev\/2025\/reinvent-the-wheel\/","description":"<p>One of the most harmful pieces of advice is to not reinvent the wheel.<\/p>\n<p>It usually comes from a good place, but is typically given by two groups of people:<\/p>\n<ul>\n<li>those who tried to invent a wheel themselves and know how hard it is<\/li>\n<li>those who never tried to invent a wheel and blindly follow the advice<\/li>\n<\/ul>\n<p>Either way, both positions lead to a climate where curiosity and exploration gets discouraged.\nI\u2019m glad that some people didn\u2019t follow that advice; we owe them many of the conveniences of modern life.<\/p>\n<p>Even on a surface level, the advice is bad:\nWe have much better wheels today than 4500\u20133300 BCE when the first wheel was invented.\nIt was also <em>crucially<\/em> important that wheels got reinvented throughout civilizations and cultures.<\/p>\n<div class=\"info\">\n    <p><strong>Note:<\/strong> When I say \u201cwheel\u201d throughout this post, please replace it with whatever\ntool, protocol, service, technology, or other invention you\u2019re personally interested in.<\/p>\n<\/div>\n<h2 id=\"inventing-wheels-is-learning\"><a class=\"anchor\" href=\"#inventing-wheels-is-learning\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Inventing Wheels Is Learning<\/h2>\n<blockquote>\n<p><strong>\u201cWhat I cannot create, I do not understand\u201d<\/strong><br \/>\n\u2013 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Richard_Feynman\">Richard Feynman<\/a>, Physicist and Nobel Prize Winner<\/p>\n<\/blockquote>\n<p>To <em>really<\/em> understand something on a fundamental level, you have to be able to implement a toy version first.\nIt doesn\u2019t matter if it\u2019s any good; you can throw it away later.<\/p>\n<p>In Computer Science, for example, there are many concepts that are commonly assumed to be beyond the abilities of mere mortals:\nprotocols, cryptography, and web servers come to mind.<\/p>\n<p>More people should know how these things work.\nAnd therefore I think people should not be afraid to recreate them.<\/p>\n<h2 id=\"everything-is-a-rabbit-hole\"><a class=\"anchor\" href=\"#everything-is-a-rabbit-hole\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Everything Is a Rabbit Hole<\/h2>\n<p>Too often, fundamental things are taken for granted.\nFor example strings or paths are super complicated concepts in programming.\nIt\u2019s a great exercise to implement a string or a path library yourself\nif you\u2019re interested in how they work.<\/p>\n<p>Even if nobody ends up using your work, I bet you\u2019ll learn a lot. For example:<\/p>\n<ul>\n<li>There is an infinite complexity in everyday things.<\/li>\n<li>Building something that even a single other person finds useful is a humbling experience.<\/li>\n<li>Humans like you created these abstractions. They are not perfect and you can make different tradeoffs in your own design.<\/li>\n<\/ul>\n<p>On the last point, everything is a tradeoff and there are dozens, sometimes hundreds of footguns with every toy problem.<\/p>\n<p>Along the way, you will have to make decisions about correctness, simplicity, functionality, scalability, performance, resource usage, portability, and so on.<\/p>\n<p>Your solution can be great in some of these things, but not all of them and not for all users.\nThat also implies that existing solutions have flaws and might not be designed to solve your particular problem; no matter how well-established the solution is.<\/p>\n<p>Going down rabbit holes is fun in its own way, but there is one other benefit:\nIt is one of the few ways to level up as an engineer\u2026 but only if you don\u2019t give up before you end up with a working version of what you tried to explore.\nIf you jump between projects too often, you will learn nothing.<\/p>\n<h2 id=\"reasons-for-reinventing-the-wheel\"><a class=\"anchor\" href=\"#reasons-for-reinventing-the-wheel\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Reasons for Reinventing the Wheel<\/h2>\n<p>There are great reasons to reinvent the wheel:<\/p>\n<ul>\n<li>Build a better wheel (for some definition of better)<\/li>\n<li>Learn how wheels are made<\/li>\n<li>Teach others about wheels<\/li>\n<li>Learn about the inventors of wheels<\/li>\n<li>Be able to change wheels or fix them when they break<\/li>\n<li>Learn the tools needed to make wheels along the way<\/li>\n<li>Learn a tiny slice of what it means to build a larger system (such as a vehicle)<\/li>\n<li>Help someone in need of a very special wheel. Maybe for a wheelchair?<\/li>\n<\/ul>\n<p>Who knows? The wheel you come up with might not be the best use for a car, but maybe for a\u2026 skateboard or a bike?\nOr you fail building a nicer wheel, but you come up with a better way to test wheels along the way.\nHeck, your wheel might not even be meant for transportation at all!\nIt might be a potter\u2019s wheel, \u201ca machine used in the shaping (known as throwing) of clay into round ceramic ware\u201d <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Wheel\">according to Wikipedia<\/a>.\nYou might end up building a totally different kind of wheel like a steering wheel or a flywheel.\nWe need more people who think outside the box.<\/p>\n<h2 id=\"reuse-vs-reinvent\"><a class=\"anchor\" href=\"#reuse-vs-reinvent\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Reuse vs Reinvent<\/h2>\n<p>Of course, don\u2019t disregard the works of others \u2013 study their work and reuse where you see fit. Don\u2019t reinvent the wheel out of distrust or ignorance of the work of others.\nOn the other side, if you never tried to put your knowledge to the test, how would you ever learn enough about your field to advance it?<\/p>\n<p>I observed you can move very quickly by running little experiments. Especially in software engineering, building small prototypes is cheap and quick. Solve your own problem, start small, keep it simple, iterate.<\/p>\n<p>So, with all of the above, here\u2019s my advice:<\/p>\n<p><strong>Reinvent for insight. Reuse for impact.<\/strong><\/p>\n"},{"title":"No Matter What","pubDate":"Sun, 13 Apr 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/no-matter-what\/","guid":"https:\/\/endler.dev\/2024\/no-matter-what\/","description":"<p>As kids, our parents established a few simple rules that we would all follow, no matter the circumstances. One of them was that we\u2019d always have dinner together in the evening, typically around 6pm.<\/p>\n<p>In almost two decades, they never broke that rule. We had dinner on 9\/11 and when mom was at the hospital. It\u2019s not always easy.<\/p>\n<p>There\u2019s a nice thing that happens when you have such a golden rule: it has ripple effects. Since we had dinner together every evening, we would always have time to talk about the day. Problems would be uncovered earlier. We would know about each other\u2019s appointments for the next day. It provided structure throughout the rest of the day. It put things into perspective. It grounded us.<\/p>\n<ul>\n<li>Bad grade at school? Dinner at 6.<\/li>\n<li>Played computer games all afternoon and lost track of time? Dinner at 6.<\/li>\n<li>No matter how bad your day was, dinner is always waiting for you.<\/li>\n<\/ul>\n<p>As a kid, it sounded like one of those \u201cstupid\u201d rules only grown-ups would come up with. And in fact, my parents knew that it was stupid. They did it anyway. As a kid, that made their life look extremely dull and boring. I remember pitying my dad once for being such a slave to society. Yet, they persisted because without it, things would fall apart. Skipping dinner is about way more than skipping dinner.<\/p>\n<h2 id=\"these-rules-are-simple-but-not-easy\"><a class=\"anchor\" href=\"#these-rules-are-simple-but-not-easy\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>These Rules Are Simple, but Not Easy<\/h2>\n<p>It\u2019s a simple rule with little room for interpretation. However, it\u2019s not easy: there are times when you have to drop something else to make dinner at 6 work. That\u2019s when the rule counts the most! That\u2019s what makes or breaks it.<\/p>\n<p>Following the rule 90% of the time is much easier than following it 100% of the time. You have to make sacrifices. You have to say no sometimes. That\u2019s the price it takes to stick to the rule.<\/p>\n<p>Yes, such rules \u201csound\u201d stupid, but there\u2019s a deeper, almost stoic realization to it:\nLife is complicated and will throw obstacles in your way. But if you really want to make progress, you have to find a way. If nothing else helps, make up a stupid rule;\nand the harder you struggle, the more specific the rule should be.<\/p>\n<p>Dinner. Every day. At 6 o\u2019clock.<\/p>\n<p>Only now am I discovering this for myself. In 2019, I mentioned to my friend Abu that I felt bad for not doing any sports. It\u2019s not that I didn\u2019t try, it\u2019s just that nothing lasted for long. He suggested going for a run together on Tuesdays \u2013 no matter what. I thought that was ridiculous. I told him that it couldn\u2019t possibly work. Why Tuesdays of all days!? It felt so random. In my mind, I started negotiating. But there\u2019s no point in negotiating with irrationality. Fast forward 5 years, and I still run every Tuesday.<\/p>\n<p>I actually suck at running. My pace isn\u2019t fast. The distance isn\u2019t far, but it\u2019s a solid effort. Time was made. It worked out. Again, it had positive rippling effects: I ran on Crete in Greece and Sardinia in Italy. Different people joined me on my runs. If Tuesday finds me elsewhere, my running shoes come along. Now, did I always manage to run on a Tuesday? No. It\u2019s not easy! But I <em>always<\/em> gave it a solid attempt and I can remember each time I didn\u2019t run. Since Abu and I run together a lot, we would talk about our week. If we didn\u2019t make up that rule, we would never have started to know each other on such a deep level.<\/p>\n<p>Some people won\u2019t understand when you tell them that you have to do a thing \u201cno matter what.\u201d Instead of telling them I have to go for a run, I say I\u2019m busy that evening. Nobody ever asks any questions.<\/p>\n<h2 id=\"isn-t-this-just-a-habit\"><a class=\"anchor\" href=\"#isn-t-this-just-a-habit\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Isn\u2019t This Just a Habit?<\/h2>\n<p>With \u201cno matter what\u201d there can be serious consequences. If you have to take care of a loved one, you can\u2019t skip a day. Or if you\u2019re an Air Traffic Controller, failure is not an option.<\/p>\n<p>My stakes are not as high, but I take them very seriously.<\/p>\n<p>\u201cNo matter what\u201d rules aren\u2019t habits, at least not in the beginning. They can, however, turn into super strong habits with time.<\/p>\n<p>I found that the best way to implement a \u201cNMW Rule\u201d is to do it on the spot. When my dentist asked me if I floss every day (I didn\u2019t), I made the decision to start right then and there and never skip a day.<\/p>\n<p>Another good way to get started is to take on some lightweight responsibility.\nFor example, I recommend getting plants.\nThen you have to water them \u2013 no matter what.<\/p>\n<p>If the plant dries out, you broke the rule; simple as that.\nThe great thing is that the watering interval is usually pretty low, so there\u2019s time to get used to it\n(but getting used to it you must).<\/p>\n<p>If it works, you\u2019ll enjoy the feeling of continuity.\nIt\u2019s like a chain of good deeds.\nA new habit is born.<\/p>\n<p>In the past, I never had any plants.\nNow our apartment is full of them.\nI love the companionship and the continuity.<\/p>\n<h2 id=\"what-s-your-nmw\"><a class=\"anchor\" href=\"#what-s-your-nmw\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What\u2019s Your \u201cNMW\u201d?<\/h2>\n<p>If you already have a \u201cno matter what\u201d rule, you have my deepest respect.<\/p>\n<p>If not, whether you want to write that book, run that marathon, or just save a few bucks each month, make it work \u2013 no matter what.<\/p>\n"},{"title":"The Best Programmers I Know","pubDate":"Fri, 04 Apr 2025 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2025\/best-programmers\/","guid":"https:\/\/endler.dev\/2025\/best-programmers\/","description":"<p>I have met a lot of developers in my life.\nLately, I asked myself: \u201cWhat does it take to be one of the best? What do they all have in common?\u201d<\/p>\n<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>\n<h2 id=\"read-the-reference\"><a class=\"anchor\" href=\"#read-the-reference\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Read the Reference<\/h2>\n<p>If there was one thing that I should have done as a young programmer,\nit would have been to <em>read the reference<\/em> of the thing I was using.\nI.e. read the <a rel=\"external\" href=\"https:\/\/httpd.apache.org\/docs\/2.4\/\">Apache Webserver Documentation<\/a>,\nthe <a rel=\"external\" href=\"https:\/\/docs.python.org\/3\/library\/index.html\">Python Standard Library<\/a>,\nor the <a rel=\"external\" href=\"https:\/\/toml.io\/en\/v1.0.0\">TOML spec<\/a>.<\/p>\n<p>Don\u2019t go to Stack Overflow, don\u2019t ask the LLM, don\u2019t <em>guess<\/em>, just go straight to the <strong>source<\/strong>.\nOftentimes, it\u2019s surprisingly accessible and well-written.<\/p>\n<h2 id=\"know-your-tools-really-well\"><a class=\"anchor\" href=\"#know-your-tools-really-well\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Know Your Tools Really Well<\/h2>\n<p>Great devs understand the technologies they use on a <strong>fundamental level<\/strong>.<\/p>\n<p>It\u2019s one thing to be able to <em>use<\/em> a tool and a whole other thing to truly <em>grok<\/em> (understand) it.\nA mere user will fumble around, get confused easily, hold it wrong and not optimize the config.<\/p>\n<p>An expert goes in (after reading the reference!)\nand sits down to write a config for the tool of which they understand every single line and can explain it to a colleague.\nThat leaves no room for doubt!<\/p>\n<p>To know a tool well, you have to know:<\/p>\n<ul>\n<li>its history: who created it? Why? To solve which problem?<\/li>\n<li>its present: who maintains it? Where do they work? On what?<\/li>\n<li>its limitations: when is the tool not a good fit? When does it break?<\/li>\n<li>its ecosystem: what libraries exist? Who uses it? What plugins?<\/li>\n<\/ul>\n<p>For example, if you are a backend engineer and you make heavy use of Kafka,\nI expect you to know a lot about Kafka \u2013 not just things you read on Reddit.\nAt least that\u2019s what I expect if you want to be one of the best engineers.<\/p>\n<h2 id=\"read-the-error-message\"><a class=\"anchor\" href=\"#read-the-error-message\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Read the Error Message<\/h2>\n<p>As in <strong>Really Read the Error Message and Try to Understand What\u2019s Written<\/strong>.\nTurns out, if you just sit and meditate about the error message, it starts to speak to you.\nThe best engineers can infer a ton of information from very little context.\nJust by reading the error message, you can fix most of the problems on your own.<\/p>\n<p>It also feels like a superpower if you help someone who doesn\u2019t have that skill.\nLike <a rel=\"external\" href=\"https:\/\/en.m.wikipedia.org\/wiki\/Tasseography\">\u201creading from a cup\u201d<\/a> or so.<\/p>\n<h2 id=\"break-down-problems\"><a class=\"anchor\" href=\"#break-down-problems\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Break Down Problems<\/h2>\n<p>Everyone gets stuck at times.\nThe best know how to get unstuck.\nThey simplify problems until they become digestible.\nThat\u2019s a hard skill to learn and requires a ton of experience.\nAlternatively, you just have awesome problem-solving skills, e.g., you\u2019re clever.\nIf not, you can train it, but there is no way around breaking down hard problems.\nThere are problems in this world that are too hard to solve at once for anyone involved.<\/p>\n<p>If you work as a professional developer, that is the bulk of the work you get paid to do:\nbreaking down problems.\nIf you do it right, it will feel like cheating:\nyou just solve simple problems until you\u2019re done.<\/p>\n<h2 id=\"don-t-be-afraid-to-get-your-hands-dirty\"><a class=\"anchor\" href=\"#don-t-be-afraid-to-get-your-hands-dirty\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be Afraid to Get Your Hands Dirty<\/h2>\n<p>The best devs I know read a lot of code and they are not afraid to touch it.\nThey never say \u201cthat\u2019s not for me\u201d or \u201cI can\u2019t help you here.\u201d\nInstead, they just start and learn.\nCode is <em>just code<\/em>.\nThey can just pick up any skill that is required with time and effort.\nBefore you know it, they become the go-to person in the team for whatever they touched.\nMostly because they were the only ones who were not afraid to touch it in the first place.<\/p>\n<h2 id=\"always-help-others\"><a class=\"anchor\" href=\"#always-help-others\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Always Help Others<\/h2>\n<p>A related point.\nGreat engineers are in high demand and are always busy, but they always try to help.\nThat\u2019s because they are naturally curious and their supportive mind is what made them great engineers in the first place.\nIt\u2019s a sheer joy to have them on your team, because they are problem solvers.<\/p>\n<h2 id=\"write\"><a class=\"anchor\" href=\"#write\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Write<\/h2>\n<p>Most awesome engineers are well-spoken and happy to share knowledge.<\/p>\n<p>The best have some outlet for their thoughts: blogs, talks, open source, or a combination of those.<\/p>\n<p>I think there is a strong correlation between writing skills and programming.\nAll the best engineers I know have good command over at least one human language \u2013 often more.\nMastering the way you write is mastering the way you think and vice versa.\nA person\u2019s writing style says so much about the way they think.\nIf it\u2019s confusing and lacks structure, their coding style will be too.\nIf it\u2019s concise, educational, well-structured, and witty at times, their code will be too.<\/p>\n<p>Excellent programmers find joy in playing with words.<\/p>\n<h2 id=\"never-stop-learning\"><a class=\"anchor\" href=\"#never-stop-learning\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Never Stop Learning<\/h2>\n<p>Some of the best devs I know are 60+ years old.\nThey can run circles around me.\nPart of the reason is that they keep learning.\nIf there is a new tool they haven\u2019t tried or a language they like, they will learn it.\nThis way, they always stay on top of things without much effort.<\/p>\n<p>That is not to be taken for granted: a lot of people stop learning really quickly after they\ngraduate from University or start in their first job.\nThey get stuck thinking that what they got taught in school is the \u201cright\u201d way to do things.\nEverything new is bad and not worth their time.\nSo there are 25-year-olds who are \u201cmentally retired\u201d and 68-year-olds who are still fresh in their mind.\nI try to one day belong to the latter group.<\/p>\n<p>Somewhat related, the best engineers don\u2019t follow trends, but they will always carefully\nevaluate the benefits of new technology. If they dismiss it, they can tell you exactly <em>why<\/em>,\nwhen the technology would be a good choice, and what the alternatives are.<\/p>\n<h2 id=\"status-doesn-t-matter\"><a class=\"anchor\" href=\"#status-doesn-t-matter\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Status Doesn\u2019t Matter<\/h2>\n<p>The best devs talk to principal engineers and junior devs alike. There is no hierarchy.\nThey try to learn from everyone, young and old.\nThe newcomers often aren\u2019t entrenched in office politics yet and still have a fresh mind.\nThey don\u2019t know why things are <em>hard<\/em> and so they propose creative solutions.\nMaybe the obstacles from the past are no more, which makes these people a great source of inspiration.<\/p>\n<h2 id=\"build-a-reputation\"><a class=\"anchor\" href=\"#build-a-reputation\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Build a Reputation<\/h2>\n<p>You can be a solid engineer if you <strong>do<\/strong> good work,\nbut you can only be one of the best if you\u2019re <strong>known<\/strong> for your good work;\nat least within a (larger) organization.<\/p>\n<p>There are many ways to build a reputation for yourself:<\/p>\n<ul>\n<li>You built and shipped a critical service for a (larger) org.<\/li>\n<li>You wrote a famous tool<\/li>\n<li>You contribute to a popular open source tool<\/li>\n<li>You wrote a book that is often mentioned<\/li>\n<\/ul>\n<p>Why do I think it is important to be known for your work?\nAll of the above are ways to extend your radius of impact in the community.\nFamous developers impact way more people than non-famous developers.\nThere\u2019s only so much code you can write.\nIf you want to \u201cscale\u201d your impact, you have to become a thought leader.<\/p>\n<p>Building a reputation is a long-term goal.\nIt doesn\u2019t happen overnight, nor does it have to.\nAnd it won\u2019t happen by accident.\nYou show up every day and do the work.\nOver time, the work will speak for itself.\nMore people will trust you and your work and they will want to work with you.\nYou will work on more prestigious projects and the circle will grow.<\/p>\n<p>I once heard about this idea that your latest work should\novershadow everything you did before.\nThat\u2019s a good sign that you are on the right track.<\/p>\n<h2 id=\"have-patience\"><a class=\"anchor\" href=\"#have-patience\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Have Patience<\/h2>\n<p>You need patience with computers and humans.\nEspecially with yourself.\nNot everything will work right away and people take time to learn.\nIt\u2019s not that people around you are stupid; they just have incomplete information.\nWithout patience, it will feel like the world is against you and\neveryone around you is just incompetent. That\u2019s a miserable place to be.\nYou\u2019re too clever for your own good.<\/p>\n<p>To be one of the best, you need an incredible amount of patience, focus, and dedication.\nYou can\u2019t afford to get distracted easily if you want to solve hard problems.\nYou have to return to the keyboard to get over it.\nYou have to put in the work to push a project over the finishing line.\nAnd if you can do so while not being an arrogant prick, that\u2019s even better.\nThat\u2019s what separates the best from the rest.<\/p>\n<h2 id=\"never-blame-the-computer\"><a class=\"anchor\" href=\"#never-blame-the-computer\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Never Blame the Computer<\/h2>\n<p>Most developers blame the software, other people, their dog, or the weather for\nflaky, seemingly \u201crandom\u201d bugs.<\/p>\n<p>The best devs don\u2019t.<\/p>\n<p>No matter how erratic or mischievous the behavior of a computer seems,\nthere is <em>always<\/em> a logical explanation: you just haven\u2019t found it yet!<\/p>\n<p>The best keep digging until they find the reason.\nThey might not find the reason immediately, they might never find it,\nbut they never blame external circumstances.<\/p>\n<p>With this attitude, they are able to make incredible progress and learn things that others fail to.\nWhen you mistake bugs for incomprehensible magic, magic is what it will always be.<\/p>\n<h2 id=\"don-t-be-afraid-to-say-i-don-t-know\"><a class=\"anchor\" href=\"#don-t-be-afraid-to-say-i-don-t-know\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Be Afraid to Say \u201cI Don\u2019t Know\u201d<\/h2>\n<p>In job interviews, I pushed candidates hard to at least say \u201cI don\u2019t know\u201d once.\nThe reason was not that I wanted to look superior (although some people certainly had that impression).\nNo, I wanted to reach the boundary of their knowledge.\nI wanted to stand with them on the edge of what they thought they knew.\nOften, I myself didn\u2019t know the answer. And to be honest, I didn\u2019t care about the answer.\nWhat I cared about was when people bullshitted their way through the interview.<\/p>\n<p>The best candidates said\n\u201cHuh, I don\u2019t know, but that\u2019s an interesting question! If I had to guess, I would say\u2026\u201d\nand then they would proceed to deduce the answer.\nThat\u2019s a sign that you have the potential to be a great engineer.<\/p>\n<p>If you are afraid to say \u201cI don\u2019t know\u201d, you come from a position of hubris or defensiveness.\nI don\u2019t like bullshitters on my team.\nBetter to acknowledge that you can\u2019t know everything.\nOnce you accept that, you allow yourself to learn.\n\u201cThe important thing is that you don\u2019t stop asking questions,\u201d said Albert Einstein.<\/p>\n<h2 id=\"don-t-guess\"><a class=\"anchor\" href=\"#don-t-guess\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Guess<\/h2>\n<p>\u201cIn the Face of Ambiguity, Refuse the Temptation to Guess\u201d\nThat is one of my favorite rules in <a rel=\"external\" href=\"https:\/\/peps.python.org\/pep-0020\/\">PEP 20 \u2013 The Zen of Python<\/a>.<\/p>\n<p>And it\u2019s so, so tempting to guess!<\/p>\n<p>I\u2019ve been there many times and I failed with my own ambition.<\/p>\n<p>When you guess, two things can happen:<\/p>\n<ul>\n<li>In the <strong>best case<\/strong> you\u2019re wrong and your incorrect assumptions lead to a bug.<\/li>\n<li>In the <strong>worst case<\/strong> you are right\u2026 and you\u2019ll never stop and second guess yourself.\nYou build up your mental model based on the wrong assumptions.\nThis can haunt you for a long time.<\/li>\n<\/ul>\n<p>Again, resist the urge to guess.\nAsk questions, read the reference, use a debugger, be thorough.\nDo what it takes to get the answer.<\/p>\n<h2 id=\"keep-it-simple\"><a class=\"anchor\" href=\"#keep-it-simple\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Keep It Simple<\/h2>\n<p>Clever engineers write clever code.\nExceptional engineers write simple code.<\/p>\n<p>That\u2019s because most of the time, simple is enough.\nAnd simple is more maintainable than complex.\nSometimes it <em>does<\/em> matter to get things right, but\nknowing the difference is what separates the best from the rest.<\/p>\n<p>You can achieve a whole lot by keeping it simple.\nFocus on the right things.<\/p>\n<h2 id=\"final-thoughts\"><a class=\"anchor\" href=\"#final-thoughts\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Final Thoughts<\/h2>\n<p>The above is not a checklist or a competition;\nand great engineering is not a race.<\/p>\n<p>Just don\u2019t trick yourself into thinking that you can skip the hard work.\nThere is no shortcut. Good luck with your journey.<\/p>\n"},{"title":"So You Want to Start a (Tech) Podcast","pubDate":"Fri, 04 Oct 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/","guid":"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/","description":"<p>For the past year, I\u2019ve been hosting the <a rel=\"external\" href=\"https:\/\/corrode.dev\/podcast\/\">Rust in\nProduction<\/a>,\na podcast about companies who shape the future of infrastructure.<\/p>\n<p>This journey has taught me a lot about what it takes to create and maintain a\nsuccessful podcast. Well, success is always relative; at the moment we have\naround 5k regular (monthly) listeners. Maybe not a ton of people, but it puts us\ncomfortably into the top 5% of podcasts \u2013 at least by <a rel=\"external\" href=\"https:\/\/www.demandsage.com\/podcast-statistics\/\">some\nstatistics<\/a>.<\/p>\n<p>Whether you\u2019re considering starting your own podcast or just curious about the\nprocess, I hope my experiences can offer some valuable insights.<\/p>\n<figure>\n    <a href=\"https:\/\/corrode.dev\/podcast\/\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/cover.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/cover.jpg\" alt=\"The 'Rust in Production' podcast cover\" width=\"650\" height=\"650\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        The \u2018Rust in Production\u2019 podcast cover\n    <\/figcaption>\n<\/figure>\n<h2 id=\"do-your-research\"><a class=\"anchor\" href=\"#do-your-research\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Do Your Research<\/h2>\n<p>Before you dive into the world of podcasting, take some time to explore the landscape. Think about branding and positioning <strong>first<\/strong>.<\/p>\n<h3 id=\"topic\"><a class=\"anchor\" href=\"#topic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Topic<\/h3>\n<p>When choosing your topic, make sure it\u2019s something you can easily generate ideas\nfor. Try to come up with at least 10 potential episode ideas\nbefore you settle on it. If you\u2019re\nplanning an interview-based podcast, ensure you have a large enough network to\nsecure at least 10 guests.<\/p>\n<h3 id=\"competition\"><a class=\"anchor\" href=\"#competition\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Competition<\/h3>\n<p>Research your competition. Listen to similar podcasts and note down what you like and dislike about them. This will help you differentiate your podcast from others in the same niche.<\/p>\n<p>If a podcast is already covering your topic, that\u2019s not necessarily a bad thing; it just shows there\u2019s an audience for it. However, you need to find a unique angle or a different format to stand out. If you can\u2019t be the first, be the best. Be the funniest, or the most in-depth, or the one with the most interesting guests.<\/p>\n<p>Be honest with yourself about what you can offer that others can\u2019t. If you can\u2019t find a unique angle, it might be better to choose a different topic.\nIf you\u2019re not sure, ask your friends or colleagues for their opinion.<\/p>\n<h3 id=\"podcast-name\"><a class=\"anchor\" href=\"#podcast-name\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Podcast Name<\/h3>\n<p>What\u2019s the title of your podcast?<\/p>\n<ul>\n<li>Is it catchy and easy to remember?<\/li>\n<li>Does it convey what your podcast is about?<\/li>\n<li>Is the domain name available?<\/li>\n<li>Are the social media handles available?<\/li>\n<li>Is there a simple abbreviation you can use for hashtags or mentions?<\/li>\n<\/ul>\n<p>Especially the last few points are often overlooked. You want to make it as easy as possible for people to find your podcast.\nI\u2019d say don\u2019t be too clever with your podcast name. It should be easy to remember and spell. If you have to explain it, it\u2019s probably too complicated. Also, don\u2019t use special characters or numbers in your podcast name. It makes it harder to remember and type.\nDon\u2019t pick a too generic name either. Be specific about your niche. So instead of \u201cThe JavaScript Podcast,\u201d go for \u201cRefactoring JavaScript\u201d or\n\u201cReact Weekly.\u201d<\/p>\n<p>Don\u2019t forget about SEO. Consider what people might search for when looking for content like yours. My podcast is titled \u201cRust in Production,\u201d which is a commonly searched term. This has helped with discoverability.\nAnother version of that, which could work, is to think about questions that people Google for.\nE.g. \u201cWhat is functional programming?\u201d or \u201cHow to refactor legacy code?\u201d\nand then coming up with a podcast name that answers that question.\nFor example, \u201cFunctional Programming Explained\u201d or \u201cRefactoring Legacy Code.\u201d<\/p>\n<h3 id=\"cover-art\"><a class=\"anchor\" href=\"#cover-art\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Cover Art<\/h3>\n<p>Your podcast\u2019s cover is equally crucial. It\u2019s the first thing people recognize about your podcast (except for the title) before they decide what to listen to, so it needs to stand out from the crowd.<\/p>\n<p>What I did was open my podcast app and look at the grid of covers.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/podcasts.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/so-you-want-to-start-a-tech-podcast\/podcasts.jpg\" alt=\"The grid of podcast covers in my podcast app\" width=\"650\" height=\"1295\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The grid of podcast covers in my podcast app\n    <\/figcaption>\n<\/figure>\n<p>I asked myself which ones stood out and why.\nI also asked a few friends and my partner to do the same. I got some great feedback that way.\nThis visual first impression can make a big difference in attracting new listeners.<\/p>\n<h3 id=\"length\"><a class=\"anchor\" href=\"#length\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Length<\/h3>\n<p>Next, decide on your podcast\u2019s length. Fifteen minutes is great for news content, 30 minutes work well for commutes, and one hour is suitable for deep dives. Anything longer, and listeners might hesitate to commit their time.<\/p>\n<h2 id=\"plan-your-content\"><a class=\"anchor\" href=\"#plan-your-content\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Plan Your Content<\/h2>\n<p>Once you\u2019ve done your research, it\u2019s time to plan your content strategy. Having a regular schedule is key - weekly or biweekly episodes work well for many podcasts. Start conservatively; you can always increase frequency later, but underestimating the workload can lead to burnout.<\/p>\n<p>I highly recommend buffering content by recording a few episodes before you start publishing. This gives you a cushion and reduces stress, especially when you\u2019re just starting out.<\/p>\n<p>Consider a season-based approach. For \u201cRust in Production,\u201d we do 7-8 episodes and then take a break. This allows for better planning and reduces ongoing pressure.<\/p>\n<h2 id=\"respect-your-guests\"><a class=\"anchor\" href=\"#respect-your-guests\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Respect Your Guests<\/h2>\n<p>If you\u2019re doing an interview-based podcast, treating your guests with respect is paramount. Explain why you want them on your show in the initial email. Keep them informed about the process and be flexible with scheduling. At the start of the recording, explain how things will work and ask if they have any time constraints.<\/p>\n<p>Remember, your guests are likely doing this for free. Respect their time and make the experience as smooth as possible for them.<\/p>\n<h2 id=\"invest-in-quality\"><a class=\"anchor\" href=\"#invest-in-quality\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Invest in Quality<\/h2>\n<p>Audio quality can make or break a podcast. Invest in good equipment - get a decent microphone and headphones, and consider ways to improve your room\u2019s acoustics. If you\u2019re interviewing guests remotely, consider their equipment too. A pre-call to check their setup can be invaluable, or you might even consider sending them equipment if you want consistent quality across episodes.<\/p>\n<p>Always remind guests to stay close to the mic. It\u2019s a small detail that can make a big difference in audio quality.\nOn two occasions, I had guests who had their condenser mic backwards, and that sounds pretty dull. You get better at picking up on these things the more you record. It helps to know which way the mic should be facing (usually the logo on the mic and the volume knob should be facing you). Both guests were very grateful for the tip and the audio quality improved significantly.<\/p>\n<h2 id=\"production-tips\"><a class=\"anchor\" href=\"#production-tips\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Production Tips<\/h2>\n<p>One of the best decisions I made was not to edit the podcast myself. I\u2019m incredibly thankful that <a rel=\"external\" href=\"https:\/\/github.com\/M3t0r\">Simon Br\u00fcggen<\/a> agreed to do the editing for \u201cRust in Production.\u201d It would have been an enormous amount of work on top of finding guests, recording, and hosting.\nIt also helps that Simon is a Rust developer and understands the content. He can give tips on how to improve the content from a technical perspective.<\/p>\n<p>For recording, tools like <a rel=\"external\" href=\"https:\/\/zencastr.com\/\">Zencastr<\/a>, <a rel=\"external\" href=\"https:\/\/riverside.fm\/\">Riverside<\/a>, or <a rel=\"external\" href=\"https:\/\/www.descript.com\/\">Descript<\/a> are excellent. They capture audio on both sides, giving you uncompressed files to work with. <a rel=\"external\" href=\"https:\/\/auphonic.com\/\">Auphonic<\/a> is great for cleaning up audio, removing filler words, and creating transcripts.<\/p>\n<p>When it comes to hosting, I use <a rel=\"external\" href=\"https:\/\/letscast.fm\/\">Letscast<\/a>. They\u2019re not the cheapest option, but their customer service is top notch and the website is fast and not bloated.<\/p>\n<h2 id=\"develop-your-style\"><a class=\"anchor\" href=\"#develop-your-style\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Develop Your Style<\/h2>\n<p>As you progress, you\u2019ll naturally develop your own podcasting style. For me, I prefer to let guests do most of the talking, only interjecting occasionally with questions or comments.\nThe motto is \u201csay less, ask more.\u201d It\u2019s a good rule of thumb for interviews. It\u2019s not about you, it\u2019s about the guest. Let them shine.\nIn pursuit of asking better questions, I wrote an essay on <a href=\"\/2024\/asking-better-questions\/\">how to ask better questions<\/a>.\nI\u2019ve also found that taking notes during recording helps me ask better follow-up questions.<\/p>\n<p>Don\u2019t be afraid to encourage your guests when they make good points. A nod, a smile, or a thumbs up can go a long way in making them feel comfortable and valued.<\/p>\n<h2 id=\"don-t-sweat-the-small-stuff\"><a class=\"anchor\" href=\"#don-t-sweat-the-small-stuff\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Don\u2019t Sweat the Small Stuff<\/h2>\n<p>While it\u2019s tempting to obsess over metrics, try not to focus on them too much. Instead, concentrate on producing content you\u2019d enjoy consuming yourself. Be passionate about your topic and create your podcast as if no one is listening - ironically, this often leads to the most engaging content.<\/p>\n<p>Starting a podcast is a lot of work, but it\u2019s incredibly rewarding. The podcast space isn\u2019t oversaturated yet - it\nreminds me of the golden age of YouTube a few years ago. Podcasting is becoming more professional now, but there\u2019s still plenty of room for new formats and perspectives.<\/p>\n<p>Remember: it\u2019s okay to start small and grow. You\u2019ll learn and improve with each new episode. The most important thing is to enjoy the process and share your personality with the world.<\/p>\n<p>If you\u2019re interested in Rust, consider listening to the <a rel=\"external\" href=\"https:\/\/corrode.dev\/podcast\/\">Rust in Production<\/a> podcast. I\u2019d love to hear what you think!<\/p>\n"},{"title":"Follow the Hackers","pubDate":"Sat, 07 Sep 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/follow-the-hackers\/","guid":"https:\/\/endler.dev\/2024\/follow-the-hackers\/","description":"<p>Want to see tomorrow\u2019s important technologies?\nWatch what hackers are passionate about today.<\/p>\n<h2 id=\"defining-hacker\"><a class=\"anchor\" href=\"#defining-hacker\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Defining \u201cHacker\u201d<\/h2>\n<p>I\u2019m using the term \u201chacker\u201d in the spirit of the Hacker Ethic, as described by authors like <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Steven_Levy\">Steven Levy<\/a> and <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pekka_Himanen\">Pekka Himanen<\/a>.\nIn this context, a hacker is someone who:<\/p>\n<ul>\n<li>Follows their passion and seeks self-fulfillment through technology<\/li>\n<li>Creates something beneficial for the wider community<\/li>\n<li>Values freedom, cooperation, and voluntary work<\/li>\n<li>Challenges traditional work ethics with a focus on creativity and sharing<\/li>\n<\/ul>\n<p>These folks are a small subset of the population, but they have some traits that make them excellent predictors of the future:<\/p>\n<ul>\n<li>They care deeply about their field - programming being just one example<\/li>\n<li>They\u2019re passionate about the things they believe in<\/li>\n<li>They\u2019d use something even if no one else cared about it<\/li>\n<li>They work at the cutting edge, so they need the best tools to do their job<\/li>\n<li>They hold strong opinions on what works and what doesn\u2019t, backed by solid evidence<\/li>\n<li>They don\u2019t care about investors, quarterly earnings reports, or politics - they purely focus on the technology\u2019s value<\/li>\n<\/ul>\n<h2 id=\"catalysts-for-success-and-red-flags\"><a class=\"anchor\" href=\"#catalysts-for-success-and-red-flags\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Catalysts for Success and Red Flags<\/h2>\n<p>Of course, not every hyped technology makes it big.\nRemember NFTs or Web3?<\/p>\n<p>The key difference?\nReal hackers were never passionate about these technologies - ordinary people were.\nAnother red flag is when the technology\u2019s benefits are hard to explain.\nIf hardcore tech people can\u2019t explain the benefits to you, that\u2019s a bad sign.\nLook deeper and you\u2019ll find different motivations at work!<\/p>\n<p>It\u2019s typically people looking to profit from technology.\nThey brand themselves as Investors, \u201cSerial Entrepreneurs\u201d, and \u201cThought Leaders\u201d.\nYou\u2019ll find them on LinkedIn, updating their profiles with the latest buzzwords every few months.\nWhile a few are legitimate, most are opportunists who couldn\u2019t explain the technology to save their lives.\nProfit is their only motivation.<\/p>\n<p>The hackers?\nThey don\u2019t care what you think about them.\nThey\u2019ve got nothing to sell you.\nThey\u2019re too busy building cool stuff!<\/p>\n<p>A question hackers care about is \u201cwho owns the platform\u201d?\nCompanies always have an agenda.\nPour in your time and effort, and they might lock you out to profit from your work.\n<a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=39772562\">Hackers don\u2019t like that.<\/a><\/p>\n<p>Therefore, all the winning ideas I mentioned are open source.\nIf a technology isn\u2019t, that\u2019s a major red flag when evaluating its future potential.\nIt\u2019s not even optional anymore - it\u2019s pretty much mandatory.<\/p>\n<p>But there\u2019s another reason why open source is a catalyst for success:\nInitially, open source projects start as minimally functional versions without user-friendly documentation.\nThey might be tough to set up, but the core idea is there.\nIf people stick with it despite the lack of hand-holding, you know it\u2019s solving a real problem - and that\u2019s a sign of a winning idea.<\/p>\n<h2 id=\"you-still-need-patience\"><a class=\"anchor\" href=\"#you-still-need-patience\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>You Still Need Patience<\/h2>\n<p>You probably know I\u2019m all in on Rust.\nAfter all, <a rel=\"external\" href=\"https:\/\/corrode.dev\">I make my living as a Rust consultant<\/a>.\nIt took Rust over a decade of development to gain any real traction in the industry.\nIt\u2019s been a slow but steady climb.<\/p>\n<p>It takes time for the public to catch up before a technology hits its stride.\nFor core technologies like programming languages or databases, it often takes a decade or more.\nThat\u2019s simply how long technology needs to mature.<\/p>\n<p>That\u2019s why I tell founders to stay slightly conservative when adopting new tech.\nThe industry needs time to catch up, and big companies need specialized tools to integrate new tech into their existing systems.\nOn the other side, investing early in promising technologies is a calculated risk because the writing is on the wall.<\/p>\n<h2 id=\"what-can-you-learn-from-this\"><a class=\"anchor\" href=\"#what-can-you-learn-from-this\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What Can You Learn from This?<\/h2>\n<p>Hackers are already living in the future.\nYou can use that to your advantage.\nAsk 10 hackers what new things they\u2019re really excited about, and you\u2019ll get a good picture of what\u2019s going to be important in a few years.<\/p>\n<p>Most business people don\u2019t talk to hackers regularly.\nThat\u2019s a fact you can use to your advantage.<\/p>\n<p>If you\u2019re selling to developers (<a href=\"\/2024\/selling-to-developers\/\">and you probably shouldn\u2019t<\/a>), the key is to really listen to what the hackers are saying and then follow their lead.<\/p>\n"},{"title":"Be Simple","pubDate":"Mon, 02 Sep 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/be-simple\/","guid":"https:\/\/endler.dev\/2024\/be-simple\/","description":"<p>Last night I realized that my life is very simple.\nThat\u2019s not by chance, but by conscious effort.\nLife becomes complex all by itself if you do nothing about it.<\/p>\n<p>One day you\u2019ll wake up and you have a mortgage, 10 on-demand subscriptions, 20 insurances, 1000 open browser tabs, a demanding job and a dog.\nAnd when you realize it, you wonder how you got there.<\/p>\n<p>I keep my life simple because I know my time is limited.\nTime and health are my best proxies for happiness.<\/p>\n<h2 id=\"simple-doesn-t-mean-boring\"><a class=\"anchor\" href=\"#simple-doesn-t-mean-boring\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Simple Doesn\u2019t Mean Boring<\/h2>\n<p>Quite the contrary: give me enough time and I find ways to entertain myself.\nMy friends might disagree, but I consider myself to be an introvert.\nI like to spend time on my own to explore and learn.\nThere hasn\u2019t been a boring moment in a long time.<\/p>\n<p>If life was more complex, that would take away my time, but time is the resource I can\u2019t replenish, so I protect it.\nHow? Mostly by saying NO.<\/p>\n<ul>\n<li>No streaming subscriptions. No Disney+, no Netflix. I rarely watch TV anyway.<\/li>\n<li>No gym memberships. Just run in the park.<\/li>\n<li>No Instagram or TikTok, but part of that is getting older.<\/li>\n<li>My shoes are 6 years old. So is my wardrobe.<\/li>\n<li>No meetings if possible. I\u2019m the guy who sits at his desk for 8 hours straight, only getting up for bathroom breaks twice.<\/li>\n<li>No property; I\u2019m a happy tenant.<\/li>\n<li>No commute; I work remotely.<\/li>\n<\/ul>\n<p>Great home cinema setup you have there.\nThanks for inviting me over!\nAt home, I don\u2019t even have external speakers.<\/p>\n<p>You\u2019re planning a trip to the Bahamas? Enjoy! Send me a photo.<\/p>\n<p>Regarding technology, that means:<\/p>\n<ul>\n<li>Even though I\u2019m a programmer, I only have a single screen.<\/li>\n<li>I evaluate tools, but I keep the number of tools limited.<\/li>\n<li>My editor doesn\u2019t have a debugger.<\/li>\n<li>No Notion or Obsidian if a text file + git is enough.<\/li>\n<li>I limit the number of browser tabs with an <a rel=\"external\" href=\"https:\/\/github.com\/kanru\/max-tabs\">extension<\/a>.<\/li>\n<\/ul>\n<h2 id=\"simple-doesn-t-mean-minimalistic\"><a class=\"anchor\" href=\"#simple-doesn-t-mean-minimalistic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Simple Doesn\u2019t Mean Minimalistic<\/h2>\n<p>My goal is not to have as few possessions as possible \u2013 I own a lot \u2013 but to lead a simple life.\nI\u2019ll happily buy things if they make my life simpler.\nThe last big life improvements were a robot vacuum cleaner (four years ago) and an automated cat litter box (two years ago).\nIf I decide to buy something, I make sure it\u2019s the absolute best I can afford.\n(My rule is actually \u201cdon\u2019t buy crap\u201d.)\nFor example, I spent a ridiculous amount on the best laptop I could buy.\nIt\u2019s my daily driver that I spend most of my time with, so it needs to be an absolute workhorse.\nMy work is also compute-intensive, so I saw the purchase as justified.<\/p>\n<p>I always pay the price in full. No lease, no monthly payments.\nI have to use services for work, but I prefer monthly payments over yearly subscriptions, even if they are 30% more expensive.\nThe fact that I can cancel at any time is more important to me.<\/p>\n<p>I know that when I buy something, it demands my attention.\nMaintenance is not fun.\nEven though I like the <em>idea<\/em> of owning something, I probably don\u2019t truly own it.\nThat makes me the worst consumer possible.\nI keep things in my Amazon basket <em>forever<\/em>. From time to time I look at the items, and when I enjoy seeing them in my basket\u2026 I keep them there.\nThe rest, I just delete.\nThis way, I get the \u201cfeeling\u201d of owning things without spending any money.<\/p>\n<h2 id=\"simple-doesn-t-mean-convenient\"><a class=\"anchor\" href=\"#simple-doesn-t-mean-convenient\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Simple Doesn\u2019t Mean Convenient<\/h2>\n<p>To live with such a person is not easy.\nWe have regular discussions about \u201cinvesting\u201d money into things that I\u2019m skeptical about.\nIt takes me ages to reach a conclusion.\nVacation planning is definitely one of my weaknesses.\nI am very well aware that my approach is not perfect at times.\nI am okay with making these sacrifices for protecting my time and therefore my happiness.<\/p>\n<p>Recently, I got a few emails from people telling me that my newsletter subscription is broken.\nI\u2019m aware of that. My newsletter provider shut down.\nI won\u2019t fix it.\nIt turns out that people find other ways to follow me; either on Mastodon or via RSS.\nI also don\u2019t have a comment section \u2013 Reddit or HN work just fine.\nEven though there are a few folks on my old newsletter list, I never got around to sending many emails.\nI don\u2019t particularly enjoy writing a newsletter, so it might be best that it finally broke.\nI will probably remove the signup box.\nIt would be nice to have it \u201cjust work\u201d, but the next best thing is to not have it at all.<\/p>\n<h2 id=\"simple-means-letting-go\"><a class=\"anchor\" href=\"#simple-means-letting-go\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Simple Means Letting Go<\/h2>\n<p>Perhaps another way to explain it is the midwit theme:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/be-simple\/midwit.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/be-simple\/midwit.jpg\" width=\"650\" height=\"367\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>I try to stay on the left side of this curve as much as I can.<\/p>\n<p>I\u2019m aware that there are \u201csmarter\u201d ways to do things, but I don\u2019t want to dedicate time to learning about them.\nI only dedicate time to things that matter to me and that I want to go really deep into.<\/p>\n<p>The meme shows simple approaches on both ends, with a complicated phase in between.\nGetting to the right side of the spectrum takes lots of effort, and I\u2019ve only made that journey a few times in my life.\nFor the rest, knowing there\u2019s an awkward complicated phase in between keeps me happily on the simple side.\nIt\u2019s fine.<\/p>\n<h2 id=\"simple-means-focused\"><a class=\"anchor\" href=\"#simple-means-focused\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Simple Means Focused<\/h2>\n<p>Greatness comes from dedicating time to the things that matter.\nThe most productive people I know are focused.\nYes, there\u2019s a creative process and they allow themselves to be creative, but they do so in a very constrained environment: their office.\nWhile others chase trends, they do the thing they\u2019re always doing.\nThey put in the hours.<\/p>\n<p>It\u2019s way easier to be focused when life is simple.\nWhen there\u2019s no room for distractions and complexity.\nI find that constraints help as well.\nTechnology is one major source of distraction.\nSome of the best stories were written with a typewriter.\nIn itself, it\u2019s a very limited environment, but it takes away all the distractions and lets you focus on the task at hand.\nI find that inspiring, liberating.\nThat\u2019s why I like constraints.\nWhen I give presentations, I wonder what I\u2019d write if I could only have 5 slides with 5 words each,\nor I could only use two colors, or only show images.\nIt keeps me focused on the message.\nIt\u2019s simple.\nSimple is beautiful.\nSimple makes me happy.<\/p>\n"},{"title":"What to Write","pubDate":"Tue, 20 Aug 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/what-to-write\/","guid":"https:\/\/endler.dev\/2024\/what-to-write\/","description":"<p>People sometimes ask me how I come up with things to write.\nTo me, it\u2019s the same as asking how I come up with things to say.\nThere\u2019s always something to say.\nIt might not be novel or interesting to most, but it\u2019s important to me\nand hopefully to someone else.<\/p>\n<p>What people <em>actually<\/em> want to know is how to come up with something <em>interesting<\/em> to write.\nBut why should that matter?\nWhat if people don\u2019t find it interesting?\nWas it a waste of time?<\/p>\n<h2 id=\"why-write\"><a class=\"anchor\" href=\"#why-write\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Write?<\/h2>\n<p>There\u2019s this funny thing which happens when you write for a while:\nyou forget what excited you about writing in the first place.\nInstead, you find yourself chasing trends, trying to get more views, and build a following.\nEven if you\u2019re aware that this is happening, it\u2019s hard to stop.\nYour inner monologue tells you that what you\u2019re writing isn\u2019t good enough\nor that your readers won\u2019t like it.<\/p>\n<p>Writing becomes a chore.<br \/>\nEventually, you stop writing.<\/p>\n<p>Somewhat tautologically, people come here exactly for one reason: to read what I write.\nIf I make it about them, I have to guess what they want to hear, which kills the joy in writing,\nand also, in reading, as the content becomes predictable.<\/p>\n<h2 id=\"interesting-doesn-t-mean-novel\"><a class=\"anchor\" href=\"#interesting-doesn-t-mean-novel\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a><em>Interesting<\/em> Doesn\u2019t Mean <em>Novel<\/em>.<\/h2>\n<p>Just because someone else wrote about the same topic doesn\u2019t mean it\u2019s off-limits.\nThere are a million love songs to disprove that.\nAs it turns out, while they all revolve around the same topic, they\u2019re all unique.\nThey are <em>personal<\/em>, which is what makes them different.<\/p>\n<p>Some of these songs I like because I can relate to them.\nTo me, that\u2019s what makes them interesting: it\u2019s the same story but told in a different way \u2013 a personal way.\nAnd that <em>personal<\/em> makes it <em>new<\/em> and that <em>new<\/em> makes it <em>interesting<\/em>.<\/p>\n<h2 id=\"if-you-take-away-the-personal-you-take-away-the-interesting\"><a class=\"anchor\" href=\"#if-you-take-away-the-personal-you-take-away-the-interesting\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>If You Take Away the Personal, You Take Away the Interesting<\/h2>\n<p>Writing is a lot like that.\nI get to learn about how other people <em>feel<\/em> and how they think.\nIt\u2019s mostly an experience; shaped into words.<\/p>\n<p>It\u2019s beautiful to think how writing is such a simple way to learn from the experiences of others.\nAnd how, with just a few words, you can emotionally connect with a stranger.\nIt\u2019s a very human experience.<\/p>\n<p>Often, what you leave out is more important than what you keep; the reader fills in the blanks.\nEventually, a story starts a life of its own; when it gets shared; when it gets retold.\nIt\u2019s no longer the author\u2019s story but the reader\u2019s.\nIt becomes part of lore.\nWho wrote it isn\u2019t that important.<\/p>\n<p>I can\u2019t tell who reads this and why should I care?\nInstead of trying to make other people enjoy my writing, I want to connect with people who like the same topics.\nBig difference.<\/p>\n<h2 id=\"knowing-that-is-liberating\"><a class=\"anchor\" href=\"#knowing-that-is-liberating\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Knowing That Is Liberating<\/h2>\n<p>It gives me confidence that I will never run out of things to write.\nAt least not as long as I remember why I write.<\/p>\n<p>It\u2019s liberating because I don\u2019t have to chase the <em>new<\/em>.\nInstead, whatever it turns out to be is enough.\nAt times, I\u2019m as clueless as the reader to see where this leads me.\nMaybe someone else will find joy in it, maybe not.<\/p>\n<p>It doesn\u2019t matter.<\/p>\n<p>What matters is what <em>you<\/em> think matters, and <em>that\u2019s<\/em> what you should write about.<\/p>\n"},{"title":"Move Slow and Fix Things","pubDate":"Thu, 15 Aug 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/","guid":"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/","description":"<p>Growing up as a kid in rural Bavaria, I always dreamed of moving to the US to run a startup.\nMany kids in my generation shared that dream.\nTo me, it felt like the <em>only<\/em> way to combine my two greatest passions: writing code and building things.<\/p>\n<p>As I got older, I became disillusioned with the narrative surrounding Silicon Valley.\nThe hockey stick growth, the VC money, the \u201cget rich quick\u201d mentality \u2013 it was all one big illusion.\nFor a long time, I couldn\u2019t put my finger on what exactly bothered me about it.<\/p>\n<p>Part of what made me increasingly uncomfortable was the glorification of hustle culture \u2013\nthe idea that you have to work yourself to the bone to make it big against all odds.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/work.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/work.jpg\" width=\"650\" height=\"328\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>The other part was the \u201cwinner takes all\u201d mentality and the mindset that you have to \u201cmove fast and break things\u201d to succeed.<\/p>\n<p>I don\u2019t believe that has to be the case.<\/p>\n<p>As it turns out, I\u2019ve always been drawn to the <em>exact opposite<\/em>:\nsustainable growth, robust solutions, and a long-term mindset.\nThat\u2019s why I\u2019ve been contributing to <a href=\"\/2021\/oss-money\">open source for 15 years<\/a>, why I only run <a href=\"\/2021\/codeprints\/\">small, bootstrapped businesses<\/a> or <a href=\"\/2020\/sponsors\/\">non-profits<\/a>,\nand why I focus on writing and knowledge sharing.<\/p>\n<p>Paul Graham and his VC buddies would have you believe that your ultimate goal as a founder should be to build a unicorn.\nBut when I look at the Ubers, Facebooks, and Googles of this world, I see greed, gatekeeping, systemic exploitation, user tracking,\nexcessive resource consumption, and lawsuits against competitors.\nThese companies will do anything in their power to stay on top \u2013 even if it means bending the law or finding legal loopholes.\nWhat kind of role model is that?<\/p>\n<h2 id=\"the-other-side\"><a class=\"anchor\" href=\"#the-other-side\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Other Side<\/h2>\n<p>Who\u2019s on the \u201cother side\u201d?\nIt\u2019s the humble minority building small but meaningful things.\nThese people advocate for privacy, develop civic tech, try to live within their means, move deliberately, and fix what\u2019s broken.\nThey fly under the radar because their success isn\u2019t measured in dollars, and they lack big marketing budgets.\nInstead, they focus on their product, doing a lot with very little.\nI find that far more inspiring.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/bootstrap.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/move-slow-and-fix-things\/bootstrap.jpg\" width=\"650\" height=\"352\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>It\u2019s incredibly rewarding to build something people love that can provide you with a comfortable living.\nThere\u2019s no need to risk it all, drop out of college, work insane hours, and leave a trail of destruction in your wake.\nYou can build something small and useful instead, without a venture capitalist breathing down your neck.\nIt\u2019s still hard work, but you\u2019re leaving the campsite a little better than you found it.<\/p>\n<p>Note that moving slowly doesn\u2019t mean you can\u2019t make quick decisions.\nIt\u2019s just that the execution should be deliberate.\nDon\u2019t wreak havoc along the way.\nBecause the time to fix what you might break rarely comes.<\/p>\n<h2 id=\"vcs-are-not-your-friends\"><a class=\"anchor\" href=\"#vcs-are-not-your-friends\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>VCs Are Not Your Friends<\/h2>\n<p>In <a rel=\"external\" href=\"https:\/\/paulgraham.com\/notnot.html\">\u201cWhy to Not Not Start a Startup\u201d<\/a>, Paul Graham writes:<\/p>\n<blockquote>\n<p>So, paradoxically, if you\u2019re too inexperienced to start a startup, what you should do is start one. That\u2019s a way more efficient cure for inexperience than a normal job. In fact, getting a normal job may actually make you less able to start a startup, by turning you into a tame animal who thinks he needs an office to work in and a product manager to tell him what software to write.<\/p>\n<\/blockquote>\n<p>Let me be blunt: that\u2019s nonsense. It paints a black and white picture of the world that simply doesn\u2019t exist.\nYou don\u2019t have to choose between starting a startup and working a soul-crushing job as a \u201ctame animal\u201d in a cubicle.\nThere\u2019s a whole spectrum of possibilities in between!\nFor instance, you could work for yourself or with a small team, making use of your creativity and coming up with your own ideas.<\/p>\n<p>Paul <em>wants<\/em> you to start a startup because he wants to fund you and profit from your hard work. His motives are purely egoistical.<\/p>\n<p>If you happen to hit the startup jackpot, Paul gets even richer and you might become wealthy too. If you don\u2019t, you\u2019re left with nothing while Paul, already rich, gets to write an essay about your failure.<\/p>\n<p>That\u2019s a whole lot of risk for very little upside.<\/p>\n<p>You might wonder why I\u2019m picking on Paul Graham so much.\nIt\u2019s because I once looked up to him and valued his essays.\nHe represents a worldview I used to believe in, but now consider harmful.\nMost of his essays seem true on the surface, but dig deeper and you\u2019ll find his claims are based on a narrow worldview and rarely supported by evidence.<\/p>\n<p>Misleading young, impressionable people is dangerous.<\/p>\n<p>Startup founders bear all the downside risk, while venture capitalists are well-insulated from failure. VCs spread their bets across numerous startups, ensuring they profit regardless of individual outcomes. For you, the founder, it\u2019s an all-or-nothing gamble with your time, energy, and often your financial stability.<\/p>\n<h2 id=\"is-all-vc-money-bad\"><a class=\"anchor\" href=\"#is-all-vc-money-bad\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Is All VC Money Bad?<\/h2>\n<p>Of course not. But I\u2019d argue it\u2019s becoming less and less relevant in today\u2019s world.\nTake building a software product, for example. You don\u2019t need a fortune to get started anymore. There are website builders, cloud hosting solutions, and open source software at your fingertips.\nWhy take on VC money when you\u2019re just starting out?\nSome might argue that you profit from valuable networking opportunities and business advice along with the funding.\nBut most of that information is freely available online these days. There\u2019s an abundance of podcasts, videos, and books on the subject if you\u2019re willing to learn.<\/p>\n<p>It\u2019s trickier, of course, if you\u2019re building a physical product.\nBut even that has become much easier in recent years.\nCould you sell a 3D printed prototype before scaling up production?\nOr launch a Kickstarter campaign to fund your first batch of products?\nThere are now print-on-demand services for t-shirts, mugs, posters, and books.\nPlus, there are plenty of brick-and-mortar stores you could approach with your business idea if you\u2019re looking to collaborate.<\/p>\n<p>Let\u2019s say you do become wildly successful and urgently need capital to scale. Maybe then VC money is one way to go. Or you could take out a loan.\nEither way, remember that money always comes with strings attached.\nFunding might force you to do things you\u2019re not comfortable with, like compromising your users\u2019 privacy or your own values.\nAnd even if not, you\u2019ll constantly be pressured to find new avenues for growth.\nWouldn\u2019t it be nicer to focus on making your product better instead?\nThat\u2019s often far more rewarding.\nBut often, if you spend enough time thinking through a problem, you might find a way to prove your concept at a smaller scale.<\/p>\n<h2 id=\"there-is-no-infinite-growth\"><a class=\"anchor\" href=\"#there-is-no-infinite-growth\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>There Is No Infinite Growth<\/h2>\n<p>Ask yourself: What truly motivates you? Is it power, money, or fame?\nIf so, there are more meaningful things in life.\nYour self-worth isn\u2019t tied to building a unicorn.\nI don\u2019t know who needs to hear this, but it\u2019s perfectly fine to be 23 and not be a millionaire founder.\nIf you\u2019re a high school or college student dreaming of running a startup, know that there\u2019s another path.<\/p>\n<p>Don\u2019t sell out your moral compass for a quick buck.\nYou don\u2019t have to jump on the AI bandwagon just because it\u2019s the flavor of the month.\n<a rel=\"external\" href=\"https:\/\/www.ycombinator.com\/companies?batch=W24&amp;tags=Artificial%20Intelligence&amp;tags=AI&amp;tags=Generative%20AI&amp;tags=AI%20Assistant\">At least 144 out of 251 companies<\/a> from the YC W24 batch are building products with \u201cAI\u201d.\nThat\u2019s 57% of the batch.\nHow many of them are actually doing something meaningful with it?\nHow many will still be around in 5 years? What lasting value do these companies bring to the world?\nWe\u2019re accumulating a massive amount of tech debt while rewarding short-term thinking and profit over sustainability.<\/p>\n<p>Sure, Paul will benefit if one of them hits it big. You can read all about it in his next essay.<\/p>\n<p>But maybe there\u2019s another way.\nMaybe it\u2019s okay to have a small business with a loyal user base that pays the bills.\nMaybe you don\u2019t need to grow exponentially.<\/p>\n<p>Maybe you can move slow and fix things instead.<\/p>\n"},{"title":"Asking Better Questions","pubDate":"Mon, 12 Aug 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/asking-better-questions\/","guid":"https:\/\/endler.dev\/2024\/asking-better-questions\/","description":"<p>Recently, I realized that I mostly get paid to ask questions.<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/corrode.dev\/\">As a consultant<\/a>, advising companies<\/li>\n<li><a rel=\"external\" href=\"https:\/\/corrode.dev\/podcast\/\">As a podcast host<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/openpodcast.app\/\">In calls with potential clients<\/a><\/li>\n<\/ul>\n<p>The curious thing is that, like most people in a similar position, I never had any formal training in asking questions!\nI basically just wing it and try to get better over time.<\/p>\n<p>That got me thinking: What makes a good question?<br \/>\nThe other day, I reflected on that. Here\u2019s what I came up with.<\/p>\n<h2 id=\"1-good-questions-are-open-ended\"><a class=\"anchor\" href=\"#1-good-questions-are-open-ended\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>1. Good Questions Are Open-Ended<\/h2>\n<p>Recently, we did a survey about our podcast, and someone mentioned that some questions I asked the guests were \u201ceither-or\u201d type of questions.<\/p>\n<p>Q: \u201cDo you prefer dogs or cats?\u201d<br \/>\nA: \u201cDogs.\u201d<\/p>\n<p>Ouch, not a very interesting conversation!<\/p>\n<p>A better one might have been \u201cWhat\u2019s your favorite pet?\u201d.\nIt allows for surprising answers.<\/p>\n<p>Q: \u201cWhat\u2019s your favorite pet?\u201d<br \/>\nA: \u201cTarantula!\u201d<\/p>\n<p>We have to ask ourselves what we want out of the answer,\nwhich leads me to my second observation:<\/p>\n<h2 id=\"2-never-ask-a-question-if-you-don-t-care-about-the-answer\"><a class=\"anchor\" href=\"#2-never-ask-a-question-if-you-don-t-care-about-the-answer\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2. Never Ask a Question If You Don\u2019t Care about the Answer<\/h2>\n<p>Or to rephrase it, \u201cOnly ask things you care about.\u201d\nIf you don\u2019t care about the other person\u2019s answer, why even ask?\nAsk something else you care about instead!<\/p>\n<p>For example, when you ask someone if they prefer dogs or cats, what are you really asking?<\/p>\n<ul>\n<li>Do you wonder if the person is <em>nice<\/em>?<\/li>\n<li>Do you care about the logistics of owning a pet as a full-time employee?<\/li>\n<li>Or do you rather want to hear a certain answer from the other person that happens to fit <em>your<\/em> narrative?\n(The obvious correct answer is \u201ccats\u201d.)<\/li>\n<\/ul>\n<p>Be honest!<\/p>\n<p>Dig deeper into \u201cwhy\u201d you\u2019re asking the question.\nIf it\u2019s one of the former two questions, get straight to the point:<\/p>\n<p>Q: \u201cAre you a nice person?\u201d<br \/>\nA: \u2026<\/p>\n<p>Q: \u201cHow do you manage having a pet if you have to work all day?\u201d<br \/>\nA: \u2026<\/p>\n<p>It will lead to better answers.<\/p>\n<p>If it\u2019s about your own agenda and you\u2019re just looking for someone to give you the answer you\u2019re hoping for (<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Confirmation_bias\">confirmation bias<\/a>):\ndon\u2019t. Again, allow them to surprise you!<\/p>\n<p>Who knows? You might learn a thing or two about your preconceptions.<\/p>\n<p>Which leads to\u2026<\/p>\n<h2 id=\"3-good-questions-reveal-something-about-the-person-who-answers-bad-questions-about-the-person-who-asks\"><a class=\"anchor\" href=\"#3-good-questions-reveal-something-about-the-person-who-answers-bad-questions-about-the-person-who-asks\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>3. Good Questions Reveal Something about the Person Who Answers; Bad Questions about the Person Who Asks<\/h2>\n<p>It\u2019s very easy to slip into a role where you\u2019re framing people, and that lets your bias speak more about <strong>you<\/strong> than\nthe person you\u2019re talking to.\nBe conscious about that so that you can avoid it when it happens.<\/p>\n<p>Q: \u201cWhy do you love X?\u201d<br \/>\nA: \u201cI don\u2019t.\u201d<\/p>\n<p>Better:<\/p>\n<p>Q: \u201cTell me something you truly believe about X\u201d<br \/>\nA: \u201cI believe that\u2026\u201d<\/p>\n<p>The more unique the answer, the more you learn about the person.\nSo I would even say that a good question is one that reveals something <em>unique<\/em> about the person who answers.<\/p>\n<ul>\n<li>What is it that only <strong>they<\/strong> can say?<\/li>\n<li>What is it that they have <strong>unique<\/strong> insight into?<\/li>\n<\/ul>\n<p>Q: \u201cAs an expert in X, who has been in the field for 20 years, what is one thing that people always get wrong about X?\u201d<br \/>\nA: \u201cPeople always think that X is about Y, but it\u2019s really about Z.\u201d<\/p>\n<h2 id=\"4-good-questions-are-stacked-on-top-of-each-other\"><a class=\"anchor\" href=\"#4-good-questions-are-stacked-on-top-of-each-other\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>4. Good Questions Are Stacked on Top of Each Other<\/h2>\n<p>Do you know the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Five_whys\"><em>Five Whys<\/em><\/a> technique?\nIt\u2019s simple: Ask \u201cwhy\u201d five times to get to the root of the issue.<\/p>\n<p>Q: Are you happy with your job?<br \/>\nA: No.<\/p>\n<p>Q: Why?<br \/>\nA: It drains my energy.<\/p>\n<p>Q: Why?<br \/>\nA: I have to do boring things.<\/p>\n<p>Q: Why?<br \/>\nA: My boss thinks they must be done by <em>someone<\/em>.<\/p>\n<p>Q: Why?<br \/>\nA: No one got around to automating them.<\/p>\n<p>Q: Why?<br \/>\nA: We don\u2019t have the skills to automate boring tasks.<\/p>\n<p>Aha! If they learn how to automate things, this might lead to better job happiness!\nThat\u2019s insightful.<\/p>\n<p>What\u2019s nice is that it was a purely mechanical process.\nWith every step, we dug deeper into the underlying question.\nAt some point, the truth revealed itself.<\/p>\n<p>I love this technique. Good questions are built on top of each other.\nThe questions themselves don\u2019t have to be complicated. It can actually be the same question asked a few times in a row \u2013 even a child could do that.<\/p>\n<p>In fact, they do. A lot!\nThis is how they learn about the world around them.<\/p>\n<p>As grown-ups, we should not unlearn this technique.\n\u201cIt\u2019s rude to ask that.\u201d \u201cDon\u2019t pry.\u201d \u201cDon\u2019t be nosy.\u201d<\/p>\n<p>We should relearn it! Ask follow-up questions to get to the root of things.<\/p>\n<p>But also!\nHold the other person accountable.<\/p>\n<p>Q: \u201cHow can we fix poverty?\u201d<br \/>\nA: \u201cI will do everything in my power to fix it.\u201d<\/p>\n<p>Q: \u201cBut how?\u201d<br \/>\nA: \u201cI will try countermeasures which were discussed with\u2026\u201d<\/p>\n<p>Q: \u201cCan you give me a concrete example?\u201d<br \/>\nA: \u201c\u2026\u201d<\/p>\n<p>When someone answers your question, ask yourself if the answer really covered everything you wanted to know.\nOften, the most interesting pieces are omitted. Sometimes on purpose. But this is the most revealing part,\nthe part at the verge of uncertainty and insecurity and you have to uncover it to get to the heart of the matter!\nIf you don\u2019t do this, conversations stay shallow.<\/p>\n<p>Speaking of which\u2026<\/p>\n<h2 id=\"5-good-questions-run-deep\"><a class=\"anchor\" href=\"#5-good-questions-run-deep\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>5. Good Questions Run Deep<\/h2>\n<ul>\n<li>\u201cWhy is the sky blue?\u201d<\/li>\n<li>\u201cHow do people fall in love?\u201d<\/li>\n<li>\u201cAre you happy?\u201d<\/li>\n<\/ul>\n<p>These are simple questions!\nBut they touch on the very foundation of what we know, our perception of the world, and ourselves.<\/p>\n<p>The simpler the question, the deeper the answer.\nAnswering with \u201cI don\u2019t know\u201d is totally fine.\nThe important part is to stay curious and to be genuinely interested in the answer.<\/p>\n<h2 id=\"6-let-the-winners-run-and-cut-your-losses-short\"><a class=\"anchor\" href=\"#6-let-the-winners-run-and-cut-your-losses-short\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>6. Let the Winners Run and Cut Your Losses Short<\/h2>\n<p>Sometimes, no matter what you try, there\u2019s just nothing in a conversation.\nYou might have ended up in that weird space where people are simply out of their depth\nand you turn circles.<\/p>\n<p>Cut the cord.<\/p>\n<p>Just acknowledge it and move on.<\/p>\n<p>Trained conversationalists do it all the time without anyone noticing.\nThe conversation gets boring, so they just move on to the next topic.\nThere doesn\u2019t even have to be a transition.<\/p>\n<p>Q: \u201cSo, what do you do for a living?\u201d<br \/>\nA: \u201cI\u2019m a plumber.\u201d<\/p>\n<p>Q: \u201cOh, interesting. So, what are your plans if you win?\u201d<br \/>\nA: \u2026<\/p>\n<p>Once you notice that, you will see it everywhere.\nWe do it all the time in our daily lives, too, for example on the phone.\nJust cut your losses, move on to the next topic.<\/p>\n<p>Similarly, if you notice that you both are really into a topic, just run with it.<\/p>\n<h2 id=\"7-give-people-space-to-think\"><a class=\"anchor\" href=\"#7-give-people-space-to-think\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>7. Give People Space to Think<\/h2>\n<p>Pauses are powerful.<\/p>\n<p>Ask your question and then\u2026 wait. Just wait.<\/p>\n<p>Don\u2019t fill the silence with your own thoughts or insecurities.\nLet the question speak for itself.<\/p>\n<p>If you\u2019re truly interested in a deeper thought, you need to give people time to unpack it - for you and for themselves.<\/p>\n<p>If you\u2019re not willing to wait, you\u2019ll miss out on the best part of the conversation.<\/p>\n<p>We are trained to give quick answers.\nIf someone asks you \u201cHow\u2019s it going?\u201d, the expected answer is \u201cGood, you?\u201d.\nPeople are surprised when I take a moment to answer and give them a truly honest answer, which might be deeply personal.<\/p>\n<p>Similarly, let people give you their quick answer first. Then wait.\nOften, they will stop and follow up with a much more personal answer.<\/p>\n<p>Use pauses to your advantage.<\/p>\n<h2 id=\"8-obvious-questions-can-be-the-best-questions\"><a class=\"anchor\" href=\"#8-obvious-questions-can-be-the-best-questions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>8. Obvious Questions Can Be the Best Questions<\/h2>\n<p>If you look close enough, which question to ask becomes obvious.<\/p>\n<ul>\n<li>\u201cWhy are we still working on this?\u201d<\/li>\n<li>\u201cShould we split up?\u201d<\/li>\n<li>\u201cHow do you feel after the diagnosis?\u201d<\/li>\n<\/ul>\n<p>You\u2019re addressing the elephant in the room!<br \/>\nBut just because you have an obvious question, that doesn\u2019t make it easy to ask!<\/p>\n<p>You might know that the question could hurt.\nOr that the answer is uncomfortable to handle.\nAnd yet, it\u2019s still the right question to ask.<\/p>\n<p>What I noticed is that oftentimes multiple people have the same \u201cobvious\u201d question in mind.\nThey are just too afraid to ask.<\/p>\n<p>Most people dance around the topic because they want to be polite.\nThey don\u2019t address problems head-on because it\u2019s easier!\nThe result is small talk.<\/p>\n<p>Especially if you get paid to ask questions, your job is to ask questions that no one else wants to ask.\nOften, politics, infighting, and hidden agendas make it very hard for people to break out of their role and ask the obvious question.<\/p>\n<p>If you\u2019re not afraid to ask the obvious question, you will look like Houdini.<\/p>\n<p>Suddenly, an avalanche of follow-up questions gets unleashed.\nAn honest, constructive conversation emerges.<\/p>\n<p>The thing is, just because you don\u2019t ask the uncomfortable question, it doesn\u2019t make the problem go away.\nIn fact, you might make it worse in the long run.\nIt\u2019s easier to get it out of the way and move on!<\/p>\n<p>Q: Why are we still working on this?<br \/>\nA: Actually, I have no idea. Let\u2019s find something else.<\/p>\n<p>Q: Should we split up?<br \/>\nA: Yes, I think so. Let\u2019s talk about it.<\/p>\n<p>Q: How do you feel after the diagnosis?<br \/>\nA: I\u2019m scared. I don\u2019t know what to do. But I\u2019m glad you asked.<\/p>\n<p>The truth is hidden in plain sight.\nIf no one dares to ask, these questions stay unanswered.\nThe trick is to accept the answer for what it is.\nDon\u2019t be mad or angry at people who honestly answer your question.\nBe mad or angry for not asking sooner.<\/p>\n<h2 id=\"if-you-don-t-understand-the-answer-ask-again\"><a class=\"anchor\" href=\"#if-you-don-t-understand-the-answer-ask-again\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>If You Don\u2019t Understand the Answer, Ask Again<\/h2>\n<p>In the past, I would often gloss over an answer and pretend I understood it.\nTurns out that it was a bad strategy:\nIn the best case, I would have missed out on a great opportunity to learn something new.\nIn the worst case, I wouldn\u2019t have a good question to follow up with.<\/p>\n<p>Funnily, I\u2019m rarely alone with this problem.\nThere\u2019s usually more than one confused person in the room.\nSo don\u2019t be afraid to refine your question to clarify any misunderstandings.<\/p>\n<p>Q: \u201cCan you explain that differently?\u201d<br \/>\nA: \u2026<\/p>\n<p>Q: \u201cAm I correct in understanding that you mean\u2026?\u201d<br \/>\nA: \u2026<\/p>\n<p>Q: \u201cCan you give me an example?\u201d<br \/>\nA: \u2026<\/p>\n<p>There\u2019s an old Chinese proverb that goes like this:<\/p>\n<blockquote>\n<p>He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever.<\/p>\n<\/blockquote>\n<h2 id=\"good-observations-yield-good-questions\"><a class=\"anchor\" href=\"#good-observations-yield-good-questions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Good Observations Yield Good Questions<\/h2>\n<p>I noticed that many people who ask great questions have exceptional observation skills.\nThey notice things that others don\u2019t.<\/p>\n<p>Q: \u201cWhy are you still working here?\u201d<br \/>\nA: \u201cI need the money.\u201d<\/p>\n<p>Q: \u201cTough luck. What\u2019s for lunch?\u201d<br \/>\nA: \u2026<\/p>\n<p>vs.<\/p>\n<p>Q: \u201cWhy are you still working here?\u201d<br \/>\nA: \u201cI need the money.\u201d<\/p>\n<p>Q: \u201cI noticed that you have this book on your desk. What\u2019s that about?\u201d<br \/>\nA: \u201cOh, that\u2019s my passion! I\u2019m reading up on sales because I want to start my own business.\u201d<\/p>\n<p>Q: \u201cNice! What is it about sales that you find so interesting?\u201d<br \/>\nA: \u2026<\/p>\n<p>See how this tiny observation about a book on the desk led to a much deeper conversation?\nSuddenly, you\u2019re talking about someone\u2019s passion and dreams.\nYou might inspire them to have more conversations with customers during work time to get some practice.<\/p>\n<p>If you want to improve your observation skills, come prepared.\nLearn more about the person you\u2019re talking to.<\/p>\n<ul>\n<li>What are they passionate about?<\/li>\n<li>Who\u2019s their role model?<\/li>\n<li>What are they doing in their free time?<\/li>\n<li>What are they reading?<\/li>\n<li>Which projects are they working on?<\/li>\n<\/ul>\n<p>If you come prepared, you\u2019ll have an easier time asking good questions.\nContext makes good questions obvious.<\/p>\n<h2 id=\"the-best-follow-up-to-an-answer-is-a-question\"><a class=\"anchor\" href=\"#the-best-follow-up-to-an-answer-is-a-question\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Best Follow-Up to an Answer Is a Question<\/h2>\n<p>Okay, you got an answer.\nNow what?<\/p>\n<p>Many people follow up with a statement about themselves.<\/p>\n<p>\u201cOh, I also like that!\u201d<br \/>\n\u201cYes, I also did that!\u201d<br \/>\n\u201cLet me tell you about my experience!\u201d<br \/>\n\u201cYou should do this!\u201d<\/p>\n<p>This shows that you\u2019re not interested in the other person, only in yourself.<\/p>\n<p>Instead, what if you could only follow up with a question?<\/p>\n<p>Q: \u201cWhat\u2019s your favorite sport?\u201d<br \/>\nA: \u201cTable tennis.\u201d<\/p>\n<p>Q: \u201cHow did you get into that?\u201d<br \/>\nA: \u201cMy dad played it when I was young.\u201d<\/p>\n<p>Q: \u201cWhat\u2019s your favorite memory of playing table tennis with your dad?\u201d<br \/>\nA: \u201cWe used to play in the basement. It was so much fun!\u201d<\/p>\n<p>Q: \u201cWhat made it so much fun?\u201d<br \/>\nA: \u201cI don\u2019t know. It was just the two of us. It was our thing.\u201d<\/p>\n<p>Q: \u201cWhat did you learn from your dad about table tennis?\u201d<br \/>\nA: \u201cHe taught me how to serve. He was really good at it.\u201d<\/p>\n<p>Q: \u201cWhat\u2019s the most important thing about serving in table tennis?\u201d<br \/>\nA: \u201cYou have to hit the ball at the right angle. Otherwise, it\u2019s easy to return.\u201d<\/p>\n<p>Q: \u201cWhat\u2019s the most difficult angle to return?\u201d<br \/>\nA: \u201cThe one that goes straight to the corner. It\u2019s hard to reach.\u201d<\/p>\n<p>See how this conversation unfolded?\nIt\u2019s like peeling an onion.\nYou get deeper and deeper into the topic.\nYou learn more about the person.\nYou learn more about the topic.\nStep by step, you tap into someone else\u2019s hard-earned wisdom.\nLook at all the things you learned in such a short time!\nTheir favorite sport, their childhood memories, their relationship with their dad, how to serve in table tennis, the most difficult angle to return a serve.\nIf you had followed up with \u201cI like that too,\u201d you would have missed out on all of this and probably never learned about it.<\/p>\n<p>All just because we kept asking questions instead of making statements.<\/p>\n<p>Think about all the people you know. Who do you like to talk to?\nI bet it\u2019s the people who ask you questions and listen to your answers instead of talking about themselves all the time.<\/p>\n<p>Interestingly, it\u2019s entirely selfish to ask questions.\nYou learn more about the other person than they learn about you.\nYou\u2019re in control of the conversation.<\/p>\n<h2 id=\"summary\"><a class=\"anchor\" href=\"#summary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Summary<\/h2>\n<p>I\u2019m still not good at asking questions.\nI wrote this mostly as practice for myself.\nMaybe it helps someone else too.<\/p>\n<p>Here\u2019s a summary of what I wrote:<\/p>\n<ol>\n<li>Good Questions Are Open-ended<\/li>\n<li>Never Ask A Question If You Don\u2019t Care About The Answer<\/li>\n<li>Good Questions Reveal Something About The Person Who Answers; Bad Questions About The Person Who Asks<\/li>\n<li>Good Questions Are Stacked On Top Of Each Other<\/li>\n<li>Good Questions Run Deep<\/li>\n<li>Let The Winners Run And Cut Your Losses Short<\/li>\n<li>Give People Space To Think<\/li>\n<li>Obvious Questions Can Be The Best Questions<\/li>\n<li>If You Don\u2019t Understand The Answer, Ask Again<\/li>\n<li>Good Observations Yield Good Questions<\/li>\n<li>The Best Follow-up To An Answer Is A Question<\/li>\n<\/ol>\n<p>Don\u2019t be mistaken! Asking good questions is hard work!\nYou have to be present, you have to listen, you have to reflect.\nIt helps to take mental notes while you\u2019re talking to someone.\nAfter a while, you will get better at spotting the patterns.<\/p>\n<p>Asking <strong>good<\/strong> questions is a skill that can be learned and improved upon.\nAsking <strong>more<\/strong> questions can\u2019t hurt along the way.<\/p>\n<p>So, how do <em>you<\/em> ask better questions?<\/p>\n"},{"title":"The Dying Web","pubDate":"Thu, 08 Aug 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/the-dying-web\/","guid":"https:\/\/endler.dev\/2024\/the-dying-web\/","description":"<p>I look left and right, and I\u2019m the only one who still uses Firefox.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/the-dying-web\/travolta.gif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/the-dying-web\/travolta.gif\" width=\"426\" height=\"213\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>At conferences and in coworking spaces, it\u2019s always the same scene: people using some flavor of Chrome.\nSometimes it\u2019s Brave, sometimes Chromium, most of the time it\u2019s just Google Chrome.<\/p>\n<p>I find that hilariously appalling.<\/p>\n<p>An entire generation grew up with access to great free tools and open standards, which helped them jumpstart their careers and\ngave them access to excellent technology for free.<\/p>\n<p>Now, the world\u2019s largest websites are owned by the same company, which also owns the world\u2019s most popular browser and\nsearch engine. Coincidentally, they are also the world\u2019s largest advertising company.\nAnd people are wondering why they can\u2019t block ads on YouTube anymore.<\/p>\n<p>We gave it all away for nothing.<\/p>\n<p>Let me be the first to admit that I too am not without sin.\nThere was a weak moment about 15 years ago when browser performance became so unbearable on anything other than Chrome\nthat it forced my hand to make the switch.\nAnd yes, for a while, life was good and websites loaded quickly.<\/p>\n<p>Reluctantly, I made the switch back to Firefox after a while, because open standards and privacy were\nmore important than a few milliseconds of loading time.\nI could still understand why people would use Chrome, but I was happy with my choice.<\/p>\n<p>Then <a rel=\"external\" href=\"https:\/\/blog.mozilla.org\/en\/mozilla\/introducing-firefox-quantum\/\">Firefox Quantum<\/a> came around, and I\ntold all my fellow developer friends about it.\nTo me, it was the best browser on the market, and I was proud to be a Firefox user again.\nIt was fast, snappy, and had a great add-on ecosystem.<\/p>\n<p>To my surprise, nobody cared.<\/p>\n<h2 id=\"bad-habits-die-hard\"><a class=\"anchor\" href=\"#bad-habits-die-hard\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bad Habits Die Hard<\/h2>\n<p>Maybe people stayed with Chrome out of habit.<\/p>\n<p>Performance and privacy aside, I just don\u2019t know how people can cope with Chrome\u2019s limited customizability.\nIt\u2019s hilarious to watch people with 200 tabs named \u201cG\u201d, \u201cY\u201d, or \u201cX\u201d struggle to find that one document they opened a week ago.<\/p>\n<p>In comparison, vertical tabs on Firefox with add-ons like <a rel=\"external\" href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/sidebery\/\">Sidebery<\/a>\nmake Chrome look like a toy.<\/p>\n<p>Anyhow, Chrome.<\/p>\n<p>There was a time when I tried to educate people on the negative effects of browser monoculture.\nOkay, my mum didn\u2019t get it, but I was more disappointed by my fellow devs.\nEveryone took the easy route and happily stayed on Uncle Google\u2019s lap.<\/p>\n<p>At this point, I neither have the willpower nor the energy to fight back;\nit\u2019s hopeless. It\u2019s probably easier to get blood from a stone\nthan to convince someone to switch back to Firefox.\nIt\u2019s so easy to switch, <a rel=\"external\" href=\"https:\/\/support.mozilla.org\/en-US\/kb\/switching-chrome-firefox\">you won\u2019t even lose any open tabs<\/a>!<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/the-dying-web\/marketshare.png\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/the-dying-web\/marketshare.png\" width=\"650\" height=\"599\"\n    \/>\n    <\/picture>\n<\/figure>\n<h2 id=\"nobody-forces-you-to-use-chrome\"><a class=\"anchor\" href=\"#nobody-forces-you-to-use-chrome\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Nobody Forces You to Use Chrome<\/h2>\n<p>True, but the issues don\u2019t stop at my front door.\nAs an outsider, I need to live with the consequences of browser monoculture every day.<\/p>\n<p>Quite a few websites are unusable by now because they got \u201coptimized for Chrome.\u201d\n<a rel=\"external\" href=\"https:\/\/github.com\/webcompat\/web-bugs\/issues\/25070#issuecomment-460721700\">Microsoft Teams<\/a>, for example,\nand <a rel=\"external\" href=\"https:\/\/github.com\/webcompat\/web-bugs\/issues?q=is%3Aopen+is%3Aissue+label%3Abrowser-firefox\">the list is long<\/a>.\nThese websites fail for no good reason.<\/p>\n<p><del>There are positive examples, too.\n<a rel=\"external\" href=\"https:\/\/zencastr.com\/\">Zencastr<\/a>, for example, used to be broken on Firefox, but they fixed it.<\/del><\/p>\n<p><strong>Update: Zencastr is still broken on Firefox.<\/strong>\nThanks to Randell from Mozilla for pointing that out. Their <a rel=\"external\" href=\"https:\/\/support.zencastr.com\/en\/articles\/5018334-system-requirements\">support page states that Chrome, Edge, or Brave are required<\/a>. They stopped supporting Firefox in February 2021 as per <a rel=\"external\" href=\"https:\/\/blog.zencastr.com\/blog\/2021\/2\/16\/zencastr-is-launching-video-recording-into-open-beta\">this blog post<\/a>. There\u2019s an <a rel=\"external\" href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1899831\">open ticket in the Mozilla Bugzilla<\/a> tracking this issue. It\u2019s currently blocked on some other issues, but there\u2019s progress being made. The <a rel=\"external\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WebCodecs_API\">WebCodecs API<\/a>, which might be related to this problem, is currently in beta and progressing through Mozilla\u2019s release process. While it\u2019s disappointing that Zencastr doesn\u2019t work on Firefox yet, it\u2019s encouraging to see that Mozilla is actively working on resolving the underlying issues.<\/p>\n<p>I also use Chrome for online calls, because tools like <a rel=\"external\" href=\"https:\/\/meet.jit.si\/\">Jitsi<\/a> don\u2019t work well on Firefox.\nMaybe it\u2019s because of Firefox\u2019s WebRTC support? Or, <a rel=\"external\" href=\"https:\/\/blog.mozilla.org\/webrtc\/\">maybe it\u2019s because of Chrome<\/a>:<\/p>\n<blockquote>\n<p><strong>Pop Quiz<\/strong>: If a website wants to play out of different speakers on your system, what permission must it have?<\/p>\n<ol>\n<li>Speaker-selection permission<\/li>\n<li>Microphone permission<\/li>\n<\/ol>\n<p>If you answered 2, then chances are you know your WebRTC stuff well, but you\u2019re probably on a Chromium browser.<\/p>\n<\/blockquote>\n<h2 id=\"how-could-google-get-free-rein\"><a class=\"anchor\" href=\"#how-could-google-get-free-rein\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How Could Google Get Free Rein?<\/h2>\n<p>Because everyone and their car stopped testing their stuff anywhere else.\nIf everyone tweaks their site for Chrome, well, of course the site will work just fine on Chrome!\nWe find ways around Chrome\u2019s weird quirks.\nMore users join the bandwagon because stuff \u201cjust works\u201d and the vicious cycle continues.\nI can\u2019t blame them.\nIt\u2019s easier to ride a horse in the direction it is going.<\/p>\n<h2 id=\"but-at-what-cost\"><a class=\"anchor\" href=\"#but-at-what-cost\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>But at What Cost?<\/h2>\n<p>*Elrond voice*: We\u2019ve been down this road before. (Okay, I was there.)\nWe called it the <em>Browser Wars<\/em>: Netscape vs Internet Explorer. Netscape lost and Microsoft ruled over the web with an iron fist. It wasn\u2019t fun.\nWe had more hacks around browser limitations than actual website functionality. Parents put their kids through college by working around browser bugs for money.<\/p>\n<p>Microsoft tried <em>really<\/em> hard to make life as miserable as possible for everybody:<\/p>\n<blockquote>\n<p>Internet Explorer has introduced an array of proprietary extensions to many of the standards, including HTML, CSS, and the DOM. This has resulted in several web pages that appear broken in standards-compliant web browsers and has introduced the need for a \u201cquirks mode\u201d to allow for rendering improper elements meant for Internet Explorer in these other browsers. \u2014 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Internet_Explorer\">Wikipedia<\/a><\/p>\n<\/blockquote>\n<p>Essentially, they broke the web and we all warmed our hands on the dumpster fire.\nAll we got in return was quirks mode.<\/p>\n<p>Google is smarter! They break the web, too, but they make you stand inside the fire.<\/p>\n<h2 id=\"why-should-i-care-about-a-browser-they-are-all-the-same-anyways\"><a class=\"anchor\" href=\"#why-should-i-care-about-a-browser-they-are-all-the-same-anyways\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Should I Care about a Browser? They Are All the Same Anyways.<\/h2>\n<p>\u2026says the developer who gets <a rel=\"external\" href=\"https:\/\/www.forbes.com\/sites\/zakdoffman\/2024\/06\/16\/google-chrome-tracking-on-windows-android-iphone-for-200-more-days\/\">tracked by Google<\/a>\nevery waking moment.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/the-dying-web\/incognito.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/the-dying-web\/incognito.jpg\" alt=\"https:\/\/www.skeletonclaw.com\/image\/710734055173472257\" width=\"650\" height=\"397\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: https:\/\/www.skeletonclaw.com\/image\/710734055173472257\n    <\/figcaption>\n<\/figure>\n<p>You see, Chrome is reeeeally good at marketing.\nThey say all the right things: We\u2019re fast! We\u2019re open source! We have the latest features!\nWhat they don\u2019t tell you is that they control the narrative of the World Wide Web.\nThey make you feel <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/browsers\/comments\/1810egw\/google_chrome_will_limit_ad_blockers_starting\/\">guilty for using adblockers<\/a> and add weird\n<a rel=\"external\" href=\"https:\/\/v4.chriskrycho.com\/2017\/chrome-is-not-the-standard.html\">nonstandard browser features<\/a> because they can.\nLately, the uBlock Origin team just threw in the towel and <a rel=\"external\" href=\"https:\/\/www.theregister.com\/2024\/08\/06\/chrome_web_store_warns_end\/\">stopped supporting Chrome<\/a>.<\/p>\n<p>But did anyone decide to jump ship?\nI get the feeling that by now people turn a blind eye to Google\u2019s evil practices.<\/p>\n<h2 id=\"but-shouldn-t-brave-edge-opera-or-vivaldi-be-sufficient\"><a class=\"anchor\" href=\"#but-shouldn-t-brave-edge-opera-or-vivaldi-be-sufficient\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>But Shouldn\u2019t Brave, Edge, Opera, or Vivaldi Be Sufficient?<\/h2>\n<p>Unfortunately not. They all use the <a rel=\"external\" href=\"https:\/\/www.chromium.org\/blink\/\">same browser engine<\/a> under the hood.\nBrowser makers make mistakes, so this engine is not perfect.\nIf it contains a bug and there\u2019s no competition, that bug becomes the standard.\nAlternative browser engines need to implement the bug as well to support websites which depend on it.<\/p>\n<h2 id=\"i-use-safari\"><a class=\"anchor\" href=\"#i-use-safari\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>I Use Safari<\/h2>\n<p>Congratulations, you switched from a browser controlled by a 2 trillion dollar company to a browser controlled by a 3 trillion dollar company. Oh, and it doesn\u2019t run on Windows or Linux.\nBoth Apple and Google would throw you under the bus if it made them more profit.\nOh, and did you know that Google paid Apple <a rel=\"external\" href=\"https:\/\/www.pymnts.com\/antitrust\/2024\/google-ruling-may-blunt-apple-services-revenue-ecosystem-growth\/\">20 billion dollars in 2022<\/a> to be the default search engine on Safari?<\/p>\n<h2 id=\"what-can-i-do\"><a class=\"anchor\" href=\"#what-can-i-do\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What Can I Do?<\/h2>\n<p>If you\u2019ve made it this far, do yourself a favor and spend a few minutes trying Firefox.\nWho knows? You might just like it.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/www.mozilla.org\/firefox\">Try Firefox today,<\/a> please?<\/p>\n"},{"title":"How to Sell to Developers","pubDate":"Mon, 27 May 2024 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2024\/selling-to-developers\/","guid":"https:\/\/endler.dev\/2024\/selling-to-developers\/","description":"<p>One of the hardest challenges I know is how to sell to developers.<\/p>\n<p>This is NOT an article for developers. Today, I want to write for non-developers whose job it is to sell to developers. My goal is to help you understand how they think.<\/p>\n<h2 id=\"developers-hate-being-sold-to\"><a class=\"anchor\" href=\"#developers-hate-being-sold-to\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Developers Hate Being Sold To<\/h2>\n<p>We tend to be a skeptical bunch! We\u2019re not reachable through Google ads because we use ad blockers. We expect software to be free and open source, so we don\u2019t usually pay for it. We subscribe to a handful of services that provide a lot of value for very little cost. Everything else we build ourselves. See the problem?<\/p>\n<p>How do you <em>sell<\/em> to these people?<\/p>\n<h2 id=\"the-developer-s-dilemma\"><a class=\"anchor\" href=\"#the-developer-s-dilemma\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Developer\u2019s Dilemma<\/h2>\n<p>Strangely enough, when developers think about starting a business, the first products they consider are often those aimed at other developers, despite there being many easier markets to sell to! We love building things so much that we try to sell the things we build to people just like us.<\/p>\n<p>Here\u2019s my advice:<\/p>\n<ol>\n<li>Don\u2019t build a product for developers.<\/li>\n<li>Seriously, don\u2019t build a product for developers.<\/li>\n<li>Since you\u2019ll likely ignore the first two pieces of advice, at least learn how to market to developers effectively.<\/li>\n<\/ol>\n<h2 id=\"what-you-need-to-know-about-marketing-to-developers\"><a class=\"anchor\" href=\"#what-you-need-to-know-about-marketing-to-developers\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What You Need to Know about Marketing to Developers<\/h2>\n<p>Here\u2019s the bitter truth. To sell to developers\u2026<\/p>\n<ul>\n<li>You will have to be present in the places where they hang out.<\/li>\n<li>You will have to invest a lot of time in community building.<\/li>\n<li>You will have to be extremely patient.<\/li>\n<li>There is no shortcut.<\/li>\n<\/ul>\n<p>What if you don\u2019t have the time or the patience? See rule 1 above.<\/p>\n<h2 id=\"my-developer-product-journey-so-far\"><a class=\"anchor\" href=\"#my-developer-product-journey-so-far\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>My Developer Product Journey So Far<\/h2>\n<p>You might ask, \u201cWhy should I listen to you? Have you ever sold a product to developers?\u201d<\/p>\n<p>I\u2019ll let you be the judge of that. Here are a few products that I have built and sold to developers:<\/p>\n<h3 id=\"codeprints\"><a class=\"anchor\" href=\"#codeprints\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a><a rel=\"external\" href=\"https:\/\/codeprints.dev\/\">codeprints<\/a><\/h3>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/selling-to-developers\/codeprints.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/selling-to-developers\/codeprints.jpg\" alt=\"Homepage of CodePrints with my GitHub profile as a print\" width=\"650\" height=\"411\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Homepage of CodePrints with my GitHub profile as a print\n    <\/figcaption>\n<\/figure>\n<p>This was a fun experiment during the pandemic. We sold posters of GitHub timelines. Our marketing strategy included posts on Reddit and Hacker News, and we sent free prints to a few \u201cdevfluencers.\u201d The novelty effect and viral marketing worked well. Eventually, we sold the company to a developer agency because we didn\u2019t want to deal with the logistics.<\/p>\n<p>Read more about CodePrints in <a href=\"\/2021\/codeprints\/\">this blog post<\/a>.<\/p>\n<h3 id=\"lychee\"><a class=\"anchor\" href=\"#lychee\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a><a rel=\"external\" href=\"https:\/\/lychee.cli.rs\/\">Lychee<\/a><\/h3>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/selling-to-developers\/lychee.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/selling-to-developers\/lychee.jpg\" alt=\"Homepage of Lychee's documentation page\" width=\"650\" height=\"435\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Homepage of Lychee\u2019s documentation page\n    <\/figcaption>\n<\/figure>\n<p>I built this tool for myself because I needed it. Lychee is a command-line tool that checks for broken links in markdown and HTML files. It has become quite popular on GitHub, with companies like Google and Amazon using it. However, I\u2019ve never made any money from it. I reached out to some companies to sponsor the project, but it was very hard to get a response or explain why they should sponsor a free tool.<\/p>\n<p>I wrote about <a href=\"\/2021\/oss-money\/\">making money with Open Source here<\/a>.<\/p>\n<h3 id=\"analysis-tools\"><a class=\"anchor\" href=\"#analysis-tools\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a><a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/\">Analysis Tools<\/a><\/h3>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/selling-to-developers\/analysis-tools-homepage.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/selling-to-developers\/analysis-tools-homepage.jpg\" alt=\"Homepage of analysis-tools.dev\" width=\"650\" height=\"436\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Homepage of analysis-tools.dev\n    <\/figcaption>\n<\/figure>\n<p>This is a directory of tools for developers. It\u2019s a side project that I started in 2015 (did I mention you need to be patient?), and it has grown to be a popular resource. Together with two friends, we sell sponsorships and ads on the site, which provides a nice side income.<\/p>\n<p>I think this project works because it\u2019s not a product for developers but <strong>a product for people who build products for developers<\/strong>.<\/p>\n<p>Our customers are mostly developer advocates, developer relations folks, and marketing people who want to reach developers.<\/p>\n<p>Sponsoring on Analysis Tools is <strong>extremely cheap<\/strong> compared to other marketing channels like Google ads. On Google, you can easily spend thousands of dollars per month trying to reach developers.<\/p>\n<p>On Analysis Tools, you can reach them for a fraction of that cost. The basic tier is $100 per month, and for that, you get your logo on the site and in every repo. Thousands of developers visit the site every month. It\u2019s basically a no-brainer to sponsor the site if you build a linter, a static code analyzer, or any other tool that developers use.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2024\/selling-to-developers\/analysis-tools-list.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2024\/selling-to-developers\/analysis-tools-list.jpg\" alt=\"Tools page of analysis-tools.dev\" width=\"650\" height=\"436\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Tools page of analysis-tools.dev\n    <\/figcaption>\n<\/figure>\n<p>Think of it this way: when was the last time these companies had the chance to reach thousands of developers for $100? What is the total cost of acquisition for a developer? How much would you pay for a developer to try out your tool?<\/p>\n<p>And still\u2026<\/p>\n<h3 id=\"only-20-of-companies-immediately-get-it\"><a class=\"anchor\" href=\"#only-20-of-companies-immediately-get-it\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Only 20% of Companies Immediately Get It<\/h3>\n<p>From the companies I\u2019ve talked to, only around 20% get it immediately. There are perhaps 30% that need a little handholding. The other 50% see it as an ad placement and want to know the click-through rate.<\/p>\n<p>Let me repeat: It\u2019s not about the click-through rate. It\u2019s about the branding and the reach.<\/p>\n<p>You will never reach a critical audience if you don\u2019t start investing in the developer community. This is not a one-time thing. You need a lot of exposure until you get noticed and developers start talking about your product. <strong>If you try to fake it, you won\u2019t get far. Devs will avoid your product like the plague and tell their friends to do the same.<\/strong><\/p>\n<p>Your main constraint is the attention of developers!<\/p>\n<p>These folks constantly get bombarded with millions of products and don\u2019t have time to evaluate them all. They stopped actively looking for new tools a long time ago. They rely on a handful of trusted sources they follow.<\/p>\n<h2 id=\"building-trust-is-the-only-way\"><a class=\"anchor\" href=\"#building-trust-is-the-only-way\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Building Trust Is the Only Way<\/h2>\n<p>Getting into their circle of trust is hard, and for that reason, you need to be patient and invest a lot of time into relationship building. If you can afford it, hire a developer advocate. A good one is heavily invested in open source and knows how to write for developers.\nAt the very least, you need to be present in the places where developers hang out. So reach out to open source maintainers in your niche and see if you can collaborate or sponsor their projects. Don\u2019t waste cash on Google ads or other traditional marketing channels. Go where the developers are.<\/p>\n<p>I hope this article helped someone who is struggling to sell to developers. Perhaps one of you will reach out to some open source maintainers in their niche and sponsor their projects. That would be a great outcome!<\/p>\n<p>There\u2019s a plus side to all of this: once you understand that you need to invest in the developer community, you will have a competitive advantage because most other companies don\u2019t get it.<\/p>\n"},{"title":"Cursed Rust: Printing Things the Wrong Way","pubDate":"Wed, 01 Nov 2023 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2023\/cursed-rust\/","guid":"https:\/\/endler.dev\/2023\/cursed-rust\/","description":"<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/qwOlWfYlq0A\"\n>\n  <picture>\n    <source srcset=\"maxresdefault.avif\" type=\"image\/avif\" \/>\n    <img src=\"maxresdefault.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p>There is a famous story about a physicist during an exam at the University of\nCopenhagen. The candidate was asked to describe how to determine a skyscraper\u2019s\nheight using a barometer. The student suggested dangling the barometer from the\nbuilding\u2019s roof using a string and then measuring the length of the string plus\nthe barometer\u2019s height. Although technically correct, the examiners were not\namused.<\/p>\n<p>After a complaint and a reevaluation, the student offered various physics-based\nsolutions, ranging from dropping the barometer and calculating the building\u2019s\nheight using the time of fall, to using the proportion between the lengths of\nthe building\u2019s shadow and that of the barometer to calculate the building\u2019s\nheight from the height of the barometer.\nHe even humorously suggested simply asking the caretaker in exchange for the\nbarometer.<\/p>\n<p>The physicist, as the legend goes, was <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Niels_Bohr\">Niels Bohr<\/a>, who\nwent on to receive a Nobel Prize in 1922. This story is also known as the\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Barometer_question\">barometer question<\/a>.<\/p>\n<h2 id=\"why-is-this-story-interesting\"><a class=\"anchor\" href=\"#why-is-this-story-interesting\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Is This Story Interesting?<\/h2>\n<p>The question and its possible answers have an important didactic side effect:\nthey convey to the learner that one can also get to the solution with unconventional\nmethods \u2014 and that these methods are often more interesting than the\ncanonical solution <em>because they reveal something about the problem itself<\/em>.<\/p>\n<p>There is virtue in learning from unconventional answers to conventional questions.\nTo some extent, this fosters new ways of thinking and problem-solving, which is\nan essential part of innovation.<\/p>\n<h2 id=\"applying-the-same-principle-to-learning-rust\"><a class=\"anchor\" href=\"#applying-the-same-principle-to-learning-rust\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Applying the Same Principle to Learning Rust<\/h2>\n<p>One of the first examples in any book on learning Rust is the \u201cHello, world!\u201d\nprogram.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>It\u2019s an easy way to test that your Rust installation is working correctly.<\/p>\n<p>However, we can also have some fun and turn the task on its head:\nlet\u2019s find ways to print \u201cHello, world!\u201d without using <code>println!<\/code>.<\/p>\n<p>Let\u2019s try to come up with as many unconventional solutions as possible.\nThe weirder, the better! As you go through each of the solutions\nbelow, try to understand <em>why<\/em> they work and what you can learn from them.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/rustjerk\/comments\/16xty71\/s_str_print_shello\/\">This started as a meme<\/a>,\nbut I decided to turn it into a full article after the post got a lot of\nattention.<\/p>\n<p>It goes without saying that you should never use any of these solutions in\nproduction code. Check out this <a rel=\"external\" href=\"https:\/\/github.com\/mTvare6\/hello-world.rs\">enterprise-ready version of\nhello world<\/a> instead.<\/p>\n<h2 id=\"solution-1-desugaring-println\"><a class=\"anchor\" href=\"#solution-1-desugaring-println\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 1: Desugaring <code>println!<\/code><\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Write<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">write!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">stdout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lock<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>This solution is interesting, because it shows that <code>println!<\/code> is just a macro that\nexpands to a call to <code>write!<\/code> with a newline character appended to the string.<\/p>\n<p>The real code is <a rel=\"external\" href=\"https:\/\/github.com\/rust-lang\/rust\/blob\/f3457dbf84cd86d284454d12705861398ece76c3\/library\/std\/src\/io\/stdio.rs#L1097\">much weirder<\/a>. Search for <code>print<\/code> in this file if you want to be amazed.\n<code>write!<\/code> itself <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/fmt\/trait.Write.html#method.write_fmt\">desugars to a call to <code>write_fmt<\/code><\/a>, which is a method of the <code>Write<\/code> trait.<\/p>\n<p>There is a real-world use case for this: if you want to print things really fast, you can\nlock <code>stdout<\/code> once and then use <code>write!<\/code>. This avoids the overhead\nof locking <code>stdout<\/code> for each call to <code>println!<\/code>. See <a href=\"\/2017\/yes\/\">this article on how to write a very\nfast version of <code>yes<\/code><\/a> with this trick.<\/p>\n<h2 id=\"solution-2-iterating-over-characters\"><a class=\"anchor\" href=\"#solution-2-iterating-over-characters\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 2: Iterating over Characters<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">chars<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">for_each<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>c<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> c<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>This shows that you can implement <code>println!<\/code> using Rust\u2019s powerful iterators.\nHere we iterate over the characters of the string and print each one of them.<\/p>\n<p><code>chars()<\/code> returns an iterator over <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/primitive.char.html\">Unicode scalar values<\/a>.<\/p>\n<p>Learn more about iterators <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html\">here<\/a>.<\/p>\n<h2 id=\"solution-3-impl-display\"><a class=\"anchor\" href=\"#solution-3-impl-display\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 3: Impl <code>Display<\/code><\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HelloWorld<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fmt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Display<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HelloWorld<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> fmt<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> f<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fmt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Formatter<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fmt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Result<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        write!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>f<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">HelloWorld<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>This teaches us a little bit about how traits work in Rust: We define a struct\nthat implements the <code>Display<\/code> trait, which allows us to print it using <code>print!<\/code>.\nIn general, <code>Display<\/code> is intended to make more complex types printable, but it\nis also possible to implement it for a hardcoded string!<\/p>\n<h2 id=\"solution-4-who-needs-display\"><a class=\"anchor\" href=\"#solution-4-who-needs-display\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 4: Who Needs <code>Display<\/code>?<\/h2>\n<p>How about we create our own trait instead of using <code>Display<\/code>?<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">trait<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Println<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Println<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>We can exploit the fact that we can name our trait methods however we want. In\nthis example, we choose <code>println<\/code>, making it look like it is part of the\nstandard library.<\/p>\n<p>This completely turns the <code>println!<\/code> macro on its head. Instead of\npassing a string as an argument, we call a method on the string itself!<\/p>\n<h2 id=\"solution-5-who-needs-println-when-you-got-panic\"><a class=\"anchor\" href=\"#solution-5-who-needs-println-when-you-got-panic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 5: Who Needs <code>println!<\/code> When You Got <code>panic!<\/code>?<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">panic!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>There are other ways to print things in Rust than using <code>println!<\/code>. In this\ncase, we use <code>panic!<\/code>, which prints the string (as a side-effect) and\nimmediately terminates the program. It works as long as we only want to print\na single string\u2026<\/p>\n<h2 id=\"solution-6-i-hearts-closures\"><a class=\"anchor\" href=\"#solution-6-i-hearts-closures\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 6: I \u2665\ufe0e\ufe0f Closures<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>s<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> s<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">hello<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Rust allows you to call a closure directly after its\ndefinition. The closure is defined as an anonymous function that takes a\nstring slice as an argument and prints it. The string slice is passed as an\nargument to the closure.<\/p>\n<p>In practice, this can be useful for defining a closure that is only used once\nand for which you don\u2019t want to come up with a name.<\/p>\n<h2 id=\"solution-7-c-style\"><a class=\"anchor\" href=\"#solution-7-c-style\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 7: C Style<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> libc<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> libc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span>c_char<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> c_int<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> core<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ffi<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">CStr<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">C<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> printf<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">fmt<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-14 z-d-10\"> c_char<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> ...<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-14 z-d-10\"> c_int<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    const<\/span><span class=\"z-l-16 z-d-16\"> HI<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">CStr<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> match<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> CStr<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_bytes_until_nul<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">b<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">hello<\/span><span class=\"z-l-15 z-d-13\">\\<\/span><span class=\"z-l-15 z-d-13\">n<\/span><span class=\"z-l-15 z-d-13\">\\<\/span><span class=\"z-l-15 z-d-13\">0<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">        Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>x<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span> x<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">        Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>_<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> panic!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    unsafe<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        printf<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">HI<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_ptr<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>You don\u2019t even need to use Rust\u2019s standard library to print things! This\nexample shows how to call the C standard library\u2019s <code>printf<\/code> function from Rust.\nIt\u2019s unsafe because we are using a raw pointer to pass the string to the\nfunction. This teaches us a little bit about how FFI works in Rust.<\/p>\n<p>Credit goes to <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/rustjerk\/comments\/16xty71\/s_str_print_shello\/k36n6be\/\">\/u\/pinespear on Reddit<\/a> and <a rel=\"external\" href=\"https:\/\/infosec.exchange\/@brk\">@brk@infosec.exchange<\/a>.<\/p>\n<h2 id=\"solution-8-c-style\"><a class=\"anchor\" href=\"#solution-8-c-style\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 8: C++ Style<\/h2>\n<p>We\u2019re well into psychopath territory now\u2026 so let\u2019s not stop here.\nIf you try extremely hard, you can bend Rust to your will and make it look\nlike C++.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fmt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Display<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ops<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Shl<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">allow<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">non_camel_case_types<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span> cout<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">allow<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">non_camel_case_types<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span> endl<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Display<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Shl<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> cout<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    type<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Output<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> cout<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> shl<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> data<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> T<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-10 z-d-12\"> Self<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Output<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> data<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        cout<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Shl<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>endl<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> cout<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    type<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Output<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> shl<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> _<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-14 z-d-10\"> endl<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-10 z-d-12\"> Self<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Output<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>cout<\/span><span class=\"z-l-2 z-d-5\"> &lt;&lt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello World<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> &lt;&lt;<\/span><span> endl<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>The <code>Shl<\/code> trait is used to implement the <code>&lt;&lt;<\/code> operator. The <code>cout<\/code>\nstruct implements <code>Shl<\/code> for any type that implements <code>Display<\/code>, which allows\nus to print any printable type. The <code>endl<\/code> struct implements <code>Shl<\/code> for <code>cout<\/code>,\nwhich prints the newline character in the end.<\/p>\n<p>Credit goes to <a rel=\"external\" href=\"https:\/\/wisha.page\/posts\/fun-rust-operators\/\">Wisha Wanichwecharungruang<\/a> for this\nsolution.<\/p>\n<h2 id=\"solution-9-unadulterated-control-with-assembly\"><a class=\"anchor\" href=\"#solution-9-unadulterated-control-with-assembly\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 9: Unadulterated Control with Assembly<\/h2>\n<p>All of these high-level abstractions stand in the way of printing things\nefficiently. We have to take back control of your CPU. Assembly is the way. No more wasted cycles.\nNo hidden instructions. Pure, unadulterated performance.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">arch<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>asm<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> SYS_WRITE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> STDOUT<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    #<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">cfg<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">not<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">target_arch <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">x86_64<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    panic!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">This only works on x86_64 machines!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> bytes_written<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    unsafe<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        asm!<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">            &quot;<\/span><span class=\"z-l-5 z-d-7\">syscall<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            inout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">rax<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-16 z-d-16\"> SYS_WRITE<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span> bytes_written<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            inout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">rdi<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-16 z-d-16\"> STDOUT<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            in<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">rsi<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_ptr<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            in<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">rdx<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">            \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> syscall clobbers these<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            out<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">rcx<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            out<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">r11<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    assert_eq!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>bytes_written<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>(<a rel=\"external\" href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=release&amp;edition=2021&amp;gist=d11b1f6ef0711681e1f5a613e5cf412b\">Rust Playground<\/a>)<\/p>\n<p>If you\u2019re wondering why we use Rust in the first place if all\nwe do is call assembly code, you\u2019re missing the point!\nThis is about way more than just printing things.\nIt is about freedom! Don\u2019t tell me how I should use my CPU.<\/p>\n<p>Okaaay, it only works on x86_64 machines, but that\u2019s a small sacrifice to make\nfor freedom.<\/p>\n<p>Submitted by <a rel=\"external\" href=\"https:\/\/github.com\/isaacthefallenapple\">isaacthefallenapple<\/a>.<\/p>\n<h2 id=\"solution-10-blazing-fast\"><a class=\"anchor\" href=\"#solution-10-blazing-fast\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Solution 10: \u201cBlazing Fast\u201d<\/h2>\n<p>Why did we pay a premium for all those CPU cores if we aren\u2019t actually using\nthem? Wasn\u2019t fearless concurrency one of Rust\u2019s promises? Let\u2019s put those cores\nto good use!<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">sync<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Arc<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Mutex<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>thread<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">time<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Duration<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">hello world<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Arc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Mutex<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">chars<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>_<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> handles<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span> i<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lock<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Arc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>phrase<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> handle<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> thread<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">spawn<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">move<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">            thread<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">sleep<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_millis<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>i<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> as<\/span><span class=\"z-l-9 z-d-9\"> u64<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            print!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> phrase<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lock<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span>i<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        handles<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">push<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>handle<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span> handle<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> handles<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        handle<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">join<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Here, each character is printed in a separate thread. The threads are spawned\nin a loop, and each thread sleeps for a certain amount of milliseconds before\nprinting its character. This uses the full power of your CPU to print a string!\nIt might not always consistently print the characters in the right order (<a rel=\"external\" href=\"https:\/\/people.ece.ubc.ca\/sasha\/papers\/eurosys16-final29.pdf\">hey, scheduling\nis hard!<\/a>), but\nthat\u2019s a worthwhile trade-off for all the raw performance gains.<\/p>\n<h2 id=\"your-turn\"><a class=\"anchor\" href=\"#your-turn\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Your Turn!<\/h2>\n<p>If you\u2019ve got more solutions, please send me a message.<\/p>\n<p>Also, if you liked this article, you might also enjoy the yearly obfuscated C\ncode contest. Check out the <a rel=\"external\" href=\"https:\/\/ioccc.org\/years.html\">previous winners here<\/a>.<\/p>\n<p>If you were actually more intrigued by the barometer story, read <a rel=\"external\" href=\"https:\/\/www.goodreads.com\/book\/show\/35167685-surely-you-re-joking-mr-feynman\">Surely You\u2019re\nJoking, Mr.\nFeynman!<\/a>,\na book by Richard Feynman, another famous physicist and Nobel Prize winner, who\nwas known for his unconventional way of thinking.<\/p>\n<p>We should all strive to think outside the box and come up with unconventional\nsolutions to problems. Who knows, maybe that\u2019s the key to a deeper\nunderstanding of the problem itself?<\/p>\n"},{"title":"Deploy Rust Code Faster","pubDate":"Wed, 25 Oct 2023 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2023\/move-fast-rust\/","guid":"https:\/\/endler.dev\/2023\/move-fast-rust\/","description":"<p>I\u2019ve come a long way in my tech journey, from dealing with bare metal servers to\nexploring the world of cloud computing. Initially, it seemed so straightforward\n\u2013 spin up a server, deploy a container, and you\u2019re done. But as I delved deeper,\nI realized that the ease of infrastructure is not as simple as it appears.<\/p>\n<p>Cloud providers offer a multitude of tools, each with its own learning curve:<\/p>\n<ul>\n<li>Google Cloud \/ AWS<\/li>\n<li>Kubernetes<\/li>\n<li>Helm<\/li>\n<li>Docker<\/li>\n<li>Terraform<\/li>\n<li>GitHub Actions<\/li>\n<\/ul>\n<p>If you\u2019re adventurous, you might even venture into managed Kubernetes services\nlike EKS or GKE. It\u2019s tempting, with just a few clicks, your application is\nready to roll. But the reality hits when you start juggling monitoring, logging,\nsecurity, scaling, and more.<\/p>\n<p>Soon, you find yourself unintentionally leading a DevOps team instead of\nfocusing on your product. You hire more staff to manage infrastructure while\nyour competitors are shipping features and growing their user base.<\/p>\n<h2 id=\"my-frustration\"><a class=\"anchor\" href=\"#my-frustration\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>My Frustration<\/h2>\n<p>The cloud promised to make infrastructure easy, but the array of tools and\nservices can be overwhelming. Even if you don\u2019t use them all, you must be aware\nof their existence and learn the basics. The result? Your focus on the product\ndiminishes.<\/p>\n<p>I appreciate dealing with infrastructure, but I also love delivering a product.\nSadly, many companies waste precious time and money on infrastructure, repeating\nthe same mistakes.<\/p>\n<p>What if there was a way to eliminate infrastructure concerns altogether?<\/p>\n<h2 id=\"the-allure-of-serverless\"><a class=\"anchor\" href=\"#the-allure-of-serverless\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Allure of Serverless<\/h2>\n<p>Serverless architecture seems promising - no servers, no containers, just pure\nbusiness logic. However, it\u2019s not without challenges:<\/p>\n<ul>\n<li>Cold start times<\/li>\n<li>Lambda size limitations<\/li>\n<li>Memory issues<\/li>\n<li>Long-running processes<\/li>\n<li>Debugging complexities<\/li>\n<li>Lack of local testing<\/li>\n<\/ul>\n<p>Serverless has its merits for certain use cases, but for larger applications,\nyou might still need some servers.<\/p>\n<h2 id=\"platform-as-a-service-paas\"><a class=\"anchor\" href=\"#platform-as-a-service-paas\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Platform-as-a-Service (PaaS)<\/h2>\n<p>Platforms like Heroku and Netlify introduced a third option \u2013 managed services\nthat handle all infrastructure for you. No more infrastructure concerns; you\nsimply push code, and it deploys. What\u2019s great about these solutions is their\ndeep integration with specific programming language ecosystems.<\/p>\n<p>I was looking for a platform tailored for Rust developers, aiming to provide a\ntop-notch developer experience. I wanted deep integration with the Rust\necosystem (serde, sqlx, axum,\u2026).<\/p>\n<p>A while ago, I came across <a rel=\"external\" href=\"https:\/\/www.shuttle.rs\/\">Shuttle<\/a> while trying to\nfind ways to make my Rust\ndevelopment workflow a bit smoother. It\u2019s a tool that kind of just fits into the\nexisting Rust ecosystem, letting you use cargo as you normally would, but with\nsome of the infrastructural heavy lifting taken out of the picture. Now, it\u2019s\nnot a magic wand that solves all problems, but what I appreciate about Shuttle\nis its simplicity. You\u2019re not thrown into a completely new environment with a\nsteep learning curve. Instead, you stick to your Rust code, and Shuttle is there\nin the background, helping manage some of the server-side complexities. So, in\nessence, it\u2019s about sticking to what you know, while maybe making life a tad\neasier when it comes to deployment and server management. It\u2019s not about a\nrevolutionary change in how you code, but more about a subtle shift in managing\nthe background processes that can sometimes be a bit of a headache.<\/p>\n<h2 id=\"my-shuttle-experience-so-far\"><a class=\"anchor\" href=\"#my-shuttle-experience-so-far\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>My Shuttle Experience So Far<\/h2>\n<p>Until now, I built two smaller Rust services with Shuttle: Zerocal and Readable.<\/p>\n<p>Shuttle takes your Rust code and with very few annotations, it can be\ndeployed to the cloud. The developer experience is pretty close to ideal\ngiven that provisioning and deployment are usually the most painful parts of\nbuilding a service.<\/p>\n<p>Instead, it\u2019s just a matter of adding a few lines of code. See for yourself.\nThe boilerplate just vanishes. What\u2019s left is the business logic.<\/p>\n <video width=\"720\" height=\"480\" autoplay muted loop>\n  <source src=\"video.mp4\" type=\"video\/mp4\">\nYour browser does not support the video tag. :( But the video is great.\n<\/video> \n<h3 id=\"zerocal-stateless-calendar-magic\"><a class=\"anchor\" href=\"#zerocal-stateless-calendar-magic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Zerocal - Stateless Calendar Magic<\/h3>\n<p>Zerocal was the first project I deployed on Shuttle.\nThe principle was very simple yet innovative: encode calendar data directly into a URL. This means creating an event was as straightforward as:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">curl<\/span><span class=\"z-l-5 z-d-7\"> https:\/\/zerocal.shuttleapp.rs?start=2023-11-04+20:00<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>duration<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>title<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">B<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-5 z-d-7\">d<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>description<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">p<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">y<\/span><\/span><\/code><\/pre>\n<p>This would return an iCal file, that you can add to your calendar.\nHere\u2019s how you create an event in the browser:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2023\/move-fast-rust\/form.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2023\/move-fast-rust\/form.jpg\" width=\"650\" height=\"195\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>I tried building this project on Shuttle when they were still fixing some things and changing their APIs here and there. Even with these small issues, it was a good experience. In just a few minutes, my app was up and running.<\/p>\n<p>Here\u2019s the code to start the service including the axum routes:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">shuttle_runtime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> axum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> shuttle_axum<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ShuttleAxum<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> just normal axum routes<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> router<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t\t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">\/<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>calendar<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t\t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">\/<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> post<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>calendar<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>router<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>I don\u2019t really need Zerocal for myself anymore, so I\u2019m hoping someone else might\nwant to take it over. I think it could be really useful for sharing invites on\nplaces like GitHub or Discord. If you want to know more about Zerocal, you can\nread <a href=\"\/2022\/zerocal\/\">this detailed breakdown<\/a>.<\/p>\n<p>I would also like to mention that someone else built a similar project inspired\nby Zerocal: <a rel=\"external\" href=\"https:\/\/github.com\/maheshsundaram\/kiwi\">kiwi<\/a> by  <a rel=\"external\" href=\"https:\/\/github.com\/maheshsundaram\/\">Mahesh Sundaram<\/a>, written in Deno. This is a really cool outcome.<\/p>\n<h3 id=\"a-reader-mode-for-my-e-reader\"><a class=\"anchor\" href=\"#a-reader-mode-for-my-e-reader\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Reader Mode for My E-Reader<\/h3>\n<p>My appreciation for <a rel=\"external\" href=\"https:\/\/support.mozilla.org\/en-US\/kb\/firefox-reader-view-clutter-free-web-pages\">Firefox\u2019s reader view<\/a> sparked the creation of a <a href=\"\/2022\/readable\/\">Reader Mode\nProxy<\/a> for a minimalist, JavaScript-free web reading experience, particularly\ntailored for e-readers. The intention was to transform verbose websites into a\nmore digestible format for distraction-free reading.<\/p>\n<p>This project deeply reflected my personal preferences, as I like simple\napps that solve a problem. With just a sprinkle of annotations, my code adapted\nsmoothly to Shuttle\u2019s environment. Initially, I had my own local mode, which\nallowed me to run the app on my machine for testing, but I found no need to\nmaintain that because Shuttle\u2019s own local mode works just as well.<\/p>\n<p>While developing the app, there were some bumps along the road. Service\ndowntimes required some code revamping. Yet, Shuttle\u2019s evolution simplified\nparts of my process, especially when it introduced native static file handling.<\/p>\n<p>Before it looked like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">shuttle_runtime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> axum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> shuttle_axum<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ShuttleAxum<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> router<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Previously, I needed to manually serve static files<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">        \t&quot;<\/span><span class=\"z-l-5 z-d-7\">\/static\/Crimson.woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        \tget<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-9 z-d-9\"> async<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            \tstatic_content<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">                \tinclude_bytes!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">..\/static\/fonts\/Crimson.woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">                \tHeaderValue<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_static<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text\/woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            \t)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        \t}<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    \t)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">        \t&quot;<\/span><span class=\"z-l-5 z-d-7\">\/static\/JetBrainsMono.woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        \tget<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-9 z-d-9\"> async<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">            \tstatic_content<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">                \tinclude_bytes!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">..\/static\/fonts\/JetBrainsMono.woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">                \tHeaderValue<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_static<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">font\/woff2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            \t)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        \t}<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    \t)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">fallback<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>readable<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>router<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Now it\u2019s just<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">shuttle_runtime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> axum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> shuttle_axum<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ShuttleAxum<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">   let<\/span><span> router<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nest_service<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">\/static<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-d-15\"> ServeDir<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">PathBuf<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">static<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    \t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">fallback<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>readable<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>router<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>To understand the intricacies of this project, <a href=\"\/2022\/readable\">here\u2019s a more comprehensive\nlook<\/a>.<\/p>\n<h2 id=\"control-and-safety\"><a class=\"anchor\" href=\"#control-and-safety\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Control and Safety<\/h2>\n<p>Initially, I was concerned that annotating my code for infrastructure would\ncause vendor lock-in. I wanted to retain full control over my project. Want to\nmove away? The Shuttle macros get rid of the boilerplate, so I could just remove\nthe 2 annotations I\u2019ve added and get the original code back. Shuttle\u2019s code is\nalso open source, so I could even set up your self-hosted instance \u2014\nalthough I wouldn\u2019t want to.<\/p>\n<h2 id=\"the-true-cost-of-diy-infrastructure\"><a class=\"anchor\" href=\"#the-true-cost-of-diy-infrastructure\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The True Cost of DIY Infrastructure<\/h2>\n<p>Infrastructure may seem easy on the surface, but maintaining it involves various\ncomplexities and costs. Updates, deployments, availability \u2013 it can be\noverwhelming. Each hour spent on these tasks carries both a direct and\nopportunity cost.<\/p>\n<p>Infrastructure can be a maze, and Shuttle seems to fit well for those working\nwith Rust. I\u2019m thinking of trying out a larger project on Shuttle soon, now that\nI\u2019ve got a decent understanding of what Shuttle can and can\u2019t do. If you\u2019re\nconsidering giving it a shot, it\u2019s wise to check their\n<a rel=\"external\" href=\"https:\/\/www.shuttle.rs\/pricing\">pricing<\/a> to ensure it aligns with your needs.<\/p>\n<p><strong>Be mindful of the real cost of infrastructure!<\/strong><\/p>\n<p>As I\u2019ve mentioned before, it\u2019s\nnot just server costs, but a lot more. The biggest factor will probably be human\nlabor for maintenance and debugging infrastructure and that is expensive. If I\nwere to use infrastructure as code, I\u2019d be spending many hours setting up my\ninfrastructure and a lot more to maintain it and that can be expensive, given\ntoday\u2019s salaries.<\/p>\n<p>Even if it was just for a hobby project, it would not be worth\nthe trouble for me. I\u2019d much rather work on features than the code that runs it\nall.<\/p>\n"},{"title":"Little Helpers","pubDate":"Thu, 05 Jan 2023 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2023\/helpers\/","guid":"https:\/\/endler.dev\/2023\/helpers\/","description":"<p>Yesterday I couldn\u2019t help but feel a sense of awe at all the conveniences modern\nlife has to offer.<\/p>\n<p>A lot of the chores in our household are taken care of by little helpers: The\ndishwasher washes the dishes, the washing machine washes the clothes, and the\nrobot vacuum cleaner cleans the floors. The refrigerator keeps our food cold,\nthe microwave heats it up, and the oven cooks it.<\/p>\n<p>We take all of this for granted because the devices rarely fail, but it\u2019s really\namazing when you think about it. It\u2019s only been a few decades since much of this\nwas tedious, time-consuming, manual labor.<\/p>\n<p>I heard stories about how people used to watch the washing machine do its thing,\njust because it was entertaining to see the machine do their work for them.<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/BZoKfap4g4w\"\n>\n  <picture>\n    <source srcset=\"rosling.avif\" type=\"image\/avif\" \/>\n    <img src=\"rosling.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p>Growing up in the 90s and early 2000s, I remember when \u201csmart home\u201d was a\nbuzzword, and now it\u2019s a reality. Smart devices control the thermostat and soon\nthe lights and the door locks in our apartment.<\/p>\n<p>Of course there were a bunch of stupid ideas that didn\u2019t work out along the way.\nI remember when they tried to sell those \u201csmart\u201d fridges that would run a web\nbrowser and let you order groceries from the fridge. Who would want to do that?\nIt\u2019s so much easier to just order groceries online from your phone or computer.\nOn the other hand, of all the people I talked to, I\u2019ve never met anyone who\nregrets buying a vacuum robot.<\/p>\n<p>We recently got a cat and quickly automated all the tedious stuff. The litter\nbox cleans itself, there\u2019s a water fountain that keeps the water fresh, and soon\nwe\u2019ll get a food dispenser. That means we have more time to focus on the fun\nstuff, like playing with the cat.<\/p>\n<p>And yes, I fully realize that this convenience comes from an incredible position of\nprivilege. A privileged position that we should never take for granted! Instead,\nwe should be grateful for the little helpers that make our lives easier and make\nthem more accessible to everyone.<\/p>\n"},{"title":"A Reader Mode Proxy for the Slow Web","pubDate":"Thu, 03 Nov 2022 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2022\/readable\/","guid":"https:\/\/endler.dev\/2022\/readable\/","description":"<figure>\n    <a href=\"https:\/\/readable.shuttleapp.rs\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/readable\/darkmode.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/readable\/darkmode.jpg\" alt=\"Reader showing an article in light and dark mode.\" width=\"650\" height=\"421\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        Reader showing an article in light and dark mode.\n    <\/figcaption>\n<\/figure>\n<div class=\"info\">\n    <p><em>tl;dr:<\/em> I built a service that takes any article and creates a pleasant-to-read, printable version.\nIt is similar to Reader View in Firefox\/Safari, but also works on older\nbrowsers, can be shared and has a focus on beautiful typography.\nCheck out the <a rel=\"external\" href=\"https:\/\/github.com\/readable-app\/readable\">source code<\/a>.<\/p>\n<\/div>\n<p>The web used to be such a fun place.<\/p>\n<p>Nowadays? Meh.\nTrackers, ads, bloat, fullscreen popups, autoplaying videos\u2026 it\u2019s all so <em>exhausting<\/em>.<\/p>\n<p>I just want to read long-form posts without distractions with a good cup of tea,\nthe cat sleeping on the windowsill and some light snow falling in front of the window.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/readable\/lofi.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/readable\/lofi.jpg\" width=\"650\" height=\"366\"\n    \/>\n    <\/picture>\n<\/figure>\n<h2 id=\"the-slow-web\"><a class=\"anchor\" href=\"#the-slow-web\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Slow Web<\/h2>\n<p>I\u2019m a big fan of the <a rel=\"external\" href=\"https:\/\/www.jackcheng.com\/the-slow-web\/\">Slow Web movement<\/a>\nand of <a rel=\"external\" href=\"https:\/\/herman.bearblog.dev\/big-fat-websites\/\">little sites that do one thing well<\/a>.<\/p>\n<p>For reading long-form text clutter-free I use <a rel=\"external\" href=\"https:\/\/support.mozilla.org\/en-US\/kb\/firefox-reader-view-clutter-free-web-pages\">Reader\nView<\/a>\nin Firefox, and while it doesn\u2019t always work and it\u2019s not the prettiest I like it.<\/p>\n<p>There are reader modes in other browsers as well, but some of them \u2014 like Chrome \u2014 <a rel=\"external\" href=\"https:\/\/www.howtogeek.com\/423643\/how-to-use-google-chromes-hidden-reader-mode\/\">hide\nit behind a feature flag<\/a>.\nOther browsers, like the one on my eBook reader, don\u2019t come with a reader mode at all,\nwhich leaves me with a subpar and slow browsing experience on my main device used for reading.<\/p>\n<p>So I built <em>a reader mode as a service<\/em> with a focus on <em>beautiful typography<\/em>\nwhich works across all browsers.\nIt\u2019s very basic, but I use it to read articles on my older devices and\nit could also make content more accessible in regions with low bandwidth or\nwhile travelling.<\/p>\n<h2 id=\"building-it\"><a class=\"anchor\" href=\"#building-it\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Building It<\/h2>\n<p>Lately I saw a post about <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=33192518\">circumflex, a Hacker News terminal\nclient<\/a>. The tool did a solid job\nat rendering website content and I wondered if I can retrofit that into a proxy\nserver.<\/p>\n<p>The Golang cleanup code is <a rel=\"external\" href=\"https:\/\/github.com\/bensadeh\/circumflex\/blob\/d69467963e4a27f1ea75f0017ee4d4decc304de4\/reader\/reader.go#L16-L36\">here<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> GetArticle<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">url<\/span><span class=\"z-l-9 z-d-9\"> string<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> title<\/span><span class=\"z-l-9 z-d-9\"> string<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> width<\/span><span class=\"z-l-9 z-d-9\"> int<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> indentationSymbol<\/span><span class=\"z-l-9 z-d-9\"> string<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">string<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> error<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    articleInRawHTML<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> httpErr<\/span><span class=\"z-l-2 z-d-5\"> :=<\/span><span> readability<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">FromURL<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span>time<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>Second<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span> httpErr<\/span><span class=\"z-l-2 z-d-5\"> !=<\/span><span class=\"z-l-10 z-d-12\"> nil<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        return<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> fmt<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Errorf<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">could not fetch url: <\/span><span class=\"z-l-5 z-d-7\">%w<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> httpErr<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>They use <a rel=\"external\" href=\"https:\/\/github.com\/go-shiori\/go-readability\">go-readability<\/a>, a port\nof <a rel=\"external\" href=\"https:\/\/github.com\/mozilla\/readability\">Mozilla\u2019s Readability<\/a>. The Rust\nequivalent is <a rel=\"external\" href=\"https:\/\/crates.io\/crates\/readability\">readability<\/a> and it\u2019s\nsimple enough to use:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> readability<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>extractor<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-14 z-d-10\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-14 z-d-10\">error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> response<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> extractor<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">scrape<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/endler.dev\/2022\/readable<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> response<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>content<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Before we write a full proxy server, let\u2019s write a simple CLI tool that takes a\nURL and outputs a clean, readable HTML file.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> readability<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>extractor<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">File<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Write<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-14 z-d-10\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-14 z-d-10\">error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\t\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> read the URL from the command line<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> url<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">expect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Please provide a URL<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> response<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> extractor<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">scrape<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> file<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> File<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">create<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">index.html<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>\tfile<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">write_all<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>response<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">content<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_bytes<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The output already looked surprisingly good.\nNext I added a simple HTML template to wrap the response content.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"html\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">&lt;!<\/span><span class=\"z-l-9 z-d-9\">DOCTYPE<\/span><span class=\"z-l-13 z-d-15\"> html<\/span><span class=\"z-l-9 z-d-9\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">html<\/span><span class=\"z-l-13 z-d-15\"> lang<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">en<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">head<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">meta<\/span><span class=\"z-l-13 z-d-15\"> charset<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">UTF-8<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">title<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>Document<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">title<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">link<\/span><span class=\"z-l-13 z-d-15\"> rel<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">stylesheet<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> href<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">yue.css<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">style<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text\/css<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">      body<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">        margin<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">        padding<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0.4<\/span><span class=\"z-l-9 z-d-9\">em<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-9 z-d-9\">em<\/span><span class=\"z-l-16 z-d-16\"> 6<\/span><span class=\"z-l-9 z-d-9\">em<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">        background<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-8 z-d-4\"> #<\/span><span>fff<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">      }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">      .<\/span><span class=\"z-l-13 z-d-15\">yue<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">        max-width<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 650<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">        margin<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span> auto<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">      }<\/span><\/span>\n<span class=\"giallo-l\"><span>    &lt;<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span class=\"z-l-3 z-d-2\">style<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;\/<\/span><span class=\"z-l-3 z-d-2\">head<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">body<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">div<\/span><span class=\"z-l-13 z-d-15\"> class<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">yue<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>{{content}}<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">div<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;\/<\/span><span class=\"z-l-3 z-d-2\">body<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">html<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p>No need to use a full-blown template engine for now; we can just use\n<code>str::replace<\/code> to replace the <code>{{content}}<\/code> placeholder with the actual content.\n\ud83d\ude09<\/p>\n<h2 id=\"proxy-setup\"><a class=\"anchor\" href=\"#proxy-setup\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Proxy Setup<\/h2>\n<p>The proxy setup is super simple with <a rel=\"external\" href=\"https:\/\/www.shuttle.rs\/\">shuttle<\/a>. It\u2019s my\nsecond project after <a href=\"\/2022\/zerocal\/\">zerocal<\/a>, which is hosted on shuttle and\nI\u2019m very happy with how smooth the process is. \ud83d\ude80\nLet\u2019s call the app <code>readable<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo shuttle init --axum --name readable<\/span><\/span><\/code><\/pre>\n<p>This creates a small <a rel=\"external\" href=\"https:\/\/github.com\/tokio-rs\/axum\">Axum<\/a> app with a simple\nhello world route.<\/p>\n<h2 id=\"roadblock-no-1-reqwest\"><a class=\"anchor\" href=\"#roadblock-no-1-reqwest\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Roadblock No. 1: <code>reqwest<\/code><\/h2>\n<p>When I integrated the <a rel=\"external\" href=\"https:\/\/crates.io\/crates\/readability\">readability<\/a> crate\ninto the project I hit a minor roadblock.<\/p>\n<p>I used <code>extractor::scrape<\/code> just like above and the proxy started locally.\nHowever when I wanted to fetch a website from the proxy, I got an error:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>thread &#39;tokio-runtime-worker&#39; panicked at<\/span><\/span>\n<span class=\"giallo-l\"><span>&#39;Cannot drop a runtime in a context where blocking is not allowed.<\/span><\/span>\n<span class=\"giallo-l\"><span>This happens when a runtime is dropped from<\/span><\/span>\n<span class=\"giallo-l\"><span>within an asynchronous context.&#39;<\/span><\/span><\/code><\/pre>\n<p>This meant that I started a runtime inside a runtime.<\/p>\n<p>After checking the source code of the <code>readability<\/code> crate, I found that it\nbuilds a <code>reqwest::blocking::Client<\/code> and uses that to fetch the URL.\nAfter that request, the client is dropped which causes the runtime to be shut\ndown.<\/p>\n<p>I fixed this by using a <code>reqwest::Client<\/code> instead of the <code>reqwest::blocking::Client<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> reqwest::blocking::Client<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> client<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> reqwest<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">blocking<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Client<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> reqwest::Client<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> client<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> reqwest<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Client<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Now I had the content of the article, but I still needed to pass it to\n<code>readability<\/code>. Fortunately they provide a function named <code>extractor::extract<\/code>\nthat takes something that implements <code>Read<\/code> and returns the extracted content.<\/p>\n<p>However, the <code>reqwest::Response<\/code> doesn\u2019t implement <code>Read<\/code> (in contrast to the\n<code>reqwest::blocking::Response<\/code>). So I needed to convert it to a <code>Read<\/code>able type\nmyself.<\/p>\n<p>Luckily, the <code>reqwest::Response<\/code> has a <code>bytes<\/code> method that returns a <code>Bytes<\/code>\nobject. The <code>Bytes<\/code> object implements <code>Read<\/code> and I can use it to call\n<code>extractor::extract<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> body<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> client<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">text<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> bytes<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> body<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">bytes<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-9 z-d-9\">await<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> response<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> extractor<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">extract<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span> res<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span>url<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><h2 id=\"roadblock-no-2-routing\"><a class=\"anchor\" href=\"#roadblock-no-2-routing\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Roadblock No. 2: Routing<\/h2>\n<p>The app didn\u2019t crash anymore, but I still didn\u2019t get any response.<\/p>\n<p>My router looked like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">shuttle_service<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> axum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> shuttle_service<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ShuttleAxum<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> router<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">\/:url<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>readable<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> sync_wrapper<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SyncWrapper<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>router<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>sync_wrapper<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Turns out that when I use <code>\/:url<\/code> as the route, it doesn\u2019t match the path\n<code>\/https:\/\/example.com<\/code> because <code>:<\/code> matches only a single segment up to the\nfirst slash.<\/p>\n<p>The solution was to use <code>\/*url<\/code> instead, which is a wildcard route that matches\nall segments until the end.<\/p>\n<h2 id=\"typography-and-layout\"><a class=\"anchor\" href=\"#typography-and-layout\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Typography and Layout<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/readable\/nyt.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/readable\/nyt.jpg\" alt=\"New York Times website (left) vs reader mode (right)\" width=\"650\" height=\"206\"\n    \/>\n    <\/picture>\n    <figcaption>\n        New York Times website (left) vs reader mode (right)\n    <\/figcaption>\n<\/figure>\n<p>For my first prototype I used a CSS framework called\n<a rel=\"external\" href=\"https:\/\/github.com\/typlog\/yue.css\">yue.css<\/a> because it was the first thing I\nfound which looked nice.<\/p>\n<p>For the final version I ended up mimicking the style of <a rel=\"external\" href=\"https:\/\/ruudvanasseldonk.com\/\">Ruud van Asseldonk\u2019s\nblog<\/a> because it always reminded me of reading a\nwell-typeset book.<\/p>\n<p>For fonts I chose two of my favorites<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/Fonthausen\/CrimsonPro\">Crimson Pro<\/a> for the body text.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jetbrains.com\/lp\/mono\/\">JetBrains Mono<\/a> for the code.<\/li>\n<\/ul>\n<p>Both are licensed under the <a rel=\"external\" href=\"https:\/\/opensource.org\/license\/openfont-html\/\">SIL Open Font License 1.1<\/a>.<\/p>\n<p>You can even use <code>readable<\/code> from the terminal.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>lynx https:\/\/readable.shuttleapp.rs\/https:\/\/en.wikipedia.org\/wiki\/Alan_Turing<\/span><\/span><\/code><\/pre><h2 id=\"caveats\"><a class=\"anchor\" href=\"#caveats\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Caveats<\/h2>\n<p>The proxy is far from perfect.\nIt\u2019s something I built in a few hours for my personal use.<\/p>\n<ul>\n<li>It doesn\u2019t always produce valid HTML.<\/li>\n<li>JavaScript is not executed, so some websites don\u2019t work properly. Some might\nsay that\u2019s feature, not a bug. \ud83d\ude09<\/li>\n<li>That is also true for websites with sophisticated paywalls or bot-detection. A\nworkaround would be to use a headless browser like\n<a rel=\"external\" href=\"https:\/\/www.scrapingbee.com\">ScrapingBee<\/a> or\n<a rel=\"external\" href=\"https:\/\/www.browserless.io\/\">Browserless<\/a>, but I didn\u2019t want to add that\ncomplexity to the project.<\/li>\n<li>The <code>readability<\/code> library takes a lot of freedom in formatting the document\nhowever it pleases. It can sometimes produce weird results. For example, it\nloves to mangle code blocks.<\/li>\n<\/ul>\n<h2 id=\"credits\"><a class=\"anchor\" href=\"#credits\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Credits<\/h2>\n<p>I was not the first person to build a readability proxy. I found out about\n<a rel=\"external\" href=\"https:\/\/github.com\/n1k0\/readable-proxy\">readable-proxy<\/a> when I did my research,\nbut the project seems to be abandoned. Nevertheless it was nice to see that\nothers had the same need.<\/p>\n<p>Thanks to <a rel=\"external\" href=\"https:\/\/ruudvanasseldonk.com\/\">Ruud van Asseldonk<\/a> for open sourcing\nhis <a rel=\"external\" href=\"https:\/\/github.com\/ruuda\/blog\">blog<\/a>. \ud83d\ude4f His writing and documentation are\nalways a great source of inspiration to me.<\/p>\n<h2 id=\"conclusion\"><a class=\"anchor\" href=\"#conclusion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Conclusion<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/readable\/kobo.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/readable\/kobo.jpg\" alt=\"The browser on my old Kobo eBook reader using the readability proxy.\" width=\"650\" height=\"436\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The browser on my old Kobo eBook reader using the readability proxy.\n    <\/figcaption>\n<\/figure>\n<p>In times where <a rel=\"external\" href=\"https:\/\/tech.co\/news\/google-chrome-ad-blockers-2023\">the most popular browser might kill off ad\nblockers<\/a>, a little service\nfor reading articles without ads or tracking can come in handy. I\u2019m not saying you\nshould use it to send all your traffic through it, but it\u2019s a nice tool to have\nin your toolbox for a rainy day, a warm drink and a great article. \u2615<\/p>\n<p>Feel free to deploy your own instance of <code>readable<\/code> or use the one I\u2019m hosting.\nThe source code is available on <a rel=\"external\" href=\"https:\/\/github.com\/mre\/readable\">GitHub<\/a>.\nMaybe one of you wants to help me maintain it.<\/p>\n"},{"title":"zerocal - A Serverless Calendar App in Rust Running on shuttle.rs","pubDate":"Wed, 05 Oct 2022 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2022\/zerocal\/","guid":"https:\/\/endler.dev\/2022\/zerocal\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2022\/zerocal\/intro.svg\" width=\"487\" height=\"264\"\n    \/>\n<\/figure>\n<p>Every once in a while my buddies and I meet for dinner.\nI value these evenings, but the worst part is scheduling these events!<\/p>\n<p>We send out a message to the group.<br \/>\nWe wait for a response.<br \/>\nWe decide on a date.<br \/>\nSomeone sends out a calendar invite.<br \/>\nThings finally happen.<\/p>\n<p>None of that is fun <em>except<\/em> for the dinner.<\/p>\n<p>Being the reasonable person you are, you would think: \u201cWhy don\u2019t you just use a\nscheduling app?\u201d.<\/p>\n<p>I have tried many of them. None of them are any good.\nThey are all\u2026 <em>too much<\/em>!<\/p>\n<p>Just let me send out an invite and whoever wants can show up.<\/p>\n<ul>\n<li>I <em>don\u2019t<\/em> want to have to create an account for your calendar\/scheduling\/whatever app.<\/li>\n<li>I <em>don\u2019t<\/em> want to have to add my friends.<\/li>\n<li>I <em>don\u2019t<\/em> want to have to add my friends\u2019 friends.<\/li>\n<li>I <em>don\u2019t<\/em> want to have to add my friends\u2019 friends\u2019 friends.<\/li>\n<li>You get the idea:\nI just want to send out an invite and get no response from you.<\/li>\n<\/ul>\n<h2 id=\"the-nerdy-introvert-engineer-s-solution\"><a class=\"anchor\" href=\"#the-nerdy-introvert-engineer-s-solution\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Nerdy, Introvert Engineer\u2019s Solution<\/h2>\n<p>\ud83d\udca1 What we definitely need is yet another calendar app which allows us to create events and send out an invite with a link to that event!\nYou probably didn\u2019t see that coming now, did you?<\/p>\n<p>Oh, and I don\u2019t want to use Google Calendar to create the event because <a rel=\"external\" href=\"https:\/\/www.businessinsider.com\/google-users-locked-out-after-years-2020-10\">I<\/a> <a rel=\"external\" href=\"https:\/\/killedbygoogle.com\/\">don\u2019t<\/a> <a rel=\"external\" href=\"https:\/\/github.com\/tycrek\/degoogle\">trust them<\/a>.<\/p>\n<p>Like any reasonable person, I wanted a way to create calendar entries from my <em>terminal<\/em>.<\/p>\n<p>That\u2019s how I pitched the idea to my buddies last time.\nThe answer was: \u201cI don\u2019t know, sounds like a solution in search of a problem.\u201d\nBut you know what they say: Never ask a starfish for directions.<\/p>\n<h2 id=\"show-don-t-tell\"><a class=\"anchor\" href=\"#show-don-t-tell\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Show, Don\u2019t Tell<\/h2>\n<p>That night I went home and built a website that would create a calendar entry\nfrom <code>GET<\/code> parameters.<\/p>\n<p>It allows you to create a calendar event from the convenience of your command line:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span> curl https:\/\/zerocal.shuttleapp.rs<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span>start<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">4<\/span><span class=\"z-l-5 z-d-7\">+<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">:<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>duration<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>title<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">B<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-5 z-d-7\">d<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>description<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">p<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">y<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">BEGIN:VCALENDAR<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">VERSION:2.0<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">PRODID:ICALENDAR-RS<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">CALSCALE:GREGORIAN<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">BEGIN:VEVENT<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">DTSTAMP:20221002T123149Z<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">CLASS:CONFIDENTIAL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">DESCRIPTION:paaarty<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">DTEND:20221002T133149Z<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">DTSTART:20221002T123149Z<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">SUMMARY:Birthday<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">UID:c99dd4bb-5c35-4d61-9c46-7a471de0e7f4<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">END:VEVENT<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">END:VCALENDAR<\/span><\/span><\/code><\/pre>\n<p>You can then save that to a file and open it with your calendar app.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span> curl https:\/\/zerocal.shuttleapp.rs<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span>start<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">4<\/span><span class=\"z-l-5 z-d-7\">+<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">:<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>duration<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>title<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">B<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-5 z-d-7\">d<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>description<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">p<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span> &gt;<\/span><span class=\"z-l-5 z-d-7\"> birthday.ics<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span> open birthday.ics<\/span><\/span><\/code><\/pre>\n<p>In a sense, it\u2019s a \u201cserverless calendar app\u201d, haha.\nThere is no state on the server, it just generates a calendar event on the fly and returns it.<\/p>\n<h2 id=\"how-i-built-it\"><a class=\"anchor\" href=\"#how-i-built-it\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How I Built It<\/h2>\n<p>You probably noticed that the URL contains \u201cshuttleapp.rs\u201d.\nThat\u2019s because I\u2019m using <a rel=\"external\" href=\"https:\/\/github.com\/shuttle-hq\/shuttle\">shuttle.rs<\/a> to host the website.<\/p>\n<p>Shuttle is a hosting service for Rust projects and I wanted to try it out for a long time.<\/p>\n<p>To initialize the project using the awesome <a rel=\"external\" href=\"https:\/\/github.com\/tokio-rs\/axum\">axum<\/a> web framework, I\u2019ve used<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo install cargo-shuttle<\/span><\/span>\n<span class=\"giallo-l\"><span>cargo shuttle init --axum --name zerocal zerocal<\/span><\/span><\/code><\/pre>\n<p>and I was greeted with everything I needed to get started:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> axum<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-13 z-d-15\">routing<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>get<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> sync_wrapper<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">SyncWrapper<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> hello_world<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">static<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> str<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">  &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">shuttle_service<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> axum<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-d-15\"> shuttle_service<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ShuttleAxum<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> router<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Router<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">route<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">\/hello<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>hello_world<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> sync_wrapper<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SyncWrapper<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>router<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">  Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>sync_wrapper<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Let\u2019s quickly commit the changes:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">git<\/span><span class=\"z-l-5 z-d-7\"> add<\/span><span class=\"z-l-5 z-d-7\"> .gitignore<\/span><span class=\"z-l-5 z-d-7\"> Cargo.toml<\/span><span class=\"z-l-5 z-d-7\"> src\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">git<\/span><span class=\"z-l-5 z-d-7\"> commit<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">m<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello World<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>To deploy the code, I needed to sign up for a shuttle account.\nThis can be done over at <a rel=\"external\" href=\"https:\/\/www.shuttle.rs\/login\">https:\/\/www.shuttle.rs\/login<\/a>.<\/p>\n<p>It will ask you to authorize it to access your Github account.<\/p>\n<p>Then:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cargo<\/span><span class=\"z-l-5 z-d-7\"> shuttle<\/span><span class=\"z-l-5 z-d-7\"> login<\/span><\/span><\/code><\/pre>\n<p>and finally:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cargo<\/span><span class=\"z-l-5 z-d-7\"> shuttle<\/span><span class=\"z-l-5 z-d-7\"> deploy<\/span><\/span><\/code><\/pre>\n<p>Now let\u2019s head over to <a rel=\"external\" href=\"https:\/\/zerocal.shuttleapp.rs\">zerocal.shuttleapp.rs<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>Hello World!<\/span><\/span><\/code><\/pre>\n<p>Deploying the first version took less than 5 minutes. Neat!\nWe\u2019re all set for our custom calendar app.<\/p>\n<h2 id=\"writing-the-app\"><a class=\"anchor\" href=\"#writing-the-app\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Writing the App<\/h2>\n<p>To create the calendar event, I used the <a rel=\"external\" href=\"https:\/\/github.com\/hoodie\/icalendar-rs\">icalendar<\/a> crate (shout out to <a rel=\"external\" href=\"https:\/\/github.com\/hoodie\">hoodie<\/a> for creating this nice library!). <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/ICalendar\">iCalendar<\/a> is a standard for creating calendar events that is supported by most calendar apps.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cargo<\/span><span class=\"z-l-5 z-d-7\"> add<\/span><span class=\"z-l-5 z-d-7\"> icalendar<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cargo<\/span><span class=\"z-l-5 z-d-7\"> add<\/span><span class=\"z-l-5 z-d-7\"> chrono<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> For date and time parsing<\/span><\/span><\/code><\/pre>\n<p>Let\u2019s create a demo calendar event:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> event<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Event<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">summary<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">test event<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">description<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">here I have something really important to do<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">starts<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Utc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">ends<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Utc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span class=\"z-l-13 z-d-15\"> Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">days<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Simple enough.<\/p>\n<h2 id=\"how-to-return-a-file\"><a class=\"anchor\" href=\"#how-to-return-a-file\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How to Return a File!?<\/h2>\n<p>Now that we have a calendar event, we need to return it to the user.\nBut how do we return it as a file?<\/p>\n<p>There\u2019s an example of how to return a file dynamically in axum <a rel=\"external\" href=\"https:\/\/github.com\/tokio-rs\/axum\/discussions\/608\">here<\/a>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> calendar<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-9 z-d-9\"> impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> IntoResponse<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> ical<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Calendar<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">push<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">      \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> add an event<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">      Event<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">summary<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">It works! \ud83d\ude00<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">description<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Meeting with the Rust community<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">starts<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Utc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span class=\"z-l-13 z-d-15\"> Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">hours<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">ends<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Utc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span class=\"z-l-13 z-d-15\"> Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">hours<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">2<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    )<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  CalendarResponse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>ical<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Some interesting things to note here:<\/p>\n<ul>\n<li>Every calendar file is a collection of events so we wrap the event in a\n<code>Calendar<\/code> object, which represents the collection.<\/li>\n<li><code>impl IntoResponse<\/code> is a trait that allows us to return any type that implements it.<\/li>\n<li><code>CalendarResponse<\/code> is a <a rel=\"external\" href=\"https:\/\/rust-unofficial.github.io\/patterns\/patterns\/behavioural\/newtype.html\">newtype wrapper<\/a> around <code>Calendar<\/code> that implements <code>IntoResponse<\/code>.<\/li>\n<\/ul>\n<p>Here is the <code>CalendarResponse<\/code> implementation:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Newtype wrapper around Calendar for `IntoResponse` impl<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">derive<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Debug<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> CalendarResponse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Calendar<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> IntoResponse<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> CalendarResponse<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> into_response<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Response<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> res<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Response<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">boxed<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Full<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    res<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">headers_mut<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">insert<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">      header<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-16 z-d-16\">CONTENT_TYPE<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">      HeaderValue<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_static<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text\/calendar<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    )<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    res<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>We just create a new <code>Response<\/code> object and set the <code>Content-Type<\/code> header to the correct MIME type for iCalendar files: <code>text\/calendar<\/code>.\nThen we return the response.<\/p>\n<h2 id=\"add-date-parsing\"><a class=\"anchor\" href=\"#add-date-parsing\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Add Date Parsing<\/h2>\n<p>This part is a bit hacky, so feel free to glance over it.\nWe need to parse the date and duration from the query string.\nI used <a rel=\"external\" href=\"https:\/\/docs.rs\/dateparser\">dateparser<\/a>, because it supports <a rel=\"external\" href=\"https:\/\/docs.rs\/dateparser\/latest\/dateparser\/#accepted-date-formats\">sooo many different date formats<\/a>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> calendar<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Query<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>params<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Query<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">HashMap<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">String<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-9 z-d-9\"> impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> IntoResponse<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> event<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Event<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>  event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">class<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Class<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Confidential<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>title<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">title<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">summary<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>title<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">summary<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">DEFAULT_EVENT_TITLE<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>description<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">description<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">description<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>description<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">description<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Powered by zerocal.shuttleapp.rs<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>start<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">start<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> start<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> dateparser<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>start<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">starts<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>start<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">duration<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">      let<\/span><span> duration<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> humantime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse_duration<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">      let<\/span><span> duration<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> chrono<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_std<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>      event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">ends<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>start<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><span> duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>end<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">end<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> end<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> dateparser<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>end<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">ends<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>end<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">duration<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">      if<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">get<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">start<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_none<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> duration<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> humantime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse_duration<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> duration<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> chrono<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Duration<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_std<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">starts<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>end<\/span><span class=\"z-l-2 z-d-5\"> -<\/span><span> duration<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">      }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> ical<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Calendar<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">push<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>event<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">done<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  CalendarResponse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>ical<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Would be nice to support more date formats like <code>now<\/code> and <code>tomorrow<\/code>, but I\u2019ll leave that for another time.<\/p>\n<p>Let\u2019s test it:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span> cargo shuttle run<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> This starts a local dev server<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span> curl 127.0.0.1:8000<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span>start<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">4<\/span><span class=\"z-l-5 z-d-7\">+<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">:<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-5 z-d-7\">0<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>duration<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>title<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">B<\/span><span class=\"z-l-5 z-d-7\">i<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-5 z-d-7\">d<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-8 z-d-4\">&amp;<\/span><span>description<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">P<\/span><span class=\"z-l-5 z-d-7\">a<\/span><span class=\"z-l-5 z-d-7\">r<\/span><span class=\"z-l-5 z-d-7\">t<\/span><span class=\"z-l-5 z-d-7\">y<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">*<\/span><span>\ud83e\udd16 bleep bloop, calendar file created<\/span><span class=\"z-l-2 z-d-5\">*<\/span><\/span><\/code><\/pre>\n<p>Nice, it works!<\/p>\n<p>Opening it in the browser creates a new event in the calendar:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/zerocal\/event.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/zerocal\/event.jpg\" alt=\"Of course, it also works on Chrome, but you do [support the open web](https:\/\/contrachrome.com\/), right?\" width=\"650\" height=\"193\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Of course, it also works on Chrome, but you do <a rel=\"external\" href=\"https:\/\/contrachrome.com\/\">support the open web<\/a>, right?\n    <\/figcaption>\n<\/figure>\n<p>And for all the odd people who don\u2019t use a terminal to create a calendar event, let\u2019s also add a form to the website.<\/p>\n<h2 id=\"add-a-form\"><a class=\"anchor\" href=\"#add-a-form\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Add a Form<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"html\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">form<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">table<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-13 z-d-15\"> for<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">title<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>Event Title<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">input<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> id<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">title<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> name<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">title<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> value<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Birthday<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;\/<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-13 z-d-15\"> for<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">desc<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>Description<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">input<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> id<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">desc<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> name<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">desc<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> value<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Party<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;\/<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-13 z-d-15\"> for<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">start<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>Start<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">input<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">datetime-local<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> id<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">start<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> name<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">start<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;\/<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-13 z-d-15\"> for<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">end<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>End<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">label<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        &lt;<\/span><span class=\"z-l-3 z-d-2\">input<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">datetime-local<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> id<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">end<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> name<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">end<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &lt;\/<\/span><span class=\"z-l-3 z-d-2\">td<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;\/<\/span><span class=\"z-l-3 z-d-2\">tr<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;\/<\/span><span class=\"z-l-3 z-d-2\">table<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">form<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p>I modified the <code>calendar<\/code> function a bit to return the form if the query string is empty:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">async<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> calendar<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Query<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>params<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Query<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">HashMap<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">String<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-9 z-d-9\"> impl<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> IntoResponse<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> if query is empty, show form<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_empty<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    return<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Response<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">builder<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">status<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">200<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">body<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">boxed<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Full<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">include_str!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">..\/static\/index.html<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">  \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>After some more tweaking, we got ourselves a nice little form in all of its web 1.0 glory:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2022\/zerocal\/form.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2022\/zerocal\/form.jpg\" alt=\"The form\" width=\"650\" height=\"195\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The form\n    <\/figcaption>\n<\/figure>\n<p>And that\u2019s it! We now have a little web app that can create calendar events.\nWell, almost. We still need to deploy it.<\/p>\n<h2 id=\"deploying\"><a class=\"anchor\" href=\"#deploying\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Deploying<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo shuttle deploy<\/span><\/span><\/code><\/pre>\n<p>Right, that\u2019s all. It\u2019s that easy.\nThanks to the folks over at <a rel=\"external\" href=\"https:\/\/github.com\/shuttle-hq\/shuttle\">shuttle.rs<\/a> for making this possible.<\/p>\n<p>The calendar app is now available at <a rel=\"external\" href=\"https:\/\/zerocal.shuttleapp.rs\">zerocal.shuttleapp.rs<\/a>.<\/p>\n<p>Now I can finally send my friends a link to a calendar event for our next pub crawl.\nThey\u2019ll surely appreciate it.<sup>yeah<sup>yeah<\/sup><\/sup><\/p>\n<h2 id=\"from-zero-to-calendar-in-100-lines-of-rust\"><a class=\"anchor\" href=\"#from-zero-to-calendar-in-100-lines-of-rust\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>From Zero to Calendar in 100 Lines of Rust<\/h2>\n<p>Boy it feels good to be writing some plain HTML again.<br \/>\nBuilding little apps never gets old.<\/p>\n<p>Check out the source code on <a rel=\"external\" href=\"https:\/\/github.com\/mre\/zerocal\">GitHub<\/a> and help me make it better! \ud83d\ude4f<\/p>\n<p>Here are some ideas:<\/p>\n<ul>\n<li>\u2705 Add location support (e.g. <code>location=Berlin<\/code> or <code>location=https:\/\/zoom.us\/test<\/code>).\nThanks to <a rel=\"external\" href=\"https:\/\/github.com\/sigaloid\">sigaloid<\/a>.<\/li>\n<li>Add support for more human-readable date formats (e.g. <code>now<\/code>, <code>tomorrow<\/code>).<\/li>\n<li>Add support for recurring events.<\/li>\n<li>Add support for timezones.<\/li>\n<li>Add Google calendar short-links (<code>https:\/\/calendar.google.com\/calendar\/render?action=TEMPLATE&amp;dates=20221003T224500Z%2F20221003T224500Z&amp;details=&amp;location=&amp;text=<\/code>).<\/li>\n<li>Add example bash command to create a calendar event from the command line.<\/li>\n<li>Shorten the URL (e.g. <code>zerocal.shuttleapp.rs\/2022-11-04T20:00\/3h\/Birthday\/Party<\/code>)?<\/li>\n<\/ul>\n<p>Check out the <a rel=\"external\" href=\"https:\/\/github.com\/mre\/zerocal\">issue tracker<\/a> and feel free to open a PR!<\/p>\n"},{"title":"The Uber of Poland","pubDate":"Mon, 14 Jun 2021 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2021\/uber-of-poland\/","guid":"https:\/\/endler.dev\/2021\/uber-of-poland\/","description":"<p>A few years ago I visited a friend in Gda\u0144sk, Poland. As we explored the\ncity, one thing I noticed was that cabs were relatively expensive and there was\nno Uber. Instead, most (young) people used a community-organized service called\n<em>Night Riders<\/em>.<\/p>\n<p>I couldn\u2019t find anything about that service on the web, so I decided to write\nabout it to preserve its history.<\/p>\n<h2 id=\"delightfully-low-tech\"><a class=\"anchor\" href=\"#delightfully-low-tech\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Delightfully Low-Tech<\/h2>\n<p>What fascinated me about <em>Night Riders<\/em> was the way the service operated \u2014\ncompletely via WhatsApp: you post a message in a group chat and one of the free\nriders would reply with a \ud83d\udc4d emoji. With that, your ride was scheduled.\nYou\u2019d pay through PayPal or cash.<\/p>\n<p>In these days of venture-backed startups that need millions in capital before\nthey turn a profit, this approach is decidedly antagonistic. Basically,\n<em>Night Riders<\/em> built on top of existing infrastructure instead of maintaining their\nown ride-hailing platform, sign-up process, or even website.<\/p>\n<p>The service would grow solely by word of mouth. Using existing infrastructure\nmeant that it was extremely cheap to run and there were almost zero upfront costs without\n<a href=\"\/2021\/first-business\/\">a single line of code to write<\/a>.<\/p>\n<p>It simply solved the customer\u2019s problem in the most straightforward way\npossible. Of course, there are legal issues regarding data protection, labor\nlaw or payment processing, but the important bit is that they had paying\ncustomers from day one.\nThe rest is easier to solve than a lack of product market fit.<\/p>\n<h2 id=\"in-defense-of-clones\"><a class=\"anchor\" href=\"#in-defense-of-clones\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>In Defense of Clones<\/h2>\n<p>Uber and Lyft can\u2019t be everywhere from the start. While they expand their\nbusinesses, others have the ability to outpace them. There\u2019s an Uber clone in\nChina (<a rel=\"external\" href=\"https:\/\/didichuxing.com\">DiDi<\/a>), one in Africa and the Middle East\n(<a rel=\"external\" href=\"https:\/\/www.careem.com\">Careem<\/a>) and basically one for every\n<a rel=\"external\" href=\"http:\/\/web.archive.org\/web\/20230211164448\/https:\/\/www.gett.com\/il\/\">country<\/a>\n<a rel=\"external\" href=\"https:\/\/www.cnbc.com\/2019\/04\/11\/uber-s-1-risk-factors-competitors-deleteuber-campaign-reputation.html\">in<\/a>\n<a rel=\"external\" href=\"https:\/\/taxi.yandex.ru\/\">the<\/a> <a rel=\"external\" href=\"https:\/\/www.gojek.com\/\">world<\/a>. The tech\nindustry rarely talks about these <em>Ubers of X<\/em>, but they serve millions of\ncustomers. While they start as exact copies of their well-known counterparts,\nsome of them end up offering better service thanks to their understanding of the\nlocal market.<\/p>\n<h2 id=\"people-always-find-a-way\"><a class=\"anchor\" href=\"#people-always-find-a-way\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>People Always Find a Way<\/h2>\n<p>With creativity, you can provide great service even without a big budget. The\nimportant part is to know which corners you can cut while staying true to your\nmission. If there\u2019s a market, there\u2019s a way. The Cubans have a word for it:\n<a rel=\"external\" href=\"https:\/\/medium.com\/@d.yau\/cubas-resolver-mentality-makes-it-the-next-startup-hub-2f10ea2096a0\"><em>resolver<\/em><\/a>,\nwhich means \u201cwe\u2019ll figure it out\u201d.<\/p>\n"},{"title":"How Does the Unix `history` Command Work?","pubDate":"Mon, 31 May 2021 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2021\/history\/","guid":"https:\/\/endler.dev\/2021\/history\/","description":"<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/history\/hero.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/history\/hero.jpg\" alt=\"Cozy attic created by [vectorpouch](https:\/\/www.freepik.com\/vectors\/poster) and tux created by [catalyststuff](https:\/\/www.freepik.com\/vectors\/baby) &mdash; freepik.com\" width=\"650\" height=\"436\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: Cozy attic created by <a rel=\"external\" href=\"https:\/\/www.freepik.com\/vectors\/poster\">vectorpouch<\/a> and tux created by <a rel=\"external\" href=\"https:\/\/www.freepik.com\/vectors\/baby\">catalyststuff<\/a> \u2014 freepik.com\n    <\/figcaption>\n<\/figure>\n<p>As the day is winding down, I have a good hour just to myself.\nPerfect time to listen to some <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=cJtL8vWNZ4o\">Billy Joel<\/a> (it\u2019s either Billy Joel or Billie Eilish for me these days) and learn how the Unix <code>history<\/code> command works.\nLife is good.<\/p>\n<p>Learning what makes Unix tick is a bit of a hobby of mine.<br \/>\nI covered <a href=\"\/2017\/yes\/\">yes<\/a>, <a href=\"\/2018\/ls\/\">ls<\/a>, and <a href=\"\/2018\/fastcat\/\">cat<\/a> before.\nDon\u2019t judge.<\/p>\n<h2 id=\"how-does-history-even-work\"><a class=\"anchor\" href=\"#how-does-history-even-work\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How Does history Even Work?<\/h2>\n<p>Every command is tracked, so I see the last few commands on my machine when I run <code>history<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">8680<\/span><span class=\"z-l-5 z-d-7\">  cd<\/span><span class=\"z-l-5 z-d-7\"> endler.dev<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">8682<\/span><span class=\"z-l-5 z-d-7\">  cd<\/span><span class=\"z-l-5 z-d-7\"> content\/2021<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">8683<\/span><span class=\"z-l-5 z-d-7\">  mkdir<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">8684<\/span><span class=\"z-l-5 z-d-7\">  cd<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">8685<\/span><span class=\"z-l-5 z-d-7\">  vim<\/span><span class=\"z-l-5 z-d-7\"> index.md<\/span><\/span><\/code><\/pre><h2 id=\"yeah-but-how-does-it-do-that\"><a class=\"anchor\" href=\"#yeah-but-how-does-it-do-that\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Yeah, but How Does It <em>Do<\/em> That?<\/h2>\n<p>The manpage on my mac is not really helpful \u2014 I also couldn\u2019t find much in the first place.<\/p>\n<p>I found <a rel=\"external\" href=\"https:\/\/medium.com\/macoclock\/forced-to-use-zsh-by-macos-catalina-lets-fix-our-history-command-first-9ce86dca540e\">this<\/a> article (it\u2019s good etiquette nowadays to warn you that this is a Medium link) and it describes a bit of what\u2019s going on.<\/p>\n<p>Every command is stored in <code>$HISTFILE<\/code>, which points to <code>~\/.zsh_history<\/code> for me.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> tail<\/span><span> $<\/span><span>HISTFILE<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-5 z-d-7\"> 1586007759:0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">cd<\/span><span class=\"z-l-5 z-d-7\"> endler.dev<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-5 z-d-7\"> 1586007763:0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">cd<\/span><span class=\"z-l-5 z-d-7\"> content\/2021<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-5 z-d-7\"> 1586007771:0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">mkdir<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-5 z-d-7\"> 1586007772:0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">cd<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-5 z-d-7\"> 1586007777:0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">vim<\/span><span class=\"z-l-5 z-d-7\"> index.md<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><\/span><\/code><\/pre>\n<p>So let\u2019s see. We got a <code>:<\/code> followed by a timestamp followed by <code>:0<\/code>, then a\nseparator (<code>;<\/code>) and finally the command itself. Each new command gets appended\nto the end of the file. Not too hard to recreate.<\/p>\n<p>Hold on, what\u2019s that 0 about!?<\/p>\n<p>It turns out it\u2019s the <strong>command duration<\/strong>, and the entire thing is called the <a rel=\"external\" href=\"https:\/\/zsh.sourceforge.io\/Doc\/Release\/Options.html#History\">extended history format<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">:<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span class=\"z-l-5 z-d-7\">beginning<\/span><span class=\"z-l-5 z-d-7\"> tim<\/span><span>e<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-5 z-d-7\">:<\/span><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-5 z-d-7\">elapsed<\/span><span class=\"z-l-5 z-d-7\"> second<\/span><span>s<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-2 z-d-5\">&lt;<\/span><span>command<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p>(Depending on your settings, your file might look different.)<\/p>\n<h2 id=\"hooking-into-history\"><a class=\"anchor\" href=\"#hooking-into-history\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Hooking into history<\/h2>\n<p>But still, how does <code>history<\/code> <em>really<\/em> work.<\/p>\n<p>It must run some code whenever I execute a command\n\u2014 <strong>a hook of some sort<\/strong>!<\/p>\n<div class=\"info\">\n    <p>\ud83d\udca5 <strong>Swoooooosh<\/strong> \ud83d\udca5<\/p>\n<p>Matthias from the future steps out of a blinding ball of light: <em>Waaait!\nThat\u2019s not really how it works!<\/em><\/p>\n<p>It turns out that shells like bash and zsh don\u2019t <em>actually<\/em> call a hook for <code>history<\/code>.\nWhy should they? When <code>history<\/code> is a shell builtin, they can just track the commands\n<em>internally<\/em>.<\/p>\n<p>Thankfully my editor-in-chief and resident Unix neckbeard <a rel=\"external\" href=\"https:\/\/github.com\/m3t0r\">Simon Br\u00fcggen<\/a>\nexplained that to me \u2014 but only <em>after<\/em> I sent him the first draft for this article. \ud83d\ude13<\/p>\n<p>As such, the next section is a bit like <em>Lord of the Rings<\/em>: a sympathetic\nbut naive fellow on a questionable mission with no clue of what he\u2019s getting\nhimself into.<\/p>\n<p>In my defense, Lord of the Rings is also enjoyed primarily for its entertainment\nvalue, not its <em>historical<\/em> accuracy\u2026. and just like in this epic story, I\npromise we\u2019ll get to the bottom of things in the end.<\/p>\n<\/div>\n<p>I found <a rel=\"external\" href=\"https:\/\/zsh.sourceforge.io\/Doc\/Release\/User-Contributions.html\">add-zsh-hook<\/a>\nand a usage example in <a rel=\"external\" href=\"https:\/\/github.com\/ellie\/atuin\/blob\/main\/atuin\/src\/shell\/atuin.zsh\">atuin\u2019s source code<\/a>.<\/p>\n<p>I might not fully comprehend all of that is written there, but I\u2019m a man of action, and I can take a solid piece of work and tear it apart.<\/p>\n<p>It\u2019s not much, but here\u2019s what I got:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Source this in your ~\/.zshrc<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">autoload<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">U<\/span><span class=\"z-l-5 z-d-7\"> add-zsh-hook<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_past_preexec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    echo<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">preexec<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_past_precmd<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    echo<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">precmd<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add-zsh-hook<\/span><span class=\"z-l-5 z-d-7\"> preexec<\/span><span class=\"z-l-5 z-d-7\"> _past_preexec<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add-zsh-hook<\/span><span class=\"z-l-5 z-d-7\"> precmd<\/span><span class=\"z-l-5 z-d-7\"> _past_precmd<\/span><\/span><\/code><\/pre>\n<p>This sets up two hooks: the first one gets called right before a command gets\nexecuted and the second one directly after. (I decided to call my little\n<code>history<\/code> replacement <em>past<\/em>. I like short names.)<\/p>\n<p>Okay, let\u2019s tell zsh to totally run this file whenever we execute a command:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">source<\/span><span class=\"z-l-5 z-d-7\"> src\/shell\/past.zsh<\/span><\/span><\/code><\/pre>\n<p>\u2026aaaaaand<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> date<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">preexec<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Fri<\/span><span class=\"z-l-5 z-d-7\"> May<\/span><span class=\"z-l-16 z-d-16\"> 28<\/span><span class=\"z-l-5 z-d-7\"> 18:53:55<\/span><span class=\"z-l-5 z-d-7\"> CEST<\/span><span class=\"z-l-16 z-d-16\"> 2021<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">precmd<\/span><\/span><\/code><\/pre>\n<p>It works! \u2728 <strong>How exciting!<\/strong> \u2728<\/p>\n<p>Actually, I just remember now that <a rel=\"external\" href=\"https:\/\/github.com\/mre\/envy\/blob\/master\/src\/hooks\/zsh.rs\">I did the same thing<\/a> for my little environment settings manager <a rel=\"external\" href=\"https:\/\/github.com\/mre\/envy\">envy<\/a> over two years ago, <a rel=\"external\" href=\"https:\/\/en.wiktionary.org\/wiki\/but_hey\">but hey<\/a>!<\/p>\n<p>So what to do with our newly acquired power?<\/p>\n<h2 id=\"let-s-run-some-rust-code\"><a class=\"anchor\" href=\"#let-s-run-some-rust-code\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Let\u2019s Run Some Rust Code<\/h2>\n<p>Here\u2019s the thing: only <code>preexec<\/code> gets the \u201creal\u201d command. <code>precmd<\/code> gets nothing:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_past_preexec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    echo<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">preexec <\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">$<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">@<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_past_precmd<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">    echo<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">precmd <\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">$<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">@<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p><code>$@<\/code> means \u201cshow me what you got\u201d and here\u2019s what it got:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> date<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">preexec<\/span><span class=\"z-l-5 z-d-7\"> date<\/span><span class=\"z-l-5 z-d-7\"> date<\/span><span class=\"z-l-5 z-d-7\"> date<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Fri<\/span><span class=\"z-l-5 z-d-7\"> May<\/span><span class=\"z-l-16 z-d-16\"> 28<\/span><span class=\"z-l-5 z-d-7\"> 19:02:11<\/span><span class=\"z-l-5 z-d-7\"> CEST<\/span><span class=\"z-l-16 z-d-16\"> 2021<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">precmd<\/span><\/span><\/code><\/pre>\n<p><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/dating\/comments\/cbomd5\/guy_asked_me_to_marry_him_after_first_date\/\">Shouldn\u2019t one \u201cdate\u201d be enough?<\/a><br \/>\nHum\u2026 let\u2019s look at the <a rel=\"external\" href=\"https:\/\/zsh.sourceforge.io\/Doc\/Release\/Functions.html\">zsh documentation for <code>preexec<\/code><\/a>:<\/p>\n<blockquote>\n<p>If the history mechanism is active [\u2026], the string that the user typed is passed as the first argument, otherwise it is an empty string. The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being executed.<\/p>\n<\/blockquote>\n<p>I don\u2019t know about you, but the third argument should be all we ever need? \ud83e\udd28<\/p>\n<p>Checking\u2026<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> ls<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">l<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">preexec<\/span><span class=\"z-l-5 z-d-7\"> ls<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">l<\/span><span class=\"z-l-5 z-d-7\"> lsd<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">l<\/span><span class=\"z-l-5 z-d-7\"> lsd<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">l<\/span><\/span><\/code><\/pre>\n<p>(Shout out to <a rel=\"external\" href=\"https:\/\/github.com\/Peltoche\/lsd\">lsd<\/a>, the next-gen ls command )<\/p>\n<p>Alright, good enough. Let\u2019s parse <code>$3<\/code> with some Rust code and write it to our own history file.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">OpenOptions<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Write<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> HISTORY_FILE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">lol<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> history<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> OpenOptions<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">create<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">true<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">append<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">true<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">open<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">HISTORY_FILE<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>command<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        writeln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>history<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> command<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> cargo<\/span><span class=\"z-l-5 z-d-7\"> run<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\"> dummy<\/span><span class=\"z-l-5 z-d-7\"> dummy<\/span><span class=\"z-l-5 z-d-7\"> hello<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> cargo<\/span><span class=\"z-l-5 z-d-7\"> run<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">-<\/span><span class=\"z-l-5 z-d-7\"> dummy<\/span><span class=\"z-l-5 z-d-7\"> dummy<\/span><span class=\"z-l-5 z-d-7\"> world<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> cat<\/span><span class=\"z-l-5 z-d-7\"> lol<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">hello<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">world<\/span><\/span><\/code><\/pre>\n<p>We\u2019re almost done \u2014 at least if we\u2019re willing to cheat a bit. \ud83d\ude0f\nLet\u2019s hardcode that format string:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">OpenOptions<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Write<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">time<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">SystemTime<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> HISTORY_FILE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">lol<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> timestamp<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u64<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SystemTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">duration_since<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">SystemTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-16 z-d-16\">UNIX_EPOCH<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>n<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_secs<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">dyn<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> history<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> OpenOptions<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">create<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">true<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">append<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">true<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">open<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">HISTORY_FILE<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Some<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>command<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        writeln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>history<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">: <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">:0;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> timestamp<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> command<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Now, if we squint a little, it sorta kinda writes our command in my history format.\n(That part about the Unix timestamp was taken <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/time\/struct.SystemTime.html\">straight from the docs<\/a>. Zero regrets.)<\/p>\n<p>Remember when I said that <code>precmd<\/code> gets nothing?<\/p>\n<p>I lied.<\/p>\n<p>In reality, you can read the exit code of the executed command (from <code>$?<\/code>). That\u2019s very helpful, but we just agree to ignore that and never talk about it again.<\/p>\n<p>With this out of the way, our final <code>past.zsh<\/code> hooks file looks like that:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">autoload<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">U<\/span><span class=\"z-l-5 z-d-7\"> add-zsh-hook<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">_past_preexec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    past<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> $<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">@<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add-zsh-hook<\/span><span class=\"z-l-5 z-d-7\"> preexec<\/span><span class=\"z-l-5 z-d-7\"> _past_preexec<\/span><\/span><\/code><\/pre>\n<p>Now here comes the dangerous part!\nStep back while I replace the original <code>history<\/code> command with my own.\nNever try this at home.\n(Actually I\u2019m exaggerating a bit. Feel free to try it. Worst thing that will happen is that you\u2019ll lose a bit of history, but don\u2019t sue me.)<\/p>\n<p>First, let\u2019s change the path to the history file to my real one:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> You should read the ${HISTFILE} env var instead ;)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> HISTORY_FILE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">\/Users\/mendler\/.zhistory<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Then let\u2019s install <code>past<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> cargo<\/span><span class=\"z-l-5 z-d-7\"> install<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">-path<\/span><span class=\"z-l-5 z-d-7\"> .<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> bleep bloop...<\/span><\/span><\/code><\/pre>\n<p>After that, it\u2019s ready to use.\nLet\u2019s add that bad boy to my <code>~\/.zshrc<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">source<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">\/Users\/mendler\/Code\/private\/past\/src\/shell\/past.zsh<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>And FINALLY we can test it.<\/p>\n<p>We open a new shell and run a few commands followed by <code>history<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\">  date<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> ls<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> it<\/span><span class=\"z-l-5 z-d-7\"> works<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><span class=\"z-l-10 z-l-i z-d-12 z-d-i\">.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\u276f\u276f\u276f<\/span><span class=\"z-l-5 z-d-7\"> history<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> 1011<\/span><span class=\"z-l-5 z-d-7\">  date<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> 1012<\/span><span class=\"z-l-5 z-d-7\">  ls<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> 1013<\/span><span class=\"z-l-5 z-d-7\">  it<\/span><span class=\"z-l-5 z-d-7\"> works<\/span><\/span><\/code><\/pre>\n<p>\u2728 <strong>Yay.<\/strong> \u2728 <a rel=\"external\" href=\"https:\/\/github.com\/mre\/past\">The source code for <code>past<\/code> is on Github.<\/a><\/p>\n<h2 id=\"how-it-really-really-works\"><a class=\"anchor\" href=\"#how-it-really-really-works\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How It <em>Really<\/em> <em>Really<\/em> Works<\/h2>\n<p>Our experiment was a great success, but I since learned that reality is a bit different.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/History_(command)#History\">\u201cIn early versions\nof Unix the history command was a separate program\u201d<\/a>, but most modern shells have <code>history<\/code> builtin.<\/p>\n<p>zsh tracks the history in its main <a rel=\"external\" href=\"https:\/\/github.com\/zsh-users\/zsh\/blob\/00d20ed15e18f5af682f0daec140d6b8383c479a\/Src\/init.c#L120\">run loop<\/a>.\nHere are the important bits. (Assume all types are in scope.)<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span>Eprog prog<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Main zsh run loop <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Init history <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    hbegin<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-2 z-d-5\">!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>prog <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> parse_event<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>ENDINPUT<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Couldn&#39;t parse command. Stop history <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        hend<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-10 z-d-12\">NULL<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        continue<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Store command in history <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">hend<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>prog<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    {<\/span><\/span>\n<span class=\"giallo-l\"><span>        LinkList args<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        args <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> newlinklist<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        addlinknode<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>args<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> hist_ring<\/span><span class=\"z-l-8 z-d-4\">-&gt;<\/span><span>node<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>nam<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        addlinknode<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>args<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> dupstring<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">getjobtext<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>prog<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> NULL<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        addlinknode<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>args<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> cmdstr <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> getpermtext<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>prog<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> NULL<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Here&#39;s the preexec hook that we used.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        * It gets passed all the args we saw earlier.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        *\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        callhookfunc<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">preexec<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> args<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> NULL<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Main routine for executing a command <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        execode<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>prog<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The history lines are kept in a hash, and also in a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Circular_buffer\">ring-buffer<\/a>\nto prevent the history from getting too big. (<a rel=\"external\" href=\"https:\/\/github.com\/zsh-users\/zsh\/blob\/00d20ed15e18f5af682f0daec140d6b8383c479a\/Src\/hist.c#L98-L103\">See here<\/a>.)<\/p>\n<p>That\u2019s smart! Without the ring-buffer, a malicious user could just thrash the history with random commands\nuntil a buffer overflow is triggered. I never thought of that.<\/p>\n<h2 id=\"history-time-see-what-i-did-there\"><a class=\"anchor\" href=\"#history-time-see-what-i-did-there\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>History Time (See What I Did There?)<\/h2>\n<p>The original <code>history<\/code> command was added to the Unix C shell (csh) in 1978.\nHere\u2019s a link to <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20220605000427\/http:\/\/www.kitebird.com\/csh-tcsh-book\/csh-intro.pdf\">the paper<\/a> by <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Bill_Joy\">Bill Joy<\/a> (hey, another Bill!).\nHe took inspiration from the <code>REDO<\/code> command in Interlisp.\nYou can find its specification in the original Interlisp manual in <a rel=\"external\" href=\"https:\/\/larrymasinter.net\/86-interlisp-manual-opt.pdf\">section 8.7<\/a>.<\/p>\n<h2 id=\"lessons-learned\"><a class=\"anchor\" href=\"#lessons-learned\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Lessons Learned<\/h2>\n<ul>\n<li>Rebuild what you don\u2019t understand.<\/li>\n<li>The history file is human-readable and pretty straightforward.<\/li>\n<li>The <code>history<\/code> command is a shell builtin, but we can use hooks to write our own.<\/li>\n<li>Fun fact: Did you know that in zsh, <code>history<\/code> is actually just an alias for <code>fc -l<\/code>? <a rel=\"external\" href=\"https:\/\/zsh.sourceforge.io\/Doc\/Release\/Shell-Builtin-Commands.html\">More info here<\/a> or <a rel=\"external\" href=\"https:\/\/github.com\/zsh-users\/zsh\/blob\/00d20ed15e18f5af682f0daec140d6b8383c479a\/Src\/builtin.c#L86\">check out the source code<\/a>.<\/li>\n<\/ul>\n<p>\u201cWhat I cannot create, I do not understand\u201d \u2014 Richard Feynman<\/p>\n"},{"title":"Spreadsheets Make for Great Business Ideas","pubDate":"Wed, 10 Mar 2021 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2021\/first-business\/","guid":"https:\/\/endler.dev\/2021\/first-business\/","description":"<p>One of the best decisions I made in 2020 was to open <a rel=\"external\" href=\"https:\/\/calendly.com\/matthias-endler\/chat\">my calendar<\/a> to everyone. People book appointments to chat about open-source projects, content creation, and business ideas.<\/p>\n<p>When we discuss business ideas, the conversation often leans towards problems suited for startups, such as using artificial intelligence to find clothes that fit or building a crowdfunding platform on the blockchain.<\/p>\n<p>While these are exciting ideas, they require significant persistence and deep pockets. It might be easier and less risky to join an existing startup in that domain.<\/p>\n<p>In reality, most people are simply looking for something cool to work on and to make their customers happy. It turns out you don\u2019t need to run a startup to achieve that (<a rel=\"external\" href=\"https:\/\/every.to\/napkin-math\/you-probably-shouldn-t-work-at-a-startup-9387b632-345c-4a22-bac0-3cb92f0eecf1\">and you probably shouldn\u2019t<\/a>). Instead, starting a side project is less risky and can organically grow into a business over time.<\/p>\n<p>Often, the solution is right in front of them: hidden within an Excel spreadsheet on their computer.<\/p>\n<h2 id=\"i-hate-excel\"><a class=\"anchor\" href=\"#i-hate-excel\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>I Hate Excel<\/h2>\n<p>I spend as little time in Excel as possible, only engaging with it when absolutely necessary. My focus is on getting tasks done quickly, not on layout or design; I\u2019d rather pay someone to do that work for me. And this is precisely my point!<\/p>\n<p>The spreadsheets and lists you create to solve your own problems can also solve someone else\u2019s. This represents a business opportunity!<\/p>\n<p>This approach has several advantages:<\/p>\n<ul>\n<li>\ud83d\udcaa It solves a real problem.<\/li>\n<li>\ud83e\udd71 It\u2019s mundane, so people might pay to avoid doing it themselves.<\/li>\n<li>\u26a1\ufe0f It wastes no time on design or infrastructure, embodying the ultimate MVP.<\/li>\n<li>\ud83d\udc22 It\u2019s low-tech: no programming required. You can start with <a rel=\"external\" href=\"https:\/\/notion.so\">Notion<\/a> and <a rel=\"external\" href=\"https:\/\/super.so\">Super.so<\/a>.<\/li>\n<li>\ud83d\udc1c It targets a niche market: if there were an established service, you\u2019d already be using it. Big corporations won\u2019t compete with you.<\/li>\n<li>\ud83d\ude80 It allows you to spend less time building and more time engaging with potential customers.<\/li>\n<\/ul>\n<h2 id=\"examples\"><a class=\"anchor\" href=\"#examples\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Examples<\/h2>\n<p>A few years ago, while researching static code analysis tools, I compiled a list, pushed it to GitHub, and moved on. Fast forward, and <a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/\">that side project<\/a> now generates revenue from sponsors and consulting gigs.<\/p>\n<p>Another example is a person who created a spreadsheet for remote work locations, shared it on Twitter, and then developed a website from it. The website is <a rel=\"external\" href=\"https:\/\/nomadlist.com\/\">NomadList<\/a>, and its creator, <a rel=\"external\" href=\"https:\/\/levels.io\/\">Pieter Levels<\/a>, now earns $300k\/year.<\/p>\n<blockquote>\n<p>\u201cInstead of building a site first, I simply made [a] public Google spreadsheet to collect the first data and see if there\u2019d be interest for this at all.\u201d \u2014 Pieter Levels on <a rel=\"external\" href=\"https:\/\/levels.io\/product-hunt-hacker-news-number-one\/\">how he created NomadList<\/a>.<\/p>\n<\/blockquote>\n<p><strong>I\u2019ve left a spot for your story here.<\/strong> Now, refine that spreadsheet (or list), share it with your friends, iterate based on their feedback, and build your first business.<\/p>\n"},{"title":"Starting a Print-on-Demand Business as a Software Engineer","pubDate":"Fri, 22 Jan 2021 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2021\/codeprints\/","guid":"https:\/\/endler.dev\/2021\/codeprints\/","description":"<p>One day I had the idea to make a print of my Github timeline.\nI liked the thought of bringing something \u201cvirtual\u201d into the real world. \ud83d\ude04<\/p>\n<p>So I called up my friend <a rel=\"external\" href=\"https:\/\/twitter.com\/schafele\">Wolfgang<\/a> and we built <a rel=\"external\" href=\"https:\/\/codeprints.dev\">codeprints<\/a>.\nIt\u2019s my first \u201cphysical\u201d product, so I decided to share my learnings.<\/p>\n<figure>\n    <a href=\"https:\/\/twitter.com\/KrauseFx\/status\/1348546742644580353\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_felix.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_felix.jpg\" alt=\"[Felix Krause](https:\/\/krausefx.com\/) of [fastlane](https:\/\/fastlane.tools\/) fame was one\nof our first customers and we are very thankful for this tweet promoting our\nservice, which gave us a huge traffic boost.\" width=\"650\" height=\"860\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        <a rel=\"external\" href=\"https:\/\/krausefx.com\/\">Felix Krause<\/a> of <a rel=\"external\" href=\"https:\/\/fastlane.tools\/\">fastlane<\/a> fame was one\nof our first customers and we are very thankful for this tweet promoting our\nservice, which gave us a huge traffic boost.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"launching-is-hard-so-launch-early\"><a class=\"anchor\" href=\"#launching-is-hard-so-launch-early\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Launching Is Hard, so Launch Early<\/h2>\n<p>Even though I knew that launching early was vital, I still didn\u2019t want to\n\u201ccommit\u201d to the final design shortly before the planned go-live. There was always that last bug to fix or that little extra feature to implement.\nFor example, I wanted to offer two designs\/layouts: the classic Github contribution timeline and a graph-based design for repositories.\nIn cases like that, it helps to have a co-founder.\nWolfgang convinced me that multiple layouts were not needed for the MVP and that whatever we\u2019d come up with would probably be wrong anyway without getting early user feedback.\nHe was right. Without Wolfgang, the shop would probably still not be live today.\nWe have a much clearer vision now of what people want to see, thanks to launching early. Turns out users were not really interested in the graph-based design after all, and it would have been a waste of time to create it.<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nEven if you know all the rules for building products, it\u2019s\ndifferent when applying them in practice for the first time. We\u2019ll probably\nnever be completely happy with the shop functionality, but it\u2019s better to launch\nearly and make incremental improvements later.<\/p>\n<\/div>\n<h2 id=\"software-development-is-easy\"><a class=\"anchor\" href=\"#software-development-is-easy\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Software Development Is Easy<\/h2>\n<p>When we started, my main concern was software development. The frontend and the\nbackend needed to be coded and work together. We didn\u2019t want to run into Github rate-limiting issues in case there were many users on the site. I was also\nthinking a lot about which web frontend to use. Should we build it in Rust using\n<a rel=\"external\" href=\"https:\/\/github.com\/yewstack\/yew\">Yew<\/a> or better go with <a rel=\"external\" href=\"https:\/\/www.gatsbyjs.com\/\">Gatsby<\/a>?<\/p>\n<p>Turns out writing the code is the easy part.<\/p>\n<p>Being software engineers, it didn\u2019t take us too long to implement the backend\nAPI and we quickly found a decent template for the frontend. Most of our time\nwas spent thinking about the product, the user experience,\nfinancing, taxes, the shipping process, marketing, and\nintegrating customer feedback.\nThese were all things I had (and still have) little experience in.<\/p>\n<p>Wolfgang suggested to \u201cjust use Shopify and the default template\u201d to get started\nquickly. In hindsight, it was the absolute right decision. I always thought\nShopify was for simple mom-and-pop stores, but it turns out it\u2019s highly\ncustomizable, integrates well with pretty much anything, and offers excellent tooling\nlike <a rel=\"external\" href=\"https:\/\/shopify.github.io\/themekit\/\">themekit<\/a>. Payments, refunds,\ndiscounts, customer analytics: it\u2019s all built into the platform. It\nsaved us sooo much development time.<\/p>\n<figure>\n    <a href=\"https:\/\/twitter.com\/matthiasendler\/status\/1349308007839109122\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_product.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_product.jpg\" width=\"650\" height=\"860\"\n    \/>\n    <\/picture>\n    <\/a>\n<\/figure>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nThere are many <a rel=\"external\" href=\"https:\/\/medium.com\/datadriveninvestor\/known-knowns-unknown-knowns-and-unknown-unknowns-b35013fb350d\">unknown\nunknowns<\/a>\n\u2014 things we are neither aware of nor understand \u2014 when starting a project.\nTry to get to the root of the problem as soon as possible to save time and avoid\nthe <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Sunk_cost\">sunk cost fallacy<\/a>.<\/p>\n<\/div>\n<h2 id=\"users-expect-great-ui-ux\"><a class=\"anchor\" href=\"#users-expect-great-ui-ux\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Users Expect Great UI\/UX<\/h2>\n<p>Giants like Amazon, Facebook, and Netflix have raised customer\nexpectations for great UX. They spend millions polishing their websites and getting every detail right. As a result, their sites work <em>just right<\/em> for millions of customers and on every device.<\/p>\n<p>An indie shop does not have these resources. Nevertheless, many customers expect the same quality user experience as on other sites they use.\nBeing on the other side of the fence for the first time, I learned how hard it\nis to build a user interface that works for 90% of the people. Every little\ndetail \u2014 like the order of form fields \u2014 makes a huge difference. Get too\nmany details wrong, and you lose a customer.<\/p>\n<p>Those things can only be found by watching real users use your product. I promise you, it will be eye-opening!<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nWatch potential customers use your service. It will be\npainful at first, but will improve the quality of your product. Use standard\nframeworks for shops if you can because they get many UI\/UX details\nright out of the box. <a rel=\"external\" href=\"https:\/\/woocommerce.com\/\">WooCommerce<\/a> or\n<a rel=\"external\" href=\"https:\/\/www.shopify.com\/\">Shopify<\/a> come to mind.<\/p>\n<\/div>\n<h2 id=\"building-products-means-being-pragmatic\"><a class=\"anchor\" href=\"#building-products-means-being-pragmatic\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Building Products Means Being Pragmatic<\/h2>\n<p>We have many ideas for future products. Many friends and customers tell us about\npotential features all the time, but the problem is how to prioritize them.\nMost ideas won\u2019t work at scale: It\u2019s tricky to find a supplier that has a\nproduct on offer, is cheap, ships worldwide, and has a working integration with\nyour shop-system. So we have to regularly scrap product ideas, simply\nbecause our suppliers\u2019 support is not there. On top of that, we run the\nbusiness next to our day job and other\nresponsibilities, so we need to make use of our time as efficiently as possible.<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nMaking services look effortless is hard work. Time is your biggest constraint.\nYou\u2019ll have to say \u201cno\u201d more often than you can say \u201cyes\u201d.<\/p>\n<\/div>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/codeprints\/whereby.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/codeprints\/whereby.jpg\" alt=\"Due to the pandemic, codeprints was\nentirely built remotely. More people should give [whereby](https:\/\/whereby.com\/)\na try.\" width=\"650\" height=\"395\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Due to the pandemic, codeprints was\nentirely built remotely. More people should give <a rel=\"external\" href=\"https:\/\/whereby.com\/\">whereby<\/a>\na try.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"getting-traction-as-a-small-business\"><a class=\"anchor\" href=\"#getting-traction-as-a-small-business\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Getting Traction as a Small Business<\/h2>\n<p>It has never been easier to launch a shop. Services like Shopify, Stripe, and a\nhost of suppliers make starting out a breeze. On the other hand, there is a lot\nmore competition now that the barrier to entry is so low.<\/p>\n<p><strong>Thousands<\/strong> of services are constantly competing for our attention. On top of\nthat, most customers just default to big platforms like Amazon, AliExpress, or eBay\nfor their shopping needs these days, and search engines send a big chunk of the traffic there.<\/p>\n<p>Since our product is custom-made, we can not offer it on those bigger platforms.\nAs an indie shop, we get most visitors through word of mouth, exceptional\ncustomer support, and advertising where developers hang out:\n<a rel=\"external\" href=\"https:\/\/twitter.com\/KrauseFx\/status\/1348546742644580353\">Twitter<\/a>, <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/github\/comments\/kvvd3j\/i_just_got_my_github_contribution_wall_art_from\/\">Reddit<\/a>, <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=25749287\">HackerNews<\/a>, <a rel=\"external\" href=\"https:\/\/lobste.rs\/s\/b5fbw8\/create_personal_prints_from_your_github\">Lobste.rs<\/a>, and friends. It\u2019s essential to focus on\nproviding value on those platforms; a plain marketing post won\u2019t get you any attention. Other\nplatforms like LinkedIn, Facebook, ProductHunt, or IndieHackers could also work, but our target audience (OSS developers with an active Github profile) doesn\u2019t\nhang out there that much.<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong> Always know where your customers are and understand their needs.<\/p>\n<\/div>\n<h2 id=\"finding-a-niche-is-only-half-the-job\"><a class=\"anchor\" href=\"#finding-a-niche-is-only-half-the-job\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Finding a Niche Is Only Half the Job<\/h2>\n<p><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/startups\/comments\/53fynp\/niche_market_and_peter_thiels_monopoly_theory\/\">Common market wisdom<\/a> is to find niche and grow from within. With codeprints we definitely found our niche: the audience is very\nnarrow but interested in our geeky products. There are 56 million developers on\nGithub today; that\u2019s a big target audience. Most profiles are not very active,\nthough. To make a print look attractive, you\u2019d have to consistently commit\ncode over a long period of time \u2014 many years. If we assume that only 1% of\ndevs are active, that limits our target audience to 560.000 users. That\u2019s still\na big but much smaller market. Now, if only 1% of these people find the shop and\norder something (which would be quite a good ratio), we\u2019re looking at 5.600\norders total. Not that much!<\/p>\n<p>In order to extend that audience, one could either increase the number of\npotential customers or focus on getting more of the existing potential customers\non the page.\nIn our case, we expanded by offering a one-year layout, reducing the\nrequired level of Github activity for a cool print. We are also working on making\nemptier profiles look more interesting and highlighting the value-producing part\nof open source contribution. Every contribution counts \u2014 no matter how tiny.<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nMake sure that your niche market is not too narrow so that you can make a sustainable business out of it.<\/p>\n<\/div>\n<figure>\n    <a href=\"https:\/\/twitter.com\/orta\/status\/1350058678418878465\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_orta.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/codeprints\/tweet_orta.jpg\" alt=\"Early adopters like [Orta\nTherox](https:\/\/orta.io\/) are incredibly precious when starting out. Not\neverybody has a rockstar profile like that, though (and that's fine).\" width=\"650\" height=\"758\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        Early adopters like <a rel=\"external\" href=\"https:\/\/orta.io\/\">Orta\nTherox<\/a> are incredibly precious when starting out. Not\neverybody has a rockstar profile like that, though (and that\u2019s fine).\n    <\/figcaption>\n<\/figure>\n<h2 id=\"make-user-feedback-actionable\"><a class=\"anchor\" href=\"#make-user-feedback-actionable\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Make User Feedback Actionable<\/h2>\n<p>Initial customer feedback is precious. You should focus on every word these\ncustomers say as they believe in your product and want you to win. (They voted\nwith their wallet after all.) Feedback from\nfriends is helpful, too, but I usually apply a bigger filter to that. Not all\nof my friends are software developers, and while they all mean well, what they\ntell me might be different from what they mean. It\u2019s like they\nare asking for <a rel=\"external\" href=\"https:\/\/hbr.org\/2011\/08\/henry-ford-never-said-the-fast\">faster\nhorses<\/a> when what they\nreally want is a car.\nFeedback on social media can be\u2026 snarky at times; be prepared for that! Your job\nis to find the grain of truth in every statement and focus on constructive\nadvice.<\/p>\n<p>For example, take <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/github\/comments\/kvvd3j\/i_just_got_my_github_contribution_wall_art_from\/gj1g015?utm_source=share&amp;utm_medium=web2x&amp;context=3\">this feedback<\/a> we got:<\/p>\n<blockquote>\n<p>How lazy can someone be to pay \u20ac36 for this.<\/p>\n<\/blockquote>\n<p>You could turn it around to make it constructive:<\/p>\n<blockquote>\n<p>Can I get a cheaper version to print myself?<\/p>\n<\/blockquote>\n<p>And that is some valuable feedback. We could provide a downloadable version in\nthe future!<\/p>\n<div class=\"info\">\n    <p><strong>Lesson learned:<\/strong>\nIt takes practice to extract actionable feedback from user input and make it fit your product vision.<\/p>\n<\/div>\n<h2 id=\"summary\"><a class=\"anchor\" href=\"#summary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Summary<\/h2>\n<p>2020 was a crazy year.\nI helped launch two small side-businesses, codeprints and\n<a rel=\"external\" href=\"https:\/\/endler.dev\/2020\/sponsors\/\">analysis-tools.dev<\/a>.<\/p>\n<p>Both have an entirely different revenue model, but\nthey have one thing in common: they were <strong>super fun<\/strong> to build! \ud83e\udd29\nIt\u2019s motivating to look back at those achievements sometimes\u2026\nThat print of 2020 pretty much encapsulates those feelings for me.\n(Note the greener spots in August and September, which is when we launched\nanalysis-tools and the days in December when we built codeprints.)<\/p>\n<figure>\n    <a href=\"https:\/\/codeprints.dev\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/codeprints\/vertical.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/codeprints\/vertical.jpg\" alt=\"My coding year in review using our new\nvertical layout.<br \/>Here's to\nbuilding more products in 2021.\" width=\"650\" height=\"1029\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        My coding year in review using our new\nvertical layout.<br \/>Here\u2019s to\nbuilding more products in 2021.\n    <\/figcaption>\n<\/figure>\n<p>Let me know if you found that post helpful and reach out if you have questions.\nOh and if you\u2019re looking for a unique way to decorate your home office, why not\nget your own print from <a rel=\"external\" href=\"https:\/\/codeprints.dev\">codeprints<\/a>? \ud83d\ude0a<\/p>\n<p>P.S.: If you\u2019re a product owner and you\u2019re looking for a unique present for your\nteam, <a href=\"mailto:support@codeprints.dev?subject=codeprints%20for%20teams&amp;body=Hi%20there\">get in contact<\/a> and be the first to get an invite to a private beta.<\/p>\n"},{"title":"So You Want to Earn Money with Open Source","pubDate":"Mon, 04 Jan 2021 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2021\/oss-money\/","guid":"https:\/\/endler.dev\/2021\/oss-money\/","description":"<p>I earned 0 Euros from maintaining OSS software for years, and I thought that\u2019s\nthe way things are. I finally looked into ways to monetize my projects last year\nand in this talk I want to share what I learned so far. It didn\u2019t make me\nrich (yet!), but I built my first sustainable side-project with\n<a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/\">analysis-tools.dev<\/a> \u2728.<\/p>\n<p>I\u2019ll talk about this and other projects and the mistakes I made on the road\ntowards sustainability.<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/NlKuICiT470\"\n>\n  <picture>\n    <source srcset=\"maxresdefault.avif\" type=\"image\/avif\" \/>\n    <img src=\"maxresdefault.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p>Related links and resources:<\/p>\n<ul>\n<li>Podcast by <a rel=\"external\" href=\"https:\/\/calebporzio.com\/\">Caleb Porzio<\/a> about why building\na business around Github sponsors is <a rel=\"external\" href=\"https:\/\/podbay.fm\/p\/building-livewire\/e\/1593614940\">so\nhard<\/a>.<\/li>\n<li>The Changelog Podcast \u2014 <a rel=\"external\" href=\"https:\/\/changelog.com\/podcast\/405\">It\u2019s OK to make money from your open source<\/a>\nwith <a rel=\"external\" href=\"https:\/\/zenorocha.com\/\">Zeno Rocha<\/a>.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/nadia.xyz\/\">Nadia Eghbal<\/a> talking about <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=TMxBf-Ohgmg\">Maintenance of our essential info-structure<\/a>. She also wrote a book on that topic\ncalled <a rel=\"external\" href=\"https:\/\/amzn.to\/3vAl43v%22\">Working in Public<\/a>.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/vadimdemedes.com\/posts\/generating-income-from-open-source\">Generating income from open source<\/a> by <a rel=\"external\" href=\"https:\/\/twitter.com\/vadimdemedes\">Vadim Demedes<\/a>, which explains different ways to monetize your projects based on various real-world examples.<\/li>\n<\/ul>\n<p>Find a full transcript of the talk below. (Sorry for the wall of text.)<\/p>\n<hr \/>\n<p>This is my talk about earning money with Open Source, which I gave at the Web\nEngineering Meetup Aachen at the end of 2020. The organizers gladly allowed me\nto share it on my YouTube channel. I\u2019m basically trying to answer the question:\n\u201cWhy am I not making 100k on Github?\u201d. I\u2019m talking about finding corporate\nsponsors for myself and the long road towards sustainability of open-source\nmaintenance.<\/p>\n<p>You might not even want to start. This is a talk for those people that have\nthe mindset that it\u2019s probably not worth it to spend that much effort on Open\nSource if it takes so long until you find success. Now, this talk turned out to\nbe a little grim. I had this very motivational talk in mind, but in reality,\nit\u2019s hard, and by hard, I mean it\u2019s really hard.<\/p>\n<p>I just want to get this point across and maybe still motivate you to do it but\nfirst: why am I entitled to talk about this? I\u2019ve been doing Open Source for 10\nyears over 10 years now. This is a talk dedicated to my former self maybe 15\nyears ago. I work at trivago, which is a hotel search company based in\nD\u00fcsseldorf. I have a blog at endler.dev. Like everyone and their mom, I also\nhave a YouTube channel. It\u2019s called <a rel=\"external\" href=\"https:\/\/corrode.dev\/hello-rust\/\/\">Hello, Rust!<\/a> and I\u2019m\nextremely active with one video every two years. Hence, you definitely want to\nsubscribe to not miss any updates. But today, I want to talk about Open Source,\nand I have a very sophisticated outline with two points my journey and revenue\nmodels.<\/p>\n<p>Let\u2019s go back all the way to 2010. The world definitely looked a bit different\nback then.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2021\/oss-money\/github.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2021\/oss-money\/github.jpg\" alt=\"Github in 2010\" width=\"650\" height=\"331\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Github in 2010\n    <\/figcaption>\n<\/figure>\n<p>This was Github, and I was a bit late to the game. I joined in January 2010, and\nby then, Github was already two years old, so my username was taken. I usually\ngo by the handle <code>mre<\/code> on platforms, and I noticed that this handle was not\nused by anyone, so I just sent a mail to support and asked if I could have it,\nand then I got an answer from this guy saying \u201cgo for it.\u201d It was Chris\nWanstrath, who goes by the handle defunct, and he\u2019s the former CEO of Github,\nand at this point in time, I was hooked. I really liked the platform. I really\nliked how they worked very hands-on with Open Source. I used it for some\nprojects of mine; you can see in the screenshot that I uploaded my blog, for\nexample, because they host it for free. It was built with Jekyll, and you just\npush it to their site. Then they statically generate it, and it\u2019s done. It goes\nwithout saying that nothing has changed in the last 10 years because my blog\nmore or less still looks like that. It\u2019s not built with jQuery and Jekyll\nanymore, but with zola and Cloudflare Worker Sites, but it\u2019s more or less the\nsame thing. For preparing for this talk, I wanted to take a step back and see\nwhere I was coming from and where I am right now, and probably the best way to\ndo it is to look up some statistics and see if the number of repositories over\ntime would give me some insights. So I queried the Github API for that.<\/p>\n<p>You can see it\u2019s pretty much a linear graph from 2010 all the way to 2020.\nExcept for 2018, where I reached peak productivity, it seems, but oh well. In\nthe end, it\u2019s more or less a linear thing, and you might say you put some work\nin you get some feedback out, but in reality, it\u2019s different. There is a\ncompound effect. If we look at my number of stars over time, you can see that\nmore or less it started very slowly, and now it\u2019s sort of growing exponentially,\nso right now, we are at 25.000 stars across all projects. Another way to look at\nit would be the number of followers. That\u2019s kind of a new metric to me, but I\ndid look up some statistics from archive.org (because Github doesn\u2019t have that\ninformation through their API), and again, it\u2019s more or less exponential growth.<\/p>\n<p>You put some work in, but you get a compound effect of your work plus some\ninterest out. This is not luck; it\u2019s work. It means you know what you\u2019re doing.\nAt the same time, there\u2019s the elephant in the room, and that is it\u2019s just a pat\non the back. We have earned zero dollars until now, and one question you might\nhave is how do you monetize this effort.<\/p>\n<p>First off, is it an effort?<\/p>\n<p>Well, I don\u2019t know about you, but I probably spend two or three hours on average\nper day on Open Source: thinking about Open Source and creating new projects,\nbut also maintaining and code review, so it really is work, and it\u2019s a lot of\nwork, and you more or less do that for free.<\/p>\n<p>There\u2019s nothing wrong with doing things for free and doing it as a hobby, but in\nthis case, you are supposed to be working on whatever you like. Open Source is\nnot like that; sometimes you have obligations, and you feel responsible for\nmaybe helping people out, which is a big part of it. You do that next to your\nregular work, so it can really be a burden. If you don\u2019t know by now, making\nthis somehow valuable is hard, it\u2019s really hard. I want to talk about some ways\nto build a proper revenue model from Open Source. It goes without saying that\nthis should probably not be your first focus if you saw the graphs before, but\nonce you reach a point where you want to get some revenue, you have a couple of\noptions. I don\u2019t want to talk about doing Open Source as part of your business,\nand I don\u2019t want to talk about bigger companies and more significant support\nhere. I want to focus on a couple things that everyone can do. Sponsoring [on\nGithub] is one. Offer paid learning materials on top of your normal\ndocumentation. For example, you might have a video series that you ask for\nmoney. Sell merchandising like Mozilla does. Consulting next to your Open Source\nbusiness Services and plugins like writing an ADFS plugin or high availability\nfunctionality are very common examples for paid features targeting enterprises.<\/p>\n<p>But let\u2019s start with the basics. Let\u2019s start with point number one, sponsoring.\nThere are two types of sponsoring: the first one is individual donations.\nIndividual sponsoring is what Github Sponsors is all about. If you want to earn\nmoney [with that model], you have to think about the funnel, and you have to\nthink about how you capture people\u2019s attention and how you monetize that. It\nstarts with a product, [which] can be anything. From there, you generate\ninterest, and this interest creates an audience, and that audience eventually\nmight pay for your service, and this is actually the entire secret. It\u2019s how you\nearn money with any product, and with Open Source, if you want to attract\nsponsors, you build a product people want.<\/p>\n<p>If you transfer that to Open Source, building a project is maybe a repository,\nand the stars indicate the interest of the audience. The audience itself is made\nout of followers (personal followers or followers of a company), and those\nfollowers might or might not become sponsors in the end. Now, I know stars are a\nterrible metric for popularity because some people use stars differently than\nothers. For example, some use it as bookmarks to check out projects later,\nothers want to thank the developers for maybe putting in a lot of effort, and so\non, but it\u2019s a good first estimation.<\/p>\n<p>Now, think about the following. Think about the number of stars I have and the\nfollowers and the number of sponsors. Think about my \u201cfunnel\u201d right now. I told\nyou that I have 25.000 stars and roughly 1000 followers, and out of those, I\nhave three sponsors, so the ratio between the stars and sponsors is 0.01. That\nlooks pretty grim. It means you need around 8.000 stars to attract a single\nsupporter. I was wondering: \u201cmaybe it\u2019s just me?\u201d. Maybe the top 1000 Github\nmaintainers did not have that problem. Well, it turns out it\u2019s exactly the same\nschema. If you take the top 1000 Github maintainers and look at their sponsors,\nit\u2019s again a pretty grim picture. For example, looking at the median, you look\nat 3421 followers per person and a median of zero sponsors. That\u2019s zero percent\nif my math is correct, and if you look at the average, you even have 5430\nfollowers (because Linus Torvalds pushes that number up). You have 2.8 sponsors\nout of that on average, and that is 0.5%, which is a bit more than I have, but\nit\u2019s roughly in the same ballpark. Now think about this: Github has 40 million\nusers, so that means the top 1000 maintainers make up 0.0025% of the entire\ncommunity. The median income of those maintainers on Github is basically zero.<\/p>\n<p>That in and on itself is maybe not the biggest problem, but keep in mind that\nthe Github revenue of 2019 was 300 million dollars. I read that <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=23219251\">comment on\nHacker News<\/a> yesterday:<\/p>\n<blockquote>\n<p>I have sponsors on Github and rake in a cool two dollars per month. It\u2019s\nobviously less after taxes, so I have to have a day job.<\/p>\n<\/blockquote>\n<p>So this is clearly not working. You have to think of different ways to monetize\nOpen Source, or you just wait until Github Sponsors becomes more popular \u2013\nwhatever happens first. One way I just want to quickly touch on is the notion of\nsponsorware. It\u2019s kind of a new concept, and some people haven\u2019t heard of it\nbefore. I honestly really like it. Generally speaking, you create a project, and\nyou keep it private. You talk about it on Twitter, though or any other platform,\nand you say: \u201chey, I\u2019m building this, but if you want early access, you have to\nbecome a sponsor,\u201d and once you reach a certain threshold of sponsored sponsors,\nor income or whatever. Then you make a project public. This initial example that\nI showed you, where someone was earning 100k on Open Source, is from someone\ndoing just that. He\u2019s building products and services, talks about them, and then\nmakes them open for everyone in the end.<\/p>\n<p>This has some advantages: first of you get early feedback from people that\nreally believe in your mission. Second, you don\u2019t have to work for free all the\ntime, and third, you might also create an audience and hype from your projects.\nThe disadvantage is that if you are a hardcore Open Source or free software\nbeliever, this goes against your ethic. You want the software to be open, to\nbegin with, without any additional requirements. So you really have to make up\nyour own mind about that. I tried, and I have an early access program, which I\nonly share with sponsors. [My first sponsorware was a] tool for getting Github\nstatistics. [The statistics from this talk were] created with that tool. I think\nyou need a big audience to pull that off. The question is if you want to put\nthat much effort in, or you just want to make it open in the first place and\nthink about other revenue models. However, I think still it\u2019s a very interesting\nconcept, and we might see that [more] in the future, so you know how it looks\nlike now, and you have a name for it.<\/p>\n<p>Another one is corporate sponsoring. This is a double-edged sword because\ncorporate sponsoring means that a company gives you money and sometimes wants\nsomething. They might want additional support, or they want the bug to be fixed,\nand more or less it feels like you are somehow beginning to work for them, but\nnevertheless, those companies put in quite a big amount of money into Open\nSource these days. Looking at two big companies, Facebook and Google, they\ninvested 177k and 845k respectively into Open Source over their lifetime on Open\nCollective, a platform for collecting those donations. That\u2019s really great. We\nneed more companies doing that, but also, as a little side note and maybe as a\nlittle rant, I believe that those companies are doing way too little.<\/p>\n<p>Facebook\u2019s revenue last year was 70 billion, and Google had 160 billion, which\nis nothing to be ashamed of, so I wonder really if this is the most they can do.\nOf course, Google, for example, also donated to other projects like Mozilla, and\nthey also organize meetups and so on. But do you really think that Facebook and\nGoogle would exist today if there was no Python or web server or Linux back in\nthe day when two Stanford students tried to build a search engine? Sometimes I\nfeel that Fortune 500 companies really don\u2019t understand how much they depend on\nOpen Source and how many people depend on a few people who maintain critical\nparts of our infrastructure.<\/p>\n<p>I don\u2019t think they invest nearly enough into Open Source. What a lot of people\nthink is that Open Source works like the panel on the left where you have a full\nroom of engineers trying to figure out the best way to build a project, and in\nreality, it\u2019s more or less someone working late at night to fix bugs and doing\nit because they believe in it. The public perception is probably wrong, and a\nreally small group of people who maintain critical infrastructure. Sometimes\nthat can lead to very tricky situations. Two of my childhood heroes talked about\nit openly: <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20221024021910\/https:\/\/kennethreitz.org\/\">Kenneth\nReitz<\/a> is\nthe core maintainer of requests for Python and <a rel=\"external\" href=\"http:\/\/invece.org\/\">antirez<\/a> is\nthe creator of\n<a rel=\"external\" href=\"https:\/\/redis.io\/\">Redis<\/a>, a key-value store. So one is front-end development\nand the other one from backend-end. They both talk about burnout here because\nthe burden of becoming an Open Source maintainer on a big scale can very much\nand very quickly lead to burnout. The internet never sleeps. You never go to\nsleep. You always get a ticket, a feature request, a pull request, an issue. You\nalways have something to work on, and on top of that, you have to do all your\nother responsibilities, so that can lead to burnout really quickly. There was\none guy who I also respect deeply. His name is Mark Pilgrim. He is the author of\nDive Into Python, and he once pulled a 410 for deleting everything [about him]\non the internet. There\u2019s actually a term for it: infocide for \u201cinformation\nsuicide.\u201d He got fed up with the ecosystem, and if you think about the Ruby\ncommunity, you might remember _why, the author of the Poignant Guide to Ruby.\nHe did kind of the same thing. Focusing on what antirez has said, \u201conce I\nstarted to receive money to work at Redis, it was no longer possible for my\nethics to have my past pattern, so I started to force myself to work on the\nnormal schedules. This, for me, is a huge struggle for many years. At this\npoint, moreover, I\u2019m sure I\u2019m doing less than I could, because of that, but this\nis how things work\u201d, so it feels like he feels guilty for maybe being forced\ninto that work schedule and maybe not performing well enough. There are some\nsigns of burnout for me somehow, and it\u2019s that love-hate relationship of Open\nSource and money. If you accept money, it becomes a job, but you\u2019re not writing\ncode most of the time. You\u2019re writing the talks, reviewing pull requests, you\u2019re\nlooking at issues, you\u2019re answering questions on StackOverflow, you\u2019re\ndiscussing on Discord, you\u2019re marketing on YouTube or conferences. When you\nbecome popular with Open Source, then it feels like you have a choice between\ntwo options: one is depression and the other one is burnout. If your project\ndoes not become successful, then suddenly you think you\u2019re a failure, you\u2019re a\nmistake. It has zero stars; nobody likes it. But if it becomes a success, then\neveryone likes it, and you get hugged to death. That\u2019s a really unfortunate\nsituation to be in, and you want to stop being overwhelmed with those\nresponsibilities. You have to set clear boundaries and pick your poison. You\nhave to be careful if you accept companies as sponsors. I want to show you one\nexample of how it can work and [point out] some risks. Earlier this year, I\nstarted working on a real project that I had been putting off for many years\nbefore.<\/p>\n<p>You see, in December 2015, I started a list of static analysis tools on Github.\nStatic analysis tools are just tools that help you improve your code, and it\nturns out that there\u2019s a lot of those tools. Just starting to collect them was\nthe first step. I didn\u2019t think much about it, but over time that became really\npopular. And you can see that this graph is more or less a linear increase in\nstars over time. In 2018, I started really thinking hard about whether there was\nmore than just a Github project here. I talked to many people that I had this\nidea of building something more from that. It really took someone else to maybe\npush me over the finishing line and convinced me that this was worth it, and\nthat is Jakub. He said, \u201cwhy not build a website from it?\u201d and over the course\nof maybe two weekends or so, we built a website. It\u2019s built with Gatsby, but it\nreally doesn\u2019t matter. We just did it, and then we saw what happened to it. We\nrender 500 tools right now, and the initial feedback was really great. People\nreally seem to like that. We got a cool 720.000 requests on the first day, and\nover the next week or so, it more or less hit 1.5 million. That was great\nbecause suddenly people started getting interested in that project. So we\nstarted finding some sponsors. Those companies are special because they believe\nin your mission, but they also know how Open Source works. They don\u2019t really\nexpect you to advertise their tool. They want to sell to developers, so they\nwant to be in the developers\u2019 minds, saying: \u201cHey! You are a developer. We built\nthis amazing tool you might want to check it out!\u201d but they also get seen as an\nOpen Source company. I think that\u2019s a win-win. I have to say it doesn\u2019t always\ngo as easily. sometimes companies expect you to just have cheap advertising\nspace. Then they jump off the moment they see you don\u2019t get that many clicks,\nbut others understand that they invest into something that maybe pays off in a\nyear or two from now. So I\u2019m really thankful that some companies understand that\nmission. However, what companies want is different than what individuals want.\nCompanies want an invoice. Companies want something tax-deductible. Companies\nwant someone that keeps the lights on and is responsive via email, so you really\nhave those obligations, and one platform that helps with that is Open\nCollective. They have a 501c6 program for Open Source projects that acts as a\nfiscal host, which means they will do all the invoicing and officially be the\nmaintainers. If you, as an Open Source maintainer or a contributor to a project,\nwant to get [reimbursed for your work], you have to send an invoice to open\ncollective.<\/p>\n<p>I think that\u2019s the best of both worlds. Again, because it\u2019s a very transparent\nprocess, companies are in the loop and don\u2019t have to deal with all the financial\nstuff. But it also means that you have to really polish your public perception.\nCompanies really want to know what they can get out of sponsoring you, and you\nhave to make that very clear. Probably the most important site that you have is\nnot your website, but it\u2019s your sponsors page on Github where you describe the\ndifferent tiers and what those tiers mean, so we have three tiers: One is\ntargeted at smaller companies and freelancers. They just get exposure, and they\nget seen as an Open Source friendly tech company. That is a hundred dollars a\nmonth. We have a middle-tier, a company sponsor that maybe is a bigger company.\nThey get the batch, too, but they also get a blog post about a static analysis\ntool that they want to promote, but we make it transparent that this is really a\nsponsored content. Finally, if you want to go all the way, you go to full\ncontent creation, which might be a video workshop, but we don\u2019t have video\nworkshop sponsors yet, so I cannot talk about that yet. I have to say I really\nwould like to try though and it\u2019s cheap really for what you get.<\/p>\n<p>Anyway, those are things that you can do today. Without really changing how you\nwork on Open Source, you can set that up, and you just see how it goes. Maybe no\none reacts, and that\u2019s fine. Everything else on that list is kind of advanced.\nYou need an audience, and so you should start with that.<\/p>\n<p>Paid learning material is something that we are doing with analysis tools in the\nfuture with a video course. There are companies like tailwind that do that\nimpressively well, so you can learn from them. For merchandising, you have to\nhave a brand. Hence, it\u2019s not something that I could do, but someone like\n<a rel=\"external\" href=\"https:\/\/mozilla.org\/\">Mozilla<\/a> or the <a rel=\"external\" href=\"https:\/\/thecodingtrain.com\/\">Coding Train<\/a> on\nYouTube could definitely do something like that. Consulting is always an option.\nStill, it\u2019s also a lot more work and probably takes you away from what you\nreally love, so it really becomes a job. You have to think about whether you\nwant to do that or not. Enterprise services are very advanced [and interesting]\nfor maybe the one percent of projects that can be run in a business and where\nyou have special requirements. I have to say start from the top and work your\nway down. Start to create an audience. It\u2019s probably easier to build an audience\non Twitter and then funnel it back to Github than the other way around. Oh, by\nthe way, did I tell you it\u2019s hard? I really don\u2019t want to end on a low note. I\nreally want to emphasize that I would do it again, all of that if I started\ntoday. I think there\u2019s no better time to contribute to Open Source than today.\nProbably tomorrow will even be a better time because suddenly, way more people\nare interested, it\u2019s way easier to set up projects, you have all those free\ntools like VSCode and Github actions, free hosting. It\u2019s just amazing how much\nyou can pull off with very little money involved. So you can try it. What\u2019s the\nworst thing that can happen? No one cares? Well, okay, then you\u2019re as good as\nme. But I have some tips for you if you want to start today. My first tip is:\n\u201cdo your homework.\u201d Many people start with learning, and then they build things,\nand then they close the circle, but there\u2019s one key piece missing here. Some\npeople hate the word, but you learn to love it eventually. It\u2019s called\nmarketing. Marketing means a lot of things to a lot of people, but what it means\nto me is getting the word out because someone else will if you don\u2019t, and you\nare awesome; you just have to realize that. Maybe not everyone knows [about your\nproject] right away, so you should really talk about it more. Maybe at\nconferences, maybe on Twitter, maybe you can just tell your friends. Maybe you\ncan ask people to contribute and to support you. Somehow it\u2019s frowned upon in\nthe community that if you do marketing, you\u2019re not doing it for real, but I\nthink that\u2019s not true. I think that if smart people and patient and passionate\npeople did marketing, then the world would be a better place; because I\u2019m pretty\nsure the evil guys do marketing. So do your homework, but rest assured that\nbeing an Open Source maintainer means running a business, and you are the\nproduct. You have to think about why someone would want to sponsor you because\nif you don\u2019t come up with an answer for that, how should they know. Also, think\nabout the funnel. How will people find you, for example? The best way for people\nto find you is probably starting a YouTube channel.<\/p>\n<p>There are easier ways, though.<\/p>\n<p>[First,] you can always help out in a different project, and you\ndon\u2019t even have to be a coder. If you are good with design, then I can tell you\nthere are so many Open Source projects that need designers. It\u2019s crazy.\nMaybe start creating a logo for a small project and start getting some\nvisibility. Another one is having fun. If you know that earning money is hard in\nOpen Source, then that can also be liberating because it means you can\nexperiment and you can be creative, and yeah, having fun is the most important\nthing, I guess.<\/p>\n<p>Second, build things you love because it\u2019s your free time in the end. The\nchances that someone will find the project is pretty low, so it better be\nsomething that you\u2019re really interested in. If you don\u2019t believe in that, just\nmove on to the next thing. It\u2019s fine if you drop a project that you don\u2019t\nbelieve in anymore. No one will hold you accountable for that unless they are\njerks, and you don\u2019t want to be surrounded by jerks.<\/p>\n<p>Third, find friendly people because you really grow with your community. You\nwant people that support your project and maybe eventually become maintainers to\nease the burden, and that takes a lot of time, sometimes years, until you find\none maintainer, so always be friendly, try to put yourself in their perspective.\nGo the extra mile if you can. For example, reintegrate the master branch into\ntheir pull request. Just do it for them. Say thanks twice if you\u2019re unsure.<\/p>\n<p>Fourth is to grow an audience.<br \/>\nRadical marketing is one way, but being approachable and being inclusive is\nanother way. You want to be the guy or the girl that people go to when they have\na tough question, or they want to know how to get into Open Source. You want to\nbe the person that helps them out on their first pull request. They will pay it\nback a thousand times. The most exciting people I have met so far are available\nfor questions, and they don\u2019t really ask for anything in return. You hold them\nvery close and dear to your heart. When the time comes, you will remember those\npeople. We will say, like, \u201cthis is an amazing person to work with; I can highly\nrecommend them,\u201d which is called a lead.<\/p>\n<p>Finally, be in it for the long run. Good things take time. You see, it took me\n10 years. Maybe it takes you five or maybe even less, but it\u2019s probably not an\novernight success. It\u2019s really a long-term investment.<\/p>\n"},{"title":"My Blog Just Got Faster: Cloudflare Workers and AVIF Support","pubDate":"Mon, 14 Sep 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/perf\/","guid":"https:\/\/endler.dev\/2020\/perf\/","description":"<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/hero.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/hero.jpg\" width=\"650\" height=\"350\"\n    \/>\n    <\/picture>\n<\/figure>\n<p>Did I mention that this website is fast?\nOh yeah, <a href=\"\/2019\/tinysearch\/\">I did<\/a>, <a href=\"\/2017\/image-previews\/\">multiple times<\/a>.<\/p>\n<p>Few reasons (from ordinary to the first signs of creeping insanity):<\/p>\n<ul>\n<li>\ud83d\udcc4 Static site<\/li>\n<li>\u2601\ufe0f Cached on Cloudflare CDN<\/li>\n<li>\ud83d\udd17 \ufe0fHTTP\/2 and HTTP\/3 support<\/li>\n<li>\ud83d\udeab No web fonts (sadly)<\/li>\n<li>\u2705 <a rel=\"external\" href=\"https:\/\/jorgelbg.me\/dashflare\/\">Edge-worker powered analytics<\/a> (no Google Analytics)<\/li>\n<li>\ud83c\udf38 Avoiding JavaScript whenever possible; CSS covers 90% of my use-cases.<\/li>\n<li>\ud83d\uddbc\ufe0f Image width and height specified in HTML to avoid page reflows.<\/li>\n<li>\ud83d\udc4d\ud83c\udffb Inlined, <a rel=\"external\" href=\"https:\/\/jakearchibald.github.io\/svgomg\/\">optimized SVG graphics<\/a> and hand-rolled CSS<\/li>\n<li>\ud83d\ude85 <a rel=\"external\" href=\"https:\/\/github.com\/tinysearch\/tinysearch\">Static WASM search<\/a> (lazy loaded)<\/li>\n<li>\ud83c\udfce\ufe0f The entire homepage is &lt;10K (brotli-compressed), including graphics, thus should fit into the <a rel=\"external\" href=\"https:\/\/www.tunetheweb.com\/blog\/critical-resources-and-the-first-14kb\/\">first HTTP round-trip<\/a>.<\/li>\n<li>\ud83d\udc9f Heck, even the favicon is optimized for size. Update: I\u2019m using an SVG icon now thanks to <a rel=\"external\" href=\"https:\/\/austingil.com\/svg-favicons\/\">this article<\/a>.<\/li>\n<\/ul>\n<p>Then again, it\u2019s 2020: <strong>everyone<\/strong> is optimizing their favicons, right? <a rel=\"external\" href=\"http:\/\/www.p01.org\/defender_of_the_favicon\/\">\u2026right!?<\/a><\/p>\n<p>Well, it turns out most other sites don\u2019t think about their user\u2019s data plans as much as I do. Actually, that\u2019s an understatement: they don\u2019t care at all. But to me, <strong>lean is beautiful<\/strong>!<\/p>\n<h2 id=\"wait-what-about-images\"><a class=\"anchor\" href=\"#wait-what-about-images\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Wait, What about Images?<\/h2>\n<p>I prefer SVG for diagrams and illustrations.\nOnly if it\u2019s a photo, I\u2019ll use JPEG or <a rel=\"external\" href=\"https:\/\/developers.google.com\/speed\/webp\/\">WebP<\/a>.<\/p>\n<p>To be honest with you, I never really liked WebP.\nThe gist is that it might not even be smaller than JPEGs compressed with <a rel=\"external\" href=\"https:\/\/siipo.la\/blog\/is-webp-really-better-than-jpeg\">MozJPEG<\/a>.\nThere is a lengthy <a rel=\"external\" href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=856375\">debate on the Mozilla bug tracker<\/a> if you want to read more.\nTo this day, <a rel=\"external\" href=\"https:\/\/caniuse.com\/?search=webp\">Safari doesn\u2019t support WebP<\/a>.<\/p>\n<h2 id=\"hello-avif-wave\"><a class=\"anchor\" href=\"#hello-avif-wave\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Hello AVIF \ud83d\udc4b<\/h2>\n<p>Meet <a rel=\"external\" href=\"https:\/\/aomediacodec.github.io\/av1-avif\/\">AVIF<\/a>, the new next-gen image compression format. Check this out:<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/stats.svg\" alt=\"[ReachLightSpeed.com](https:\/\/reachlightspeed.com\/blog\/using-the-new-high-performance-avif-image-format-on-the-web-today\/)\" width=\"768\" height=\"216\"\n    \/>\n    <figcaption>\n        Source: <a rel=\"external\" href=\"https:\/\/reachlightspeed.com\/blog\/using-the-new-high-performance-avif-image-format-on-the-web-today\/\">ReachLightSpeed.com<\/a>\n    <\/figcaption>\n<\/figure>\n<p>It\u2019s already supported by Chrome 85 and Firefox 80.<br \/>\n<a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=BixwVsiDdZM\">Then it hit me like a hurricane<\/a> \ud83c\udf2a\ufe0f:<\/p>\n<div class=\"info\">\n    <p>\ud83d\ude32 Holy smokes, AVIF is supported by major browsers now!?<br \/>\nI want this for my blog!<\/p>\n<\/div>\n<p>Yes and no.<\/p>\n<p>I\u2019m using <a rel=\"external\" href=\"https:\/\/www.getzola.org\/\">Zola<\/a> for my blog, and\n<a rel=\"external\" href=\"https:\/\/github.com\/image-rs\/image\/issues\/1152\">AVIF support for Zola<\/a> is not yet there, but I want it now!\nSo I whipped up an <a rel=\"external\" href=\"https:\/\/github.com\/mre\/endler.dev\/blob\/master\/helpers\/img\/src\/main.rs\">ugly Rust script<\/a> (as you do) that creates AVIF images from my old JPEG and PNG images. I keep the original raw files around just in case.<\/p>\n<p>Under the hood, it calls <a rel=\"external\" href=\"https:\/\/github.com\/kornelski\/cavif\">cavif<\/a> by <a rel=\"external\" href=\"https:\/\/github.com\/kornelski\">Kornel Lesi\u0144ski<\/a>.<\/p>\n<h2 id=\"data-savings\"><a class=\"anchor\" href=\"#data-savings\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Data Savings<\/h2>\n<p>The results of AVIF on the blog were nothing short of impressive:<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/own_stats.svg\" alt=\"Total image size for [endler.dev\/2020\/sponsors](https:\/\/endler.dev\/2020\/sponsors)\" width=\"768\" height=\"156\"\n    \/>\n    <figcaption>\n        Total image size for <a rel=\"external\" href=\"https:\/\/endler.dev\/2020\/sponsors\">endler.dev\/2020\/sponsors<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"check-your-browser\"><a class=\"anchor\" href=\"#check-your-browser\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Check Your Browser<\/h2>\n<p>But hold on for a sec\u2026 is your browser even capable of showing AVIF?<\/p>\n<picture>\n  <source srcset=\"avif_supported.avif\" type=\"image\/avif\" \/>\n  <img src=\"avif_not_supported.jpg\" \/>\n<\/picture>\n<p>If that reads \u201cyup,\u201d you\u2019re all set.<br \/>\nIf that reads \u201cnope,\u201d then you have a few options:<\/p>\n<ul>\n<li><strong>On Firefox<\/strong>: Open <code>about:config<\/code> from the address bar and search for <code>avif<\/code>.<\/li>\n<li><strong>On Chrome<\/strong>: Make sure to update to the latest version.<\/li>\n<li><strong>On Safari<\/strong>: I\u2019m not sure what you\u2019re doing with your life. Try a real browser instead. \ud83d\ude0f<\/li>\n<\/ul>\n<h2 id=\"workaround-i-fallback-for-older-browsers\"><a class=\"anchor\" href=\"#workaround-i-fallback-for-older-browsers\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Workaround I: Fallback for Older Browsers<\/h2>\n<p>HTML is great in that your browser ignores unknown new syntax.\nSo I can use the <code>&lt;picture&gt;<\/code> element to serve the right format to you. (Look ma, no JavaScript!)<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"html\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">picture<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">source<\/span><span class=\"z-l-13 z-d-15\"> srcset<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">fancy_browser.avif<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">source<\/span><span class=\"z-l-13 z-d-15\"> srcset<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">decent_browser.webp<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">img<\/span><span class=\"z-l-13 z-d-15\"> src<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">meh_browser.jpg<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">picture<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/mre\/endler.dev\/blob\/master\/templates\/components\/figure.html\">The real\nthing<\/a>\nis a bit more convoluted, but you get the idea.<\/p>\n<h2 id=\"workaround-ii-wrong-content-type-on-github-pages\"><a class=\"anchor\" href=\"#workaround-ii-wrong-content-type-on-github-pages\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Workaround II: Wrong Content-Type on GitHub Pages<\/h2>\n<p>There was one ugly problem with Github and AVIF, though: Their server returned a\n<code>Content-Type: application\/octet-stream<\/code> header.<\/p>\n<p>This meant that the images <em>did not load<\/em> on Firefox.<\/p>\n<p>There is no way to fix that on my side as Github is hosting my page. Until now!\nI wanted to try Cloudflare\u2019s <a rel=\"external\" href=\"https:\/\/workers.cloudflare.com\/sites\">Workers Sites<\/a> for a long time, and this bug\nfinally made me switch. Basically, I run the full website as an edge worker\nright on the CDN; no own web server is needed. What\u2019s great about it is that\nthe site is fast <em>everywhere<\/em> now \u2014 even in remote locations \u2014 no more\nroundtrips to a server.<\/p>\n<p>By running an edge worker, I also gained full control over the request- and response objects.\nI added <a rel=\"external\" href=\"https:\/\/github.com\/mre\/endler.dev\/blob\/1f142c14ab40ca264c4c8c599a5db6b91ca9cbaa\/workers-site\/index.js#L53-L56\">this gem<\/a> of a snippet to intercept the worker response:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"javascript\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">if<\/span><span> (<\/span><span class=\"z-l-15 z-d-13\">\/<\/span><span class=\"z-l-15 z-d-13\">\\.<\/span><span class=\"z-l-5 z-d-7\">avif<\/span><span class=\"z-l-9 z-d-9\">$<\/span><span class=\"z-l-15 z-d-13\">\/<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">test<\/span><span>(<\/span><span>url<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>  response<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>headers<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">set<\/span><span>(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Content-Type<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">image\/avif<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>  response<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>headers<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">set<\/span><span>(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Content-Disposition<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">inline<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span>)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>And bam, Bob\u2019s your uncle. Firefox is happy.\nYou can read more about modifying response objects <a rel=\"external\" href=\"https:\/\/developers.cloudflare.com\/workers\/examples\/modify-response\">here<\/a>.<\/p>\n<p>Another side-effect of Workers Sites is that a production deployment takes <a rel=\"external\" href=\"https:\/\/github.com\/mre\/endler.dev\/actions\">one minute<\/a> now.<\/p>\n<h2 id=\"performance-results-after-moving-to-cloudflare\"><a class=\"anchor\" href=\"#performance-results-after-moving-to-cloudflare\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Performance Results after Moving to Cloudflare<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/cdn_before.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/cdn_before.jpg\" alt=\"Website response time before\" width=\"650\" height=\"511\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Website response time before\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/tools.keycdn.com\/performance?url=https:\/\/endler.dev\">KeyCDN<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/cdn_after.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/cdn_after.jpg\" alt=\"Website response time after\" width=\"650\" height=\"511\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Website response time after\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/tools.keycdn.com\/performance?url=https:\/\/endler.dev\">KeyCDN<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/pingdom_before.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/pingdom_before.jpg\" alt=\"Page size and rating before\" width=\"650\" height=\"214\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Page size and rating before\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/tools.pingdom.com\/#5d1d402401400000\">Pingdom.com<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/pingdom_after.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/pingdom_after.jpg\" alt=\"Page size and rating after\" width=\"650\" height=\"214\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Page size and rating after\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/tools.pingdom.com\/#5d226db3af800000\">Pingdom.com<\/a>\n    <\/figcaption>\n<\/figure>\n<p>I don\u2019t have to hide from a comparison with well-known sites either:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/perf\/speedcurve.png\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/perf\/speedcurve.png\" alt=\"Comparison with some other blogs I read\" width=\"650\" height=\"440\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Comparison with some other blogs I read\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/speedcurve.com\">Speedcurve<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"further-reading\"><a class=\"anchor\" href=\"#further-reading\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Further Reading<\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/reachlightspeed.com\/blog\/using-the-new-high-performance-avif-image-format-on-the-web-today\/\">How to Use AVIF: The New Next-Gen Image Compression Format<\/a> \u2014 Nice introduction that highlights some common pitfalls when integrating AVIF. It inspired me to add AVIF support.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/jakearchibald.com\/2020\/avif-has-landed\/\">AVIF has landed<\/a> by Jake Archibald \u2014 Compares image sizes and qualities of different formats: SVG, JPEG, PNG, WebP, and AVIF.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/avif.io\/\">avif.io<\/a> \u2014 Fast, configurable, client-side image compression that works on desktop and mobile.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/squoosh.app\/\">Squoosh<\/a> \u2014 another image compression service built with WebAssembly that supports AVIF<\/li>\n<li><a rel=\"external\" href=\"https:\/\/developers.cloudflare.com\/workers\/examples\">Tons of great examples on how to configure Cloudflare workers<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/workers.cloudflare.com\/sites\">Cloudflare Workers Sites<\/a><\/li>\n<\/ul>\n"},{"title":"Launching a Side Project Backed by GitHub Sponsors","pubDate":"Fri, 21 Aug 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/sponsors\/","guid":"https:\/\/endler.dev\/2020\/sponsors\/","description":"<p>Yesterday we launched <a rel=\"external\" href=\"https:\/\/analysis-tools.dev\">analysis-tools.dev<\/a>, and boy had I underestimated the response.<\/p>\n<figure>\n    <a href=\"https:\/\/analysis-tools.dev\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/website.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/website.jpg\" width=\"650\" height=\"983\"\n    \/>\n    <\/picture>\n    <\/a>\n<\/figure>\n<p>It\u2019s a side project about comparing static code analysis tools.\nStatic analysis helps improve code quality by detecting bugs in source code\nwithout even running it.<\/p>\n<p>What\u2019s best about the project is that it\u2019s <a rel=\"external\" href=\"https:\/\/github.com\/analysis-tools-dev\/\">completely open-source<\/a>. We wanted to\nbuild a product that wouldn\u2019t depend on showing ads or tracking users. Instead,\nwe were asking for sponsors on Github \u2014 that\u2019s it. We learned a lot in the\nprocess, and if you like to do the same, keep reading!<\/p>\n<h2 id=\"first-some-stats\"><a class=\"anchor\" href=\"#first-some-stats\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>First, Some Stats<\/h2>\n<p>Everyone likes business metrics. Here are some of ours:<\/p>\n<ul>\n<li>The project started as an <em>awesome list<\/em> on Github in <a rel=\"external\" href=\"https:\/\/endler.dev\/2017\/obsolete\/\">December\n2015<\/a>.<\/li>\n<li>We\u2019re currently listing 470 static analysis tools.<\/li>\n<li>Traffic grew continuously. Counting 7.5k stars and over 190 contributors at\nthe moment.<\/li>\n<li>500-1000 unique users per week.<\/li>\n<li>I had the idea to build a website for years now, but my coworker <a rel=\"external\" href=\"https:\/\/github.com\/jakubsacha\">Jakub<\/a>\njoined in May 2020 to finally make it a reality.<\/li>\n<\/ul>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/star-history.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/star-history.jpg\" alt=\"Github stars over time. That graph screams BUSINESS OPPORTUNITY.\" width=\"650\" height=\"424\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Github stars over time. That graph screams BUSINESS OPPORTUNITY.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/star-history.t9t.io\">star-history.t9t.io<\/a>\n    <\/figcaption>\n<\/figure>\n<p>\u201cWhy did it take five years to build a website!?\u201d, I hear you ask. Because I\nthought the idea was so obvious that others must have tried before and failed.<\/p>\n<p>I put it off, even though nobody stepped in to fill this niche.<br \/>\nI put it off, even though I kept the list up-to-date for five years, just to\nlearn about the tools out there.<br \/>\nYou get the gist: don\u2019t put things off for too long. When ideas sound obvious, it\u2019s probably because they are.<\/p>\n<h2 id=\"revenue-model\"><a class=\"anchor\" href=\"#revenue-model\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Revenue Model<\/h2>\n<p>It took a while to figure out how to support the project financially. We knew\nwhat we didn\u2019t want: an SEO landfill backed by AdWords. Neither did we want to\n\u201csell user data\u201d to trackers.<\/p>\n<p>We owe it to the contributors on Github to keep all data free for everyone.\nHow could we still build a service around it?\nInitially, we thought about swallowing the infrastructure costs\nourselves, but we\u2019d have no incentive to maintain the site or extend it with new\nfeatures.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/sponsors\">Github Sponsors<\/a> was still quite new at that time. Yet, as soon as we realized\nthat it was an option, it suddenly clicked: Companies that are not afraid of a\ncomparison with the competition have an incentive to support an open platform\nthat facilitates that. Furthermore, we could avoid bias and\nbuild a product that makes comparing objective and accessible.<\/p>\n<p>Sponsoring could be the antidote to soulless growth and instead allow us to build\na lean, sustainable side business. We don\u2019t expect analysis-tools.dev ever to be\na full-time job. The market might be too small for that \u2014 and that\u2019s fine.<\/p>\n<h2 id=\"tech\"><a class=\"anchor\" href=\"#tech\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Tech<\/h2>\n<p>Once we had a revenue model, we could focus on the tech. We\u2019re both engineers,\nwhich helps with iterating quickly.<\/p>\n<p>Initially, I wanted to build something fancy with\n<a rel=\"external\" href=\"https:\/\/github.com\/yewstack\/yew\">Yew<\/a>. It\u2019s a Rust\/Webassembly framework and\nyour boy <a rel=\"external\" href=\"https:\/\/endler.dev\/2019\/tinysearch\/\">likes Rust\/Webassembly<\/a>\u2026<\/p>\n<p>I\u2019m glad Jakub suggested something else: <a rel=\"external\" href=\"https:\/\/www.gatsbyjs.com\/\">Gatsby<\/a>. Now, let me be honest with\nyou: I couldn\u2019t care less about Gatsby. And that\u2019s what I said to Jakub: \u201cI\ncouldn\u2019t care less about Gatsby.\u201d But that\u2019s precisely the point: not being\nemotionally attached to something makes us focus on the job and not the tool.\nWe get more stuff done!<\/p>\n<p>From there on, it was pretty much easy going: we used a starter template, Jakub\nshowed me how the GraphQL integration worked, and we\neven got to use some Rust! The site runs on Cloudflare as an <a rel=\"external\" href=\"https:\/\/workers.cloudflare.com\/\">edge\nworker<\/a> built on top of Rust. (Yeah, I cheated\na bit.)<\/p>\n<p>Count to three, MVP!<\/p>\n<h2 id=\"finding-sponsors\"><a class=\"anchor\" href=\"#finding-sponsors\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Finding Sponsors<\/h2>\n<p>So we had our prototype but zero sponsors so far. What started now was (and\nstill is) by far the hardest part: convincing people to support us.<\/p>\n<p>We were smart enough not to send cold e-mails because most companies ignore\nthem. Instead, we turned to our network and realized that developers reached out\nbefore to add their company\u2019s projects to the old static analysis list on\nGithub.<\/p>\n<p>These were the people we contacted first. We tried to keep the messages short\nand personal.<\/p>\n<p>What worked best was a medium-sized e-mail with some context and a reminder that\nthey contributed to the project before. We included a link to our <a rel=\"external\" href=\"https:\/\/github.com\/sponsors\/analysis-tools-dev\/\">sponsors\npage<\/a>.<\/p>\n<p>Businesses want reliable partners and a reasonable value proposal,\nso a prerequisite is that the sponsor page has to be meticulously polished.<\/p>\n<figure>\n    <a href=\"https:\/\/github.com\/sponsors\/analysis-tools-dev\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/sponsors.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/sponsors.jpg\" alt=\"Our Github Sponsors page\" width=\"650\" height=\"1179\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        Our Github Sponsors page\n    <\/figcaption>\n<\/figure>\n<p>Just like <em>Star Wars Episode IX<\/em>, we received mixed reviews: many people never\nreplied, others passed the message\non to their managers, which in turn never replied, while others again had no\ninterest in sponsoring open-source projects in general. That\u2019s all fair game:\npeople are busy, and sponsorware is quite a new concept.<\/p>\n<blockquote>\n<p>A little rant: I\u2019m of the opinion that tech businesses don\u2019t nearly sponsor\nenough compared to all the value they get from Open Source. Would your company\nexist if there hadn\u2019t been a free operating system like Linux or a web server\nlike Nginx or Apache when it was founded?<\/p>\n<\/blockquote>\n<p>There was, however, a rare breed of respondents, which expressed interest but\nneeded some guidance. For many, it is the first step towards sponsoring <em>any<\/em>\ndeveloper through Github Sponsors \/ OpenCollective.<\/p>\n<p>It helped that we use OpenCollective as our fiscal host, which handles invoicing\nand donation transfers. <a rel=\"external\" href=\"https:\/\/docs.opencollective.com\/help\/\">Their docs<\/a>\nhelped us a lot when getting started.<\/p>\n<p>The task of finding sponsors <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=LT_y5qri00o\">is never\ndone<\/a>, but it was very reassuring\nto hear from <a rel=\"external\" href=\"https:\/\/www.deepcode.ai\/\">DeepCode<\/a> - an AI-based semantic\nanalysis service, that they were willing to take a chance on us.<\/p>\n<p>Thanks to them, we could push product over the finishing line. Because of them,\nwe can keep the site free for everybody. It also means the website is kept free\nfrom ads and trackers.<\/p>\n<p>In turn, DeepCode gets exposed to many great developers that care about code\nquality and might become loyal customers. Also, they get recognized as an\nopen-source-friendly tech company, which is more important than ever if you\u2019re\ntrying to sell dev tools. Win-win!<\/p>\n<h2 id=\"marketing\"><a class=\"anchor\" href=\"#marketing\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Marketing<\/h2>\n<p>Jakub and I both had started businesses before, but this was the first truly\n<em>open<\/em> product we would build.<\/p>\n<p><strong>Phase 1: Ship early \ud83d\ude80<\/strong><\/p>\n<p>We decided for a soft launch: deploy the site as early as possible and let the\ncrawlers index it. The fact that the page is statically rendered and follows\nsome basic SEO guidelines sure helped with improving our search engine rankings\nover time.<\/p>\n<p><strong>Phase 2: Ask for feedback from your target audience \ud83d\udcac<\/strong><\/p>\n<p>After we got some organic traffic and our first votes, we reached out to our\ndeveloper friends to test the page and vote on tools they know and love. This\nserved as an early validation, and we got some honest feedback, which helped us\ncatch the most blatant flaws.<\/p>\n<p><strong>Phase 3: Prepare announcement post \ud83d\udcdd<\/strong><\/p>\n<p>We wrote a blog post which, even if clickbaity, got the job done: <a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/blog\/static-analysis-is-broken-lets-fix-it\">Static\nAnalysis is Broken \u2014 Let\u2019s Fix\nIt!<\/a> It\npretty much captures our frustration about the space and why building an open\nplatform is important. We could have done a better job explaining the technical\ndifferences between the different analysis tools, but that\u2019s for another day.<\/p>\n<p><strong>Phase 4: Announce on social media \ud83d\udd25<\/strong><\/p>\n<p>Shortly before the official announcement, we noticed that the search\nfunctionality was broken (of course). Turns out, we hit the free quota limit on\n<a rel=\"external\" href=\"https:\/\/algolia.com\">Algolia<\/a> a biiit earlier than expected. \ud83d\ude05 No biggie: quick\nexchange with Algolia\u2019s customer support, and they moved us over to the\nopen-source plan (which we didn\u2019t know existed). We were back on track!<\/p>\n<blockquote>\n<p>Side note: Algolia customer support is top-notch. Responsive, tech-savvy,\nand helpful. Using Algolia turned out to be a great fit for our product.\nResponse times are consistently in the low milliseconds and the integration\nwith Gatsby was quick and easy.<\/p>\n<\/blockquote>\n<figure>\n    <a href=\"https:\/\/twitter.com\/matthiasendler\/status\/1296162427797671936\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/tweet.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/tweet.jpg\" alt=\"We got quite a bit of buzz from that\ntweet: 63 retweets, 86 likes and counting\" width=\"650\" height=\"230\"\n    \/>\n    <\/picture>\n    <\/a>\n    <figcaption>\n        We got quite a bit of buzz from that\ntweet: 63 retweets, 86 likes and counting\n    <\/figcaption>\n<\/figure>\n<p>Clearly, everyone knew that we were asking for support here, but we are thankful\nfor every single one that liked and retweeted. It\u2019s one of these situations\nwhere having a network of like-minded people can help.<\/p>\n<p>As soon as we were confident that the site wasn\u2019t <em>completely<\/em> broken, we set off\nto announce it on\n<a rel=\"external\" href=\"https:\/\/lobste.rs\/s\/n2ecfs\/static_analysis_is_broken_let_s_fix_it\">Lobste.rs<\/a>\n(2 downvotes),\n<a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/SideProject\/comments\/icupeu\/we_made_a_website_to_compare_470_static_analysis\/\">\/r\/SideProject<\/a>\n(3 upvotes) and <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=24221708\">Hacker News<\/a> (173\nupvotes, 57 comments). Social media is kind of unpredictable.\nIt helps to cater the message to each audience and stay humble, though.<\/p>\n<p>The response from all of that marketing effort was <strong>nuts<\/strong>:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/traffic.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/traffic.jpg\" alt=\"Traffic on launch day\" width=\"650\" height=\"298\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Traffic on launch day\n    <\/figcaption>\n<\/figure>\n<p>Perhaps unsurprisingly, the Cloudflare edge workers didn\u2019t break a sweat.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/worker.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/worker.jpg\" alt=\"Edge worker CPU time on Cloudflare\" width=\"650\" height=\"353\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Edge worker CPU time on Cloudflare\n    <\/figcaption>\n<\/figure>\n<p>My boss <a rel=\"external\" href=\"https:\/\/twitter.com\/xo4n\">Xoan Vilas<\/a> even did a quick performance\nanalysis and he approved. (Thanks boss!)<\/p>\n<figure>\n    <a href=\"https:\/\/twitter.com\/xo4n\/status\/1296432035788193794\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/perf.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/perf.jpg\" width=\"650\" height=\"489\"\n    \/>\n    <\/picture>\n    <\/a>\n<\/figure>\n<p>High fives all around!<\/p>\n<h2 id=\"now-what\"><a class=\"anchor\" href=\"#now-what\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Now What?<\/h2>\n<p>Of course, we\u2019ll add new features; of course, we have more plans for the future,\nyada yada yada. Instead, let\u2019s reflect on that milestone: a healthy little\nbusiness with no ads or trackers, solely carried by sponsors. \ud83c\udf89<\/p>\n<p>Finally, I want you to <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=9XGyxOwM0tE\">look deep inside yourself and find your own little\nproduct to work on<\/a>. It\u2019s probably\nright in front of your nose, and like myself, you\u2019ve been putting it off for too\nlong. Well, not anymore! The next success story is yours. So go out and build\nthings.<\/p>\n<p>Oh wait! \u2026before you leave, would you mind checking out\n<a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/\">analysis-tools.dev<\/a> and smashing that upvote button\nfor a few tools you like? Hey, and if you feel super generous today\n(or you have a fabulous employer that cares about open-source), why not check out\nour <a rel=\"external\" href=\"https:\/\/github.com\/sponsors\/analysis-tools-dev\/\">sponsorship page<\/a>?<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/sponsors\/team.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/sponsors\/team.jpg\" alt=\"Jakub and me in Vienna, Austria. I'm not actually that small.\" width=\"650\" height=\"488\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Jakub and me in Vienna, Austria. I\u2019m not actually that small.\n    <\/figcaption>\n<\/figure>\n"},{"title":"What Happened to Programming in the 2010s?","pubDate":"Thu, 02 Jul 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/review\/","guid":"https:\/\/endler.dev\/2020\/review\/","description":"<p>A while ago, I read an article titled <a rel=\"external\" href=\"https:\/\/avc.com\/2019\/12\/what-happened-in-the-2010s\/\">\u201cWhat Happened In The\n2010s\u201d<\/a> by Fred Wilson. The\npost highlights key changes in technology and business during the last ten\nyears. This inspired me to think about a much more narrow topic: <em>What Happened To\nProgramming In The 2010s?<\/em><\/p>\n<div class=\"info\">\n    <p>\ud83d\ude93 I probably forgot like 90% of what actually happened. Please\ndon\u2019t sue me.\nMy goal is to reflect on the <u>past<\/u> so that you can better predict the <u>future<\/u>.<\/p>\n<\/div>\n<h2 id=\"where-to-start\"><a class=\"anchor\" href=\"#where-to-start\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Where to Start?<\/h2>\n<p>From a mile-high perspective, programming is still the same as a decade ago:<\/p>\n<ol>\n<li>Punch program into editor<\/li>\n<li>Feed to compiler (or interpreter)<\/li>\n<li>Bleep Boop \ud83e\udd16<\/li>\n<li>Receive output<\/li>\n<\/ol>\n<p>But if we take a closer look, a <em>lot<\/em> has changed around us.\nMany things we take for granted today didn\u2019t exist a decade ago.<\/p>\n<h2 id=\"what-happened-before\"><a class=\"anchor\" href=\"#what-happened-before\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What Happened Before?<\/h2>\n<p>Back in 2009, we wrote <a rel=\"external\" href=\"https:\/\/jquery.com\/\">jQuery<\/a> plugins, ran websites on\nshared hosting services, and uploaded content via\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/File_Transfer_Protocol\">FTP<\/a>. Sometimes code was\ncopy-pasted from dubious forums, tutorials on blogs, or even hand-transcribed\nfrom books. <a rel=\"external\" href=\"https:\/\/stackoverflow.com\/\">Stack Overflow<\/a> (which launched on\n15<sup>th<\/sup> of September 2008) was still in its infancy. Version control\nwas done with <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Concurrent_Versions_System\">CVS<\/a> or\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Apache_Subversion\">SVN<\/a> \u2014 or not at all.\n<a rel=\"external\" href=\"https:\/\/endler.dev\/2018\/github\/\">I signed up for Github<\/a> on 3<sup>rd<\/sup> of\nJanuary 2010. Nobody had even heard of a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Raspberry_Pi\">Raspberry\nPi<\/a> (which only got released in\n2012).<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/review\/xkcd_2324.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/review\/xkcd_2324.jpg\" alt=\"<a href='https:\/\/xkcd.com\/2324\/'>xkcd #2324<\/a>\" width=\"640\" height=\"572\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: <a href='https:\/\/xkcd.com\/2324\/'>xkcd #2324<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"an-explosion-of-new-programming-languages\"><a class=\"anchor\" href=\"#an-explosion-of-new-programming-languages\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>An Explosion of New Programming Languages<\/h2>\n<p>The last decade saw the creation of a vast number of new and exciting programming\nlanguages.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/crystal-lang.org\/\">Crystal<\/a>, <a rel=\"external\" href=\"https:\/\/dart.dev\/\">Dart<\/a>, <a rel=\"external\" href=\"https:\/\/elixir-lang.org\/\">Elixir<\/a>, <a rel=\"external\" href=\"https:\/\/elm-lang.org\/\">Elm<\/a>, <a rel=\"external\" href=\"https:\/\/golang.org\/\">Go<\/a>, <a rel=\"external\" href=\"https:\/\/julialang.org\/\">Julia<\/a>, <a rel=\"external\" href=\"https:\/\/kotlinlang.org\/\">Kotlin<\/a>, <a rel=\"external\" href=\"https:\/\/nim-lang.org\/\">Nim<\/a>, <a rel=\"external\" href=\"https:\/\/www.rust-lang.org\/\">Rust<\/a>, <a rel=\"external\" href=\"https:\/\/swift.org\/\">Swift<\/a>, <a rel=\"external\" href=\"https:\/\/www.typescriptlang.org\/\">TypeScript<\/a>\nall released their first stable version!<\/p>\n<p>Even more exciting: <em>all<\/em> of the above languages are developed in the open now, and the source code is\nfreely available on Github. That means, everyone can contribute to their development \u2014 a big testament to Open Source.<\/p>\n<p>Each of those languages introduced new ideas that were not widespread before:<\/p>\n<ul>\n<li><em>Strong Type Systems<\/em>: Kotlin and Swift made <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Nullable_type\">optional null types<\/a>\nmainstream, TypeScript brought types to JavaScript, Algebraic datatypes are\ncommon in Kotlin, Swift, TypeScript, and Rust.<\/li>\n<li><em>Interoperability<\/em>: Dart compiles to JavaScript, Elixir interfaces with\nErlang, Kotlin with Java, and Swift with Objective-C.<\/li>\n<li><em>Better Performance<\/em>: Go promoted Goroutines and channels for easier\nconcurrency and impressed with a\n<a rel=\"external\" href=\"https:\/\/blog.golang.org\/ismmkeynote\">sub-millisecond<\/a> Garbage Collector,\nwhile Rust avoids Garbage Collector overhead altogether thanks to ownership and borrowing.<\/li>\n<\/ul>\n<p>This is just a short list, but innovation in the programming language field has\ngreatly accelerated.<\/p>\n<h2 id=\"more-innovation-in-older-languages\"><a class=\"anchor\" href=\"#more-innovation-in-older-languages\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>More Innovation in Older Languages<\/h2>\n<p>Established languages didn\u2019t stand still either. A few examples:<\/p>\n<p>C++ woke up from its long winter sleep and released C++11 after its last major\nrelease in 1998. It introduced numerous new features like Lambdas, <code>auto<\/code>\npointers, and range-based loops to the language.<\/p>\n<p>At the beginning of the last decade, the latest PHP version was 5.3. We\u2019re at\n7.4 now. (We skipped 6.0, but I\u2019m not ready to talk about it yet.) Along the\nway, it got over twice as fast. <a rel=\"external\" href=\"https:\/\/stephencoakley.com\/2020\/06\/10\/dumb-reasons-to-hate-php\">PHP is a truly modern programming language\nnow<\/a> with a\nthriving ecosystem.<\/p>\n<p>Heck, even Visual Basic has tuples now. (Sorry, I couldn\u2019t resist.)<\/p>\n<h2 id=\"faster-release-cycles\"><a class=\"anchor\" href=\"#faster-release-cycles\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Faster Release Cycles<\/h2>\n<p>Most languages adopted a quicker release cycle. Here\u2019s a list for some popular languages:<\/p>\n<table><thead><tr><th style=\"text-align: left\">Language<\/th><th style=\"text-align: left\">Current release cycle<\/th><\/tr><\/thead><tbody>\n<tr><td style=\"text-align: left\">C<\/td><td style=\"text-align: left\">irregular<\/td><\/tr>\n<tr><td style=\"text-align: left\">C#<\/td><td style=\"text-align: left\">~ 12 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">C++<\/td><td style=\"text-align: left\">~ 3 years<\/td><\/tr>\n<tr><td style=\"text-align: left\">Go<\/td><td style=\"text-align: left\">6 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">Java<\/td><td style=\"text-align: left\">6 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">JavaScript (ECMAScript)<\/td><td style=\"text-align: left\">12 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">PHP<\/td><td style=\"text-align: left\">12 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">Python<\/td><td style=\"text-align: left\">12 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">Ruby<\/td><td style=\"text-align: left\">12 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">Rust<\/td><td style=\"text-align: left\">6 weeks (!)<\/td><\/tr>\n<tr><td style=\"text-align: left\">Swift<\/td><td style=\"text-align: left\">6 months<\/td><\/tr>\n<tr><td style=\"text-align: left\">Visual Basic .NET<\/td><td style=\"text-align: left\">~ 24 months<\/td><\/tr>\n<\/tbody><\/table>\n<h2 id=\"the-slow-death-of-null\"><a class=\"anchor\" href=\"#the-slow-death-of-null\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Slow Death of Null<\/h2>\n<p>Close to the end of the last decade, in a talk from 25<sup>th<\/sup>of August 2009,\nTony Hoare described the <code>null<\/code> pointer as his <a rel=\"external\" href=\"https:\/\/www.infoq.com\/presentations\/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare\/\">Billion Dollar\nMistake<\/a>.<\/p>\n<p>A study by the Chromium project found that <a rel=\"external\" href=\"https:\/\/www.chromium.org\/Home\/chromium-security\/memory-safety\">70% of their serious security bugs were memory safety problems<\/a> (<a rel=\"external\" href=\"https:\/\/www.zdnet.com\/article\/microsoft-70-percent-of-all-security-bugs-are-memory-safety-issues\/\">same for Microsoft<\/a>). Fortunately, the notion that our <a rel=\"external\" href=\"https:\/\/medium.com\/@sgrif\/no-the-problem-isnt-bad-coders-ed4347810270\">memory safety problem isn\u2019t bad coders<\/a>\nhas finally gained some traction.<br \/>\nMany mainstream languages embraced safer alternatives to <code>null<\/code>: nullable\ntypes, <code>Option<\/code>, and <code>Result<\/code> types. Languages like Haskell had these features\nbefore, but they only gained popularity in the 2010s.<\/p>\n<h2 id=\"revenge-of-the-type-system\"><a class=\"anchor\" href=\"#revenge-of-the-type-system\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Revenge of the Type System<\/h2>\n<p>Closely related is the <a rel=\"external\" href=\"https:\/\/www.johndcook.com\/blog\/2010\/06\/09\/dynamic-typing-and-risk-homeostasis\/\">debate about type\nsystems<\/a>.\nThe past decade has seen type systems make their stage comeback; TypeScript,\nPython, and PHP (just to name a few) started to embrace type systems.<\/p>\n<p>The trend goes towards type inference: add types to make your intent clearer for\nother humans and in the face of ambiguity \u2014 otherwise, skip them. Java,\nC++, Go, Kotlin, Swift, and Rust are popular examples with type inference support. I\ncan only speak for myself, but I think writing Java has become a lot more\nergonomic in the last few years.<\/p>\n<h2 id=\"exponential-growth-of-libraries-and-frameworks\"><a class=\"anchor\" href=\"#exponential-growth-of-libraries-and-frameworks\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Exponential Growth of Libraries and Frameworks<\/h2>\n<p>As of today, npm hosts <a rel=\"external\" href=\"https:\/\/www.npmjs.com\/\">1,330,634 packages<\/a>. That\u2019s over a million\npackages that somebody else is maintaining for you. Add another <a rel=\"external\" href=\"https:\/\/rubygems.org\/stats\">160,488 Ruby\ngems<\/a>, <a rel=\"external\" href=\"https:\/\/pypi.org\/\">243,984 Python projects<\/a>,\nand top it off with <a rel=\"external\" href=\"https:\/\/crates.io\/\">42,547 Rust crates<\/a>.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/review\/module_counts.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/review\/module_counts.jpg\" alt=\"Number of packages for popular programming languages.<br \/> Don't ask me what happened to npm in 2019.\" width=\"650\" height=\"494\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Number of packages for popular programming languages.<br \/> Don\u2019t ask me what happened to npm in 2019.\n        <br \/>\n        Source: <a href='http:\/\/www.modulecounts.com\/'>Module Counts<\/a>\n    <\/figcaption>\n<\/figure>\n<p>Of course, there\u2019s the occasional\n<a rel=\"external\" href=\"https:\/\/www.davidhaney.io\/npm-left-pad-have-we-forgotten-how-to-program\/\">leftpad<\/a>,\nbut it also means that we have to write less library code ourselves and can\nfocus on business value instead. On the other hand, there are more potential\npoints of failure, and auditing is difficult. <a rel=\"external\" href=\"https:\/\/sambleckley.com\/writing\/npm.html\">There is also a large number of outdated\npackages<\/a>. For a more in-depth discussion, I recommend the <a rel=\"external\" href=\"https:\/\/www.coreinfrastructure.org\/wp-content\/uploads\/sites\/6\/2020\/02\/census_ii_vulnerabilities_in_the_core.pdf\">Census II report by\nthe Linux Foundation &amp; Harvard<\/a> [PDF].<\/p>\n<p>We also went a bit crazy on frontend frameworks:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/angularjs.org\/\">Angular<\/a> in 2010<\/li>\n<li><a rel=\"external\" href=\"https:\/\/reactjs.org\/\">React<\/a> in 2013<\/li>\n<li><a rel=\"external\" href=\"https:\/\/vuejs.org\/\">Vue<\/a> in 2014<\/li>\n<li><a rel=\"external\" href=\"https:\/\/svelte.dev\/\">Svelte<\/a> in 2016<\/li>\n<li>\u2026and soon <a rel=\"external\" href=\"https:\/\/github.com\/yewstack\/yew\/\">Yew<\/a>?<\/li>\n<\/ul>\n<h2 id=\"no-free-lunch\"><a class=\"anchor\" href=\"#no-free-lunch\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>No Free Lunch<\/h2>\n<p>A review like this wouldn\u2019t be complete without taking a peek at <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Moore&#x27;s_law\">Moore\u2019s Law<\/a>.\nIt has held up surprisingly well in the last decade:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/review\/moore_2018.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/review\/moore_2018.jpg\" alt=\"<a href='https:\/\/en.wikipedia.org\/wiki\/Moore%27s_law'>Wikipedia<\/a>\" width=\"650\" height=\"469\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: <a href='https:\/\/en.wikipedia.org\/wiki\/Moore%27s_law'>Wikipedia<\/a>\n    <\/figcaption>\n<\/figure>\n<p>There\u2019s a catch, though.\nLooking at single-core performance, the curve is flattening:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/review\/moore_single.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/review\/moore_single.jpg\" alt=\"<a href='https:\/\/www.youtube.com\/watch?v=Azt8Nc-mtKM&'>Stanford University: The Future of Computing (video)<\/a>\" width=\"650\" height=\"347\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: <a href='https:\/\/www.youtube.com\/watch?v=Azt8Nc-mtKM&'>Stanford University: The Future of Computing (video)<\/a>\n    <\/figcaption>\n<\/figure>\n<p>The new transistors prophesied by Moore don\u2019t make our CPUs faster but instead\nadd other kinds of processing capabilities like more parallelism or hardware\nencryption.\nThere is no free lunch anymore. Engineers have to find new ways of making their\napplications faster, e.g. by <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Concurrent_computing\">embracing concurrent\nexecution<\/a>.<\/p>\n<p>Callbacks, coroutines, and eventually async\/await are becoming industry\nstandards.<\/p>\n<p>GPUs (Graphical Processing Units) became very powerful, allowing for massively\nparallel computations, which caused a renaissance of Machine Learning for practical use-cases:<\/p>\n<blockquote>\n<p>Deep learning becomes feasible, which leads to machine learning becoming\nintegral to many widely used software services and applications.\n\u2014 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Timeline_of_machine_learning\">Timeline of Machine Learning on Wikipedia<\/a><\/p>\n<\/blockquote>\n<p><em>Compute<\/em> is ubiquitous, so in most cases, energy efficiency plays a more prominent role now than raw performance (at least for consumer devices).<\/p>\n<h2 id=\"unlikely-twists-of-fate\"><a class=\"anchor\" href=\"#unlikely-twists-of-fate\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Unlikely Twists of Fate<\/h2>\n<ul>\n<li>Microsoft is a cool kid now. It acquired Github, announced the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Windows_Subsystem_for_Linux\">Windows subsystem for Linux<\/a> (which should really be called Linux Subsystem for Windows), open sourced\n<a rel=\"external\" href=\"https:\/\/github.com\/Microsoft\/MS-DOS\">MS-DOS<\/a> and <a rel=\"external\" href=\"http:\/\/news.microsoft.com\/2014\/11\/12\/microsoft-takes-net-open-source-and-cross-platform-adds-new-development-capabilities-with-visual-studio-2015-net-2015-and-visual-studio-online\/\">.NET<\/a>.\nEven the <a rel=\"external\" href=\"https:\/\/github.com\/Microsoft\/calculator\">Microsoft Calculator<\/a> is now open source.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.redhat.com\/en\/blog\/red-hat-ibm-creating-leading-hybrid-cloud-provider\">IBM acquired Red Hat<\/a>.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/lore.kernel.org\/lkml\/CA+55aFy+Hv9O5citAawS+mVZO+ywCKd9NQ2wxUmGsz9ZJzqgJQ@mail.gmail.com\/\">Linus Torvalds apologized for his behavior, took time off<\/a>.<\/li>\n<li>Open source became the default for software development (?).<\/li>\n<\/ul>\n<h2 id=\"learnings\"><a class=\"anchor\" href=\"#learnings\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Learnings<\/h2>\n<p>If you\u2019re now thinking: <em>Matthias, you totally forgot X<\/em>, then I brought\nthat point home. This is not even close to everything that happened. You\u2019d\nroughly need a decade to talk about all of it.<\/p>\n<p>Personally, I\u2019m excited about the <em>next<\/em> ten years.\nSoftware is eating the world \u2014 at an ever-faster pace.<\/p>\n"},{"title":"Tips for Faster Rust Compile Times","pubDate":"Sun, 21 Jun 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/rust-compile-times\/","guid":"https:\/\/endler.dev\/2020\/rust-compile-times\/","description":"<div class=\"info\">\n    <p>This post has <a rel=\"external\" href=\"https:\/\/corrode.dev\/blog\/tips-for-faster-rust-compile-times\/\">moved to my other blog<\/a>.\nIt will be updated there in the future.<\/p>\n<\/div>\n"},{"title":"Gravity","pubDate":"Fri, 29 May 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/gravity\/","guid":"https:\/\/endler.dev\/2020\/gravity\/","description":"<p>Here\u2019s a test to show your age:<\/p>\n<p>Do you still remember <a rel=\"external\" href=\"https:\/\/josephpcohen.com\/w\/gravityscript\/\">that funny JavaScript gravity effect<\/a>, which Google used on their homepage ten years ago? This one?<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/wskgClFNlJw\"\n>\n  <picture>\n    <source srcset=\"gravity.avif\" type=\"image\/avif\" \/>\n    <img src=\"gravity.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p>I wanted to have some fun and integrated it into a website I was building.\nUnfortunately, it didn\u2019t work out-of-the-box.\nIt choked on some DOM elements that were not strictly classes (like SVG elements).\nSo, in good hacker fashion, I quickly patched up the script (it\u2019s just a three-line change), and now it\u2019s back to its former glory.<\/p>\n<p>Test it here! (Caution: you\u2019ll have to reload the page after that. \ud83d\ude0f)<\/p>\n<p><a class=\"btn\" href='#' id='gravity'>Apply Gravity<\/a><\/p>\n<script defer type=\"text\/javascript\">\n    var myLink = document.getElementById('gravity');\n\n    myLink.onclick = function(){\n\n        var script = document.createElement(\"script\");\n        script.type = \"text\/javascript\";\n        script.src = \"gravity.js\"; \n        document.getElementsByTagName(\"head\")[0].appendChild(script);\n        return false;\n    }\n<\/script>\n<p>Anyway, feel free to add it to your own sites and have some fun.\nIt\u2019s also great to prank your friends.\nSimply add that single line to any website and weeee!<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"html\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">script<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">  type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">text\/javascript<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">  src<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/endler.dev\/2020\/gravity\/gravity.js<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&gt;<\/span><span>&lt;<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span class=\"z-l-3 z-d-2\">script<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p>Sometimes I miss those simple times of the early web\u2026<\/p>\n"},{"title":"Hacker Folklore","pubDate":"Fri, 24 Apr 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/folklore\/","guid":"https:\/\/endler.dev\/2020\/folklore\/","description":"<p>Some computer terms have a surprising legacy. Many of them are derived from\nlong-obsolete technologies. This post tries to dust off the exciting history of\nsome\nof these terms that we use every day but aren\u2019t quite sure about their origins.\nLet\u2019s jump right in!<\/p>\n<h2 id=\"bike-shedding\"><a class=\"anchor\" href=\"#bike-shedding\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bike-Shedding<\/h2>\n<p><em>Today\u2019s meaning: A pointless discussion about trivial issues.<\/em><\/p>\n<p>The term bike-shed effect or bike-shedding was coined as a metaphor to\nilluminate the law of triviality; it was popularised in the Berkeley Software\nDistribution community by the Danish computer developer <a rel=\"external\" href=\"http:\/\/phk.freebsd.dk\/sagas\/bikeshed\/\">Poul-Henning Kamp in\n1999 on the FreeBSD mailing list<\/a> and has\nspread from there to the whole software industry.<\/p>\n<p>The concept was first presented as a corollary of his broader \u201cParkinson\u2019s law\u201d\nspoof of management. He dramatizes this \u201claw of triviality\u201d with the example of\na committee\u2019s deliberations on an atomic reactor, contrasting it to\ndeliberations on a bicycle shed. As he put it: \u201cThe time spent on any item of\nthe agenda will be in inverse proportion to the sum of money involved.\u201d<\/p>\n<p>A reactor is so vastly expensive and complicated that an average person cannot\nunderstand it, so one assumes that those who work on it understand it. On the\nother hand, everyone can visualize a cheap, simple bicycle shed, so planning one\ncan result in endless discussions because everyone involved wants to add a touch\nand show personal contribution.<br \/>\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Law_of_triviality\">Reference - Wikipedia: Law of Triviality<\/a><\/p>\n<h2 id=\"boilerplate\"><a class=\"anchor\" href=\"#boilerplate\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Boilerplate<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/bending-roll.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/bending-roll.jpg\" alt=\"An old machine that bended steel\nplates to water boilers.\" width=\"650\" height=\"386\"\n    \/>\n    <\/picture>\n    <figcaption>\n        An old machine that bended steel\nplates to water boilers.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Modern_mechanism,_exhibiting_the_latest_progress_in_machines,_motors,_and_the_transmission_of_power,_being_a_supplementary_volume_to_Appletons&#x27;_cyclopaedia_of_applied_mechanics_(1892)_(14583761620).jpg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<p><em>Today\u2019s meaning: A chunk of code that is copied over and over again with little\nor no changes made to it in the process.<\/em><\/p>\n<p><em>Boiler plate<\/em> originally referred to the rolled steel used to make water\nboilers but is used in the media to refer to hackneyed or unoriginal writing.\nThe term refers to the metal printing plates of pre-prepared text such as\nadvertisements or syndicated columns that were distributed to small, local\nnewspapers. These printing plates came to be known as \u2018boilerplates\u2019 by analogy.\nOne large supplier to newspapers of this kind of boilerplate was the Western\nNewspaper Union, which supplied \u201cready-to-print stories [which] contained\nnational or international news\u201d to papers with smaller geographic footprints,\nwhich could include advertisements pre-printed next to the conventional content.<\/p>\n<p>References:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Boilerplate_text\">Wikipedia<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/a\/3997441\/270334\">Stack Overflow<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/english.stackexchange.com\/questions\/464924\/boilerplate-versus-template\/464929\">StackExchange - English Language &amp;\nUsage<\/a><\/li>\n<\/ul>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/boilerplate.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/boilerplate.jpg\" alt=\"The man in the foreground is holding\na rounded printing plate. Plates like this were provided by companies such as\nWestern Newspaper Union to many smaller newspapers.\" width=\"650\" height=\"506\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The man in the foreground is holding\na rounded printing plate. Plates like this were provided by companies such as\nWestern Newspaper Union to many smaller newspapers.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/english.stackexchange.com\/a\/464929\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"boot-reboot-bootstrapping\"><a class=\"anchor\" href=\"#boot-reboot-bootstrapping\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Boot \/ Reboot \/ Bootstrapping<\/h2>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/muenchhausen.svg\" alt=\"Lithography of Baron M&uuml;nchhausen\npulling himself out of a swamp by his pigtail\" width=\"2050\" height=\"2351\"\n    \/>\n    <figcaption>\n        Lithography of Baron M\u00fcnchhausen\npulling himself out of a swamp by his pigtail\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Zentralbibliothek_Solothurn_-_M%C3%BCnchhausen_zieht_sich_am_Zopf_aus_dem_Sumpf_-_a0400.tif#filelinks\">Wikimedia<\/a>\n    <\/figcaption>\n<\/figure>\n<p>The term <em>boot<\/em> is used in the context of computers to refer to the process of\nstarting a computer.<\/p>\n<p>In compiler development, the term <em>bootstrapping<\/em> refers to the process of\nrewriting a compiler in a new language: The first compiler is written in an\nexisting language. Then it gets rewritten in the new language and compiled by\nitself.<\/p>\n<p>The saying \u201cto pull oneself up by one\u2019s bootstraps\u201d dates back to the 19th\ncentury. Tall boots may have a tab, loop or handle at the top allowing one to\nhelp pulling them on. The metaphor spawned additional metaphors for\nself-sustaining processes that proceed without external help.<\/p>\n<p>According to <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Bootstrapping_(computing)\">Wikipedia<\/a>,<\/p>\n<blockquote>\n<p>The idiom dates at least to 1834, when it appeared in the Workingman\u2019s\nAdvocate: \u201cIt is conjectured that Mr. Murphee will now be enabled to hand\nhimself over the Cumberland river or a barn yard fence by the straps of his\nboots.\u201d<\/p>\n<\/blockquote>\n<p>There\u2019s also a nice summary in <a rel=\"external\" href=\"https:\/\/www.merriam-webster.com\/words-at-play\/reboot-boot-word-origin\">Merriam-Webster<\/a>.<\/p>\n<h2 id=\"bug\"><a class=\"anchor\" href=\"#bug\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bug<\/h2>\n<p><em>Today\u2019s meaning: A defect in a piece of code or hardware.<\/em><\/p>\n<p>The origins are unknown!<\/p>\n<p>Contrary to popular belief it <em>predates the bug\nfound by Grace Hopper in the Mark II computer<\/em>.<\/p>\n<p>The term was used by engineers way before that; at least since the 1870s.\nIt predates electronic computers and computer software.\nThomas Edison used the term \u201cbug\u201d in his notes.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Software_bug#Etymology\">Reference<\/a><\/p>\n<h2 id=\"bit\"><a class=\"anchor\" href=\"#bit\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bit<\/h2>\n<p>The term\u2019s invention is credited to John W. Tukey, who in a memo written for\nBell Labs on January 9, 1947, had shortened \u201cbinary information digit\u201d to \u201cbit\u201d.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Bit#History\">Reference<\/a><\/p>\n<h2 id=\"byte\"><a class=\"anchor\" href=\"#byte\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Byte<\/h2>\n<p>The term \u201cbyte\u201d was first introduced by <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Werner_Buchholz\">Werner\nBuchholz<\/a> in June 1956. This was\nduring the initial design stage for the IBM Stretch computer. The computer had a\ndesign that enabled addressing down to the individual bit and allowed variable\nfield length instructions, with the size of the byte encoded into the\ninstruction itself. The choice of spelling as \u201cbyte\u201d instead of \u201cbite\u201d was\nintentional to prevent any accidental alteration to \u201cbit\u201d.<\/p>\n<h2 id=\"carriage-return-and-line-feed\"><a class=\"anchor\" href=\"#carriage-return-and-line-feed\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Carriage Return and Line Feed<\/h2>\n<p><em>Today\u2019s meaning: Set the cursor to the beginning of the next line.<\/em><\/p>\n<p>These two terms were adopted from typewriters.<\/p>\n<p>The carriage holds the paper and is moving from left to right to advance the\ntyping position as the keys are pressed. It \u201ccarries\u201d the paper with it. The\ncarriage return is the operation when the carriage gets moved into its original\nposition on the very left end side of the paper.<\/p>\n<p>Simply returning the carriage to the left is not enough to start with a new\nline, however. The carriage would still be on the same line than before \u2014\njust at the beginning of the line. To go to a new line, a <em>line feed<\/em> was\nneeded. It would move the paper inside the typewriter up by one line.<\/p>\n<p>These two operations \u2014 carriage return (CR) and line feed (LF) \u2014\nwere commonly done at once by pushing the carriage return lever.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/typewriter-top.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/typewriter-top.jpg\" alt=\"A mechanical typewriter. The lever for the carriage return is\non the outer left side.\" width=\"650\" height=\"434\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A mechanical typewriter. The lever for the carriage return is\non the outer left side.\n        <br \/>\n        Source: Source:\n<a rel=\"external\" href=\"https:\/\/www.piqsels.com\/da\/public-domain-photo-spbhs\">piqsels<\/a>\n    <\/figcaption>\n<\/figure>\n<ul>\n<li>On Unix systems (like Linux or macOS), a <code>\\n<\/code> still stands for a<br \/>\n<em>line feed<\/em> (ASCII symbol: LF) or <em>newline<\/em>.<\/li>\n<li>On CP\/M, DOS, and Windows, <code>\\r\\n<\/code> is used, where <code>\\r<\/code> stands for\n<em>carriage return<\/em> and <code>\\n<\/code> stands for line feed (CR+LF).<\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Newline\">Reference<\/a><\/li>\n<\/ul>\n<p>Here is an old video that shows the basic mechanics of carriage return and\nline-feed:<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/EWfElq1vgLA\" data-start=\"842\"\n>\n  <picture>\n    <source srcset=\"typewriter.avif\" type=\"image\/avif\" \/>\n    <img src=\"typewriter.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<h2 id=\"command-key-symbol\"><a class=\"anchor\" href=\"#command-key-symbol\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Command Key Symbol (\u2318)<\/h2>\n<p><em>Today\u2019s meaning: A meta-key available on Apple computers to provide additional\nkeyboard combinations.<\/em><\/p>\n<p>Directly quoting Wikipedia (emphasis mine):<\/p>\n<p>The \u2318 symbol came into the Macintosh project at a late stage. The development\nteam originally went for their old Apple key, but Steve Jobs found it\nfrustrating when \u201capples\u201d filled up the Mac\u2019s menus next to the key commands,\nbecause he felt that this was an over-use of the company logo. He then opted for\na different key symbol. With only a few days left before deadline, the team\u2019s\nbitmap artist Susan Kare started researching for the Apple logo\u2019s successor. She\nwas browsing through a symbol dictionary when she came across the\ncloverleaf-like symbol, commonly used in Nordic countries as an indicator of\ncultural locations and <strong>places of interest<\/strong> (it is the official road sign for\ntourist attraction in Denmark, Finland, Iceland, Norway, and Sweden and the\ncomputer key has often been called Fornminne \u2014 ancient monument \u2014 by Swedish Mac\nusers and Sev\u00e6rdighedstegn by Danish users). When she showed it to the rest of\nthe team, everyone liked it, and so it became the symbol of the 1984 Macintosh\ncommand key. Susan Kare states that it has since been told to her that the\nsymbol had been picked for its Scandinavian usage due to its resembling the\nshape of a square castle with round corner towers as seen from above looking\ndown, notably Borgholm Castle.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/severdighet.png\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/severdighet.png\" alt=\"Norwegian Severdighet road sign\" width=\"200\" height=\"200\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Norwegian Severdighet road sign\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Severdighet.svg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/borgholm.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/borgholm.jpg\" alt=\"Aerial view of Borgholm Castle, which could have been the model for the symbol \" width=\"650\" height=\"434\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Aerial view of Borgholm Castle, which could have been the model for the symbol\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Borgholms_slottsruin_fr%C3%A5n_luften.jpg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<p>References:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Command_key\">Wikipedia: Command Key<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.cultofmac.com\/181495\/what-are-the-macs-command-%E2%8C%98-and-option-%E2%8C%A5-symbols-supposed-to-represent\/\">Cult of Mac: What Are The Mac\u2019s Command \u2318 And Option \u2325 Symbols Supposed To\nRepresent?<\/a><\/li>\n<\/ul>\n<h2 id=\"cookie\"><a class=\"anchor\" href=\"#cookie\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Cookie<\/h2>\n<p><em>Today\u2019s meaning: A small piece of data sent from a website and stored in the\nuser\u2019s web browser.<\/em><\/p>\n<p>The term <em>cookie<\/em> was coined by  23-year-old web browser programmer Lou Montulli\nin the fall of 1994. It was\ninspired by the term <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Magic_cookie\"><em>magic cookie<\/em><\/a>, which is a packet of data a program\nreceives and sends back unchanged, used by Unix programmers.\nThis term in turn derives from the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Fortune_cookie\">fortune cookie<\/a>, which is a cookie with an embedded message.<\/p>\n<p>Montulli used the\nterm <em>cookie<\/em> to describe the small packets of data that the web browser\nreceives and sends back unchanged to the web server.<\/p>\n<blockquote>\n<p>\u201cSo, yeah, the cookie,\u201d Montulli says with a laugh. \u201cIt\u2019s one week of my life that turned into the most important thing that I ever did.\u201d (<a rel=\"external\" href=\"https:\/\/hiddenheroes.netguru.com\/lou-montulli\">Reference<\/a>)<\/p>\n<\/blockquote>\n<h2 id=\"core-dump\"><a class=\"anchor\" href=\"#core-dump\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Core Dump<\/h2>\n<p><em>Today\u2019s meaning: Retrieving a snapshot of a (crashed) program\u2019s state by\nstoring all of its memory for offline analysis.<\/em><\/p>\n<p>The name comes from <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Magnetic-core_memory\">magnetic core\nmemory<\/a>, which is an early\nstorage mechanism based on a grid of toroid magnets. It has since become\nobsolete, but the term is still used today for getting a snapshot of a computer\nprocess. <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Core_dump\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/corememory.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/corememory.jpg\" alt=\"A 32 x 32 core memory plane storing\n1024 bits (or 128 bytes) of data. The first core dumps were printed on paper, which sounds reasonable given these small amounts of bytes.\" width=\"650\" height=\"650\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A 32 x 32 core memory plane storing\n1024 bits (or 128 bytes) of data. The first core dumps were printed on paper, which sounds reasonable given these small amounts of bytes.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:KL_CoreMemory.jpg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"cursor\"><a class=\"anchor\" href=\"#cursor\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Cursor<\/h2>\n<p><em>Today\u2019s meaning: a visual cue (such as a flashing vertical line) on a video display that indicates position (as for data entry). <a rel=\"external\" href=\"https:\/\/www.merriam-webster.com\/dictionary\/cursor\">Merriam-Webster<\/a><\/em><\/p>\n<p><em>Cursor<\/em> is Latin for <em>runner<\/em>. A cursor is the name given to the transparent\nslide engraved with a hairline that is used for marking a point on a slide rule.\nThe term was then transferred to computers through analogy.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Cursor_(user_interface)\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/slide-rule.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/slide-rule.jpg\" alt=\"A December 1951 advertisement for the\nIBM 604 Electronic Calculating Punch that was first produced in 1948. The\nadvertisement claims the IBM 604 can do the work of 150 engineers with slide\nrules. The cursor (or runner) is the transparent part in the middle of the\nslide.\" width=\"650\" height=\"835\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: A December 1951 advertisement for the\nIBM 604 Electronic Calculating Punch that was first produced in 1948. The\nadvertisement claims the IBM 604 can do the work of 150 engineers with slide\nrules. The cursor (or runner) is the transparent part in the middle of the\nslide.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"daemon\"><a class=\"anchor\" href=\"#daemon\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Daemon<\/h2>\n<p>In computing, a daemon is a background process that handles requests for\nservices such as print spooling and file transfers, and then terminates. The\nterm was coined by the programmers of <a rel=\"external\" href=\"https:\/\/www.britannica.com\/topic\/Project-Mac\">MIT\u2019s Project MAC (Mathematics and Computation)<\/a> in 1963. They took the name from\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Maxwell%27s_demon\">Maxwell\u2019s demon<\/a>, a hypothetical creature from a thought experiment that\nconstantly works in the background, sorting molecules.<\/p>\n<blockquote>\n<p>The MIT programmers thought demon would be an appropriate name for a background process that worked tirelessly to perform system chores. But instead of using the term demon, they used daemon, which is an older form of the word. (<a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20230405225031\/https:\/\/www.techtarget.com\/whatis\/definition\/daemon\">Reference<\/a>)<\/p>\n<\/blockquote>\n<h2 id=\"dashboard\"><a class=\"anchor\" href=\"#dashboard\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Dashboard<\/h2>\n<p><em>Today\u2019s meaning: A user interface that provides a quick overview of a system\u2019s\nstatus.<\/em><\/p>\n<p>Originally a plank of wood at the front of a horse-drawn carriage to protect the\ndriver from mud \u2018dashed\u2019 backward by a horses hooves.<\/p>\n<p>When automobiles were manufactured, the board in front of the driver was given\nthe same name. That was the logical place to put the necessary gauges so the\ndriver could see them easily. In time, the term became more associated with the\nreadouts than the protection it offered.\n<a rel=\"external\" href=\"https:\/\/www.quora.com\/What-common-phrases-are-derived-from-obsolete-technologies\/answer\/Geoffrey-Widdison\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/dashboard.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/dashboard.jpg\" alt=\"A dashboard of a horse carriage.\" width=\"650\" height=\"538\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A dashboard of a horse carriage.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Dashboard_(PSF).png\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"firewall\"><a class=\"anchor\" href=\"#firewall\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Firewall<\/h2>\n<p><em>Today\u2019s meaning: A network security system that establishes a barrier between a trusted internal network and an untrusted external network, such as the Internet.<\/em><\/p>\n<p>Fire walls are used mainly in terraced houses, but also in individual residential buildings. They prevent fire and smoke from spreading to another part of the building in the event of a fire. Large fires can thus be prevented. The term is used in computing since the 80s.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Firewall_(computing)#History\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/firewall.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/firewall.jpg\" alt=\"Firewall residential construction, separating the building into two separate residential units, and fire areas.\" width=\"650\" height=\"655\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Firewall residential construction, separating the building into two separate residential units, and fire areas.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Brandwand_2.jpg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"firmware\"><a class=\"anchor\" href=\"#firmware\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Firmware<\/h2>\n<p><em>Today\u2019s meaning: A class of computer software that provides the low-level\ncontrol for the device\u2019s specific hardware and closely tied to the hardware it runs on.<\/em><\/p>\n<p><a rel=\"external\" href=\"https:\/\/archive.org\/details\/TNM_4th_generation_software_hardware_-_Datamation_20171010_0125\/mode\/2up\">Ascher\nOpler<\/a>\ncoined the term <em>firmware<\/em> in a 1967 Datamation article. As originally used,\nfirmware contrasted with hardware (the CPU itself) and software (normal\ninstructions executing on a CPU). It existed on the boundary between hardware\nand software; thus the name \u201cfirmware\u201d. The original article is available on the\n<a rel=\"external\" href=\"https:\/\/archive.org\/details\/TNM_4th_generation_software_hardware_-_Datamation_20171010_0125\/mode\/2up\">Internet\nArchive<\/a>.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Firmware\">Reference<\/a><\/p>\n<h2 id=\"foo-and-bar\"><a class=\"anchor\" href=\"#foo-and-bar\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Foo and Bar<\/h2>\n<p><em>Today\u2019s meaning: Common placeholder variable names.<\/em><\/p>\n<p>Originally the term might come from the military term <em>FUBAR<\/em>.\nThere are a few variations, but a common meaning is <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_military_slang_terms#FUBAR\">FUBAR: \u201cf***ed up beyond all recognition\u201d<\/a>.<\/p>\n<p>The use of <code>foo<\/code> in a programming context is generally credited to the Tech\nModel Railroad Club (TMRC) of MIT from circa 1960. In the complex model system,\nthere were scram switches located at numerous places around the room that could\nbe thrown if something undesirable was about to occur, such as a train going\nfull-bore at an obstruction.<\/p>\n<p>The way I understood it was that they literally had emergency buttons labeled\n<code>foo<\/code> for lack of a better name.\nMaybe related to the original military meaning of FUBAR to indicate that something is going very very wrong.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/scram.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/scram.jpg\" alt=\"A scram switch (button), that could be\npressed to prevent inadvertent operation. Maybe the TMRC had buttons labeled `foo` instead\" width=\"580\" height=\"480\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A scram switch (button), that could be\npressed to prevent inadvertent operation. Maybe the TMRC had buttons labeled <code>foo<\/code> instead\n        <br \/>\n        Source: Source <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:EBR-I_-_SCRAM_button.jpg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<p>References:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Foobar#History_and_etymology\">Wikipedia<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/a\/6727104\/270334\">Stack Overflow<\/a>.<\/li>\n<\/ul>\n<h2 id=\"freelancer\"><a class=\"anchor\" href=\"#freelancer\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Freelancer<\/h2>\n<p><em>Today\u2019s meaning: A self-employed person, which is not committed to a particular employer long-term.<\/em><\/p>\n<p>The term first appears in the novel <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Ivanhoe\">Ivanhoe<\/a> by Sir Walter Scott. (The novel also had a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Ivanhoe#Lasting_influence_on_the_Robin_Hood_legend\">lasting influence<\/a> on the Robin Hood legend.)<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/ivanhoe.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/ivanhoe.jpg\" alt=\"Cover of a Classic Comics book\" width=\"512\" height=\"688\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Cover of a Classic Comics book\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:CC_No_02_Ivanhoe_2.jpg\">Wikimedia Commons<\/a>\n    <\/figcaption>\n<\/figure>\n<p>In it, a Lord offers his paid army of \u2018free lances\u2019 to King Richard:<\/p>\n<blockquote>\n<p>I offered Richard the service of my Free Lances, and he refused them\n\u2014 I will lead them to Hull, seize on shipping, and embark for Flanders;\nthanks to the bustling times, a man of action will always find employment.<\/p>\n<\/blockquote>\n<p>Therefore, a \u201cfree lancer\u201d is someone who fights for whoever pays the most.\nFree does not mean \u201cwithout pay\u201d, but refers to the additional freedom to work for any employer. <a rel=\"external\" href=\"https:\/\/www.merriam-webster.com\/words-at-play\/freelance-origin-meaning\">Reference<\/a><\/p>\n<h2 id=\"hash\"><a class=\"anchor\" href=\"#hash\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Hash<\/h2>\n<p><em>Today\u2019s meaning: A hash function is any function that can be used to map data of arbitrary size to fixed-size values.<\/em><\/p>\n<p>According to Wikipedia, the use of the word \u201chash\u201d in hash function\n\u201ccomes by way of analogy with its non-technical meaning, to \u201cchop and mix\u201d.\nIndeed, typical hash functions, like the mod operation, \u201cchop\u201d the input domain\ninto many sub-domains that get \u201cmixed\u201d into the output range to improve the\nuniformity of the key distribution.\u201c<\/p>\n<p>References:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/softwareengineering.stackexchange.com\/a\/108127\">Software Engineering StackExchange<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Hash_function#History\">Wikipedia<\/a><\/li>\n<\/ul>\n<h2 id=\"log-logfile\"><a class=\"anchor\" href=\"#log-logfile\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Log \/ Logfile<\/h2>\n<p><em>Today\u2019s meaning: A file that records events of a computer program or system.<\/em><\/p>\n<p>Sailors used so-called log lines to measure the speed of their ship. A flat\npiece of wood (the log) was attached to a long rope. The log had regularly\nspaced knots in it. As the log would drift away, the sailors would count the\nnumber of knots that went out in a fixed time interval, and this would be the\nship\u2019s speed \u2014 in knots.<\/p>\n<p>The ship\u2019s speed was important for navigation, so the sailors noted it down in a book, aptly called the <em>log book<\/em>, together with other information to establish the position of the ship more accurately, like landmark sightings and weather events. Later, additional information, more generally concerning the ship, was added \u2014 or logged \u2014 such as harbor fees and abnormal provision depletion.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/www.usna.edu\/Users\/oceano\/pguth\/website\/shipwrecks\/logbooks_lesson\/logbooks_lesson.htm\">Reference<\/a>.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/log-seamen.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/log-seamen.jpg\" alt=\"Sailors measuring ship speed with a\nlog line\" width=\"650\" height=\"575\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Sailors measuring ship speed with a\nlog line\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/sites.rootsweb.com\/~mosmd\/logln.htm\">The Pilgrims &amp; Plymouth Colony:1620 by Duane A.\nCline<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/log-line.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/log-line.jpg\" alt=\"The parts of a log-line\" width=\"650\" height=\"839\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The parts of a log-line\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/sites.rootsweb.com\/~mosmd\/logln.htm\">The\nPilgrims &amp; Plymouth Colony:1620 by Duane A.\nCline<\/a>\n    <\/figcaption>\n<\/figure>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/logfile.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/logfile.jpg\" alt=\"Page from the log-file of the British\nWinchelsea. The second column denotes the number of knots measured with the\nlog-line, which indicates the ship's speed\" width=\"650\" height=\"773\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Page from the log-file of the British\nWinchelsea. The second column denotes the number of knots measured with the\nlog-line, which indicates the ship\u2019s speed\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/www.usna.edu\/Users\/oceano\/pguth\/website\/shipwrecks\/logbooks_lesson\/logbooks_lesson.htm\">Navigation and Logbooks\nin the Age of Sail by Peter\nReaveley<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"patch\"><a class=\"anchor\" href=\"#patch\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Patch<\/h2>\n<p><em>Today\u2019s meaning: A piece of code that can be applied to fix or improve a\ncomputer program.<\/em><\/p>\n<p>In the early days of computing history, if you made a programming mistake, you\u2019d\nhave to fix a paper tape or a punched card by putting a patch on top of a hole.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/patch.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/patch.jpg\" alt=\"A program tape with physical patches used\nto correct punched holes by covering them.\" width=\"639\" height=\"960\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A program tape with physical patches used\nto correct punched holes by covering them.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/americanhistory.si.edu\/archives\">Smithsonian Archives\nCenter<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"ping\"><a class=\"anchor\" href=\"#ping\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Ping<\/h2>\n<p><em>Today\u2019s meaning: A way to check the availability and response time of a computer over the network.<\/em><\/p>\n<p>Ping is a terminal program originally written by Mike Muuss in 1983 that is included in\nevery version of UNIX, Windows, and macOS. He named it \u201cafter the sound that a\nsonar makes, inspired by the whole principle of echo-location. [\u2026] ping uses\ntimed <code>IP\/ICMP ECHO_REQUEST<\/code> and <code>ECHO_REPLY<\/code> packets to probe the \u201cdistance\u201d to the\ntarget machine.\u201c The <a rel=\"external\" href=\"https:\/\/ftp.arl.army.mil\/~mike\/ping.html\">reference<\/a> is\nwell worth a read.<\/p>\n<h2 id=\"pixel\"><a class=\"anchor\" href=\"#pixel\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Pixel<\/h2>\n<p><em>Today\u2019s meaning: The smallest controllable element of a picture represented on the screen.<\/em><\/p>\n<p>The word pixel is a combination of <em>pix<\/em> (from \u201cpictures\u201d, shortened to \u201cpics\u201d) and <em>el<\/em> (for \u201celement\u201d).\nSimilarly, <em>voxel<\/em> is a volume element and <em>texel<\/em> is a texture element.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pixel\">Reference<\/a><\/p>\n<h2 id=\"shell\"><a class=\"anchor\" href=\"#shell\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Shell<\/h2>\n<p><em>Today\u2019s meaning: An interactive, commonly text-based runtime to interact with a\ncomputer system.<\/em><\/p>\n<p>The inventor of the term, Louis Pouzin, does not give an explanation for the\nname in his essay <a rel=\"external\" href=\"https:\/\/www.multicians.org\/shell.html\">The Origins of the\nShell<\/a>. It can however be traced back to\nUnix\u2019 predecessor Multics. It is described in the <a rel=\"external\" href=\"https:\/\/www.multicians.org\/mgs.html\">Multics\nglossary<\/a> like so:<\/p>\n<blockquote>\n<p>[The shell] is passed a command line for execution by the <strong>listener<\/strong>.<\/p>\n<\/blockquote>\n<p>The <em>The New Hacker\u2019s Dictionary<\/em>, (also known as the <em>Jargon File<\/em>) by <a rel=\"external\" href=\"http:\/\/www.catb.org\/~esr\/\">Eric S.\nRaymond<\/a> contains <a rel=\"external\" href=\"http:\/\/www.catb.org\/jargon\/html\/S\/shell.html\">the\nfollowing<\/a>:<\/p>\n<blockquote>\n<p>Historical note: Apparently, the original Multics shell (sense 1) was so\ncalled because it was a shell (sense 3);<\/p>\n<\/blockquote>\n<p>where sense 3 refers to<\/p>\n<blockquote>\n<p>A skeleton program, created by hand or by another program (like, say, a parser\ngenerator), which provides the necessary incantations to set up some task and\nthe control flow to drive it (the term driver is sometimes used synonymously).\nThe user is meant to fill in whatever code is needed to get real work done.\nThis usage is common in the AI and Microsoft Windows worlds, and confuses Unix\nhackers.<\/p>\n<\/blockquote>\n<p>Unfortunately, the book does not provide any evidence to back up this claim.<\/p>\n<p>I like the (possibly historically incorrect) analogy to a nut with the shell\nbeing on the outside, protecting the kernel.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/unix.stackexchange.com\/questions\/14934\/why-was-the-word-shell-used-to-descibe-a-command-line-interface\">Reference<\/a><\/p>\n<h2 id=\"slab-allocator\"><a class=\"anchor\" href=\"#slab-allocator\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Slab Allocator<\/h2>\n<p><em>Today\u2019s meaning: An efficient memory allocation technique, which reuses\nprevious allocations.<\/em><\/p>\n<p>Slab allocation was invented by <a rel=\"external\" href=\"https:\/\/www.usenix.org\/publications\/library\/proceedings\/bos94\/full_papers\/bonwick.ps\">John\nBonwick<\/a>\n(Note: PDF file) in 1994 and has since been used by services like\n<a rel=\"external\" href=\"https:\/\/www.memcached.org\/\">Memcached<\/a> and the Linux Kernel.<\/p>\n<blockquote>\n<p>With slab allocation, a cache for a certain type or size of data object has a\nnumber of pre-allocated \u201cslabs\u201d of memory; within each slab there are memory\nchunks of fixed size suitable for the objects.\n(<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Slab_allocation#Basis\">Wikipedia<\/a>)<\/p>\n<\/blockquote>\n<p>The name <em>slab<\/em> comes from a teenage friend of Bonwick. He <a rel=\"external\" href=\"https:\/\/blogs.oracle.com\/bonwick\/now-it-can-be-told\">tells the\nstory<\/a> on the Oracle blog:<\/p>\n<p>While watching TV together, a commercial by Kellogg\u2019s came on with the tag line,\n\u201cCan you pinch an inch?\u201d<\/p>\n<blockquote>\n<p>The implication was that you were overweight if you could pinch more than an\ninch of fat on your waist \u2014 and that hoovering a bowl of corn flakes would\nhelp.<\/p>\n<\/blockquote>\n<blockquote>\n<p>Without missing a beat, Tommy, who weighed about 250 pounds, reached for his\nmidsection and offered his response: \u201cHell, I can grab a slab!\u201d<\/p>\n<\/blockquote>\n<p>A decade later, Bonwick remembered that term when he was looking for a word to\ndescribe the allocation of a larger chunk of memory.<\/p>\n<p>Here is the original Kellogg\u2019s advertisement:<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/A8zYYg8wfmM\"\n>\n  <picture>\n    <source srcset=\"kellogs.avif\" type=\"image\/avif\" \/>\n    <img src=\"kellogs.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<h2 id=\"spam\"><a class=\"anchor\" href=\"#spam\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Spam<\/h2>\n<p><em>Today\u2019s meaning: Unsolicited electronic communications, for example by sending\nmass-emails or posting in forums and chats.<\/em><\/p>\n<p>The term goes back to a sketch by the British comedy group Monty Python from 1970.\nIn the sketch, a cafe is including\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Spam_(food)\">Spam<\/a> (a brand of canned cooked\npork) in almost every dish.\nSpam is a <a rel=\"external\" href=\"https:\/\/time.com\/4827451\/spam-history-80th-anniversary\/\">portmanteau of <em>spiced<\/em> and <em>ham<\/em><\/a>.\nThe excessive amount of Spam mentioned is a\nreference to the ubiquity of it and other imported canned meat products in the\nUK after World War II (a period of rationing in the UK) as the country struggled\nto rebuild its agricultural base.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Spamming#Etymology\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/spam.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/spam.jpg\" alt=\"Vintage Ad: Look What You Can Do With One\nCan of Spam \" width=\"500\" height=\"734\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Vintage Ad: Look What You Can Do With One\nCan of Spam\n        <br \/>\n        Source: By user <a rel=\"external\" href=\"https:\/\/www.flickr.com\/photos\/jbcurio\/3878241798\">Jamie (jbcurio) on\nflickr.com<\/a>\n    <\/figcaption>\n<\/figure>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/player.vimeo.com\/video\/329001211\"\n>\n  <picture>\n    <source srcset=\"spam_preview.avif\" type=\"image\/avif\" \/>\n    <img src=\"spam_preview.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p><a rel=\"external\" href=\"https:\/\/vimeo.com\/329001211\">Monty Pythons Flying Circus (1974) - SPAM<\/a> from\n<a rel=\"external\" href=\"https:\/\/vimeo.com\/user97138516\">Testing Tester<\/a> on <a rel=\"external\" href=\"https:\/\/vimeo.com\">Vimeo<\/a>.<\/p>\n<h2 id=\"mainframe\"><a class=\"anchor\" href=\"#mainframe\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Mainframe<\/h2>\n<p><em>Today\u2019s meaning: A large computer system, often used by large organizations.<\/em><\/p>\n<p>Originally, the term referred to the frame that held the main components of a\ncomputer. The main components were the CPU, memory, and I\/O devices. The term\nwas used in the 1960s and 1970s when computers were large and required a lot of\nspace.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/mainframe.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/mainframe.jpg\" alt=\"This diagram shows how the IBM 701 mainframe swings open for access to the circuitry. From 'Type 701 EDPM [Electronic Data Processing Machine] Installation Manual', IBM. From Computer History Museum archives.\" width=\"1930\" height=\"1378\"\n    \/>\n    <\/picture>\n    <figcaption>\n        This diagram shows how the IBM 701 mainframe swings open for access to the circuitry. From \u2018Type 701 EDPM [Electronic Data Processing Machine] Installation Manual\u2019, IBM. From Computer History Museum archives.\n    <\/figcaption>\n<\/figure>\n<p>Read more about that on <a rel=\"external\" href=\"http:\/\/www.righto.com\/2025\/02\/origin-of-mainframe-term.html\">Ken Shirriff\u2019s blog<\/a>.<\/p>\n<h2 id=\"radio-button\"><a class=\"anchor\" href=\"#radio-button\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Radio Button<\/h2>\n<p><em>Today\u2019s meaning: A UI element that allows to choose from a predefined set of\nmutually exclusive options<\/em><\/p>\n<p>\u201cRadio buttons\u201d are named after the analogous pendant of mechanical buttons that\nwere used in radios. The UI concept has later been used in tape recorders,\ncassette recorders and wearable audio players (the famous \u201cWalkman\u201d and\nsimilar). And later in VCRs and video cameras.\n<a rel=\"external\" href=\"https:\/\/www.jitbit.com\/radio-button\/\">Reference<\/a><\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/radio-buttons.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/radio-buttons.jpg\" alt=\"An old car radio (left) and CSS\nradio buttons (right). Only a single option can be selected at any point in\ntime. As a kid, I would push two buttons at once so they would interlock. Good\ntimes.\" width=\"650\" height=\"295\"\n    \/>\n    <\/picture>\n    <figcaption>\n        An old car radio (left) and CSS\nradio buttons (right). Only a single option can be selected at any point in\ntime. As a kid, I would push two buttons at once so they would interlock. Good\ntimes.\n        <br \/>\n        Source: Images by <a rel=\"external\" href=\"https:\/\/twitter.com\/themattcoady\">Matt Coady<\/a>\n    <\/figcaption>\n<\/figure>\n<h2 id=\"uppercase-and-lowercase\"><a class=\"anchor\" href=\"#uppercase-and-lowercase\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Uppercase and Lowercase<\/h2>\n<p><em>Today\u2019s meaning: Distinction between capital letters and small letters on a\nkeyboard.<\/em><\/p>\n<p>Back when typesetting was a manual process where single letters made of lead were\n\u201ctype set\u201d to form words and sentences, upper- and lowercase letters were kept\nin separate containers \u2014 or cases \u2014 to make this rather tedious process a little faster.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/folklore\/printers_cases.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/printers_cases.jpg\" alt=\"A set of printers cases\" width=\"650\" height=\"575\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A set of printers cases\n        <br \/>\n        Source: From the book \u2018Printing types, their history, forms, and use; a study in\nsurvivals\u2019 by Updike, Daniel Berkeley, 1860-1941. <a rel=\"external\" href=\"https:\/\/archive.org\/details\/printingtypesthe01updi\/\">Freely available on\narchive.org<\/a>.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"honorable-mentions\"><a class=\"anchor\" href=\"#honorable-mentions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Honorable Mentions<\/h2>\n<h3 id=\"404\"><a class=\"anchor\" href=\"#404\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>404<\/h3>\n<p><em>Today\u2019s meaning: HTTP Status Code for \u201cFile not found\u201d.<\/em><\/p>\n<p>There is a story that the number comes from the server room where the World Wide\nWeb\u2019s central database was located. In there, administrators would manually\nlocate the requested files and transfer them, over the network, to the person\nwho made that request. If a file didn\u2019t exist, they\u2019d return an error message:\n\u201cRoom 404: file not found\u201d.<\/p>\n<p>This, however, seems to be a myth and the status code was chosen rather\narbitrarily based on the then well-established FTP status codes.\n<a rel=\"external\" href=\"https:\/\/knowyourmeme.com\/memes\/404\">Reference<\/a><\/p>\n<h2 id=\"programming-languages-and-abbreviations\"><a class=\"anchor\" href=\"#programming-languages-and-abbreviations\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Programming Languages and Abbreviations<\/h2>\n<p>The etymology of programming language names and common abbreviations would\nprobably warrant its own article, but I\u2019ve decided to note down some of my\nfavorites for the time being.<\/p>\n<h3 id=\"c\"><a class=\"anchor\" href=\"#c\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>C++<\/h3>\n<p>C++ is a programming language based on C by Bjarne Stroustrup. The name is a\nprogrammer pun by Rick Mascitti, a coworker of Stroustrup. The <code>++<\/code> refers to\nthe post-increment operator, that is common in many C-like languages. It\nincreases the value of a variable by 1. In that sense, C++ can be seen as the\nspiritual \u201csuccessor\u201d of C.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/C%2B%2B#History\">Reference<\/a><\/p>\n<h3 id=\"c-sharp\"><a class=\"anchor\" href=\"#c-sharp\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>C Sharp<\/h3>\n<p>Similarly to C++, C# is a C-like programming language. The name again refers to\n\u201cincremental\u201d improvements on top of C++. The <code>#<\/code> in the name looks like four\nplus signs. Hence <code>C# == (C++)++<\/code>. But on top of that, the name was also\ninspired by the musical notation where a sharp indicates that the written note\nshould be made a semitone higher in pitch.\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/C_Sharp_(programming_language)#Name\">Reference<\/a><\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2020\/folklore\/csharp.svg\" alt=\"A C-Sharp note.\" width=\"274\" height=\"227\"\n    \/>\n    <figcaption>\n        A C-Sharp note.\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Treblecsharp5.svg\">Wikimedia\nCommons<\/a>\n    <\/figcaption>\n<\/figure>\n<h3 id=\"png\"><a class=\"anchor\" href=\"#png\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>PNG<\/h3>\n<p>Officially, PNG stands for <em>Portable Network Graphics<\/em>. It was born out of\nfrustration over a CompuServe announcement in 1994 that programs supporting GIF\nwould have to pay licensing fees from now on. A working group led by hacker\n<a rel=\"external\" href=\"https:\/\/boutell.dev\/\">Thomas Boutell<\/a> created the <code>.webp<\/code> file format, a\npatent-free replacement for GIF. Therefore I prefer the format\u2019s unofficial\nname: <em>PNG\u2019s Not GIF<\/em>. Here\u2019s a <a rel=\"external\" href=\"https:\/\/people.apache.org\/~jim\/NewArchitect\/webrevu\/1997\/05_09\/designers\/05_09_97_1.html\">great\narticle<\/a>\non PNG\u2019s history.\n<a rel=\"external\" href=\"https:\/\/encyclopedia2.thefreedictionary.com\/PNG%27s+Not+GIF\">Reference<\/a><\/p>\n<h2 id=\"credits\"><a class=\"anchor\" href=\"#credits\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Credits<\/h2>\n<p>Most of the content comes from sources like Wikipedia (with reference where\nappropriate), but the explanations are difficult to hunt down if you don\u2019t know\nwhat you\u2019re looking for.<br \/>\nThis is a living document, and I\u2019m planning to update it in case of reader\nsubmissions.<\/p>\n<h2 id=\"conclusion\"><a class=\"anchor\" href=\"#conclusion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Conclusion<\/h2>\n<blockquote>\n<p>You have to know the past to understand the present.<br \/>\n\u2014 Dr. Carl Sagan (1980)<\/p>\n<\/blockquote>\n<p>I hope you enjoyed this trip down memory lane. Now it\u2019s your turn!<br \/>\n\ud83d\udc49 Do you know any other stories? Send me a message, and I\u2019ll add them here.<\/p>\n<h2 id=\"related-projects\"><a class=\"anchor\" href=\"#related-projects\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Related Projects<\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/watson\/awesome-computer-history\">Awesome Computer History<\/a>:\nA curated list of computer history videos, documentaries and related folklore\nmaintained by Thomas Watson.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_computer_term_etymologies\">Wikipedia: List of computer term etymologies<\/a>:\nList of the origins of computer-related terms or terms used in the computing world.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=2KTK2qD4-gs\">Talk: The Etymology of Programming by Brittany Storoz - JSConf EU\n2018<\/a>: A talk that explains the background behind a few programming terms. Careful here: the explanation for \u201cbug\u201d is probably wrong as mentioned above.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Typewriter#Terminology\">Typewriter terminology that has survived into the personal computer\nera<\/a>:\nA list of computer terms that have their origins from typewriters.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.folklore.org\">Folklore - The Original Macintosh<\/a>:\nAnecdotes about the development of Apple\u2019s original Macintosh, and the people who made it.<\/li>\n<\/ul>\n"},{"title":"A Timelapse of Timelapse","pubDate":"Tue, 04 Feb 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2020\/timelapse\/","guid":"https:\/\/endler.dev\/2020\/timelapse\/","description":"<p><a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\">Timelapse<\/a> is a little open-source screen\nrecorder for macOS. It takes a screenshot every second and creates a movie in\nthe end.<\/p>\n<p>To celebrate its unlikely 1.0 release today, I present here a \u201ctimelapse\u201d of\nthis project\u2019s journey. It just took <em>ten years<\/em> to get here.<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/_QEmxAZqQhE\"\n>\n  <picture>\n    <source srcset=\"timelapse.avif\" type=\"image\/avif\" \/>\n    <img src=\"timelapse.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<h2 id=\"2011-how-it-all-began\"><a class=\"anchor\" href=\"#2011-how-it-all-began\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2011 - How It All Began<\/h2>\n<p>To be honest, I don\u2019t remember why I initially wrote the tool. I must have had a\npersonal need for a screen recorder, I guess\u2026<\/p>\n<p>In May 2011, when I started the project, I was doing my Masters Degree in\nComputer Science. I might have needed the tool for University; most likely,\nhowever, I was just trying to find an excuse for not working on an assignment.<\/p>\n<p>During that time, I wrote a lot of tools like that. Mainly to scratch a personal\nitch, learn a new programming language, or just have fun.<\/p>\n<p>Among them are tools like a <a rel=\"external\" href=\"https:\/\/github.com\/mre\/ihatesubways\">random sandwich\ngenerator<\/a> for Subway (the American\nfast-food chain), <a rel=\"external\" href=\"https:\/\/github.com\/mre\/DrawRoom\">DrawRoom<\/a>, a keyboard-driven\ndrawing app inspired by\n<a rel=\"external\" href=\"http:\/\/www.hogbaysoftware.com\/products\/writeroom\">WriteRoom<\/a>, and the\n<a rel=\"external\" href=\"https:\/\/github.com\/mre\/Creamy\">obligatory CMS software<\/a>, that I sold to\nclients. Surprisingly, none of them were a great success.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2020\/timelapse\/drawroom.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2020\/timelapse\/drawroom.jpg\" alt=\"DrawRoom, a tool that I wrote around the same time, is a real piece of art. To this day it has five commits and a single Github star (by myself, don't judge...).\" width=\"650\" height=\"393\"\n    \/>\n    <\/picture>\n    <figcaption>\n        DrawRoom, a tool that I wrote around the same time, is a real piece of art. To this day it has five commits and a single Github star (by myself, don\u2019t judge\u2026).\n    <\/figcaption>\n<\/figure>\n<p>What I <em>do<\/em> know for sure is that I was unhappy with all existing screen\nrecorders. They could roughly be categorized into these three groups:<\/p>\n<ul>\n<li>Proprietary solutions that cost money or could call home.<\/li>\n<li>Tools that didn\u2019t work on macOS.<\/li>\n<li>Small, fragile, one-off scripts that people passed around in forums or as\nGithub gists. They rarely worked as advertised.<\/li>\n<\/ul>\n<p>Among the remaining tools were none that provided any timelapse functionality;\nso I set out to write my own.<\/p>\n<p>This all sounds very epic, but in reality, I worked on it for a day. After five\nheroic commits on May 11, 2011, it sat there, idle, for seven years\u2026<\/p>\n<h2 id=\"2018\"><a class=\"anchor\" href=\"#2018\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2018<\/h2>\n<p>A lot of time elapsed before anything exciting happened.<\/p>\n<p>In January \u201918, seemingly out of nowhere, the first user filed a bug report. It\nwas titled <a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\/issues\/1\">hung when creating the\navi<\/a> \ud83d\ude31. Turns out that a game\ndeveloper from Canada,\n<a rel=\"external\" href=\"https:\/\/www.youtube.com\/channel\/UCs2DJ9xpGic1pQkWNMwAUHw\">juul1a<\/a>, was trying\nto use the tool to track her progress on an indie game \u2014 how cool is that?<\/p>\n<p>To help her out, I decided to do some general cleanup, finally write down some\ninstructions on how to even use the program, add a <code>requirements.txt<\/code>, and <a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\/commit\/0b43515037670604143bf3b3eb06061ecfbbe108\">port\nthe tool from mencoder to\nffmpeg<\/a>.<\/p>\n<p>After that, timelapse was ready for prime-time. \ud83c\udfac Here is some live action from\nher videos featuring timelapses:<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/vv2CCwEM8Ws\"\n>\n  <picture>\n    <source srcset=\"preview.avif\" type=\"image\/avif\" \/>\n    <img src=\"preview.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<p>At that point, the tool was still very wobbly and could only be used from the\ncommandline, but I began to see some potential for building a proper app from\nit; I just never found the <em>time<\/em>.<\/p>\n<p>In October \u201918, I decided to ask for support during\n<a rel=\"external\" href=\"https:\/\/hacktoberfest.digitalocean.com\/\">Hacktoberfest<\/a>. I created a few\ntickets and labeled them with <code>hacktoberfest<\/code> to try and find contributors.<\/p>\n<p>And then, I waited.<\/p>\n<p>First, <a rel=\"external\" href=\"https:\/\/github.com\/ShreyaPrabhu\">Shreya V Prabhu<\/a> fixed an issue where a\nnew recording was overwriting the previous one by adding a <a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\/pull\/3\">timestamp to the\nvideo name<\/a>. Then <a rel=\"external\" href=\"https:\/\/github.com\/abnerpc\">Abner\nCampanha<\/a> and Shane\nCreedon (no longer on Github) created a basic test structure.\n<a rel=\"external\" href=\"https:\/\/github.com\/seleregb\">Gbenro Selere<\/a> added a CI pipeline for Travis CI.\nIt really worked, and the project was in much better shape after that!<\/p>\n<h2 id=\"2019\"><a class=\"anchor\" href=\"#2019\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2019<\/h2>\n<p>One year passes by, and <a rel=\"external\" href=\"https:\/\/github.com\/Kerl1310\">Kyle Jones<\/a> adds some\ncontribution guidelines, while I move the CI pipeline to the newly released\nGithub actions.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/cmangla\">Chaitanya<\/a> fixed a bug where the program would hang when\nthe recording stopped by <a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\/pull\/24\">moving the video creation from threads to a separate\nprocess<\/a>. He continued to make the\ncodebase more robust and became a core contributor, reviewing pull requests and\nhandling releases.<\/p>\n<p>Thanks to <a rel=\"external\" href=\"https:\/\/github.com\/orcutt989\">orcutt989<\/a>, the app now made use of\n<a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\/pull\/33\">type hints in Python 3.6<\/a>.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/gkpln3\">gkpln3<\/a> added support for multi-monitor\nconfigurations. The screen captured will always be the one with the mouse on it.<\/p>\n<h2 id=\"2020\"><a class=\"anchor\" href=\"#2020\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2020<\/h2>\n<p>Fast forward to today, and after almost <em>ten years<\/em>, we finally created a true\nmacOS app using the awesome <a rel=\"external\" href=\"https:\/\/github.com\/ronaldoussoren\/py2app\">py2app<\/a>\nbundler. This should make the tool usable by non-developers.<\/p>\n<h2 id=\"back-to-the-future\"><a class=\"anchor\" href=\"#back-to-the-future\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Back to the Future<\/h2>\n<p>We reached the end of our little journey.<\/p>\n<p>A long time has passed until 1.0. This project is a testament to the wonders of\nopen source collaboration, and I am proud to work on it with contributors from\naround the world. It doesn\u2019t have to be a life-changing project to bring people\ntogether who have fun building things. If this were the end of the story, I\u2019d be\nokay with that. I doubt it, though. Here\u2019s to the next ten years!<\/p>\n<p>\ud83c\udfac <a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse\">Download timelapse on Github<\/a>.<\/p>\n<h2 id=\"bonus\"><a class=\"anchor\" href=\"#bonus\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bonus<\/h2>\n<p>The video at the beginning is a timelapse of how I finish this article.<br \/>\nHow meta.<\/p>\n"},{"title":"Github Stars","pubDate":"Wed, 01 Jan 2020 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/static\/about\/stars\/","guid":"https:\/\/endler.dev\/static\/about\/stars\/","description":"<table><thead><tr><th style=\"text-align: left\">Repository<\/th><th style=\"text-align: right\">Stars<\/th><\/tr><\/thead><tbody>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/analysis-tools-dev\/static-analysis\">analysis-tools-dev\/static-analysis<\/a><\/td><td style=\"text-align: right\">14875 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/idiomatic-rust\">mre\/idiomatic-rust<\/a><\/td><td style=\"text-align: right\">7907 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee\">lycheeverse\/lychee<\/a><\/td><td style=\"text-align: right\">4099 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/tinysearch\/tinysearch\">tinysearch\/tinysearch<\/a><\/td><td style=\"text-align: right\">2980 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/the-coding-interview\">mre\/the-coding-interview<\/a><\/td><td style=\"text-align: right\">1746 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/analysis-tools-dev\/dynamic-analysis\">analysis-tools-dev\/dynamic-analysis<\/a><\/td><td style=\"text-align: right\">1109 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/ReceiptManager\/receipt-parser-legacy\">ReceiptManager\/receipt-parser-legacy<\/a><\/td><td style=\"text-align: right\">856 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/lycheeverse\/lychee-action\">lycheeverse\/lychee-action<\/a><\/td><td style=\"text-align: right\">526 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/hyperjson\">mre\/hyperjson<\/a><\/td><td style=\"text-align: right\">511 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/cargo-inspect\">mre\/cargo-inspect<\/a><\/td><td style=\"text-align: right\">383 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/hello-rust\/show\">hello-rust\/show<\/a><\/td><td style=\"text-align: right\">317 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/fcat\">mre\/fcat<\/a><\/td><td style=\"text-align: right\">281 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/vscode-snippet\">mre\/vscode-snippet<\/a><\/td><td style=\"text-align: right\">256 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/kafka-influxdb\">mre\/kafka-influxdb<\/a><\/td><td style=\"text-align: right\">218 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/ReceiptManager\/receipt-manager-app\">ReceiptManager\/receipt-manager-app<\/a><\/td><td style=\"text-align: right\">218 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/timelapse-python\">mre\/timelapse-python<\/a><\/td><td style=\"text-align: right\">212 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/prettyprint\">mre\/prettyprint<\/a><\/td><td style=\"text-align: right\">201 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/zerocal\">mre\/zerocal<\/a><\/td><td style=\"text-align: right\">170 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/endler.dev\">mre\/endler.dev<\/a><\/td><td style=\"text-align: right\">112 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/mre\/mos6502\">mre\/mos6502<\/a><\/td><td style=\"text-align: right\">112 \u2605<\/td><\/tr>\n<tr><td style=\"text-align: left\"><a rel=\"external\" href=\"https:\/\/github.com\/ReceiptManager\/receipt-parser-server\">ReceiptManager\/receipt-parser-server<\/a><\/td><td style=\"text-align: right\">102 \u2605<\/td><\/tr>\n<\/tbody><\/table>\n"},{"title":"A Tiny, Static, Full-Text Search Engine Using Rust and WebAssembly","pubDate":"Thu, 17 Oct 2019 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2019\/tinysearch\/","guid":"https:\/\/endler.dev\/2019\/tinysearch\/","description":"<div class=\"info\">\n    <p>I wrote a basic search module that you can add to a static website.\nIt\u2019s very lightweight (50kB-100kB gzipped) and works with Hugo, Zola, and\nJekyll. Only searching for entire words is supported. Try the search box on the\nleft for a demo. <a rel=\"external\" href=\"https:\/\/github.com\/mre\/tinysearch\">The code is on Github<\/a>.<\/p>\n<\/div>\n<p>Static site generators are magical. They combine the best of both worlds:\ndynamic content without sacrificing performance.<\/p>\n<p>Over the years, this blog has been running on <a rel=\"external\" href=\"https:\/\/github.com\/mre\/mre.github.io.v1\">Jekyll<\/a>, <a rel=\"external\" href=\"https:\/\/github.com\/mre\/mre.github.io.v2\">Cobalt<\/a>, and, lately,\n<a rel=\"external\" href=\"https:\/\/www.getzola.org\/\">Zola<\/a>.<\/p>\n<p>One thing I always disliked, however, was the fact that static websites don\u2019t\ncome with \u201cstatic\u201d search engines, too. Instead, people resort to <a rel=\"external\" href=\"https:\/\/cse.google.com\/about\">custom Google\nsearches<\/a>, external search engines like <a rel=\"external\" href=\"https:\/\/www.algolia.com\/\">Algolia<\/a>, or pure\nJavaScript-based solutions like <a rel=\"external\" href=\"https:\/\/lunrjs.com\/\">lunr.js<\/a> or <a rel=\"external\" href=\"http:\/\/elasticlunr.com\/\">elasticlunr<\/a>.<\/p>\n<p>All of these work fine for most sites, but it never felt like the final answer.<\/p>\n<p>I didn\u2019t want to add yet another dependency on Google; neither did I want to use\na stand-alone web-backend like Algolia, which adds latency and is proprietary.<\/p>\n<p>On the other side, I\u2019m not a huge fan of JavaScript-heavy websites. For example,\njust the search indices that lunr creates can be <a rel=\"external\" href=\"https:\/\/github.com\/olivernn\/lunr.js\/issues\/268#issuecomment-304490937\">multiple megabytes\nin size<\/a>.\nThat feels lavish - even by today\u2019s bandwidth standards. On top of that,\n<a rel=\"external\" href=\"https:\/\/v8.dev\/blog\/cost-of-javascript-2019\">parsing JavaScript is still\ntime-consuming<\/a>.<\/p>\n<p>I wanted some simple, lean, and self-contained search, that could be deployed\nnext to my other static content.<\/p>\n<p>As a consequence, I refrained from adding search functionality to my blog at\nall. That\u2019s unfortunate because, with a growing number of articles, it gets\nharder and harder to find relevant content.<\/p>\n<h2 id=\"the-idea\"><a class=\"anchor\" href=\"#the-idea\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Idea<\/h2>\n<p>Many years ago, in 2013, I read <a rel=\"external\" href=\"https:\/\/www.stavros.io\/posts\/bloom-filter-search-engine\/\">\u201cWriting a full-text search engine using Bloom\nfilters\u201d<\/a> \u2014 and it was a revelation.<\/p>\n<p>The idea was simple: Let\u2019s run all my blog articles through a generator that\ncreates a tiny, self-contained search index using this magical data structure\ncalled a\n\u2728<em>Bloom Filter<\/em> \u2728.<\/p>\n<h2 id=\"wait-what-s-a-bloom-filter\"><a class=\"anchor\" href=\"#wait-what-s-a-bloom-filter\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Wait, What\u2019s a Bloom Filter?<\/h2>\n<p>A <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Bloom_filter\">Bloom filter<\/a> is a space-efficient way to\ncheck if an element is in a set.<\/p>\n<p>The trick is that it doesn\u2019t store the elements themselves; it just knows with\nsome confidence that they were stored before. In our case, it can say with a\ncertain <em>error rate<\/em> that a word is in an article.<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2019\/tinysearch\/bloomfilter.svg\" alt=\"A Bloom filter stores a\n'fingerprint' (a number of hash values) of all input values instead of the raw\ninput. The result is a low-memory-footprint data structure. This is an example\nof 'hello' as an input.\" width=\"345\" height=\"230\"\n    \/>\n    <figcaption>\n        A Bloom filter stores a\n\u2018fingerprint\u2019 (a number of hash values) of all input values instead of the raw\ninput. The result is a low-memory-footprint data structure. This is an example\nof \u2018hello\u2019 as an input.\n    <\/figcaption>\n<\/figure>\n<p>Here\u2019s the Python code from the original article that generates the Bloom\nfilters for each post (courtesy of <a rel=\"external\" href=\"https:\/\/www.stavros.io\">Stavros\nKorokithakis<\/a>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span>filters<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span> name<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> words<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> split_posts<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">items<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">  filters<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">name<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-d-2\"> BloomFilter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">capacity<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>words<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> error_rate<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-16 z-d-16\">0.1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  for<\/span><span> word<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> words<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">    filters<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">name<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>word<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>The memory footprint is extremely small, thanks to <code>error_rate<\/code>, which allows\nfor a negligible number of false positives.<\/p>\n<p>I immediately knew that I wanted something like this for my homepage. My idea\nwas to directly ship the Bloom filters and the search engine to the browser. I\ncould finally have a small, static search without the need for a backend!<\/p>\n<h2 id=\"headaches\"><a class=\"anchor\" href=\"#headaches\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Headaches<\/h2>\n<p>Disillusionment came quickly.<\/p>\n<p>I had no idea how to bundle and minimize the generated Bloom filters, let alone\nrun them on clients. The original article briefly touches on this:<\/p>\n<blockquote>\n<p>You need to implement a Bloom filter algorithm on the client-side. This will\nprobably not be much longer than the inverted index search algorithm, but it\u2019s\nstill probably a bit more complicated.<\/p>\n<\/blockquote>\n<p>I didn\u2019t feel confident enough in my JavaScript skills to pull this off. Back in\n2013, NPM was a mere three years old, and WebPack just turned one, so I also\ndidn\u2019t know where to look for existing solutions.<\/p>\n<p>Unsure what to do next, my idea remained a pipe dream.<\/p>\n<h2 id=\"a-new-hope\"><a class=\"anchor\" href=\"#a-new-hope\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A New Hope<\/h2>\n<p>Five years later, in 2018, the web had become a different place. Bundlers were\nubiquitous, and the Node ecosystem was flourishing. One thing, in particular,\nrevived my dreams about the tiny static search engine: <a rel=\"external\" href=\"https:\/\/webassembly.org\/\">WebAssembly<\/a>.<\/p>\n<blockquote>\n<p>WebAssembly (abbreviated Wasm) is a binary instruction format for a\nstack-based virtual machine. Wasm is designed as a portable target for\ncompilation of high-level languages like C\/C++\/Rust, enabling deployment on\nthe web for client and server applications. [<a rel=\"external\" href=\"https:\/\/webassembly.org\/\">source<\/a>]<\/p>\n<\/blockquote>\n<p>This meant that I could use a language that I was familiar with to write the\nclient-side code \u2014 Rust! \ud83c\udf89<\/p>\n<p>My journey started with a <a rel=\"external\" href=\"https:\/\/github.com\/mre\/tinysearch\/commit\/82c1d36835348718f04c9ca0dd2c1ebf8b19a312\">prototype back in January\n2018<\/a>.\nIt was just a direct port of the Python version from above:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> filters<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HashMap<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>name<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> words<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> articles<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> filter<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> BloomFilter<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">with_rate<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> words<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> as<\/span><span class=\"z-l-9 z-d-9\"> u32<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  for<\/span><span> word<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> words<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    filter<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">insert<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>word<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span>  filters<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">insert<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>name<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> filter<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>While I managed to create the Bloom filters for every article, I <em>still<\/em> had no\nclue how to package it for the web\u2026 until <a rel=\"external\" href=\"https:\/\/github.com\/rustwasm\/wasm-pack\/commit\/125431f97eecb6f3ca5122f8b345ba5b7eee94c7\">wasm-pack came along in\nFebruary\n2018<\/a>.<\/p>\n<h2 id=\"whoops-i-shipped-some-rust-code-to-your-browser\"><a class=\"anchor\" href=\"#whoops-i-shipped-some-rust-code-to-your-browser\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Whoops! I Shipped Some Rust Code to Your Browser.<\/h2>\n<p>Now I had all the pieces of the puzzle:<\/p>\n<ul>\n<li>Rust \u2014 A language I was comfortable with<\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/rustwasm\/wasm-pack\">wasm-pack<\/a> \u2014 A bundler for WebAssembly modules<\/li>\n<li>A working prototype that served as a proof-of-concept<\/li>\n<\/ul>\n<p>The search box you see on the left side of this page is the outcome. It fully runs on Rust using\nWebAssembly (a.k.a the <a rel=\"external\" href=\"https:\/\/twitter.com\/timClicks\/status\/1181822319620063237\">RAW stack<\/a>). Try it now if you like.<\/p>\n<p>There were quite a few obstacles along the way.<\/p>\n<h2 id=\"bloom-filter-crates\"><a class=\"anchor\" href=\"#bloom-filter-crates\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bloom Filter Crates<\/h2>\n<p>I looked into a few Rust libraries (crates) that implement Bloom filters.<\/p>\n<p>First, I tried jedisct1\u2019s\n<a rel=\"external\" href=\"https:\/\/github.com\/jedisct1\/rust-bloom-filter\">rust-bloom-filter<\/a>, but the types\ndidn\u2019t implement\n<a rel=\"external\" href=\"https:\/\/docs.serde.rs\/serde\/trait.Serialize.html\">Serialize<\/a>\/<a rel=\"external\" href=\"https:\/\/docs.serde.rs\/serde\/trait.Deserialize.html\">Deserialize<\/a>.\nThis meant that I could not store my generated Bloom filters inside the binary and load\nthem on the client-side.<\/p>\n<p>After trying a few others, I found the\n<a rel=\"external\" href=\"https:\/\/github.com\/seiflotfy\/rust-cuckoofilter\">cuckoofilter<\/a> crate, which\nsupported serialization. The behavior is similar to Bloom filters, but if you\u2019re\ninterested in the differences, you can look at <a rel=\"external\" href=\"https:\/\/brilliant.org\/wiki\/cuckoo-filter\/\">this\nsummary<\/a>.<\/p>\n<p>Here\u2019s how to use it:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> cf<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> cuckoofilter<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Add data to the filter<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> value<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">hello world<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> success<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> cf<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">add<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>value<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Lookup if data was added before<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> success<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> cf<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">contains<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>value<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> success ==&gt; true<\/span><\/span><\/code><\/pre>\n<p>Let\u2019s check the output size when bundling the filters for ten articles on my blog using cuckoo filters:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>~\/C\/p\/tinysearch \u276f\u276f\u276f l storage<\/span><\/span>\n<span class=\"giallo-l\"><span>Permissions Size User    Date Modified Name<\/span><\/span>\n<span class=\"giallo-l\"><span>.rw-r--r--   44k mendler 24 Mar 15:42  storage<\/span><\/span><\/code><\/pre>\n<p><strong>44kB<\/strong> doesn\u2019t sound too shabby, but these are just the cuckoo filters for ten\narticles, serialized as a Rust binary. On top of that, we have to add the search\nfunctionality and the helper code. In total, the client-side code weighed in at\n<strong>216kB<\/strong> using vanilla wasm-pack. Too much.<\/p>\n<h2 id=\"trimming-binary-size\"><a class=\"anchor\" href=\"#trimming-binary-size\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Trimming Binary Size<\/h2>\n<p>After the sobering first result of 216kB for our initial prototype, we have a\nfew options to bring the binary size down.<\/p>\n<p>The first is following <a rel=\"external\" href=\"https:\/\/github.com\/johnthagen\">johnthagen\u2019s<\/a> advice on\n<a rel=\"external\" href=\"https:\/\/github.com\/johnthagen\/min-sized-rust\">minimizing Rust binary size<\/a>.<\/p>\n<p>By setting a few options in our <code>Cargo.toml<\/code>, we can shave off quite a few bytes:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&quot;opt-level = &#39;z&#39;&quot; =&gt; 249665 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>&quot;lto = true&quot;      =&gt; 202516 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>&quot;opt-level = &#39;s&#39;&quot; =&gt; 195950 bytes<\/span><\/span><\/code><\/pre>\n<p>Setting <code>opt-level<\/code> to <code>s<\/code> means we trade size for speed,\nbut we\u2019re preliminarily interested in minimal size anyway. After all, a small download size also improves performance.<\/p>\n<p>Next, we can try <a rel=\"external\" href=\"https:\/\/github.com\/rustwasm\/wee_alloc\">wee_alloc<\/a>, an alternative Rust allocator\nproducing a small <code>.wasm<\/code> code size.<\/p>\n<blockquote>\n<p>It is geared towards code that makes a handful of initial dynamically sized allocations, and then performs its heavy lifting without any further allocations. This scenario requires some allocator to exist, but we are more than happy to trade allocation performance for small code size.<\/p>\n<\/blockquote>\n<p>Exactly what we want. Let\u2019s try!<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&quot;wee_alloc and nightly&quot; =&gt; 187560 bytes<\/span><\/span><\/code><\/pre>\n<p>We shaved off another 4% from our binary.<\/p>\n<p>Out of curiosity, I tried to set <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/rustc\/codegen-options\/index.html#codegen-units\">codegen-units<\/a> to 1, meaning we only use a single thread for code generation. Surprisingly, this resulted in a slightly smaller binary size.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&quot;codegen-units = 1&quot; =&gt; 183294 bytes<\/span><\/span><\/code><\/pre>\n<p>Then I got word of a Wasm optimizer called <code>binaryen<\/code>.\nOn macOS, it\u2019s available through homebrew:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>brew install binaryen<\/span><\/span><\/code><\/pre>\n<p>It ships a binary called <code>wasm-opt<\/code> and that shaved off another 15%:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&quot;wasm-opt -Oz&quot; =&gt; 154413 bytes<\/span><\/span><\/code><\/pre>\n<p>Then I removed web-sys as we don\u2019t have to bind to the DOM: 152858 bytes.<\/p>\n<p>There\u2019s a tool called <a rel=\"external\" href=\"https:\/\/github.com\/rustwasm\/twiggy\">twiggy<\/a> to profile the code size of Wasm binaries.\nIt printed the following output:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>twiggy top -n 20 pkg\/tinysearch_bg.wasm<\/span><\/span>\n<span class=\"giallo-l\"><span> Shallow Bytes \u2502 Shallow % \u2502 Item<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500<\/span><\/span>\n<span class=\"giallo-l\"><span>         79256 \u250a    44.37% \u250a data[0]<\/span><\/span>\n<span class=\"giallo-l\"><span>         13886 \u250a     7.77% \u250a &quot;function names&quot; subsection<\/span><\/span>\n<span class=\"giallo-l\"><span>          7289 \u250a     4.08% \u250a data[1]<\/span><\/span>\n<span class=\"giallo-l\"><span>          6888 \u250a     3.86% \u250a core::fmt::float::float_to_decimal_common_shortest::hdd201d50dffd0509<\/span><\/span>\n<span class=\"giallo-l\"><span>          6080 \u250a     3.40% \u250a core::fmt::float::float_to_decimal_common_exact::hcb5f56a54ebe7361<\/span><\/span>\n<span class=\"giallo-l\"><span>          5972 \u250a     3.34% \u250a std::sync::once::Once::call_once::{{closure}}::ha520deb2caa7e231<\/span><\/span>\n<span class=\"giallo-l\"><span>          5869 \u250a     3.29% \u250a search<\/span><\/span><\/code><\/pre>\n<p>From what I can tell, the biggest chunk of our binary is occupied by the raw data section for our articles.\nNext up, we got the function headers and some float to decimal helper functions, that most likely come from deserialization.<\/p>\n<p>Finally, I tried <a rel=\"external\" href=\"https:\/\/github.com\/rustwasm\/wasm-snip\">wasm-snip<\/a>, which replaces a WebAssembly function\u2019s body with an <code>unreachable<\/code> like so, but it didn\u2019t reduce code size:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>wasm-snip --snip-rust-fmt-code --snip-rust-panicking-code -o pkg\/tinysearch_bg_snip.wasm pkg\/tinysearch_bg_opt.wasm<\/span><\/span><\/code><\/pre>\n<p>After tweaking with the parameters of the cuckoo filters a bit and removing\n<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Stop_words\">stop words<\/a> from the articles, I\narrived at <strong>121kB<\/strong> (51kB gzipped) \u2014 not bad considering the average image size on the web is <a rel=\"external\" href=\"https:\/\/httparchive.org\/reports\/state-of-images#bytesImg\">around 900kB<\/a>.\nOn top of that, the search functionality only gets loaded when a user clicks into the search field.<\/p>\n<h2 id=\"update\"><a class=\"anchor\" href=\"#update\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Update<\/h2>\n<p>Recently I moved the project from cuckoofilters to <a rel=\"external\" href=\"https:\/\/arxiv.org\/abs\/1912.08258\">XOR filters<\/a>.\nI used the awesome <a rel=\"external\" href=\"https:\/\/github.com\/ayazhafiz\/xorf\">xorf<\/a> project, which comes with built-in serde serialization.\nwhich allowed me to remove a lot of custom code.<\/p>\n<p>With that, I could reduce the payload size by another 20-25% percent. I\u2019m down to <strong>99kB<\/strong> (<strong>49kB gzipped<\/strong>) on my blog now. \ud83c\udf89<\/p>\n<p>The new version is released <a rel=\"external\" href=\"https:\/\/crates.io\/crates\/tinysearch\">on crates.io<\/a> already, if you want to give it a try.<\/p>\n<h2 id=\"frontend-and-glue-code\"><a class=\"anchor\" href=\"#frontend-and-glue-code\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Frontend- and Glue Code<\/h2>\n<p>wasm-pack will auto-generate the JavaScript code to talk to Wasm.<\/p>\n<p>For the search UI, I customized a few JavaScript and CSS bits from\n<a rel=\"external\" href=\"https:\/\/www.w3schools.com\/howto\/tryit.asp?filename=tryhow_js_autocomplete\">w3schools<\/a>.\nIt even has keyboard support!\nNow when a user enters a search query, we go through the cuckoo filter of each\narticle and try to match the words. The results are scored by the number of\nhits. Thanks to my dear colleague <a rel=\"external\" href=\"https:\/\/github.com\/jorgelbg\/\">Jorge Luis Betancourt<\/a> for adding that part.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2019\/tinysearch\/anim-opt2.gif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2019\/tinysearch\/anim-opt2.gif\" alt=\"Video of the search functionality\" width=\"600\" height=\"238\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Video of the search functionality\n    <\/figcaption>\n<\/figure>\n<p>(Fun fact: this animation is about the same size as the uncompressed Wasm search itself.)<\/p>\n<h2 id=\"caveats\"><a class=\"anchor\" href=\"#caveats\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Caveats<\/h2>\n<p>Only whole words are matched. I would love to add prefix-search, but the\nbinary became too big when I tried.<\/p>\n<h2 id=\"usage\"><a class=\"anchor\" href=\"#usage\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Usage<\/h2>\n<p>The standalone binary to create the Wasm file is called <code>tinysearch<\/code>.\nIt expects a single path to a JSON file as an input:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>tinysearch path\/to\/corpus.json<\/span><\/span><\/code><\/pre>\n<p>This <code>corpus.json<\/code> contains the text you would like to index. The format is pretty straightforward:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"json\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">title<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Article 1<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">url<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/example.com\/article1<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">body<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">This is the body of article 1.<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">title<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Article 2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">url<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/example.com\/article2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    &quot;<\/span><span class=\"z-l-3 z-d-2\">body<\/span><span class=\"z-l-8 z-d-4\">&quot;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">This is the body of article 2.<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">]<\/span><\/span><\/code><\/pre>\n<p>You can generate this JSON file with any static site generator.\n<a rel=\"external\" href=\"https:\/\/github.com\/mre\/mre.github.io\/tree\/1c731717b48afb584e54ca4dd5fd649f9b74e51c\/templates\">Here\u2019s my version for Zola<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"jinja\"><span class=\"giallo-l\"><span>{%<\/span><span class=\"z-l-9 z-d-9\"> set<\/span><span> section<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> get_section<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>path<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">_index.md<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span> %}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>[<\/span><\/span>\n<span class=\"giallo-l\"><span>  {%-<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> post<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span> section<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>pages<\/span><span> -%}<\/span><\/span>\n<span class=\"giallo-l\"><span>    {%<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span class=\"z-l-9 z-d-9\"> not<\/span><span> post<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>draft<\/span><span> %}<\/span><\/span>\n<span class=\"giallo-l\"><span>      {<\/span><\/span>\n<span class=\"giallo-l\"><span>        &quot;title&quot;: <\/span><span>{{<\/span><span> post<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>title<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> striptags<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> json_encode<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> safe<\/span><span> }}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>        &quot;url&quot;: <\/span><span>{{<\/span><span> post<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>permalink<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> json_encode<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> safe<\/span><span> }}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>        &quot;body&quot;: <\/span><span>{{<\/span><span> post<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>content<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> striptags<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> json_encode<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span> safe<\/span><span> }}<\/span><\/span>\n<span class=\"giallo-l\"><span>      }<\/span><\/span>\n<span class=\"giallo-l\"><span>      {%<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span class=\"z-l-9 z-d-9\"> not<\/span><span> loop<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>last<\/span><span> %}<\/span><span>,<\/span><span>{%<\/span><span class=\"z-l-9 z-d-9\"> endif<\/span><span> %}<\/span><\/span>\n<span class=\"giallo-l\"><span>    {%<\/span><span class=\"z-l-9 z-d-9\"> endif<\/span><span> %}<\/span><\/span>\n<span class=\"giallo-l\"><span>  {%-<\/span><span class=\"z-l-9 z-d-9\"> endfor<\/span><span> -%}<\/span><\/span>\n<span class=\"giallo-l\"><span>]<\/span><\/span><\/code><\/pre>\n<p>I\u2019m pretty sure that the Jekyll version looks quite similar.\n<a rel=\"external\" href=\"https:\/\/learn.cloudcannon.com\/jekyll\/output-json\/\">Here\u2019s a starting point<\/a>.\nIf you get something working for your static site generator, <a rel=\"external\" href=\"https:\/\/github.com\/tinysearch\/tinysearch\/tree\/master\/howto\">please let me know<\/a>.<\/p>\n<h2 id=\"observations\"><a class=\"anchor\" href=\"#observations\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Observations<\/h2>\n<ul>\n<li>This is still the wild west: unstable features, nightly Rust, documentation\ngets outdated almost every day.<br \/>\nBring your thinking cap!<\/li>\n<li>Creating a product out of a good idea is a lot of work. One has to pay\nattention to many factors: ease-of-use, generality, maintainability,\ndocumentation, and so on.<\/li>\n<li>Rust is very good at removing dead code, so you usually don\u2019t pay for what\nyou don\u2019t use. I would still advise you to be very conservative about the\ndependencies you add to a Wasm binary because it\u2019s tempting to add features\nthat you don\u2019t need and which will add to the binary size. For example, I\nused <a rel=\"external\" href=\"https:\/\/github.com\/TeXitoi\/structopt\">StructOpt<\/a> during testing, and I had a <code>main()<\/code> function that was parsing\nthese command-line arguments. This was not necessary for Wasm, so I\nremoved it later.<\/li>\n<li>I understand that not everyone wants to write Rust code. It\u2019s <a rel=\"external\" href=\"https:\/\/endler.dev\/2017\/go-vs-rust\/\">complicated to\nget started with<\/a>, but the cool thing is that you can\nuse almost any other language, too. For example, you can write Go code and\ntranspile to Wasm, or maybe you prefer PHP or Haskell. There is support for\n<a rel=\"external\" href=\"https:\/\/github.com\/appcypher\/awesome-wasm-langs\">many languages<\/a> already.<\/li>\n<li>A lot of people dismiss WebAssembly as a toy technology. They couldn\u2019t be\nfurther from the truth. In my opinion, WebAssembly will revolutionize the way we build\nproducts for the web and beyond. What was very hard just two years ago is now\neasy: shipping code in any language to every browser. I\u2019m super excited about\nits future.<\/li>\n<li>If you\u2019re looking for a standalone, self-hosted search index for your company\nwebsite, check out <a rel=\"external\" href=\"https:\/\/journal.valeriansaliou.name\/announcing-sonic-a-super-light-alternative-to-elasticsearch\/\">sonic<\/a>.\nAlso check out <a rel=\"external\" href=\"https:\/\/github.com\/jameslittle230\/stork\">stork<\/a> as an alternative.<\/li>\n<\/ul>\n<h2 id=\"try-it\"><a class=\"anchor\" href=\"#try-it\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Try It!<\/h2>\n<p>The code for <a rel=\"external\" href=\"https:\/\/github.com\/mre\/tinysearch\">tinysearch is on Github<\/a>.<\/p>\n<p>Please be aware of these limitations:<\/p>\n<ul>\n<li><strong>Only searches for entire words.<\/strong> There are no search suggestions.\nThe reason is that prefix search blows up binary size like <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=b6u9WJ01Oxs\">Mentos and Diet Coke<\/a>.<\/li>\n<li>Since we bundle all search indices for all articles into one static binary, I\n<strong>only recommend to use it for low- to medium-sized websites<\/strong>. Expect around 4kB\n(non-compressed) per article.<\/li>\n<li><strike>The <strong>compile times are abysmal<\/strong> at the moment (around 1.5 minutes after a\nfresh install on my machine), mainly because we\u2019re compiling the Rust crate\nfrom scratch every time we rebuild the index.<\/strike><br \/>\nUpdate: This is mostly fixed thanks to the awesome work of\n<a rel=\"external\" href=\"https:\/\/github.com\/CephalonRho\">CephalonRho<\/a> in PR\n<a rel=\"external\" href=\"https:\/\/github.com\/mre\/tinysearch\/pull\/13\">#13<\/a>. Thanks again!<\/li>\n<\/ul>\n<p>The final Wasm code is laser-fast because we save the roundtrips to a\nsearch-server. The instant feedback loop feels more like filtering a list than\nsearching through posts. It can even work fully offline, which might be nice if\nyou like to bundle it with an app.<\/p>\n"},{"title":"Maybe You Don't Need Kubernetes","pubDate":"Thu, 21 Mar 2019 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2019\/maybe-you-dont-need-kubernetes\/","guid":"https:\/\/endler.dev\/2019\/maybe-you-dont-need-kubernetes\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2019\/maybe-you-dont-need-kubernetes\/scooter.svg\" alt=\"A woman riding a scooter\" width=\"617\" height=\"347\"\n    \/>\n    <figcaption>\n        A woman riding a scooter\n        <br \/>\n        Source: Illustration created by <a rel=\"external\" href=\"https:\/\/www.freepik.com\/free-photos-vectors\/car\">freepik<\/a>, Nomad logo by <a rel=\"external\" href=\"https:\/\/www.nomadproject.io\/\">HashiCorp<\/a>.\n    <\/figcaption>\n<\/figure>\n<p>Kubernetes is the 800-pound gorilla of container orchestration.<br \/>\nIt powers some of the biggest deployments worldwide, but it comes\nwith a price tag.<\/p>\n<p>Especially for smaller teams, it can be time-consuming to maintain and has a\nsteep learning curve. For what our team of four wanted to achieve at <a rel=\"external\" href=\"https:\/\/tech.trivago.com\">trivago<\/a>, it\nadded too much overhead. So we looked into alternatives \u2014 and fell in love with\n<a rel=\"external\" href=\"https:\/\/www.nomadproject.io\/\">Nomad<\/a>.<\/p>\n<h2 id=\"the-wishlist\"><a class=\"anchor\" href=\"#the-wishlist\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Wishlist<\/h2>\n<p>Our team runs a number of typical services for monitoring and performance\nanalysis: API endpoints for metrics written in Go, Prometheus exporters, log\nparsers like Logstash or <a rel=\"external\" href=\"https:\/\/github.com\/trivago\/gollum\">Gollum<\/a>, and databases like InfluxDB or Elasticsearch.\nEach of these services run in their own container. We needed a simple system to\nkeep those jobs running.<\/p>\n<p>We started with a list of requirements for container orchestration:<\/p>\n<ul>\n<li>Run a fleet of services across many machines.<\/li>\n<li>Provide an overview of running services.<\/li>\n<li>Allow for communication between services.<\/li>\n<li>Restart them automatically when they die.<\/li>\n<li>Be manageable by a small team.<\/li>\n<\/ul>\n<p>On top of that, the following things were nice to have but not strictly\nrequired:<\/p>\n<ul>\n<li>Tag machines by their capabilities (e.g., label machines with fast disks for\nI\/O heavy services.)<\/li>\n<li>Be able to run these services independently of any orchestrator (e.g. in\ndevelopment).<\/li>\n<li>Have a common place to share configurations and secrets.<\/li>\n<li>Provide an endpoint for metrics and logging.<\/li>\n<\/ul>\n<h2 id=\"why-kubernetes-was-not-a-good-fit-for-us\"><a class=\"anchor\" href=\"#why-kubernetes-was-not-a-good-fit-for-us\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Kubernetes Was Not a Good Fit for Us<\/h2>\n<p>When creating a prototype with Kubernetes, we noticed that we started adding\never-more complex layers of logic to operate our services. Logic on which we\nimplicitly relied on.<\/p>\n<p>As an example, Kubernetes allows embedding service configurations using\n<a rel=\"external\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/configure-pod-configmap\/\">ConfigMaps<\/a>. Especially when merging multiple config files or\nadding more services to a pod, this can get quite confusing quickly.\nKubernetes - or <a rel=\"external\" href=\"https:\/\/helm.sh\/\">helm<\/a>, for that matter - allows injecting external configs\ndynamically to ensure separation of concerns. But this can\nlead to tight, implicit coupling between your project and Kubernetes.\nHelm and ConfigMaps are optional features so you don\u2019t have to use them. You\nmight as well just copy the config into the Docker image. However, it\u2019s tempting\nto go down that path and build unnecessary abstractions that can later bite you.<\/p>\n<p>On top of that, the Kubernetes ecosystem is still rapidly evolving. It takes a\nfair amount of time and energy to stay up-to-date with the best practices and\nlatest tooling. Kubectl, minikube, kubeadm, helm, tiller, kops, oc - the list\ngoes on and on. Not all tools are necessary to get started with Kubernetes, but\nit\u2019s hard to know which ones are, so you have to be at least aware of them.\nBecause of that, the learning curve is quite steep.<\/p>\n<h2 id=\"when-to-use-kubernetes\"><a class=\"anchor\" href=\"#when-to-use-kubernetes\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>When to Use Kubernetes<\/h2>\n<p>At trivago specifically, many teams use Kubernetes and are quite happy with it.\nThese instances are managed by Google or Amazon however, which have the capacity to do so.<\/p>\n<p>Kubernetes comes with <a rel=\"external\" href=\"https:\/\/jvns.ca\/blog\/2017\/08\/05\/how-kubernetes-certificates-work\/\">amazing\nfeatures<\/a>,\nthat make container orchestration at scale more manageable:<\/p>\n<ul>\n<li>Fine-grained <a rel=\"external\" href=\"https:\/\/kubernetes.io\/docs\/reference\/access-authn-authz\/authorization\/\">rights management<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/extend-kubernetes\/api-extension\/custom-resources\/#custom-controllers\">Custom controllers<\/a> allow getting logic into the cluster. These are just\nprograms that talk to the Kubernetes API.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/run-application\/horizontal-pod-autoscale\/\">Autoscaling<\/a>! Kubernetes can scale your services up and down on demand. It\nuses service metrics to do this without manual intervention.<\/li>\n<\/ul>\n<p>The question is if you really need all those features. You can\u2019t rely on these\nabstractions to just work; <a rel=\"external\" href=\"https:\/\/jvns.ca\/blog\/2017\/08\/05\/how-kubernetes-certificates-work\/\">you\u2019ll have to learn what\u2019s going on under the\nhood<\/a>.<\/p>\n<p>Especially in our team, which runs most services on-premise (because of its\nclose connection to trivago\u2019s core infrastructure), we didn\u2019t want to afford\nrunning our own Kubernetes cluster; we wanted to ship services instead.<\/p>\n<figure>\n    <a href=\"https:\/\/twitter.com\/QuinnyPig\/status\/1093261169614356490\">\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2019\/maybe-you-dont-need-kubernetes\/nuclear-kubernetes.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2019\/maybe-you-dont-need-kubernetes\/nuclear-kubernetes.jpg\" alt=\"Nuclear hot take: nobody will care about Kubernetes in five years. -A tweet by Corey Quinn\" width=\"650\" height=\"485\"\n    \/>\n    <\/picture>\n    <\/a>\n<\/figure>\n<h2 id=\"batteries-not-included\"><a class=\"anchor\" href=\"#batteries-not-included\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Batteries Not Included<\/h2>\n<p>Nomad is the 20% of service orchestration that gets you 80% of the way. All it\ndoes is manage deployments. It takes care of your rollouts and restarts your\ncontainers in case of errors, and that\u2019s about it.<\/p>\n<p>The entire point of Nomad is that it does <em>less<\/em>: it doesn\u2019t include\nfine-grained rights management or <a rel=\"external\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/network-policies\/\">advanced network policies<\/a>, and that\u2019s by\ndesign. Those components are provided as enterprise services, by a third-party\n\u2014 or not at all.<\/p>\n<p>I think Nomad hit a sweet-spot between ease of use and expressiveness. It\u2019s good\nfor small, mostly independent services. If you need more control, you\u2019ll have to\nbuild it yourself or use a different approach. Nomad is <em>just<\/em> an orchestrator.<\/p>\n<p>The best part about Nomad is that it\u2019s easy to <em>replace<\/em>. There is little to no\nvendor lock-in because the functionality it provides can easily be integrated\ninto any other system that manages services. It just runs as a plain old single\nbinary on every machine in your cluster; that\u2019s it!<\/p>\n<h2 id=\"the-nomad-ecosystem-of-loosely-coupled-components\"><a class=\"anchor\" href=\"#the-nomad-ecosystem-of-loosely-coupled-components\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Nomad Ecosystem of Loosely Coupled Components<\/h2>\n<p>The real power of Nomad lies within its ecosystem. It integrates very well with\nother - completely optional - products like <a rel=\"external\" href=\"https:\/\/www.consul.io\/\">Consul<\/a> (a key-value store) or\n<a rel=\"external\" href=\"https:\/\/www.vaultproject.io\/\">Vault<\/a> (for secrets handling). Inside your Nomad file, you can have sections\nfor fetching data from those services:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">template<\/span><span class=\"z-l-5 z-d-7\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  data<\/span><span class=\"z-l-5 z-d-7\"> =<\/span><span class=\"z-l-2 z-d-5\"> &lt;&lt;<\/span><span class=\"z-l-5 z-d-7\">EOH<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">LOG_LEVEL=&quot;{{key &quot;service\/geo-api\/log-verbosity&quot;}}&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">API_KEY=&quot;{{with secret &quot;secret\/geo-api-key&quot;}}{{.Data.value}}{{end}}&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">EOH<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  destination<\/span><span class=\"z-l-5 z-d-7\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">secrets\/file.env<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  env<\/span><span class=\"z-l-5 z-d-7\">         =<\/span><span class=\"z-l-16 z-d-16\"> true<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>This will read the <code>service\/geo-api\/log-verbosity<\/code> key from Consul and expose it\nas a <code>LOG_LEVEL<\/code> environment variable inside your job. It\u2019s also exposing\n<code>secret\/geo-api-key<\/code> from Vault as <code>API_KEY<\/code>. Simple, but powerful!<\/p>\n<p>Because it\u2019s so simple, Nomad can also be easily extended with other services\nthrough its API. For example, jobs can be tagged for service discovery. At\ntrivago, we tag all services, which expose metrics, with <code>trv-metrics<\/code>. This\nway, Prometheus finds the services via Consul and periodically scrapes the\n<code>\/metrics<\/code> endpoint for new data. The same can be done for logs by integrating\n<a rel=\"external\" href=\"https:\/\/grafana.com\/oss\/loki\">Loki<\/a> for example.<\/p>\n<p>There are many other examples for extensibility:<\/p>\n<ul>\n<li>Trigger a Jenkins job using a webhook and Consul watches to redeploy your\nNomad job on service config changes.<\/li>\n<li>Use Ceph to add a distributed file system to Nomad.<\/li>\n<li>Use <a rel=\"external\" href=\"https:\/\/github.com\/fabiolb\/fabio\">fabio<\/a> for load balancing.<\/li>\n<\/ul>\n<p>All of this allowed us to <a rel=\"external\" href=\"https:\/\/tech.trivago.com\/post\/2019-01-25-nomadourexperiencesandbestpractices\/\">grow our infrastructure organically<\/a> without too much\nup-front commitment.<\/p>\n<h2 id=\"fair-warning\"><a class=\"anchor\" href=\"#fair-warning\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Fair Warning<\/h2>\n<p>No system is perfect. I advise you not to use any fancy new features in\nproduction right now. There are <a rel=\"external\" href=\"https:\/\/github.com\/hashicorp\/nomad\/issues?q=is%3Aopen+is%3Aissue+label%3Abug\">bugs<\/a> and <a rel=\"external\" href=\"https:\/\/github.com\/hashicorp\/nomad\/issues\/698\">missing features<\/a> of course - but\n<a rel=\"external\" href=\"https:\/\/github.com\/kubernetes\/kubernetes\/issues?q=is%3Aopen+is%3Aissue+label%3Akind%2Fbug\">that\u2019s also the case for\nKubernetes<\/a>.<\/p>\n<p>Compared to Kubernetes, there is far less momentum behind Nomad. Kubernetes has\nseen around 75.000 commits and 2000 contributors so far, while Nomad sports about\n14.000 commits and 300 contributors. It will be hard for Nomad to keep up with\nthe velocity of Kubernetes, but maybe it doesn\u2019t have to! The scope is much more\nnarrow and the smaller community could also mean that it\u2019ll be easier to get your\npull request accepted, in comparison to Kubernetes.<\/p>\n<h2 id=\"summary\"><a class=\"anchor\" href=\"#summary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Summary<\/h2>\n<p>The takeaway is: <strong>don\u2019t use Kubernetes just because everyone else does<\/strong>.\nCarefully evaluate your requirements and check which tool fits the bill.<\/p>\n<p>If you\u2019re planning to deploy a fleet of homogenous services on large-scale\ninfrastructure, Kubernetes might be the way to go. Just be aware of the\nadditional <a rel=\"external\" href=\"https:\/\/twitter.com\/ka_szczepanski\/status\/1394296607806525440\">complexity and operational costs<\/a>. Some of these costs can be\navoided by using a managed Kubernetes environment like <a rel=\"external\" href=\"https:\/\/cloud.google.com\/kubernetes-engine\/\">Google Kubernetes\nEngine<\/a> or <a rel=\"external\" href=\"https:\/\/aws.amazon.com\/eks\/\">Amazon EKS<\/a>.<\/p>\n<p>If you\u2019re just looking for a reliable orchestrator that is easy to maintain and\nextendable, why not give <a rel=\"external\" href=\"https:\/\/www.nomadproject.io\/\">Nomad<\/a> a try? You might be surprised by how far it\u2019ll get you.<\/p>\n<p>If Kubernetes were a car, Nomad would be a scooter. Sometimes you prefer one and\nsometimes the other. Both have their right to exist.<\/p>\n"},{"title":"What Is Rust Doing behind the Curtains?","pubDate":"Sun, 02 Dec 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/cargo-inspect\/","guid":"https:\/\/endler.dev\/2018\/cargo-inspect\/","description":"<p>Rust allows for a lot of syntactic sugar, that makes it a pleasure to write. It is sometimes hard, however, to look behind the curtain and see what the compiler is really doing with our code.<\/p>"},{"title":"The Unreasonable Effectiveness of Excel Macros","pubDate":"Mon, 05 Nov 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/excel\/","guid":"https:\/\/endler.dev\/2018\/excel\/","description":"<p>I never was a big fan of internships, partially because all the exciting\ncompanies were far away from my little village in Bavaria and partially because\nI was too shy to apply.<\/p>\n<p>Only once I applied for an internship in Ireland as part of a school program.\nOur teacher assigned the jobs and so my friend got one at Apple and I ended up\nat a medium-sized IT distributor \u2014 let\u2019s call them PcGo.<\/p>"},{"title":"Switching from a German to a US Keyboard Layout - Is It Worth It?","pubDate":"Sun, 02 Sep 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/keyboard\/","guid":"https:\/\/endler.dev\/2018\/keyboard\/","description":"<p>For the first three decades of my life, I\u2019ve exclusively used a German keyboard layout for programming. In 2018, I finally switched to a US layout.\nThis post summarizes my thoughts around the topic.\nI was looking for a similar article before jumping the gun, but I couldn\u2019t find one \u2014 so I wrote it.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2018\/keyboard\/keychron.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2018\/keyboard\/keychron.jpg\" alt=\"My current keyboard (as of April 2021), the low-profile, tenkeyless Keychron K1 is close to my favorite input device. Yes, I got the RGB version. &mdash; [Amazon referral link](https:\/\/amzn.to\/3tRatjU).\" width=\"650\" height=\"352\"\n    \/>\n    <\/picture>\n    <figcaption>\n        My current keyboard (as of April 2021), the low-profile, tenkeyless Keychron K1 is close to my favorite input device. Yes, I got the RGB version. \u2014 <a rel=\"external\" href=\"https:\/\/amzn.to\/3tRatjU\">Amazon referral link<\/a>.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"why-switch-to-the-us-layout\"><a class=\"anchor\" href=\"#why-switch-to-the-us-layout\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Switch to the US Layout?<\/h2>\n<p>I was reasonably efficient when writing prose, but felt like\na <a rel=\"external\" href=\"https:\/\/www.etsy.com\/listing\/896826954\/funny-piano-art-print-leptodactylous-aye\">lemur on a piano<\/a> when programming:\nlots of finger-stretching while trying to reach the special keys like <code>{<\/code>, <code>;<\/code>, or <code>\/<\/code>.<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2018\/keyboard\/KB_Germany.svg\" alt=\"German Keyboard Layout\" width=\"650\" height=\"217\"\n    \/>\n    <figcaption>\n        German Keyboard Layout\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/w\/index.php?curid=1058095\">Image by Wikipedia<\/a>\n    <\/figcaption>\n<\/figure>\n<p>Here\u2019s <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/German_keyboard_layout\">Wikipedia\u2019s polite\nexplanation<\/a> why the\nGerman keyboard <strong>sucks for programming<\/strong>:<\/p>\n<blockquote>\n<p>Like many other non-American keyboards, German keyboards change the right Alt\nkey into an <b>Alt Gr key to access a third level<\/b> of key assignments. This is\nnecessary because the umlauts and some other special characters leave no room\nto have all the special symbols of ASCII, needed by programmers among others,\navailable on the first or second (shifted) levels without unduly increasing\nthe size of the keyboard.<\/p>\n<\/blockquote>\n<h2 id=\"but-why-switch-now\"><a class=\"anchor\" href=\"#but-why-switch-now\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>But Why Switch <strong>Now<\/strong>?<\/h2>\n<p>After many years of using a rubber-dome <a rel=\"external\" href=\"https:\/\/support.logitech.com\/en_us\/product\/cordless-desktop-wave\/\">Logitech Cordless Desktop\nWave<\/a>, I\nhad to get a mechanical keyboard again.<\/p>\n<p>Those rubber domes just feel too mushy to me now. In addition to that, I enjoy the\nclicky sound of a mechanical keyboard and the noticeable tactile bump. (I\u2019m using\n<a rel=\"external\" href=\"https:\/\/amzn.to\/3mm2WHf\">Cherry MX Brown Keys<\/a> with <a rel=\"external\" href=\"https:\/\/amzn.to\/3miCfTK\">O-Ring dampeners<\/a> to contain the anger of my coworkers.)<\/p>\n<p>Most mechanical keyboards come with an ANSI US layout only, so I figured, I\u2019d\nfinally make the switch.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2018\/keyboard\/durgod_taurus.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2018\/keyboard\/durgod_taurus.jpg\" alt=\"My first mechanical keyboard &mdash; [Durgod Taurus K320](https:\/\/www.amazon.de\/gp\/product\/B07QK16RDQ\/ref=as_li_tl?ie=UTF8&tag=matthiasendle-21&camp=1638&creative=6742&linkCode=as2&creativeASIN=B07QK16RDQ&linkId=fb0a782ecbc713f8266b90b941375a5f) (referral link). They also have a fancy [white-pink](https:\/\/www.amazon.de\/gp\/product\/B081LZV2QM?ie=UTF8&tag=matthiasendle-21&camp=1638&linkCode=xm2&creativeASIN=B081LZV2QM) ISO version now.\" width=\"650\" height=\"278\"\n    \/>\n    <\/picture>\n    <figcaption>\n        My first mechanical keyboard \u2014 <a rel=\"external\" href=\"https:\/\/www.amazon.de\/gp\/product\/B07QK16RDQ\/ref=as_li_tl?ie=UTF8&amp;tag=matthiasendle-21&amp;camp=1638&amp;creative=6742&amp;linkCode=as2&amp;creativeASIN=B07QK16RDQ&amp;linkId=fb0a782ecbc713f8266b90b941375a5f\">Durgod Taurus K320<\/a> (referral link). They also have a fancy <a rel=\"external\" href=\"https:\/\/www.amazon.de\/gp\/product\/B081LZV2QM?ie=UTF8&amp;tag=matthiasendle-21&amp;camp=1638&amp;linkCode=xm2&amp;creativeASIN=B081LZV2QM\">white-pink<\/a> ISO version now.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"how-long-did-it-take-to-get-accustomed-to-the-new-layout\"><a class=\"anchor\" href=\"#how-long-did-it-take-to-get-accustomed-to-the-new-layout\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How Long Did It Take to Get Accustomed to the New Layout?<\/h2>\n<p>Working as a Software Engineer, my biggest fear was, that the switch would slow\ndown my daily work. This turned out not to be true. I was reasonably productive\n<strong>from day one<\/strong>, and nobody even noticed any difference. (That\u2019s a good thing,\n<em>right<\/em>?)<\/p>\n<p>At first, I didn\u2019t like the <em>bar-shaped US-Return key<\/em>. I preferred the European\nlayout with a <em>vertical enter key<\/em>. I was afraid that I would hit the key by\naccident. After a while, I find that the US return key to be even more convenient.\nI never hit it by accident, and it\u2019s easy to reach with my pinky from the home position.<\/p>\n<p>Within two weeks, I was back to 100% typing speed.<\/p>\n<h2 id=\"did-my-programming-speed-improve-noticeably\"><a class=\"anchor\" href=\"#did-my-programming-speed-improve-noticeably\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Did My Programming Speed Improve Noticeably?<\/h2>\n<p>Yup. I\u2019d say I can type programs about 30% faster.<\/p>\n<p>Especially when using special characters (<code>\/<\/code>, <code>;<\/code>, <code>{<\/code>, and so on) I\u2019m much\nfaster now; partly because the key locations feel more intuitive, but mainly\nbecause my fingers stay at their dedicated positions.<\/p>\n<p>Somehow the position of special characters feels <em>just right<\/em>. I can finally understand the\nreason why Vim is using <code>\/<\/code> for search or why the pipe symbol is <code>|<\/code>: both are\neasy to reach! <a href=\"\/2018\/ten-years-of-vim\">It all makes sense!<\/a>\n(For a fun time, try that on a German keyboard!)<\/p>\n<p>I understand why Microsoft chose <code>\\<\/code> as a directory separator: it\u2019s easily\naccessible from a US keyboard. On the German layout, it\u2019s\u2026 just\u2026 awful\n(<code>Alt Gr<\/code>+<code>\u00df<\/code> on Windows, <code>Shift<\/code> + <code>Option<\/code> + <code>7<\/code> on Mac).<\/p>\n<p>The opening curly brace on a German layout Mac is produced with <code>Alt<\/code>+<code>8<\/code>, which\nalways made me leave the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Touch_typing#Home_row\">home\nrow<\/a> and break my typing\nflow. Now there are dedicated keys for parentheses. Such a relief!<\/p>\n<p><em>Update:<\/em> It also helps greatly when looking up hotkeys for IDEs, text editors,\nphoto editors, etc. because some programs remap shortcuts for the German market,\nwhich means that all the English documentation is totally worthless.\nThanks to the English layout, I can just use the shortcuts mentioned and move on with my life.<\/p>\n<h2 id=\"am-i-slower-when-writing-german-texts-now\"><a class=\"anchor\" href=\"#am-i-slower-when-writing-german-texts-now\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Am I Slower When Writing German Texts Now?<\/h2>\n<p>In the beginning, I was.<\/p>\n<p>Somehow my brain associated the German layout with German\ntexts. First, I used the macOS layout switcher.\nThis turned out to be cumbersome and take time.<\/p>\n<p>Then I found the \u201c<a rel=\"external\" href=\"https:\/\/hci.rwth-aachen.de\/usgermankeyboard\">US with Umlauts via Option Key\nLayout<\/a>\u201d. It works perfectly fine for\nme. It allows me to use a single Keyboard layout but insert German umlauts at will\n(e.g. \u00f6 is <code>Option<\/code>+<code>o<\/code>). There is probably a similar layout for other language combinations.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/www.stefanimhoff.de\/\">Stefan Imhoff<\/a> notified me that there\u2019s also a\n<a rel=\"external\" href=\"https:\/\/www.stefanimhoff.de\/\">Karabiner<\/a> rule which does the same. Might come\nin handy in case you already use this tool.<\/p>\n<h2 id=\"is-switching-between-keyboards-painful\"><a class=\"anchor\" href=\"#is-switching-between-keyboards-painful\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Is Switching between Keyboards Painful?<\/h2>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2018\/keyboard\/KB_United_States.svg\" alt=\"US keyboard layout\" width=\"650\" height=\"216\"\n    \/>\n    <figcaption>\n        US keyboard layout\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:KB_United_States.svg\">Wikipedia<\/a>\n    <\/figcaption>\n<\/figure>\n<p>My built-in MacBook Pro keyboard layout is still German. I was afraid, that switching between\nthe internal German and the external English keyboard would confuse me. This\nturned out not to be a problem. I rarely look at the print anyway.\n(Update: can\u2019t remember when I last looked at the print.)<\/p>\n<h2 id=\"how-often-do-you-switch-back-to-a-german-layout-now\"><a class=\"anchor\" href=\"#how-often-do-you-switch-back-to-a-german-layout-now\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How Often Do You Switch Back to a German Layout Now?<\/h2>\n<p>Never. My Girlfriend has a German keyboard and every time I have to use it, I switch to the US layout. It makes her very happy when I do this and forget to switch back to German when I\u2019m done.<\/p>\n<h2 id=\"summary\"><a class=\"anchor\" href=\"#summary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Summary<\/h2>\n<p>If you consider switching, just do it! I don\u2019t look back at all\nand apart from the initial transition period, I still couldn\u2019t find any downsides.<\/p>\n<p>Since posting this article, many of my friends made the switch as well and\nhad similar experiences:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/wolfgang.gassler.org\/switch-keyboard-german-to-english-linux-fedora\/\">Wolfgang Gassler wrote a post about his layout switch on Linux<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/twitter.com\/ro14nd\/status\/1304360915840753664\">Discussion of the article on Twitter<\/a><\/li>\n<\/ul>\n"},{"title":"fastcat - A Faster `cat` Implementation Using Splice","pubDate":"Tue, 31 Jul 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/fastcat\/","guid":"https:\/\/endler.dev\/2018\/fastcat\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2018\/fastcat\/fastcat.svg\" width=\"650\" height=\"270\"\n    \/>\n<\/figure>\n<p>Lots of people asked me to write another piece about the internals of well-known\nUnix commands. Well, actually, nobody asked, but it makes for a good\nintro. I\u2019m sure you\u2019ve read the previous parts about <a href=\"https:\/\/endler.dev\/2017\/yes\/\"><code>yes<\/code><\/a> and\n<a href=\"https:\/\/endler.dev\/2018\/ls\/\"><code>ls<\/code><\/a> \u2014 they are epic.<\/p>\n<p>Anyway, today we talk about <code>cat<\/code>, which is used to concatenate files - or, more\ncommonly, abused to print a file\u2019s contents to the screen.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Concatenate files, the intended purpose<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span class=\"z-l-5 z-d-7\"> input1.txt<\/span><span class=\"z-l-5 z-d-7\"> input2.txt<\/span><span class=\"z-l-5 z-d-7\"> input3.txt<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span class=\"z-l-5 z-d-7\"> output.txt<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Print file to screen, the most common use-case<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span class=\"z-l-5 z-d-7\"> myfile<\/span><\/span><\/code><\/pre><h2 id=\"implementing-cat\"><a class=\"anchor\" href=\"#implementing-cat\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Implementing cat<\/h2>\n<p>Here\u2019s a naive <code>cat<\/code> in Ruby:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">!\/usr\/bin\/env ruby<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> cat<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>  args<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">each<\/span><span class=\"z-l-9 z-d-9\"> do<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>arg<\/span><span class=\"z-l-8 z-d-4\">|<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    IO<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">foreach<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>arg<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> do<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>line<\/span><span class=\"z-l-8 z-d-4\">|<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">      puts<\/span><span> line<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    end<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  end<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">end<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">ARGV<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>This program goes through each file and prints its contents line by line.\nEasy peasy! But wait, how fast is this tool?<\/p>\n<p>I quickly created a random 2 GB file for the benchmark.<\/p>\n<p>Let\u2019s compare the speed of our naive implementation with the system one\nusing the awesome <a rel=\"external\" href=\"https:\/\/www.ivarch.com\/programs\/pv.shtml\">pv<\/a> (Pipe Viewer) tool.\nAll tests are averaged over five runs on a warm cache (file in memory).<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># Ruby 2.5.1<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; .\/rubycat myfile | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[196MiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Not bad, I guess? How does it compare with my system\u2019s cat?<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cat myfile | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[1.90GiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Uh oh, <a rel=\"external\" href=\"https:\/\/git.savannah.gnu.org\/gitweb\/?p=coreutils.git;a=blob;f=src\/cat.c;h=3c319511c767f65d2e420b3bff8fa6197ddbb37b;hb=HEAD\">GNU cat<\/a> is <strong>ten times faster<\/strong> than our little Ruby cat. \ud83d\udc8e\ud83d\udc08\ud83d\udc0c<\/p>\n<h2 id=\"making-our-ruby-cat-a-little-faster\"><a class=\"anchor\" href=\"#making-our-ruby-cat-a-little-faster\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Making Our Ruby cat a Little Faster<\/h2>\n<p>Our naive Ruby code can be tweaked a bit.\nTurns out line buffering hurts performance in the end<sup><a href=\"#fn1\" id=\"ref1\">1<\/a><\/sup>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">!\/usr\/bin\/env ruby<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> cat<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>  args<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">each<\/span><span class=\"z-l-9 z-d-9\"> do<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>arg<\/span><span class=\"z-l-8 z-d-4\">|<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    IO<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">copy_stream<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>arg<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> STDOUT<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  end<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">end<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">ARGV<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>rubycat myfile | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[1.81GiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Wow\u2026 we didn\u2019t really try hard, and we\u2019re already approaching the speed of a\ntool that gets optimized <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Cat_(Unix)\">since\n1971<\/a>. \ud83c\udf89<\/p>\n<p>But before we celebrate too much, let\u2019s see if we can go even faster.<\/p>\n<h2 id=\"splice\"><a class=\"anchor\" href=\"#splice\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Splice<\/h2>\n<p>What initially motivated me to write about <code>cat<\/code> was <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=15455897\">this comment by user\nwahern on\nHacker News<\/a>:<\/p>\n<blockquote>\n<p>I\u2019m surprised that neither GNU yes nor GNU cat uses splice(2).<\/p>\n<\/blockquote>\n<p>Could this <em>splice<\/em> thing make printing files even faster? \u2014 I was intrigued.<\/p>\n<p>Splice was first introduced to the Linux Kernel in 2006, and there is a nice\n<a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20130305002825\/https:\/\/kerneltrap.org\/node\/6505\">summary from Linus Torvalds himself<\/a>,\nbut I prefer the description from the <a rel=\"external\" href=\"https:\/\/linux.die.net\/man\/2\/splice\">manpage<\/a>:<\/p>\n<blockquote>\n<p><strong>splice()<\/strong> moves data between two file descriptors without copying\nbetween kernel address space and user address space. It transfers up\nto <code>len<\/code> bytes of data from the file descriptor <code>fd_in<\/code> to the file\ndescriptor <code>fd_out<\/code>, where one of the file descriptors must refer to a\npipe.<\/p>\n<\/blockquote>\n<p>If you really want to dig deeper, here\u2019s the corresponding <a rel=\"external\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/6ed0529fef09f50ef41d396cb55c5519e4936b16\/fs\/splice.c\">source code from the\nLinux Kernel<\/a>,\nbut we don\u2019t need to know all the nitty-gritty details for now.\nInstead, we can just inspect the header from the C implementation:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">#<\/span><span class=\"z-l-13 z-d-15\">include<\/span><span class=\"z-l-5 z-d-7\"> &lt;<\/span><span class=\"z-l-5 z-d-7\">fcntl.h<\/span><span class=\"z-l-5 z-d-7\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">ssize_t<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> splice<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">int<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> fd_in<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> loff_t<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">off_in<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> int<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> fd_out<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">                loff_t<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">off_out<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> size_t<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> len<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">                unsigned<\/span><span class=\"z-l-9 z-d-9\"> int<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> flags<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>To break it down even more, here\u2019s how we would copy the entire <code>src<\/code> file to <code>dst<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-9 z-d-9\"> ssize_t<\/span><span> r <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> splice<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>src<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> NULL<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> dst<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-10 z-d-12\"> NULL<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> size<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>The cool thing about this is that all of it happens inside the Linux kernel, which means we won\u2019t copy a single byte to userspace (where our program runs).\nIdeally, splice works by remapping pages and does not actually copy\nany data, which may improve I\/O performance\n(<a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Splice_(system_call)\">reference<\/a>).<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2018\/fastcat\/buffers.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2018\/fastcat\/buffers.jpg\" alt=\"File icon by Aleksandr Vector from the Noun Project. Terminal icon by useiconic.com from the Noun Project.\" width=\"650\" height=\"488\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Source: File icon by Aleksandr Vector from the Noun Project. Terminal icon by useiconic.com from the Noun Project.\n    <\/figcaption>\n<\/figure>\n<h2 id=\"using-splice-from-rust\"><a class=\"anchor\" href=\"#using-splice-from-rust\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Using splice from Rust<\/h2>\n<p>I have to say I\u2019m not a C programmer and I prefer Rust because it offers a safer\ninterface. <a rel=\"external\" href=\"https:\/\/github.com\/nix-rust\/nix\/blob\/ebf75050f2f2726808308f76253f27c97aa6db15\/src\/fcntl.rs#L320-L329\">Here\u2019s the same thing in Rust<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">cfg<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">any<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">target_os <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">linux<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> target_os <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">android<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> splice<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    fd_in<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> RawFd<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    off_in<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Option<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span class=\"z-l-14 z-d-10\"> libc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-14 z-d-10\">loff_t<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    fd_out<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> RawFd<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    off_out<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Option<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span class=\"z-l-14 z-d-10\"> libc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-14 z-d-10\">loff_t<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    len<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-14 z-d-10\">    flags<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SpliceFFlags<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">usize<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><\/span><\/code><\/pre>\n<p>Now, I didn\u2019t implement the Linux bindings myself. Instead, I just used a library called\n<a rel=\"external\" href=\"https:\/\/github.com\/nix-rust\/nix\">nix<\/a>, which provides Rust friendly bindings to *nix APIs.<\/p>\n<p>There is one caveat, though:\nWe cannot really copy the file directly to standard out, because splice\nrequires one file descriptor to be a pipe.\nThe way around that is to create a pipe, which consists of a reader and a\nwriter (<code>rd<\/code> and <code>wr<\/code>).\nWe pipe the file into the writer, and then we read from the pipe and push the data to stdout.<\/p>\n<p>You can see that I use a relatively big buffer of 16384 bytes (2<sup>14<\/sup>) to improve performance.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> nix<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">File<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>io<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">os<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">unix<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">AsRawFd<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> nix<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fcntl<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span>splice<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SpliceFFlags<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> nix<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">unistd<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>pipe<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> BUF_SIZE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 16384<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span> path<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">skip<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> input<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> File<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">open<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>path<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">expect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">fcat: <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">: No such file or directory<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> path<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>rd<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> wr<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> pipe<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> stdout<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">stdout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span> _handle<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> stdout<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lock<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        loop<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            let<\/span><span> res<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> splice<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span>                input<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_raw_fd<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">                None<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>                wr<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">                None<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">                BUF_SIZE<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">                SpliceFFlags<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">empty<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            )<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            if<\/span><span> res<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">                \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> We read 0 bytes from the input,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">                \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> which means we&#39;re done copying.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">                break<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            let<\/span><span> _res<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> splice<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span>                rd<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">                None<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>                stdout<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">as_raw_fd<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">                None<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">                BUF_SIZE<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">                SpliceFFlags<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">empty<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            )<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>So, how fast is this?<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>fcat myfile | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[5.90GiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Holy guacamole. That\u2019s <strong>over three times as fast as system cat<\/strong>.<\/p>\n<h2 id=\"operating-system-support\"><a class=\"anchor\" href=\"#operating-system-support\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Operating System Support<\/h2>\n<ul>\n<li><strong>Linux<\/strong> and <strong>Android<\/strong> are fully supported.<\/li>\n<li><strong><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/questions\/12230316\/do-other-operating-systems-implement-the-linux-system-call-splice?lq=1\">OpenBSD<\/a><\/strong>\nalso has some sort of splice implementation called\n<a rel=\"external\" href=\"https:\/\/man.openbsd.org\/sosplice\"><code>sosplice<\/code><\/a>. I didn\u2019t test that, though.<\/li>\n<li>On <strong>macOS<\/strong>, the closest thing to splice is its bigger brother,\n<a rel=\"external\" href=\"https:\/\/www.unix.com\/man-page\/osx\/2\/sendfile\/\">sendfile<\/a>, which can send a\nfile to a socket within the Kernel. Unfortunately, it does not support sending\nfrom file to file.<sup><a href=\"#fn2\" id=\"ref2\">2<\/a><\/sup> There\u2019s also\n<a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20180401103335\/https:\/\/developer.apple.com\/legacy\/library\/documentation\/Darwin\/Reference\/ManPages\/man3\/copyfile.3.html\"><code>copyfile<\/code><\/a>,\nwhich has a similar interface, but unfortunately, it is not zero-copy. (I\nthought so in the beginning, but <a rel=\"external\" href=\"https:\/\/github.com\/rust-lang\/libc\/pull\/886\">I was\nwrong<\/a>.)<\/li>\n<li><strong>Windows<\/strong> doesn\u2019t provide zero-copy file-to-file transfer\n(only file-to-socket transfer using the <a rel=\"external\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/mswsock\/nf-mswsock-transmitfile\">TransmitFile API<\/a>).<\/li>\n<\/ul>\n<p>Nevertheless, in a production-grade\nimplementation, the splice support could be activated on systems that support\nit, while using a generic implementation as a fallback.<\/p>\n<h2 id=\"nice-but-why-on-earth-would-i-want-that\"><a class=\"anchor\" href=\"#nice-but-why-on-earth-would-i-want-that\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Nice, but Why on Earth Would I Want That?<\/h2>\n<p>I have no idea. Probably you don\u2019t, because your bottleneck is somewhere else.\nThat said, many people use <code>cat<\/code> for piping data into another process like<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">#<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Count all lines in C files<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span> *<\/span><span class=\"z-l-5 z-d-7\">.c<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> wc<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">l<\/span><\/span><\/code><\/pre>\n<p>or<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cat<\/span><span class=\"z-l-5 z-d-7\"> kittens.txt<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> grep<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">dog<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>In this case, if you notice that <code>cat<\/code> is the bottleneck try <code>fcat<\/code> (but first,\n<a rel=\"external\" href=\"http:\/\/porkmail.org\/era\/unix\/award.html\">try to avoid <code>cat<\/code> altogether<\/a>).<\/p>\n<p>With some more work, <code>fcat<\/code> could also be used to directly route packets from one\nnetwork card to another, <a rel=\"external\" href=\"https:\/\/nc110.sourceforge.io\/\">similar to netcat<\/a>.<\/p>\n<h2 id=\"lessons-learned\"><a class=\"anchor\" href=\"#lessons-learned\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Lessons Learned<\/h2>\n<ul>\n<li>The closer we get to bare metal, the more our hard-won abstractions fall\napart, and we are back to low-level systems programming.<\/li>\n<li>Apart from a fast cat, there\u2019s also a use-case for a slow cat: old computers.\nFor that purpose, there\u2019s \u2014 you guessed it \u2014 <a rel=\"external\" href=\"https:\/\/grox.net\/software\/mine\/slowcat\/\">slowcat<\/a>.<\/li>\n<\/ul>\n<p>That said, I still have no idea why GNU cat does not use splice on Linux. \ud83e\udd14\nThe <a rel=\"external\" href=\"https:\/\/github.com\/mre\/fcat\">source code for fcat is on Github<\/a>.\nContributions welcome!<\/p>\n<h2 id=\"footnotes\"><a class=\"anchor\" href=\"#footnotes\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Footnotes<\/h2>\n<p><sup id=\"fn1\">1. Thanks to reader <a href=\"https:\/\/www.reddit.com\/r\/rust\/comments\/93fbrj\/fascat_a_faster_cat_implementation_using_splice\/e3d2chn\/\">Freeky<\/a> for making this code more idiomatic.<a href=\"#ref1\" title=\"Jump back to footnote 1 in the text.\">\u21a9<\/a><\/sup><br \/>\n<sup id=\"fn2\">2. Thanks to reader <a href=\"https:\/\/www.reddit.com\/r\/rust\/comments\/93fbrj\/fascat_a_faster_cat_implementation_using_splice\/e3cu3rk\/\">masklinn<\/a> for the hint.<a href=\"#ref2\" title=\"Jump back to footnote 2 in the text.\">\u21a9<\/a><\/sup><\/p>\n"},{"title":"That Octocat on the Wall","pubDate":"Sat, 09 Jun 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/github\/","guid":"https:\/\/endler.dev\/2018\/github\/","description":"<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2018\/github\/octocat.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2018\/github\/octocat.jpg\" alt=\"Photo of my office with Github's octocat on the wall over my couch\" width=\"650\" height=\"433\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Photo of my office with Github\u2019s octocat on the wall over my couch\n    <\/figcaption>\n<\/figure>\n<p>So I\u2019m in a bit of a sentimental mood lately.\nGithub got acquired by Microsoft.\nWhile I think the acquisition was well-deserved, I still wish it didn\u2019t happen.\nLet me explain.<\/p>\n<h2 id=\"my-early-days\"><a class=\"anchor\" href=\"#my-early-days\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>My Early Days<\/h2>\n<p>I joined Github on 3rd of January 2010.\nSince I was a bit late to the game, my usual handle (<a rel=\"external\" href=\"https:\/\/github.com\/mre\/\">mre<\/a>) was already taken.\nSo I naively sent a mail to Github, asking if I could bag the name as it seemed to be abandoned.\nTo my surprise, I got an answer.\nThe response came from a guy named <a rel=\"external\" href=\"https:\/\/github.com\/defunkt\">Chris Wanstrath<\/a>.<\/p>\n<p>All he wrote was \u201cit\u2019s yours.\u201d<\/p>\n<p>That was the moment I fell in love with Github.\nI felt encouraged to collaborate on projects, that everybody could contribute something valuable.\nOnly later I found out that Chris was one of the founders and the CEO of the company.<\/p>\n<h2 id=\"living-on-github\"><a class=\"anchor\" href=\"#living-on-github\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Living on GitHub<\/h2>\n<p>Before Github, there was <a rel=\"external\" href=\"https:\/\/sourceforge.net\/\">SourceForge<\/a>, and I only went there to download binaries.\nGithub showed me, that there was an entire community of like-minded people\nout there, who \u2764\ufe0f to work on code in their free-time.\nTo me, Github is much more than a git interface; it\u2019s a social network.\nWhile other people browse Facebook or Instagram, I browse Github.<\/p>\n<p>I can still vividly remember getting my <a rel=\"external\" href=\"https:\/\/github.com\/mre\/Creamy\/stargazers\">first star<\/a> and <a rel=\"external\" href=\"https:\/\/github.com\/mre\/Creamy\/issues\/1\">my first issue on one of my projects<\/a> coming from a real (!) person other than myself.<\/p>\n<p>After so many years, a pull-request still feels like the most personal gift anyone could give to me.<\/p>\n<h2 id=\"github-the-culture\"><a class=\"anchor\" href=\"#github-the-culture\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>GitHub - The Culture<\/h2>\n<p>After a while, I started to admire some Github employees deeply:<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/zachholman.com\/\">Zach Holman<\/a> (who is about my age) is a great <a rel=\"external\" href=\"https:\/\/zachholman.com\/talk\/utc-is-enough-for-everyone-right\">writer<\/a>, <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=YVb2GsJHejo\">speaker<\/a>, and one of the most <a rel=\"external\" href=\"https:\/\/github.com\/holman\/spark\">creative developers<\/a> I can think of.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/scottchacon.com\/about.html\">Scott Chacon<\/a>, who <a rel=\"external\" href=\"https:\/\/git-scm.com\/book\/de\/v2\">taught me a lot about git<\/a> and whose presentation tool, <a rel=\"external\" href=\"https:\/\/github.com\/puppetlabs\/showoff\">showoff<\/a>, I\u2019ve <a rel=\"external\" href=\"https:\/\/github.com\/mre\/Talks\/tree\/master\/cuda\/Presentation\">used at University<\/a>.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/mojombo\">Tom Preston-Werner<\/a>, who I admire for refusing an offer from Microsoft to pursue his dream and build Github, for establishing a <a rel=\"external\" href=\"https:\/\/www.wired.com\/2013\/09\/github-office\/\">super-nerdy company culture<\/a>, and for <a rel=\"external\" href=\"https:\/\/jekyllrb.com\/\">Jekyll<\/a>.<\/li>\n<\/ul>\n<p>All three developers have since left the company.\nI can\u2019t help but notice that Github has changed.\nThe harassment accusations and letting Zach Holman go are only part of the story.<\/p>\n<p>It has become a company like any other, maintaining a mature product.\nIt doesn\u2019t <em>excite<\/em> me anymore.<\/p>\n<h2 id=\"an-alternative-reality\"><a class=\"anchor\" href=\"#an-alternative-reality\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>An Alternative Reality<\/h2>\n<p>There\u2019s still a bitter taste in my mouth when I think that Github has fallen prey to one of the tech giants. I loved Github while it was a small, friendly community of passionate developers.\nCould this have been sustainable?<\/p>\n<p>Maybe through paid features for project maintainers.<\/p>\n<p>You see, if you do Open Source every day, it can be a lot of work.\nPeople start depending on your projects, and you feel responsible for keeping the lights on.<\/p>\n<p>To ease the burden, I\u2019d love to have deeper insights into my project usage: visitor statistics for longer than two weeks,\na front page where you could filter and search for events, a better way to handle discussions\n(<a rel=\"external\" href=\"https:\/\/nikolas.github.io\/github-drama\/\">which can get out of hand quickly<\/a>), better <a rel=\"external\" href=\"https:\/\/docs.gitlab.com\/ee\/topics\/autodevops\/\">CI integration \u00e0 la Gitlab<\/a>.<\/p>\n<p>These features would be targeted at the top 10% of Github users, a group of 3 million people.\nWould this be enough to pay the bills? Probably. Would it be enough to grow? Probably not.<\/p>\n<h2 id=\"so-what\"><a class=\"anchor\" href=\"#so-what\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>So What?<\/h2>\n<p>I don\u2019t think the acquisition will kill the culture. Microsoft is a strong partner and <a rel=\"external\" href=\"https:\/\/nat.github.io\/hello\/\">Nat Friedman<\/a> is one of us.\nOn the other side, I\u2019m not as enthusiastic as I used to be.\nThere\u2019s room for competitors now and I\u2019m beginning to wonder what will be the next Github.\nThat said, I will keep the Octocat on my office wall, in the hope that the excitement comes back.<\/p>\n"},{"title":"Ten Years of Vim","pubDate":"Sun, 20 May 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/ten-years-of-vim\/","guid":"https:\/\/endler.dev\/2018\/ten-years-of-vim\/","description":"<div class=\"vim\">\n<div class=\"cursor\"><\/div>\n<\/div>\n<p>When I opened Vim by accident for the first time, I thought it was broken. My\nkeystrokes changed the screen in unpredictable ways, and I wanted to undo things\nand quit. Needless to say, it was an unpleasant experience. There was something\nabout it though, that kept me coming back and it became my main editor.<\/p>\n<p>Fast forward ten years (!) and I still use Vim.\nAfter all the Textmates and Atoms and PhpStorms I tried, I still find myself at home in Vim.\nPeople keep asking me: Why is that?<\/p>\n<h2 id=\"why-vim\"><a class=\"anchor\" href=\"#why-vim\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Why Vim?<\/h2>\n<p>Before Vim, I had used many other editors like notepad or nano. They all behaved more or less as expected: you insert text, you move your cursor with the arrow keys or your mouse, and you save with <code>Control + S<\/code> or by using the menu bar. VI (and Vim, its spiritual successor) is different.<\/p>\n<p>EVERYTHING in Vim is different, and that\u2019s why it\u2019s so highly effective. Let me explain.<\/p>\n<h2 id=\"the-zen-of-vim\"><a class=\"anchor\" href=\"#the-zen-of-vim\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>The Zen of Vim<\/h2>\n<p>The philosophy behind Vim takes a while to sink in:\nWhile other editors focus on <em>writing<\/em> as the central part of working with text, Vim thinks it\u2019s <em>editing<\/em>.<\/p>\n<p>You see, most of the time I don\u2019t spend writing <em>new<\/em> text; instead, I edit <em>existing<\/em> text.<br \/>\nI mold text, form it, turn it upside down.\nWriting text is craftsmanship and hard work. You have to shape your thoughts with your cold, bare hands until they somewhat form a coherent whole.\nThis painful process is what Vim tries to make at least bearable. It helps you keep control.\nIt does that, by providing you sharp, effective tools to modify text.\nThe core of Vim is a language for editing text.<\/p>\n<h2 id=\"vim-the-language\"><a class=\"anchor\" href=\"#vim-the-language\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Vim, the Language<\/h2>\n<p>The Vim commands are not cryptic, you already know them.<\/p>\n<ul>\n<li>To <u>u<\/u>ndo, type <code>u<\/code>.<\/li>\n<li>To <u>f<\/u>ind the next <u>t<\/u>, type <code>ft<\/code>.<\/li>\n<li>To <u>d<\/u>elete <u>a<\/u> <u>w<\/u>ord, type <code>daw<\/code>.<\/li>\n<li>To <u>c<\/u>hange <u>a<\/u> <u>s<\/u>entence, type <code>cas<\/code>.<\/li>\n<\/ul>\n<p>More often than not, you can <em>guess<\/em> the correct command by thinking of an operation you want to execute and an object to execute it on.\nThen just take the first character of every word. Try it!\nIf anything goes wrong, you can always hit <code>ESC<\/code> and type <code>u<\/code> for undo.<\/p>\n<p><strong>Operations<\/strong>: delete, find, change, back, insert, append,\u2026<br \/>\n<strong>Objects<\/strong>: word, sentence, parentheses, (html) tag,\u2026 (see <code>:help text-objects<\/code>)<\/p>\n<p>Inserting text is just another editing operation, which can be triggered with <code>i<\/code>.\nThat\u2019s why, by default, you are in <a rel=\"external\" href=\"https:\/\/en.wikibooks.org\/wiki\/Learning_the_vi_Editor\/Vim\/Modes\">normal mode<\/a> \u2014 also called command mode \u2014 where all those operations work.<\/p>\n<p>Once you know this, Vim makes a lot more sense, and that\u2019s when you start to be productive.<\/p>\n<h2 id=\"how-my-workflow-changed-over-the-years\"><a class=\"anchor\" href=\"#how-my-workflow-changed-over-the-years\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>How My Workflow Changed over the Years<\/h2>\n<p>When I was a beginner, I was very interested in how people with more Vim experience would use the editor.\nNow that I\u2019m a long-time user, here\u2019s my answer: there\u2019s no secret sauce.\nI certainly feel less exhausted after editing text for a day, but 90% of the commands I use fit on a post-it note.<\/p>\n<p>That said, throughout the years, my Vim habits changed.<br \/>\nI went through several phases:<\/p>\n<p>Year 1: I\u2019m happy if I can insert text and quit again.<br \/>\nYear 2: That\u2019s cool, let\u2019s learn more shortcuts.<br \/>\nYear 3-5: Let\u2019s add <em>all<\/em> the features!!!<br \/>\nYear 6-10: My <code>.vimrc<\/code> is five lines long.<\/p>\n<p>Year three is when I started to learn the Vim ecosystem for real.\nI tried all sorts of flavors like <a rel=\"external\" href=\"https:\/\/macvim-dev.github.io\/macvim\/\">MacVim<\/a> and distributions like <a rel=\"external\" href=\"https:\/\/github.com\/carlhuda\/janus\">janus<\/a>.\nFor a while, I even maintained <a rel=\"external\" href=\"https:\/\/github.com\/mre\/dotVim\/blob\/master\/.vimrc\">my own Vim configuration\n<\/a>, which was almost 400 lines long.<\/p>\n<p>All of that certainly helped me learn what\u2019s out there, but I\u2019m not sure if I would recommend that to a Vim beginner.\nAfter all, you don\u2019t really <em>need<\/em> all of that. Start with a vanilla Vim editor which works just fine!<\/p>\n<p>My current Vim setup is pretty minimalistic. I don\u2019t use plugins anymore, mostly out of laziness and because built-in Vim commands or macros can replace them.<\/p>\n<p>Here are three concrete examples of how my workflow changed over the years:<\/p>\n<ol>\n<li>\n<p>In the beginning, I used a lot of \u201cnumber powered movements\u201d. That is, if you have a command like <code>b<\/code>, which goes back one word in the text, you can also say <code>5b<\/code> to go back five words. Nowadays I mostly use <code>\/<\/code> to move to a matching word because it\u2019s quicker.<\/p>\n<\/li>\n<li>\n<p>I don\u2019t use arrow keys to move around in text anymore but forced myself to use <code>h<\/code>, <code>j<\/code>, <code>k<\/code>, <code>l<\/code>. Many people say that this is faster. After trying this for a few years, I don\u2019t think that is true (at least for me). I now just stick to it out of habit.<\/p>\n<\/li>\n<li>\n<p>On my main working machine I use Vim for quick text editing and Visual Studio Code plus the awesome <a rel=\"external\" href=\"https:\/\/github.com\/VSCodeVim\/Vim\">Vim plugin<\/a> for projects. This way, I get the best of both worlds.<\/p>\n<\/li>\n<\/ol>\n<h2 id=\"workflow-issues-i-still-struggle-with\"><a class=\"anchor\" href=\"#workflow-issues-i-still-struggle-with\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Workflow Issues I Still Struggle With<\/h2>\n<p>After all these years I\u2019m still not a Vim master \u2014 far from it.\nAs every other Vim user will tell you, we\u2019re all still learning.<\/p>\n<p>Here are a few things I wish I could do better:<\/p>\n<ul>\n<li><strong>Jumping around in longer texts<\/strong>: I know the basics, like searching (<code>\/<\/code>), jumping to a matching bracket (<code>%<\/code>) or jumping to specific lines (for line 10, type <code>10G<\/code>), but I still could use <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Symbol_(programming)\">symbols<\/a> more often for navigation.<\/li>\n<li><strong>Using visual mode for moving text around<\/strong>: Sometimes it can be quite complicated to type the right combination of letters to cut (delete) the text I want to move around. That\u2019s where visual mode (<code>v<\/code>) shines. It highlights the selected text. I should use it more often.<\/li>\n<li><strong>Multiple registers for copy and paste<\/strong>: Right now I only use one register (like a pastebin) for copying text, but Vim supports multiple registers. That\u2019s cool if you want to move around more than one thing at the same time. <a rel=\"external\" href=\"https:\/\/vim.fandom.com\/wiki\/Copy%2c_cut_and_paste\">Let\u2019s use more of those!<\/a><\/li>\n<li><strong>Tabs<\/strong>: I know <a rel=\"external\" href=\"https:\/\/vim.fandom.com\/wiki\/Using_tab_pages\">how tabs work<\/a>, but all the typing feels clunky. That\u2019s why I never extensively used them. Instead, I mostly use multiple terminal tabs or an IDE with Vim bindings for bigger projects.<\/li>\n<\/ul>\n<h2 id=\"would-i-learn-vim-again\"><a class=\"anchor\" href=\"#would-i-learn-vim-again\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Would I Learn Vim Again?<\/h2>\n<p>That\u2019s a tough question to answer.<\/p>\n<p>On one side, I would say no.\nThere\u2019s a steep learning curve in Vim and seeing all those modern IDEs become better at understanding the user\u2019s intent, editing text became way easier and faster in general.<\/p>\n<p>On the other side, Vim is the fastest way for me to write down my thoughts and code. As a bonus, it runs on every machine and might well be around for decades to come. In contrast, I don\u2019t know if the IntelliJ shortcuts will be relevant in ten years (note: if you read this in the future and ask yourself \u201cWhat is IntelliJ?\u201d, the answer might be no).<\/p>\n<h2 id=\"takeaways\"><a class=\"anchor\" href=\"#takeaways\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Takeaways<\/h2>\n<p>If I can give you one tip, don\u2019t learn Vim by memorizing commands. Instead, look at your current workflow and try to make it better, then see how Vim can make that easier. It helps to look at <a rel=\"external\" href=\"https:\/\/youtu.be\/yG-UaBJXZ80?t=43m12s\">other people using Vim to get inspired<\/a> (Youtube link with sound).<\/p>\n<p>You will spend a lot of time writing text, so it\u2019s well worth the time investment to learn one editor really well \u2014 especially if you are a programmer.<\/p>\n<p>After ten years, Vim is somehow ingrained in my mind. I <em>think<\/em> Vim when I\u2019m editing text. It has become yet another natural language to me. I\u2019m looking forward to the next ten years.<\/p>\n"},{"title":"Refactoring Go Code to Avoid File I\/O in Unit Tests","pubDate":"Thu, 22 Mar 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/go-io-testing\/","guid":"https:\/\/endler.dev\/2018\/go-io-testing\/","description":"<p>At work today, I refactored some simple Go code to make it more testable.\nThe idea was to avoid file handling in unit tests without mocking or using temporary files by separating data input\/output and data manipulation.<\/p>"},{"title":"A Tiny `ls` Clone Written in Rust","pubDate":"Fri, 09 Mar 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/ls\/","guid":"https:\/\/endler.dev\/2018\/ls\/","description":"<p>In my series of <a href=\"https:\/\/endler.dev\/2017\/yes\/\">useless Unix tools rewritten in Rust<\/a>, today I\u2019m going to be covering one of my all-time favorites: <code>ls<\/code>.<\/p>\n<p>First off, let me say that you probably don\u2019t want to use this code as a replacement for <code>ls<\/code> on your local machine (although you could!).\nAs we will find out, <code>ls<\/code> is actually quite a powerful tool under the hood.\nI\u2019m not going to come up with a full rewrite, but instead only cover the very basic output that you would expect from calling <code>ls -l<\/code> on your command line.\nWhat is this output? I\u2019m glad you asked.<\/p>\n<h2 id=\"expected-output\"><a class=\"anchor\" href=\"#expected-output\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Expected Output<\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&gt; ls -l<\/span><\/span>\n<span class=\"giallo-l\"><span>drwxr-xr-x 2 mendler  staff    13468 Feb  4 11:19 Top Secret<\/span><\/span>\n<span class=\"giallo-l\"><span>-rwxr--r-- 1 mendler  staff  6323935 Mar  8 21:56 Never Gonna Give You Up - Rick Astley.mp3<\/span><\/span>\n<span class=\"giallo-l\"><span>-rw-r--r-- 1 mendler  staff        0 Feb 18 23:55 Thoughts on Chess Boxing.doc<\/span><\/span>\n<span class=\"giallo-l\"><span>-rw-r--r-- 1 mendler  staff   380434 Dec 24 16:00 nobel-prize-speech.txt<\/span><\/span><\/code><\/pre>\n<p>Your output may vary, but generally, there are a couple of notable things going on. From left to right, we\u2019ve got the following fields:<\/p>\n<ul>\n<li>The <code>drwx<\/code> things in the beginning are the <em>file permissions<\/em> (also called the file mode). If <code>d<\/code> is set, it\u2019s a directory. <code>r<\/code> means read, <code>w<\/code> means write and <code>x<\/code> execute.\nThis <code>rwx<\/code> pattern gets repeated three times for the current user, the group, and other computer users respectively.<\/li>\n<li>Next we got the hardlink count when referring to a file, or the number of contained directory entries when referring to a directory. (<a rel=\"external\" href=\"https:\/\/unix.stackexchange.com\/a\/43047\">Reference<\/a>)<\/li>\n<li>Owner name<\/li>\n<li>Group name<\/li>\n<li>Number of bytes in the file<\/li>\n<li>Date when the file was last modified<\/li>\n<li>Finally, the path name<\/li>\n<\/ul>\n<p>For more in-depth information, I can recommend reading the manpage of <code>ls<\/code> from the <a rel=\"external\" href=\"https:\/\/linux.die.net\/man\/1\/ls\">GNU coreutils<\/a> used in most Linux distributions and the one from <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20170909164539\/https:\/\/developer.apple.com\/legacy\/library\/documentation\/Darwin\/Reference\/ManPages\/man1\/ls.1.html\">Darwin<\/a> (which powers MacOS).<\/p>\n<p>Whew, that\u2019s a lot of information for such a tiny tool.\nBut then again, it can\u2019t be so hard to port that to Rust, right? Let\u2019s get started!<\/p>\n<h2 id=\"a-very-basic-ls-in-rust\"><a class=\"anchor\" href=\"#a-very-basic-ls-in-rust\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Very Basic <code>ls<\/code> in Rust<\/h2>\n<p>Here is the most bare-bones version of <code>ls<\/code>, which just prints all files in the current directory:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>fs<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">path<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Path<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>process<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">ref<\/span><span> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">Path<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">.<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\t\tprintln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">\t\tprocess<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">exit<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">dir<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Path<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span> dir<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_dir<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\tfor<\/span><span> entry<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-13 z-d-15\"> fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">read_dir<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>dir<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\t\tlet<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\t\tlet<\/span><span> file_name<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> entry<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">\t\t\t\t\t\t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">file_name<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">\t\t\t\t\t\t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">\t\t\t\t\t\t.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">or_else<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>f<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Invalid entry: <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:?<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> f<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\t\t\t\tprintln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> file_name<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span><\/code><\/pre>\n<p>We can copy that straight out of the <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/fs\/fn.read_dir.html#examples\">documentation<\/a>.\nWhen we run it, we get the expected output:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&gt; cargo run<\/span><\/span>\n<span class=\"giallo-l\"><span>Cargo.lock<\/span><\/span>\n<span class=\"giallo-l\"><span>Cargo.toml<\/span><\/span>\n<span class=\"giallo-l\"><span>src<\/span><\/span>\n<span class=\"giallo-l\"><span>target<\/span><\/span><\/code><\/pre>\n<p>It prints the files and exits. Simple enough.<\/p>\n<p>We should stop for a moment and celebrate our success, knowing that we just wrote our first little Unix utility from scratch.\n<em>Pro Tip<\/em>: You can install the binary with <code>cargo install<\/code> and call it like any other binary from now on.<\/p>\n<p>But we have higher goals, so let\u2019s continue.<\/p>\n<h2 id=\"adding-a-parameter-to-specify-the-directory\"><a class=\"anchor\" href=\"#adding-a-parameter-to-specify-the-directory\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Adding a Parameter to Specify the Directory<\/h2>\n<p>Usually, if we type <code>ls mydir<\/code>, we expect to get the file listing of no other directory than <code>mydir<\/code>. We should add the same functionality to our version.<\/p>\n<p>To do this, we need to accept command line parameters.\nOne Rust crate that I love to use in this case is <a rel=\"external\" href=\"https:\/\/github.com\/TeXitoi\/structopt\">structopt<\/a>. It makes argument parsing very easy.<\/p>\n<p>Add it to your <code>Cargo.toml<\/code>. (You need cargo-edit for the following command).<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo add structopt<\/span><\/span><\/code><\/pre>\n<p>Now we can import it and use it in our project:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">macro_use<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> structopt<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> use std::...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> structopt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">StructOpt<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">derive<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">StructOpt<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Debug<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">struct<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Opt<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\t\/\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Output file<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\t#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">structopt<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">default_value <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">.<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> parse<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">from_os_str<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span>\tpath<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> PathBuf<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> opt<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Opt<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from_args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">ref<\/span><span> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>opt<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">path<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\t\t\tprintln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">\t\t\tprocess<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">exit<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">dir<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">PathBuf<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\t\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Same as before<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>By adding the <code>Opt<\/code> struct, we can define the command line flags, input parameters, and the <code>help<\/code> output super easily.\nThere are tons of configuration options, so it\u2019s worth checking out the <a rel=\"external\" href=\"https:\/\/github.com\/TeXitoi\/structopt\">project homepage<\/a>.<\/p>\n<p>Also note, that we changed the type of the path variable from <code>Path<\/code> to <code>PathBuf<\/code>. The difference is, that <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/src\/std\/path.rs.html#1107-1109\"><code>PathBuf<\/code> owns the inner path string<\/a>, while <code>Path<\/code> <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/src\/std\/path.rs.html#1629-1631\">simply provides a reference to it<\/a>. The relationship is similar to <code>String<\/code> and <code>&amp;str<\/code>.<\/p>\n<h2 id=\"reading-the-modification-time\"><a class=\"anchor\" href=\"#reading-the-modification-time\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Reading the Modification Time<\/h2>\n<p>Now let\u2019s deal with the metadata.\nFirst, we try to retrieve the modification time from the file.\nA quick look at <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/stable\/std\/fs\/struct.Metadata.html\">the documentation<\/a> shows us how to do it:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>fs<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">metadata<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">foo.txt<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">if<\/span><span class=\"z-l-9 z-d-9\"> let<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>time<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">modified<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\tprintln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:?<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> time<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The output might not be what you expect: we receive a <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/stable\/std\/time\/struct.SystemTime.html\"><code>SystemTime<\/code><\/a> object, which represents the measurement of the system clock. E.g. <a rel=\"external\" href=\"https:\/\/play.rust-lang.org\/?gist=96e18ed541abe896f761d601cdf50561&amp;version=stable\">this code<\/a><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:?<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> SystemTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Prints: SystemTime { tv_sec: 1520554933, tv_nsec: 610406401 }<\/span><\/span><\/code><\/pre>\n<p>But the format that we would like to have is something like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Mar<\/span><span class=\"z-l-16 z-d-16\">  9<\/span><span class=\"z-l-16 z-d-16\"> 01<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\">24<\/span><\/span><\/code><\/pre>\n<p>Thankfully, there is a library called <code>chrono<\/code>, which can read this format and convert it into any human readable output we like:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> current<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> DateTime<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Local<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> DateTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">SystemTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">now<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> current<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">%_d %b %H:%M<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>this prints<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>9 Mar 01:29<\/span><\/span><\/code><\/pre>\n<p>(Yeah, I know it\u2019s getting late.)<\/p>\n<p>Armed with that knowledge, we can now read our file modification time.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo add chrono<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> chrono<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">DateTime<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Local<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> run<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">dir<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">PathBuf<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Box<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Error<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span> dir<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_dir<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\tfor<\/span><span> entry<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-13 z-d-15\"> fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">read_dir<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>dir<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tlet<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tlet<\/span><span> file_name<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-2 z-d-5\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tlet<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">metadata<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tlet<\/span><span> size<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tlet<\/span><span> modified<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> DateTime<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Local<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> DateTime<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">from<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>metadata<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">modified<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">\t\t\tprintln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">\t\t\t\t&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:&gt;5<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\tsize<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\tmodified<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">%_d %b %H:%M<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\tfile_name<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t\t)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">\tOk<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>This <code>{:&gt;5}<\/code> might look weird. It\u2019s a formatting directive provided by <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/fmt\/\"><code>std::fmt<\/code><\/a>.\nIt means \u201cright align this field with a space padding of 5\u201d - just like our bigger brother <code>ls -l<\/code> is doing it.<\/p>\n<p>Similarly, we retrieved the size in bytes with <code>metadata.len()<\/code>.<\/p>\n<h2 id=\"unix-file-permissions-are-a-zoo\"><a class=\"anchor\" href=\"#unix-file-permissions-are-a-zoo\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Unix File Permissions Are a Zoo<\/h2>\n<p>Reading the file permissions is a bit more tricky.\nWhile the <code>rwx<\/code> notation is very common in Unix derivatives such as *BSD or GNU\/Linux, many other operating systems ship their own permission management.\nThere are even <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/File_system_permissions\">differences between the Unix derivatives<\/a>.<\/p>\n<p>Wikipedia lists a few extensions to the file permissions that you might encounter:<\/p>\n<ul>\n<li>+ (plus) suffix indicates an <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Access_control_list\">access control list<\/a> that can control additional permissions.<\/li>\n<li>. (dot) suffix indicates an <a rel=\"external\" href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_enterprise_linux\/6\/html\/security-enhanced_linux\/chap-security-enhanced_linux-selinux_contexts\">SELinux context<\/a> is present. Details may be listed with the command ls -Z.<\/li>\n<li>@ suffix indicates <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Extended_file_attributes\">extended file attributes<\/a> are present.<\/li>\n<\/ul>\n<p>That just goes to show, that there are a lot of important details to be considered when implementing this in real life.<\/p>\n<h2 id=\"implementing-very-basic-file-mode\"><a class=\"anchor\" href=\"#implementing-very-basic-file-mode\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Implementing Very Basic File Mode<\/h2>\n<p>For now, we just stick to the basics and assume we are on a platform that supports the <code>rwx<\/code> file mode.<\/p>\n<p>Behind the <code>r<\/code>, the <code>w<\/code> and the <code>x<\/code> are in reality octal numbers. That\u2019s easier for computers to work with and many hardcore users even prefer to type the numbers over the symbols.\nThe ruleset behind those octals is as follows. I took that from the <code>chmod<\/code> manpage.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\tModes may be absolute or symbolic.<\/span><\/span>\n<span class=\"giallo-l\"><span>\tAn absolute mode is an octal number constructed<\/span><\/span>\n<span class=\"giallo-l\"><span>\tfrom the sum of one or more of the following values<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>\t 0400    Allow read by owner.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0200    Allow write by owner.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0100    For files, allow execution by owner.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0040    Allow read by group members.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0020    Allow write by group members.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0010    For files, allow execution by group members.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0004    Allow read by others.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0002    Allow write by others.<\/span><\/span>\n<span class=\"giallo-l\"><span>\t 0001    For files, allow execution by others.<\/span><\/span><\/code><\/pre>\n<p>For example, to set the permissions for a file so that the owner can read, write and execute it and nobody else can do anything would be 700 (400 + 200 +100).<\/p>\n<p>Granted, those numbers are the same since the 70s and are not going to change soon, but it\u2019s still a bad idea to compare our file permissions directly with the values; if not for compatibility reasons, then for readability and to avoid magic numbers in our code.<\/p>\n<p>Therefore, we use the <code>libc<\/code> crate, which provides constants for those magic numbers.\nAs mentioned above, these file permissions are Unix specific, so we need to import a Unix-only library named <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/os\/unix\/fs\/trait.PermissionsExt.html\"><code>std::os::unix::fs::PermissionsExt;<\/code><\/a> for that.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> libc<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Examples:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> * `S_IRGRP` stands for &quot;read permission for group&quot;,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> * `S_IXUSR` stands for &quot;execution permission for user&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> libc<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">S_IRGRP<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IROTH<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IRUSR<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWGRP<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWOTH<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWUSR<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXGRP<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXOTH<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXUSR<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">os<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">unix<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">fs<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">PermissionsExt<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>We can now get the file permissions like so:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> entry<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">metadata<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> mode<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> metadata<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">permissions<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">mode<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse_permissions<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>mode<\/span><span class=\"z-l-9 z-d-9\"> as<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p><code>parse_permissions()<\/code> is a little helper function defined as follows:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> parse_permissions<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">mode<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> user<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> triplet<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>mode<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IRUSR<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWUSR<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXUSR<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> group<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> triplet<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>mode<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IRGRP<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWGRP<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXGRP<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tlet<\/span><span> other<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> triplet<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>mode<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IROTH<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IWOTH<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> S_IXOTH<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t[<\/span><span>user<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> group<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> other<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">join<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>It takes the file mode as a <code>u16<\/code> (simply because the libc constants are <code>u16<\/code>)\nand calls <code>triplet<\/code> on it.\nFor each flag <code>read<\/code>, <code>write<\/code>, and <code>execute<\/code>, it runs a binary <code>&amp;<\/code> operation on <code>mode<\/code>.\nThe output is matched exhaustively against all possible permission patterns.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> triplet<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">mode<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> read<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> write<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> execute<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u16<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tmatch<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>mode<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span> read<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> mode<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span> write<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> mode<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span> execute<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">---<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span>_<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">r--<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">-w-<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">--x<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span>_<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">r-x<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span>_<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">rw-<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">-wx<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t(<\/span><span>_<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> _<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">rwx<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">to_string<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><h2 id=\"wrapping-up\"><a class=\"anchor\" href=\"#wrapping-up\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Wrapping Up<\/h2>\n<p>The final output looks like this. Close enough.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&gt; cargo run<\/span><\/span>\n<span class=\"giallo-l\"><span>rw-r--r--     7  6 Mar 23:10 .gitignore<\/span><\/span>\n<span class=\"giallo-l\"><span>rw-r--r-- 15618  8 Mar 00:41 Cargo.lock<\/span><\/span>\n<span class=\"giallo-l\"><span>rw-r--r--   185  8 Mar 00:41 Cargo.toml<\/span><\/span>\n<span class=\"giallo-l\"><span>rwxr-xr-x   102  5 Mar 21:31 src<\/span><\/span>\n<span class=\"giallo-l\"><span>rwxr-xr-x   136  6 Mar 23:07 target<\/span><\/span><\/code><\/pre>\n<p>That\u2019s it! You can find the <a rel=\"external\" href=\"https:\/\/gist.github.com\/mre\/91ebb841c34df69671bd117ead621a8b\">final version of our toy <code>ls<\/code> on Github<\/a>.\nWe are still far away from a full-fledged <code>ls<\/code> replacement, but at least we learned a thing or two about its internals.<\/p>\n<p>If you\u2019re looking for a proper <code>ls<\/code> replacement written in Rust, go check out <a rel=\"external\" href=\"https:\/\/github.com\/Peltoche\/lsd\"><code>lsd<\/code><\/a>.\nIf, instead, you want to read another blog post from the same series, check out <a href=\"https:\/\/endler.dev\/2017\/yes\/\"><em>A Little Story About the <code>yes<\/code> Unix Command<\/em><\/a>.<\/p>\n"},{"title":"Rust in 2018","pubDate":"Tue, 09 Jan 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/rust-2018\/","guid":"https:\/\/endler.dev\/2018\/rust-2018\/","description":"<p>I wrote about the <a href=\"https:\/\/endler.dev\/2017\/future-of-rust\/\">future of Rust<\/a> before and it seems like nobody stops me from doing it again! Quite the contrary: this time the Rust core team even <a rel=\"external\" href=\"https:\/\/blog.rust-lang.org\/2018\/01\/03\/new-years-rust-a-call-for-community-blogposts.html\">asked for it<\/a>.\nI\u2019m a bit late to the party, but here are my 2 cents about the priorities for Rust in 2018.<\/p>"},{"title":"Functional Programming for Mathematical Computing","pubDate":"Tue, 02 Jan 2018 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2018\/functional-mathematics\/","guid":"https:\/\/endler.dev\/2018\/functional-mathematics\/","description":"<p>Programming languages help us describe general solutions for problems; the result just happens to be executable by machines. Every programming language comes with a different set of strengths and weaknesses, one reason being that its syntax and semantics heavily influence the range of problems which can easily be tackled with it.<\/p>\n<p><strong>tl;dr:<\/strong> <em>I think that functional programming is better suited for mathematical computations than the more common imperative approach.<\/em><\/p>\n<h2 id=\"using-built-in-abstractions-for-mathematics\"><a class=\"anchor\" href=\"#using-built-in-abstractions-for-mathematics\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Using Built-In Abstractions for Mathematics<\/h2>\n<p>The ideas behind a language (the underlying programming paradigms) are distinctive for the community that builds around it. The developers create a unique ecosystem of ready-to-use libraries and frameworks around the language core. As a consequence, some languages are stronger in areas such as business applications (one could think of Cobol), others work great for systems programming (like C or Rust).<\/p>\n<p>When it comes to solving mathematical and numerical problems with computers, Fortran might come to mind. Although Fortran is a general-purpose language, it is mostly known for scientific computing. Of course, the language was created with that purpose in mind \u2013 hence the name, <em>Formula Translation<\/em>.<\/p>\n<p>One reason for its popularity in this area is that it offers some built-in domain-specific keywords to express mathematical concepts, while keeping an eye on performance. For instance, it has a dedicated datatype for complex numbers \u2013 <code>COMPLEX<\/code> \u2013 and a keyword named <code>DIMENSION<\/code> which is quite similar to the mathematical term and can be used to create arrays and vectors.<\/p>\n<h2 id=\"imperative-vs-functional-style\"><a class=\"anchor\" href=\"#imperative-vs-functional-style\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Imperative vs Functional Style<\/h2>\n<p>Built-in keywords can help expand the expressiveness of a language into a specific problem space, but this approach is severely limited. It\u2019s not feasible to extend the language core <em>ad infinitum<\/em>; it would just be harder to maintain and take longer to learn. Therefore, most languages provide other ways of abstraction \u2013 like <em>functions<\/em>, <em>subroutines<\/em>, <em>classes<\/em> and <em>objects<\/em> \u2013 to split a routine into smaller, more manageable parts. These mechanisms might help to control the complexity of a program, but especially when dealing with mathematical problems, one has to be careful not to obfuscate the solution with boilerplate code.<\/p>\n<h3 id=\"specimen-i-factorial\"><a class=\"anchor\" href=\"#specimen-i-factorial\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Specimen I - Factorial<\/h3>\n<p>As an example, the stated problem might be to translate the following formula, which calculates the factorial of a positive number n, into program code:<\/p>\n<p><img src=\"https:\/\/endler.dev\/2018\/functional-mathematics\/.\/example_faculty.svg\" alt=\"The mathematical definition of a faculty: n! = 1 * 2 * 3 \u2026 * n\" \/><\/p>\n<p>An implementation of the above formula using imperative style Java might look like this:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"java\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">public<\/span><span class=\"z-l-9 z-d-9\"> static<\/span><span class=\"z-l-9 z-d-9\"> long<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> fact<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">final<\/span><span class=\"z-l-9 z-d-9\"> int<\/span><span> n<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    if<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>n <\/span><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">        \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Negative numbers not allowed<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        return<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    long<\/span><span> prod<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    for<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">int<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span> i <\/span><span class=\"z-l-2 z-d-5\">&lt;=<\/span><span> n<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-2 z-d-5\"> ++<\/span><span>i<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        prod <\/span><span class=\"z-l-2 z-d-5\">*=<\/span><span> i<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    return<\/span><span> prod<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>This is quite a long solution for such a short problem definition.\n(Note that writing a version with an explicit loop from 1 to n was on purpose; a recursive function would be shorter, but uses a concept which was not introduced by the mathematical formula.)<\/p>\n<p>Also, the program contains many language-specific keywords, such as <code>public<\/code>, <code>static<\/code>, and <code>System.err.println()<\/code>. On top of that, the programmer must explicitly provide all data types for the variables in use \u2013 a tiresome obligation.<\/p>\n<p>All of this obfuscates the mathematical definition.<\/p>\n<p>Compare this with the following version written in a functional language, like Haskell.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"haskell\"><span class=\"giallo-l\"><span>fact n <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span> product <\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-10 z-d-12\">..<\/span><span>n<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span><\/code><\/pre>\n<p>This is an almost direct translation from the problem definition into code. It needs no explicit types, no temporary variables and no access modifiers (such as public).<\/p>\n<h3 id=\"specimen-ii-dot-product\"><a class=\"anchor\" href=\"#specimen-ii-dot-product\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Specimen II - Dot Product<\/h3>\n<p>One could argue that the above Haskell program owes its brevity to the fact, that the language provides just the right abstractions (namely the <code>product<\/code> keyword and the <code>[1..n]<\/code> range syntax) for that specific task.\nTherefore let\u2019s examine a simple function which is neither available in Haskell nor in Java: The dot product of two vectors. The mathematical definition is as follows:<\/p>\n<p><img src=\"https:\/\/endler.dev\/2018\/functional-mathematics\/.\/example_vector_dot.svg\" alt=\"The mathematical definition of a vector dot product: a\u00b7b= aibi =a1b1+a2b2+\u00b7\u00b7\u00b7+anbn =abT\" \/><\/p>\n<p>For vectors with three dimensions, it can be written as<\/p>\n<p><img src=\"https:\/\/endler.dev\/2018\/functional-mathematics\/.\/example_vector_3d.svg\" alt=\"Vector dot product for three dimensions: a\u00b7b = a1 * b1 + a2 * b2 + a3* b3\" \/><\/p>\n<p>First, a Haskell implementation:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"haskell\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">type<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Scalar<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">data<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vector<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-d-2\"> Vector<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-9 z-d-9\"> deriving<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Show<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">dot<\/span><span class=\"z-l-8 z-d-4\"> ::<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Num<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> =&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vector<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vector<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Scalar<\/span><span class=\"z-l-14 z-d-10\"> a<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-d-2\">Vector<\/span><span> a1 a2 a3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> `<\/span><span class=\"z-l-2 z-d-5\">dot<\/span><span class=\"z-l-2 z-d-5\">`<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-3 z-d-2\">Vector<\/span><span> b1 b2 b3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> a1<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span>b1 <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span> a2<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span>b2 <\/span><span class=\"z-l-2 z-d-5\">+<\/span><span> a3<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span>b3<\/span><\/span><\/code><\/pre>\n<p>Note, that the mathematical types can be defined in one line each. Further note, that we define the dot function in infix notation, that is, we place the first argument of dot in front of the function name and the second argument behind it. This way, the code looks more like its mathematical equivalent.\nAn example call of the above function would be<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"haskell\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-3 z-d-2\">Vector<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> \u2019<\/span><span>dot<\/span><span class=\"z-l-2 z-d-5\">\u2019<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-3 z-d-2\">Vector<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>which is short, precise and readable.<\/p>\n<p>Now, a similar implementation in Java.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"java\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">public<\/span><span class=\"z-l-9 z-d-9\"> static<\/span><span class=\"z-l-9 z-d-9\"> class<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">T<\/span><span class=\"z-l-9 z-d-9\"> extends<\/span><span class=\"z-l-9 z-d-9\"> Number<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    private<\/span><span class=\"z-l-9 z-d-9\"> T<\/span><span> x<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> y<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> z<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    public<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> Vector<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">T<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> x<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> T<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> y<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> T<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> z<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">        this<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>x<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> x<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">        this<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>y<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> y<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">        this<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>z<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> z<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    public<\/span><span class=\"z-l-9 z-d-9\"> double<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> dot<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">?<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> v<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        return<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>x<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> v<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>x<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><\/span>\n<span class=\"giallo-l\"><span>                y<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> v<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>y<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> +<\/span><\/span>\n<span class=\"giallo-l\"><span>                z<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span> v<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>z<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">doubleValue<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    public<\/span><span class=\"z-l-9 z-d-9\"> static<\/span><span class=\"z-l-9 z-d-9\"> void<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">String<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span> args<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">Integer<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span> a<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> new<\/span><span class=\"z-l-9 z-d-9\"> Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">Integer<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">Integer<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span> b<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> new<\/span><span class=\"z-l-9 z-d-9\"> Vector<\/span><span class=\"z-l-8 z-d-4\">&lt;<\/span><span class=\"z-l-9 z-d-9\">Integer<\/span><span class=\"z-l-8 z-d-4\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        System<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>out<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>a<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">dot<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>b<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>For a proper textual representation of Vectors, the toString() Method would also need to be overwritten. In Haskell, one can simply derive from the <code>Show<\/code> typeclass as shown in the code.<\/p>\n<h2 id=\"creating-new-abstractions\"><a class=\"anchor\" href=\"#creating-new-abstractions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Creating New Abstractions<\/h2>\n<p>If functions and types are not sufficient to write straightforward programs, Haskell also offers simple constructs to create new operators and keywords which extend the language core itself. This makes domain-specific-languages feasible and enables the developer to work more directly on the actual problem instead of working around peculiarities of the programming language itself (such as memory management or array iteration). Haskell embraces this concept; Java has no such functionality.<\/p>\n<h2 id=\"conclusion\"><a class=\"anchor\" href=\"#conclusion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Conclusion<\/h2>\n<p>I\u2019m not trying to bash Java or worship Haskell here. Both languages have their place.\nI merely picked Java, because lots of programmers can read it.<\/p>\n<p>The comparison is more between a functional and an imperative approach for numerical and symbolical programming; and for that, I prefer a functional approach every day. It removes clutter and yields elegant solutions. It provides convenient methods to work on a high level of abstraction and speak in mathematical terms and still, these strengths are disregarded by many programmers.<\/p>\n<p>Abraham H. Maslow\u2019s observation in his 1966 book <a rel=\"external\" href=\"https:\/\/www.goodreads.com\/book\/show\/1510050.The_Psychology_of_Science\">The Psychology of Science<\/a> seems fitting:<\/p>\n<blockquote>\n<p>\u201cI suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.\u201d<\/p>\n<\/blockquote>\n"},{"title":"Rust for Rubyists","pubDate":"Sun, 17 Dec 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/rust-for-rubyists\/","guid":"https:\/\/endler.dev\/2017\/rust-for-rubyists\/","description":"<p>Recently I came across a delightful article on idiomatic Ruby.\nI\u2019m not a good Ruby developer by any means, but I realized, that a lot of the patterns are also quite common in Rust.\nWhat follows is a side-by-side comparison of idiomatic code in both languages.<\/p>\n<p>The Ruby code samples are from the <a rel=\"external\" href=\"https:\/\/medium.com\/the-renaissance-developer\/idiomatic-ruby-1b5fa1445098\">original article<\/a>.<\/p>\n<h2 id=\"map-and-higher-order-functions\"><a class=\"anchor\" href=\"#map-and-higher-order-functions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Map and Higher-Order Functions<\/h2>\n<p>The first example is a pretty basic iteration over elements of a container using <code>map<\/code>.<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span>user_ids<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> users<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>user<\/span><span class=\"z-l-8 z-d-4\">|<\/span><span> user<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">id<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><\/span><\/code><\/pre>\n<p>The <code>map<\/code> concept is also pretty standard in Rust.\nCompared to Ruby, we need to be a little more explicit here:\nIf <code>users<\/code> is a vector of <code>User<\/code> objects, we first need to create an iterator from it:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=5a61b7b44ff01fabbc07dba9409d9b97&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> user_ids<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> users<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>user<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> user<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>You might say that\u2019s quite verbose, but this additional abstraction allows us to express an important concept:\nwill the iterator take ownership of the vector, or will it not?<\/p>\n<ul>\n<li>With <code>iter()<\/code>, you get a \u201cread-only view\u201d into the vector. After the iteration, it will be unchanged.<\/li>\n<li>With <code>into_iter()<\/code>, you take ownership over the vector. After the iteration, the vector will be gone.\nIn Rust terminology, it will have <em>moved<\/em>.<\/li>\n<li>Read some more about the <a rel=\"external\" href=\"https:\/\/hermanradtke.com\/2015\/06\/22\/effectively-using-iterators-in-rust.html\">difference between <code>iter()<\/code> and <code>into_iter()<\/code> here<\/a>.<\/li>\n<\/ul>\n<p>The above Ruby code can be simplified like this:<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span>user_ids<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> users<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-10 z-d-12\">id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>In Ruby, higher-order functions (like <code>map<\/code>) take <a rel=\"external\" href=\"https:\/\/blog.appsignal.com\/2018\/09\/04\/ruby-magic-closures-in-ruby-blocks-procs-and-lambdas.html\">blocks or procs<\/a> as an argument and the language provides a convenient shortcut for method invocation \u2014 <code>&amp;:id<\/code> is the same as <code>{|o| o.id()}<\/code>.<\/p>\n<p>Something similar could be done in Rust:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=131027a481d4691821315ad308d26dc9&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> id<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span>u<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">User<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> u<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>id<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> user_ids<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> users<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>This is probably not the most idiomatic way to do it, though. What you will see more often is the use of <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/book\/first-edition\/ufcs.html\">Universal Function Call Syntax<\/a> in this case:<sup><a href=\"#fn1\" id=\"ref1\">1<\/a><\/sup><\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=51069ee76e5d534621ccd6633474b630&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> user_ids<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> users<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-d-15\">User<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>In Rust, higher-order functions take <strong>functions<\/strong> as an argument. Therefore <code>users.iter().map(Users::id)<\/code> is more or less equivalent to <code>users.iter().map(|u| u.id())<\/code>.<sup><a href=\"#fn2\" id=\"ref2\">2<\/a><\/sup><\/p>\n<p>Also, <code>map()<\/code> in Rust returns another iterator and not a collection.\nIf you want a collection, you would have to run <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html#examples-23\"><code>collect()<\/code><\/a> on that, as we\u2019ll see later.<\/p>\n<h2 id=\"iteration-with-each\"><a class=\"anchor\" href=\"#iteration-with-each\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Iteration with Each<\/h2>\n<p>Speaking of iteration, one pattern that I see a lot in Ruby code is this:<\/p>\n<a class=\"example\" href=\"https:\/\/gist.github.com\/mre\/f6552360a4c08f2c064da7f00d434d5c\">\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Ruby<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Rust<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Python<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Cobol<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">each<\/span><span class=\"z-l-9 z-d-9\"> do<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>lang<\/span><span class=\"z-l-8 z-d-4\">|<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  puts<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Hello <\/span><span class=\"z-l-8 z-d-4\">#{<\/span><span>lang<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">end<\/span><\/span><\/code><\/pre><\/a>\n<p>Since <a rel=\"external\" href=\"https:\/\/blog.rust-lang.org\/2017\/10\/12\/Rust-1.21.html\">Rust 1.21<\/a>, this is now also possible:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=549d38bc43549fd5444c731d2bc3a47b&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Ruby<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Rust<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Python<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Cobol<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">for_each<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>lang<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">lang<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> lang<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> lang<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Although, more commonly one would write that as a normal for-loop in Rust:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=a7691b56b1dfd1fb19aa00a91b39589d&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">for<\/span><span> lang<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Ruby<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Rust<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Python<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Cobol<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">lang<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> lang<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> lang<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><\/a>\n<h2 id=\"select-and-filter\"><a class=\"anchor\" href=\"#select-and-filter\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Select and Filter<\/h2>\n<p>Let\u2019s say you want to extract only even numbers from a collection in Ruby.<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span>even_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>element<\/span><span class=\"z-l-8 z-d-4\">|<\/span><span> element <\/span><span class=\"z-l-9 z-d-9\">if<\/span><span> element<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">even?<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> [ni, 2, nil, 4, nil]<\/span><\/span>\n<span class=\"giallo-l\"><span>even_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> even_numbers<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">compact<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> #<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> [2, 4]<\/span><\/span><\/code><\/pre>\n<p>In this example, before calling <code>compact<\/code>, our <code>even_numbers<\/code> array had <code>nil<\/code> entries.\nWell, in Rust there is no concept of <code>nil<\/code> or <code>Null<\/code>. You don\u2019t need a <code>compact<\/code>.\nAlso, <code>map<\/code> doesn\u2019t take predicates. You would use <code>filter<\/code> for that:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=494d6e3ff016c21931e3495b10c8f6ee&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> even_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>element<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> element<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>or, to make a vector out of the result<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=45c6dbd2d35316c73165c5571d66df9d&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Result: [2, 4]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> even_numbers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">i64<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>element<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> element<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Some hints:<\/p>\n<ul>\n<li>I\u2019m using the type hint <code>Vec&lt;i64&gt;<\/code> here because, without it, Rust does not know what collection I want to build when calling <code>collect<\/code>.<\/li>\n<li><code>vec!<\/code> is a macro for creating a vector.<\/li>\n<li>Instead of <code>iter<\/code>, I use <code>into_iter<\/code>. This way, I take ownership of the elements in the vector. With <code>iter()<\/code> I would get a <code>Vec&lt;&amp;i64&gt;<\/code> instead.<\/li>\n<\/ul>\n<p>In Rust, there is no <code>even<\/code> method on numbers, but that doesn\u2019t keep us from defining one!<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=c289c2a1cf8bd870cbd5cc2cd60ea791&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> even<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span>x<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-9 z-d-9\">i64<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> x<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> even_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>even<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>In a real-world scenario, you would probably use a third-party package (crate) like <a rel=\"external\" href=\"https:\/\/github.com\/rust-num\/num\"><code>num<\/code><\/a> for numerical mathematics:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=e4bbbf60b7b1cbbedfb363672731bf53&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> num<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> num<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Integer<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> even_numbers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">i64<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>x<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> x<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_even<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><\/a>\n<p>In general, it\u2019s quite common to use crates in Rust for functionality that is not in the standard lib.\nPart of the reason why this is so well accepted is that <a rel=\"external\" href=\"https:\/\/github.com\/rust-lang\/cargo\">cargo<\/a> is such a rad package manager.\n(Maybe because it was built by no other than <a rel=\"external\" href=\"https:\/\/yehudakatz.com\/about\/\">Yehuda Katz<\/a> of Ruby fame. \ud83d\ude09)<\/p>\n<p>As mentioned before, Rust does not have <code>nil<\/code>. However, there is still the concept of operations that can fail.\nThe canonical type to express that is called <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/result\/\"><code>Result<\/code><\/a>.<\/p>\n<p>Let\u2019s say you want to convert a vector of strings to integers.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=1365d177503ee2d32c4aa594263ee4d4&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> maybe_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">nah<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">nope<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> numbers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>_<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> maybe_numbers<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>i<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u64<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>That looks nice, but maybe the output is a little unexpected. <code>numbers<\/code> will also contain the parsing errors:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=1365d177503ee2d32c4aa594263ee4d4&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">2<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ParseIntError<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> kind<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> InvalidDigit<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Err<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">ParseIntError<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> kind<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> InvalidDigit<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span><\/code><\/pre><\/a>\n<p>Sometimes you\u2019re just interested in the successful operations.\nAn easy way to filter out the errors is to use <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html#method.filter_map\"><code>filter_map<\/code><\/a>:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=afdc823ec2e165ac0a03948fb323d305&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> maybe_numbers<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> vec!<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">1<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">2<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">nah<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">nope<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">3<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> numbers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>_<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> maybe_numbers<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter_map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>i<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">parse<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u64<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>I changed two things here:<\/p>\n<ul>\n<li>Instead of <code>map<\/code>, I\u2019m now using <code>filter_map<\/code>.<\/li>\n<li><code>parse<\/code> returns a <code>Result<\/code>, but <code>filter_map<\/code> expects an <code>Option<\/code>. We can convert a <code>Result<\/code> into an <code>Option<\/code> by calling <code>ok()<\/code> on it<sup><a href=\"#fn3\" id=\"ref3\">3<\/a><\/sup>.<\/li>\n<\/ul>\n<p>The return value contains all successfully converted strings:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=afdc823ec2e165ac0a03948fb323d305&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span><\/code><\/pre><\/a>\n<p>The <code>filter_map<\/code> is similar to the <code>select<\/code> method in Ruby:<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">select<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\"> |<\/span><span>element<\/span><span class=\"z-l-8 z-d-4\">|<\/span><span> element<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">even?<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><\/span><\/code><\/pre><h2 id=\"random-numbers\"><a class=\"anchor\" href=\"#random-numbers\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Random Numbers<\/h2>\n<p>Here\u2019s how to get a random number from an array in Ruby:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=a66785b44094bacb78fa8dd822bfeab5&version=stable\">\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">sample<\/span><\/span><\/code><\/pre><\/a>\n<p>That\u2019s quite nice and idiomatic!\nCompare that to Rust:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=bed7fca31737bcbf4b9aed427cc22713&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> rng<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> thread_rng<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>rng<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">choose<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre><\/a>\n<p>For the code to work, you need the <code>rand<\/code> crate. Click on the snippet for a running example.<\/p>\n<p>There are some differences to Ruby. Namely, we need to be more explicit about what random number generator\nwe want <em>exactly<\/em>. We decide for a <a rel=\"external\" href=\"https:\/\/docs.rs\/rand\/latest\/rand\/fn.thread_rng.html\">lazily-initialized thread-local random number generator, seeded by the system<\/a>.\nIn this case, I\u2019m using a <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/slice\/\">slice<\/a> instead of a vector. The main difference is that the slice has a fixed size while the vector does not.<\/p>\n<p>Within the standard library, Rust doesn\u2019t have a <code>sample<\/code> or <code>choose<\/code> method on the slice itself.\nThat\u2019s a design decision: the core of the language is kept small to allow evolving the language in the future.<\/p>\n<p>This doesn\u2019t mean that you cannot have a nicer implementation today.\nFor instance, you could define a <code>Choose<\/code> <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/book\/second-edition\/ch10-00-generics.html\">trait<\/a> and implement it for <code>[T]<\/code>.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=a66785b44094bacb78fa8dd822bfeab5&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> rand<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> rand<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span>thread_rng<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Rng<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">trait<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Choose<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> choose<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Option<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">impl<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Choose<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> choose<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Option<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">T<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> rng<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> thread_rng<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>        rng<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">choose<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><\/a>\n<p>This boilerplate could be put into a crate to make it reusable for others.\nWith that, we arrive at a solution that rivals Ruby\u2019s elegance.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=a66785b44094bacb78fa8dd822bfeab5&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 8<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 16<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 32<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">choose<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre><\/a>\n<h2 id=\"implicit-returns-and-expressions\"><a class=\"anchor\" href=\"#implicit-returns-and-expressions\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Implicit Returns and Expressions<\/h2>\n<p>Ruby methods automatically return the result of the last statement.<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get_user_ids<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">users<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>  users<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-8 z-d-4\">:<\/span><span class=\"z-l-10 z-d-12\">id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">end<\/span><\/span><\/code><\/pre>\n<p>Same for Rust. Note the missing semicolon.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=c7130debb2f712269380bd04819069ff&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> get_user_ids<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">users<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">User<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u64<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    users<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>user<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> user<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">id<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><\/a>\n<p>But in Rust, this is just the beginning, because <em>everything<\/em> is an expression.\nThe following block splits a string into characters, removes the <code>h<\/code>, and returns the result as a <code>HashSet<\/code>.\nThis <code>HashSet<\/code> will be assigned to <code>x<\/code>.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=9ad54a58d3e5f1c06e795b5f7dca451e&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> x<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HashSet<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span>_<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Get unique chars of a word {&#39;h&#39;, &#39;e&#39;, &#39;l&#39;, &#39;o&#39;}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> unique<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">hello<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">chars<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> filter out the &#39;h&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>    unique<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">filter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">char<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> char<\/span><span class=\"z-l-2 z-d-5\"> !=<\/span><span class=\"z-l-8 z-d-4\"> &#39;<\/span><span class=\"z-l-5 z-d-7\">h<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Same works for conditions:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=cec96176079e8812ff62ad84a432ac9d&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> x<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">absolutely!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-9 z-d-9\"> else<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">no seriously<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Since a <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/1.2.0\/book\/match.html\"><code>match<\/code><\/a> statement is also an expression, you can assign the result to a variable, too!<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=a6b32fae6257787432cf607f5772693e&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">enum<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Unit<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Meter<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Yard<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Angstroem<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Lightyear<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> length_in_meters<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-9 z-d-9\"> match<\/span><span> unit<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Unit<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Meter<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Unit<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Yard<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-16 z-d-16\">91<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Unit<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Angstroem<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-16 z-d-16\">0000000001<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Unit<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Lightyear<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-16 z-d-16\"> 9<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-16 z-d-16\">461<\/span><span class=\"z-l-2 z-d-5\">e<\/span><span class=\"z-l-2 z-d-5\">+<\/span><span class=\"z-l-16 z-d-16\">15<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<h2 id=\"multiple-assignments\"><a class=\"anchor\" href=\"#multiple-assignments\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Multiple Assignments<\/h2>\n<p>In Ruby you can assign multiple values to variables in one step:<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">def<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> values<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  [<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">end<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>one<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> two<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> three <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span> values<\/span><\/span><\/code><\/pre>\n<p>In Rust, you can only decompose tuples into tuples, but not a vector into a tuple for example.\nSo this will work:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=11b02c318ec35456b8247c3161cb341b&version=nightly\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>one<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> two<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> three<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>But this won\u2019t:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=11b02c318ec35456b8247c3161cb341b&version=nightly\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>one<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> two<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> three<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">    ^^^^^^^^^^^^^^^^^ expected array of 3 elements, found tuple<\/span><\/span><\/code><\/pre><\/a>\n<p>Neither will this:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=11b02c318ec35456b8247c3161cb341b&version=nightly\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>one<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> two<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> three<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">iter<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">collect<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> a collection of type `(_, _, _)` cannot be built from an iterator over elements of type `&amp;{integer}`<\/span><\/span><\/code><\/pre><\/a>\n<p>But with nightly Rust, you can now do this:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=11b02c318ec35456b8247c3161cb341b&version=nightly\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span>one<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> two<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> three<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 3<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>On the other hand, there\u2019s <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/book\/second-edition\/ch18-03-pattern-syntax.html\">a lot more you can do with destructuring<\/a> apart from multiple assignments. You can write beautiful, ergonomic code using pattern syntax.<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=969612861bc6028e3b98345e21a4289e&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> x<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 4<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> y<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-10 z-d-12\"> false<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">match<\/span><span> x<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">    4<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-16 z-d-16\"> 5<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-16 z-d-16\"> 6<\/span><span class=\"z-l-9 z-d-9\"> if<\/span><span> y<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">yes<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>    _<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">no<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre><\/a>\n<p>To quote <em><a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/book\/second-edition\/ch18-03-pattern-syntax.html\">The Book<\/a><\/em>:<\/p>\n<blockquote>\n<p>This prints <code>no<\/code> since the if condition applies to the whole pattern <code>4 | 5 | 6<\/code>, not only to the last value 6.<\/p>\n<\/blockquote>\n<h2 id=\"string-interpolation\"><a class=\"anchor\" href=\"#string-interpolation\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>String Interpolation<\/h2>\n<p>Ruby has <a rel=\"external\" href=\"https:\/\/ruby-doc.org\/docs\/ruby-doc-bundle\/ProgrammingRuby\/book\/ref_m_kernel.html#Kernel.sprintf\">extensive string interpolation support<\/a>.<\/p>\n<div class=\"ruby lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"ruby\"><span class=\"giallo-l\"><span>programming_language<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Ruby<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">#{<\/span><span>programming_language<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\"> is a beautiful programming language<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>This can be translated like so:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=6920e723137e44c4befe3398721fafa1&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">let<\/span><span> programming_language<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">Rust<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\"> is also a beautiful programming language<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> programming_language<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Named arguments are also possible, albeit much less common:<\/p>\n<a class=\"example\" href=\"https:\/\/play.rust-lang.org\/?gist=6920e723137e44c4befe3398721fafa1&version=stable\">\n<div class=\"rust lang-icon\"><\/div>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">language<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\"> is also a beautiful programming language<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> language<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Rust<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre><\/a>\n<p>Rust\u2019s <code>println!()<\/code> syntax is even more extensive than Ruby\u2019s. <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/fmt\/\">Check the docs<\/a> if you\u2019re curious about what else you can do.<\/p>\n<h2 id=\"that-s-it\"><a class=\"anchor\" href=\"#that-s-it\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>That\u2019s It!<\/h2>\n<p>Ruby comes with syntactic sugar for many common usage patterns, which allows for very elegant code.\nLow-level programming and raw performance are no primary goals of the language.<\/p>\n<p>If you do need that, Rust might be a good fit, because it provides fine-grained hardware control with comparable ergonomics.\nIf in doubt, Rust favors explicitness, though; it eschews magic.<\/p>\n<p>Did I whet your appetite for idiomatic Rust? Have a look at <a rel=\"external\" href=\"https:\/\/github.com\/mre\/idiomatic-rust\">this Github project<\/a>. I\u2019d be thankful for contributions.<\/p>\n<h2 id=\"footnotes\"><a class=\"anchor\" href=\"#footnotes\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Footnotes<\/h2>\n<p><sup id=\"fn1\">1. Thanks to <a href=\"https:\/\/twitter.com\/Argorak\">Florian Gilcher<\/a> for the hint.<a href=\"#ref1\" title=\"Jump back to footnote 1 in the text.\">\u21a9<\/a><\/sup><br \/>\n<sup id=\"fn2\">2. Thanks to <a href=\"https:\/\/www.reddit.com\/user\/masklinn\">masklin<\/a> for pointing out multiple inaccuracies.<a href=\"#ref2\" title=\"Jump back to footnote 2 in the text.\">\u21a9<\/a><\/sup><br \/>\n<sup id=\"fn3\">3. In the first version, I said that <code>ok()<\/code> would convert a <code>Result<\/code> into a <code>boolean<\/code>, which was wrong. Thanks to <a href=\"https:\/\/news.ycombinator.com\/item?id=16003080\">isaacg<\/a> for the correction.<a href=\"#ref3\" title=\"Jump back to footnote 3 in the text.\">\u21a9<\/a><\/sup><\/p>\n"},{"title":"Making Myself Obsolete","pubDate":"Sun, 10 Dec 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/obsolete\/","guid":"https:\/\/endler.dev\/2017\/obsolete\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/obsolete\/dinosaur.svg\" alt=\"The Stegosaurus had better days 150 million years ago.\" width=\"1187\" height=\"531\"\n    \/>\n    <figcaption>\n        The Stegosaurus had better days 150 million years ago.\n        <br \/>\n        Source: Paleontologists once thought it had a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Stegosaurus#.22Second_brain.22\">brain in its butt<\/a>.\n    <\/figcaption>\n<\/figure>\n<p>In December 2015 I was looking for static analysis tools to integrate into <a rel=\"external\" href=\"https:\/\/tech.trivago.com\/\">trivago<\/a>\u2019s CI process.\nThe idea was to detect typical programming mistakes automatically.\nThat\u2019s quite a common thing, and there are lots of helpful tools out there which fit the bill.<\/p>\n<p>So I looked for a list of tools\u2026<\/p>\n<p>To my surprise, <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_tools_for_static_code_analysis\">the only list I found was on Wikipedia<\/a> \u2014 and it was outdated.\nThere was no such project on Github, where most modern static analysis tools were hosted.<\/p>\n<p>Without overthinking it, I opened up my editor and wrote down a few tools I found through my initial research. After that, I pushed the list to Github.<\/p>\n<p>I called the project <a rel=\"external\" href=\"https:\/\/github.com\/analysis-tools-dev\/static-analysis\">Awesome Static Analysis<\/a>.<\/p>\n<p>Fast forward two years and the list has grown quite a bit.\nSo far, it has 75 contributors, 277 forks, and received over 2,000 stars.\n(Thanks for all the support!)\n(Update May 2018: 91 contributors, 363 forks, over 3,000 stars.)\n(Update October 2025: 316 contributors, 1,400 forks, over 14,000 stars.)<\/p>\n<p>Around 1000 unique visitors find the list every week. Not much by any means, but I feel obliged to keep it up-to-date\nbecause it has become an essential source of information for many people.<\/p>\n<p>It now lists around 300 tools for static analysis. Everything from Ada to TypeScript is on there.\nWhat I find particularly motivating is, that now the authors themselves create pull requests to add their tools!<\/p>\n<p>There was one problem though: The list of pull requests got longer and longer, as I was busy doing other things.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/obsolete\/pull_requests.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/obsolete\/pull_requests.jpg\" alt=\"The list of Github Pull requests for awesome-static-analysis\" width=\"650\" height=\"528\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The list of Github Pull requests for awesome-static-analysis\n    <\/figcaption>\n<\/figure>\n<h2 id=\"adding-contributors\"><a class=\"anchor\" href=\"#adding-contributors\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Adding Contributors<\/h2>\n<p>I always try to make team members out of regular contributors. My friend and colleague <a rel=\"external\" href=\"https:\/\/github.com\/andygrunwald\">Andy Grunwald<\/a> as well as <a rel=\"external\" href=\"https:\/\/github.com\/impredicative\">Ouroboros Chrysopoeia<\/a> are both valuable collaborators. They help me weed out new PRs whenever they find the time.<\/p>\n<p>But let\u2019s face it: checking the pull requests is a dull, manual task.\nWhat needs to be checked for each new tool can be summarized like this:<\/p>\n<ul>\n<li>Formatting rules are satisfied<\/li>\n<li>Project URL is reachable<\/li>\n<li>License annotation is correct<\/li>\n<li>Tools of each section are alphabetically ordered<\/li>\n<li>Description is not too long<\/li>\n<\/ul>\n<p>I guess it\u2019s obvious what we should do with that checklist: automate it!<\/p>\n<h2 id=\"a-linter-for-linting-linters\"><a class=\"anchor\" href=\"#a-linter-for-linting-linters\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Linter for Linting Linters<\/h2>\n<p>So why not write an analysis tool, which checks our list of analysis tools!\nWhat sounds pretty meta, is actually pretty straightforward.<\/p>\n<p>With every pull request, we trigger our bot, which checks the above rules and responds with a result.<\/p>\n<p>The first step was to read the <a rel=\"external\" href=\"https:\/\/developer.github.com\/v3\/guides\/building-a-ci-server\/\">Github documentation about building a CI server<\/a>.<\/p>\n<p>Just for fun, I wanted to create the bot in <a rel=\"external\" href=\"https:\/\/www.rust-lang.org\/\">Rust<\/a>.\nThe two most popular Github clients for Rust were github-rs (now deprecated) and <a rel=\"external\" href=\"https:\/\/github.com\/softprops\/hubcaps\">hubcaps<\/a>.\nBoth looked pretty neat, but then I found <a rel=\"external\" href=\"https:\/\/github.com\/softprops\/afterparty\">afterparty<\/a>, a \u201cGithub webhook server\u201d.<\/p>\n<p>The example looked fabulous:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">#<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">macro_use<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> log<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> env_logger<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> afterparty<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">extern<\/span><span class=\"z-l-9 z-d-9\"> crate<\/span><span> hyper<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> afterparty<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Delivery<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Hub<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> hyper<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Server<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">    env_logger<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">init<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> addr<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">0.0.0.0:<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 4567<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> hub<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Hub<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    hub<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">handle<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">pull_request<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span>delivery<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Delivery<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        match<\/span><span> delivery<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">payload <\/span><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">            Event<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">PullRequest<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-9 z-d-9\"> ref<\/span><span> action<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-9 z-d-9\"> ref<\/span><span> sender<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-2 z-d-5\"> ..<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">                \/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> TODO: My code here!<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">                println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">sender <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\"> action <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> sender<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-d-2\">login<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> action<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            }<\/span><\/span>\n<span class=\"giallo-l\"><span>            _<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> srvc<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Server<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">http<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>addr<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">                   .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">                   .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">handle<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>hub<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">listening on <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> addr<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    srvc<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>This allowed me to focus on the actual analysis code,\nwhich makes for a pretty boring read. It mechanically checks for the things mentioned above and could be written in any language.\nIf you want to have a look (or even contribute!), <a rel=\"external\" href=\"https:\/\/github.com\/mre\/awesome-static-analysis-ci\">check out the repo<\/a>.<\/p>\n<h2 id=\"talking-to-github\"><a class=\"anchor\" href=\"#talking-to-github\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Talking to GitHub<\/h2>\n<p>After the analysis code was done, I had a bot, running locally, waiting for incoming pull requests.<\/p>\n<p>But how could I talk to Github?<br \/>\nI found out, that I should use the <a rel=\"external\" href=\"https:\/\/developer.github.com\/v3\/repos\/statuses\/\">Status API<\/a>\nand send a <code>POST<\/code> request to <code>\/repos\/mre\/awesome-static-analysis\/statuses\/:sha<\/code><br \/>\n(<code>:sha<\/code> is the commit ID that points to the <code>HEAD<\/code> of the pull request):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>  &quot;state&quot;: &quot;success&quot;,<\/span><\/span>\n<span class=\"giallo-l\"><span>  &quot;description&quot;: &quot;The build succeeded!&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>I could have used one of the existing Rust Github clients, but I decided to write a simple function to update the pull request status code.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> set_status<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">status<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Status<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> desc<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> String<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> repo<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> sha<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">str<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Result<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-14 z-d-10\">reqwest<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Response<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> token<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">var<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">GITHUB_TOKEN<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> client<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> reqwest<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Client<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> params<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> HashMap<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">new<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">insert<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">state<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> status<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    params<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">insert<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">description<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> desc<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Sending status: <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-5 z-d-7\">:#?<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> params<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> status_url<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/api.github.com\/repos\/<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">\/statuses\/<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> repo<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> sha<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Status url: <\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> status_url<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">    Ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>client<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">request<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">            reqwest<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">Method<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Post<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">            &amp;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">format!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-7\">                &quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">?access_token=<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>                status_url<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>                token<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            )<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        )<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">json<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>params<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">        .<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">send<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>You can see that I pass in a Github token from the environment and then I send the <code>JSON<\/code> payload as a post request using the <a rel=\"external\" href=\"https:\/\/github.com\/seanmonstar\/reqwest\">reqwest<\/a> library.<\/p>\n<p>That turned out to become a problem in the end: while afterparty was using version 0.9 of <a rel=\"external\" href=\"https:\/\/github.com\/hyperium\/hyper\">hyper<\/a>, reqwest was using 0.11. Unfortunately, these two versions depend on a different build of the <a rel=\"external\" href=\"https:\/\/crates.io\/crates\/openssl-sys\">openssl-sys<\/a> bindings. That\u2019s a <a rel=\"external\" href=\"https:\/\/github.com\/rust-lang\/cargo\/issues\/886\">well-known problem<\/a> and the only way to fix it, is to resolve the conflict.<\/p>\n<p>I was stuck for a while, but then I saw, that there was an open pull request to <a rel=\"external\" href=\"https:\/\/github.com\/softprops\/afterparty\/pull\/26\">upgrade afterparty to hyper 0.10<\/a>.<\/p>\n<p>So inside my <code>Cargo.toml<\/code>, I locked the version of afterparty to the version of the pull request:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"toml\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">[<\/span><span>dependencies<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span>afterparty<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span> git<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">https:\/\/github.com\/ms705\/afterparty<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\"> }<\/span><\/span><\/code><\/pre>\n<p>This fixed the build, and I could finally move on.<\/p>\n<h2 id=\"deployment\"><a class=\"anchor\" href=\"#deployment\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Deployment<\/h2>\n<p>I needed a place to host the bot.<\/p>\n<p>Preferably for free, as it was a non-profit Open Source project.\nAlso, the provider would have to run binaries.<\/p>\n<p>For quite some time, I was following a product named <a rel=\"external\" href=\"https:\/\/zeit.co\/\">zeit<\/a>.\nIt runs any Docker container using an intuitive command line interface called <code>now<\/code>.<\/p>\n<p>I fell in love the first time I saw their demo on the site, so I wanted to give it a try.<\/p>\n<p>So I added a <a rel=\"external\" href=\"https:\/\/docs.docker.com\/engine\/userguide\/eng-image\/multistage-build\/\">multi-stage Dockerfile<\/a> to my project:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"docker\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">FROM<\/span><span> rust <\/span><span class=\"z-l-9 z-d-9\">as<\/span><span> builder<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">COPY<\/span><span> . \/usr\/src\/app<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">WORKDIR<\/span><span> \/usr\/src\/app<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">RUN<\/span><span> cargo build --release<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">FROM<\/span><span> debian:stretch<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">RUN<\/span><span> apt update \\<\/span><\/span>\n<span class=\"giallo-l\"><span>    &amp;&amp; apt install -y libssl1.1 ca-certificates \\<\/span><\/span>\n<span class=\"giallo-l\"><span>    &amp;&amp; apt clean -y \\<\/span><\/span>\n<span class=\"giallo-l\"><span>    &amp;&amp; apt autoclean -y \\<\/span><\/span>\n<span class=\"giallo-l\"><span>    &amp;&amp; apt autoremove -y<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">COPY<\/span><span> --from=builder target\/release\/check .<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">EXPOSE<\/span><span> 4567<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">ENTRYPOINT<\/span><span> [<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">.\/check<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">CMD<\/span><span> [<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">--help<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span>]<\/span><\/span><\/code><\/pre>\n<p>The first part would build a static binary, the second part would run it at container startup.\nWell, that didn\u2019t work, because <code>zeit<\/code> <a rel=\"external\" href=\"https:\/\/github.com\/zeit\/now\/issues\/962\">does not support multi-stage builds yet<\/a>.<\/p>\n<p>The workaround was to split up the Dockerfile into two and <a rel=\"external\" href=\"https:\/\/github.com\/mre\/awesome-static-analysis-ci\/blob\/master\/Makefile\">connect them both with a Makefile<\/a>. Makefiles are pretty powerful, <a href=\"https:\/\/endler.dev\/2017\/makefiles\/\">you know<\/a>?<\/p>\n<p>With that, I had all the parts for deployment together.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># Build Rust binary for Linux<\/span><\/span>\n<span class=\"giallo-l\"><span>docker run --rm -v $(CURDIR):\/usr\/src\/ci -w \/usr\/src\/ci rust cargo build --release<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># Deploy Docker images built from the local Dockerfile<\/span><\/span>\n<span class=\"giallo-l\"><span>now deploy --force --public -e GITHUB_TOKEN=${GITHUB_TOKEN}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># Set domain name of new build to `check.now.sh`<\/span><\/span>\n<span class=\"giallo-l\"><span># (The deployment URL was copied to the clipboard and is retrieved with pbpaste on macOS)<\/span><\/span>\n<span class=\"giallo-l\"><span>now alias `pbpaste` check.now.sh<\/span><\/span><\/code><\/pre>\n<p>Here\u2019s the output of the deploy using <code>now<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&gt; Deploying ~\/Code\/private\/awesome-static-analysis-ci\/deploy<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Ready! https:\/\/deploy-sjbiykfvtx.now.sh (copied to clipboard) [2s]<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Initializing\u2026<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Initializing\u2026<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Building<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; \u25b2 docker build<\/span><\/span>\n<span class=\"giallo-l\"><span>Sending build context to Docker daemon 2.048 kBkB<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Step 1 : FROM mre0\/ci:latest<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; latest: Pulling from mre0\/ci<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; ...<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Digest: sha256:5ad07c12184755b84ca1b587e91b97c30f7d547e76628645a2c23dc1d9d3fd4b<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Status: Downloaded newer image for mre0\/ci:latest<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt;  ---&gt; 8ee1b20de28b<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Successfully built 8ee1b20de28b<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; \u25b2 Storing image<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; \u25b2 Deploying image<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; \u25b2 Container started<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; listening on 0.0.0.0:4567<\/span><\/span>\n<span class=\"giallo-l\"><span>&gt; Deployment complete!<\/span><\/span><\/code><\/pre>\n<p>The last step was to add <code>check.now.sh<\/code> as a webhook inside the awesome-static-analysis <a rel=\"external\" href=\"https:\/\/developer.github.com\/webhooks\/creating\/\">project settings<\/a>.<\/p>\n<p>Now, whenever a new pull request is coming in, you see that little bot getting active!<\/p>\n<p><img src=\"\/2017\/obsolete\/pull_request_success.jpg\" alt=\"A successful pull request, which was checked by the bot\" \/><\/p>\n<h2 id=\"outcome-and-future-plans\"><a class=\"anchor\" href=\"#outcome-and-future-plans\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Outcome and Future Plans<\/h2>\n<p>I am very pleased with my choice of tools: afterparty saved me from a lot of manual work, while zeit made deployment really easy.<br \/>\nIt feels like <a rel=\"external\" href=\"https:\/\/aws.amazon.com\/lambda\/features\/\">Amazon Lambda<\/a> on steroids.<\/p>\n<p>If you look at the <a rel=\"external\" href=\"https:\/\/github.com\/mre\/awesome-static-analysis-ci\/blob\/master\/src\/main.rs\">code<\/a> and the <a rel=\"external\" href=\"https:\/\/github.com\/mre\/awesome-static-analysis-ci\/commits\/master\">commits<\/a> for my bot, you can see all my little missteps, until I got everything just right. Turns out, parsing human-readable text is tedious.<br \/>\nTherefore I was thinking about turning the list of analysis tools into a structured format like <code>YAML<\/code>. This would greatly simplify the parsing and have the added benefit of having a machine-readable list of tools that can be used for other projects.<\/p>\n<h2 id=\"update-may-2018\"><a class=\"anchor\" href=\"#update-may-2018\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Update May 2018<\/h2>\n<p>While attending the <a rel=\"external\" href=\"https:\/\/www.wearedevelopers.com\/\">WeAreDevelopers conference in Vienna<\/a> (can recommend that), I moved the CI pipeline from <a rel=\"external\" href=\"https:\/\/zeit.co\/\">zeit.co<\/a> to <a rel=\"external\" href=\"https:\/\/travis-ci.org\/\">Travis CI<\/a>.\nThe reason was, that I wanted the linting code next to the project, which greatly simplified things.\nFirst and foremost I don\u2019t need the web request handling code anymore, because travis takes care of that.\nIf you like, you can compare the <a rel=\"external\" href=\"https:\/\/github.com\/mre\/awesome-static-analysis-ci\/blob\/master\/src\/main.rs\">old<\/a> and the <a rel=\"external\" href=\"https:\/\/github.com\/analysis-tools-dev\/static-analysis\/blob\/d03bd8a602b231205915a4403e2b6dc4159962f8\/ci\/src\/lib.rs\">new<\/a> version.<\/p>\n<h2 id=\"update-october-2025\"><a class=\"anchor\" href=\"#update-october-2025\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Update October 2025<\/h2>\n<p>Most everything about that project has changed since then.\nI now use Github Actions to run the CI checks, and the <code>README.md<\/code> is completely auto-generated from the YAML files for each tool.\nWe support special metadata fields like a list of additional resources (tutorials, videos, etc) or the list of paid plans a tool offers.\nWe have a <a rel=\"external\" href=\"https:\/\/analysis-tools.dev\/\">fancy website<\/a> now, where we list all 700+ tools and allow people to vote.\nThe website is built with Next.js and uses Algolia for search.\nWe also have a bunch of sponsors now, who help us pay for hosting and other expenses.\nIt\u2019s crazy to see how projects grow if you give them some love and your time!\nI hope this serves as an inspiration for you to start your own open source project!\nIt\u2019s not that hard, and incredibly rewarding.<\/p>\n"},{"title":"Modern Day Annoyances - Digital Clocks","pubDate":"Tue, 07 Nov 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/digitial-clocks\/","guid":"https:\/\/endler.dev\/2017\/digitial-clocks\/","description":"<p>This morning I woke up to the beeping noise of our oven\u2019s alarm clock.\nThe reason was that I tried to correct the oven\u2019s local time the day before \u2014 and I pushed the wrong buttons.\nAs a result I didn\u2019t set the correct time, instead, I set a cooking timer\u2026 and that\u2019s what woke me up today.<\/p>"},{"title":"Learn Some Rust during Hacktoberfest","pubDate":"Sun, 15 Oct 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/hacktoberfest\/","guid":"https:\/\/endler.dev\/2017\/hacktoberfest\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/hacktoberfest\/hacktoberfest.svg\" alt=\"Dirndl, Lederhose, Brezn, Beer, Rust\" width=\"330\" height=\"90\"\n    \/>\n    <figcaption>\n        Dirndl, Lederhose, Brezn, Beer, Rust\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/www.freepik.com\/free-vector\/food-items-oktoberfest-festival_911290.htm\">Designed by Freepik<\/a>\n    <\/figcaption>\n<\/figure>\n<p>October is the perfect time to contribute to Open Source \u2014 at least according to Github and DigitalOcean.\nBecause that\u2019s when they organize Hacktoberfest, a global event where you <strong>get a free shirt and lots of street cred<\/strong> for creating pull requests. Read the official announcement <a rel=\"external\" href=\"https:\/\/hacktoberfest.digitalocean.com\/\">here<\/a>.<\/p>\n<p>Some people think they cannot contribute anything of value. Either because they lack the programming skills or because they don\u2019t know where to start.<\/p>\n<p>This guide is trying to change that!<\/p>\n<p>Let me show you, how <em>everybody<\/em> can contribute code to <a rel=\"external\" href=\"https:\/\/www.rust-lang.org\/\">Rust<\/a>, a safe systems programming language.\nI was inspired to write this by a <a rel=\"external\" href=\"https:\/\/twitter.com\/llogiq\/status\/915288482314178560\">tweet from llogiq<\/a>.<\/p>\n<h2 id=\"1-find-a-great-rust-project-to-work-on\"><a class=\"anchor\" href=\"#1-find-a-great-rust-project-to-work-on\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>1. Find a Great Rust Project to Work On<\/h2>\n<p>We all want our work to be appreciated.<br \/>\nTherefore I suggest to start contributing to medium-sized projects, because they gained some momentum but are still driven by a small number of maintainers, so help is always welcome. By contrast, tiny projects are mostly useful to the original author only, while large projects can be intimidating at first and have stricter guidelines.<\/p>\n<p>For now, let\u2019s look at repositories with 5-100 stars, which were updated within this year.\nGithub supports <a rel=\"external\" href=\"https:\/\/help.github.com\/articles\/understanding-the-search-syntax\">advanced search options based on Lucene syntax<\/a>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>language:Rust stars:5..100 pushed:&gt;2017-01-01<\/span><\/span><\/code><\/pre>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/search?q=language%3ARust+stars%3A5..100+pushed%3A%3E2017-01-01\">Here<\/a>\u2019s a list of projects, which match this filter.<\/p>\n<h2 id=\"2-install-the-rust-toolchain\"><a class=\"anchor\" href=\"#2-install-the-rust-toolchain\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>2. Install the Rust Toolchain<\/h2>\n<p>To start contributing, we need a working Rust compiler and the cargo package manager.\nFortunately, the installation should be straightforward.\nI recommend <a rel=\"external\" href=\"https:\/\/rustup.rs\/\">rustup<\/a> for that.<\/p>\n<p>Run the following command in your terminal, then follow the onscreen instructions.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>curl https:\/\/sh.rustup.rs -sSf | sh<\/span><\/span><\/code><\/pre>\n<p>If you\u2019re unsure, just accept the defaults.\nAfter the installation is done, we also need to get the nightly version of the compiler for later.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>rustup install nightly<\/span><\/span><\/code><\/pre>\n<p>Questions so far? Find more detailed installation instructions <a rel=\"external\" href=\"https:\/\/asquera.de\/blog\/2017-03-03\/setting-up-a-rust-devenv\/\">here<\/a>.<\/p>\n<h2 id=\"3-fork-the-project-and-clone-it-to-your-computer\"><a class=\"anchor\" href=\"#3-fork-the-project-and-clone-it-to-your-computer\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>3. Fork the Project and Clone It to Your Computer<\/h2>\n<p>First, click on the little <em>fork<\/em> button on the top right of the Github project page. Then clone your fork to your computer.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>git clone git@github.com:yourusername\/project.git<\/span><\/span><\/code><\/pre>\n<p>For more detailed instructions, go <a rel=\"external\" href=\"https:\/\/guides.github.com\/activities\/forking\/\">here<\/a>.<\/p>\n<h2 id=\"4-does-it-build\"><a class=\"anchor\" href=\"#4-does-it-build\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>4. Does It Build?<\/h2>\n<p>Before we start modifying the codebase, we should make sure that it is in a workable state.\nThe following commands should work right away from inside the project folder.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo build<\/span><\/span>\n<span class=\"giallo-l\"><span>cargo test<\/span><\/span><\/code><\/pre>\n<p>If not, you might want to consult the <code>README<\/code> for further instructions. (But feel free to choose another project.)<\/p>\n<h2 id=\"5-the-magic-sauce\"><a class=\"anchor\" href=\"#5-the-magic-sauce\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>5. The Magic Sauce<\/h2>\n<p>Here\u2019s the trick: we use a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Lint_(software)\">linter<\/a> called <a rel=\"external\" href=\"https:\/\/github.com\/rust-lang\/rust-clippy\">clippy<\/a> to show us improvement areas in any Rust codebase.<\/p>\n<p>To get clippy, install it like so:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo +nightly install clippy<\/span><\/span><\/code><\/pre>\n<p>Afterwards, run it from the project root as often as you like.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>rustup run nightly cargo clippy<\/span><\/span><\/code><\/pre>\n<p>This should give you actionable information on how to improve the codebase.<\/p>\n<p>Here\u2019s some sample output:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span>warning<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> useless<\/span><span class=\"z-l-9 z-d-9\"> use<\/span><span> of `format<\/span><span class=\"z-l-2 z-d-5\">!<\/span><span>`<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">   -<\/span><span class=\"z-l-2 z-d-5\">-&gt;<\/span><span> src<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span>mach<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span>header<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>rs<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span>420<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span>49<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><\/span>\n<span class=\"giallo-l\"><span>420 <\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-9 z-d-9\">             let<\/span><span> error <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-13 z-d-15\"> error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">Error<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Malformed<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>format<\/span><span class=\"z-l-2 z-d-5\">!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>&quot;bytes size is smaller than an <\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Mach<\/span><span class=\"z-l-2 z-d-5\">-<\/span><span>o header&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><span class=\"z-l-2 z-d-5\">                                                 ^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    =<\/span><span> note<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> #<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">warn<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">useless_format<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span> on<\/span><span> by<\/span><span> default<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    =<\/span><span> help<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> further<\/span><span> information<\/span><span> visit<\/span><span> https<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">rust-lang-nursery.github.io\/rust-clippy\/v0.0.165\/index.html#useless_format<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>warning<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> this<\/span><span> expression<\/span><span> borrows<\/span><span> a<\/span><span> reference<\/span><span> that<\/span><span> is<\/span><span> immediately<\/span><span> dereferenced<\/span><span> by<\/span><span> the<\/span><span> compiler<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">   -<\/span><span class=\"z-l-2 z-d-5\">-&gt;<\/span><span> src<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span>mach<\/span><span class=\"z-l-2 z-d-5\">\/<\/span><span>header<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span>rs<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\">423<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\">36<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">423<\/span><span class=\"z-l-2 z-d-5\"> |<\/span><span class=\"z-l-9 z-d-9\">             let<\/span><span> magic<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> mach<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">peek<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span>bytes<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><span class=\"z-l-2 z-d-5\">                                    ^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span class=\"z-l-2 z-d-5\">^<\/span><span> help<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> change<\/span><span> this<\/span><span> to<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> `<\/span><span>bytes<\/span><span>`<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    =<\/span><span> help<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> for<\/span><span> further<\/span><span> information<\/span><span> visit<\/span><span> https<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/\/<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">rust-lang-nursery.github.io\/rust-clippy\/v0.0.165\/index.html#needless_borrow<\/span><\/span><\/code><\/pre>\n<p>Just try some of the suggestions and see if the project still compiles and the tests still pass.\nCheck out the links to the documentation in the help section to learn more.\nStart small to make your changes easier to review.<\/p>\n<h2 id=\"6-creating-a-pull-request\"><a class=\"anchor\" href=\"#6-creating-a-pull-request\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>6. Creating a Pull Request<\/h2>\n<p>If you\u2019re happy with your changes, now is the time to publish them!\nIt\u2019s best to create a new branch for your changes and then push it to your fork.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>git checkout -b codestyle<\/span><\/span>\n<span class=\"giallo-l\"><span>git commit -am &quot;Minor codestyle fixes&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>git push --set-upstream origin codestyle<\/span><\/span><\/code><\/pre>\n<p>Afterwards, go to the homepage of your fork on Github.\nThere should be a button titled <em>Compare &amp; pull request<\/em>.\nPlease add a meaningful description and then submit the pull request.<\/p>\n<p>Congratulations! You\u2019ve contributed to the Rust ecosystem. Thank you! \ud83c\udf89<\/p>\n<h2 id=\"trophy-case\"><a class=\"anchor\" href=\"#trophy-case\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Trophy Case<\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/m4b\/goblin\/pull\/55\">m4b\/goblin<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/gimli-rs\/cpp_demangle\/pull\/100\">fitzgen\/cpp_demangle<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/fdehau\/tui-rs\/pull\/19\">fdehau\/tui-rs<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/christophertrml\/rs-natural\/pull\/15\">christophertrml\/rs-natural<\/a><\/li>\n<\/ul>\n<h2 id=\"bonus\"><a class=\"anchor\" href=\"#bonus\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Bonus!<\/h2>\n<p>If all of the manual fixing and checking sounds too dull, you can automate step number 5 using <a rel=\"external\" href=\"https:\/\/github.com\/killercup\/rustfix\"><code>rustfix<\/code><\/a> by Pascal Hertleif (<a rel=\"external\" href=\"https:\/\/github.com\/killercup\/\">@killercup<\/a>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>rustfix --yolo &amp;&amp; cargo check<\/span><\/span><\/code><\/pre>"},{"title":"A Little Story about the `yes` Unix Command","pubDate":"Tue, 10 Oct 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/yes\/","guid":"https:\/\/endler.dev\/2017\/yes\/","description":"<p>What\u2019s the simplest Unix command you know?<br \/>\nThere\u2019s <code>echo<\/code>, which prints a string to stdout and <code>true<\/code>, which always terminates with an exit code of 0.<\/p>\n<p>Among the series of simple Unix commands, there\u2019s also <code>yes<\/code>.\nIf you execute it without arguments, you get an infinite stream of y\u2019s, separated by a newline:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>y<\/span><\/span>\n<span class=\"giallo-l\"><span>y<\/span><\/span>\n<span class=\"giallo-l\"><span>y<\/span><\/span>\n<span class=\"giallo-l\"><span>y<\/span><\/span>\n<span class=\"giallo-l\"><span>(...you get the idea)<\/span><\/span><\/code><\/pre>\n<p>What seems to be pointless in the beginning turns out to be pretty helpful :<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>yes | sh boring_installation.sh<\/span><\/span><\/code><\/pre>\n<p>Ever installed a program, which required you to type \u201cy\u201d and hit enter to keep going?\n<code>yes<\/code> to the rescue! It will carefully fulfill its duty, so you can keep watching <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=yhBExhldRXQ\">Pootie Tang<\/a>.<\/p>\n<h2 id=\"writing-yes\"><a class=\"anchor\" href=\"#writing-yes\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Writing yes<\/h2>\n<p>Here\u2019s a basic version in\u2026 uhm\u2026 BASIC.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>10 PRINT &quot;y&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>20 GOTO 10<\/span><\/span><\/code><\/pre>\n<p>And here\u2019s the same thing in Python:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">while<\/span><span class=\"z-l-16 z-d-16\"> True<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">    print<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>Simple, eh? Not so quick!<br \/>\nTurns out, that program is quite slow.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>python yes.py | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[4.17MiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Compare that with the built-in version on my Mac:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>yes | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[34.2MiB\/s]<\/span><\/span><\/code><\/pre>\n<p>So I tried to write a quicker version in Rust. Here\u2019s my first attempt:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> expletive<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap_or<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  loop<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    println!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> expletive<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Some explanations:<\/p>\n<ul>\n<li>The string we want to print in a loop is the first command line parameter and is named <em>expletive<\/em>. I learned this word from the <code>yes<\/code> manpage.<\/li>\n<li>I use <code>unwrap_or<\/code> to get the <em>expletive<\/em> from the parameters. In case the parameter is not set, we use \u201cy\u201d as a default.<\/li>\n<li>The default parameter gets converted from a string slice (<code>&amp;str<\/code>) into an <em>owned<\/em> string on the heap (<code>String<\/code>) using <code>into()<\/code>.<\/li>\n<\/ul>\n<p>Let\u2019s test it.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cargo run --release | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>   Compiling yes v0.1.0<\/span><\/span>\n<span class=\"giallo-l\"><span>    Finished release [optimized] target(s) in 1.0 secs<\/span><\/span>\n<span class=\"giallo-l\"><span>     Running `target\/release\/yes`<\/span><\/span>\n<span class=\"giallo-l\"><span>[2.35MiB\/s]<\/span><\/span><\/code><\/pre>\n<p>Whoops, that doesn\u2019t look any better. It\u2019s even slower than the Python version!\nThat caught my attention, so I looked around for the source code of a C implementation.<\/p>\n<p>Here\u2019s the <a rel=\"external\" href=\"https:\/\/github.com\/dspinellis\/unix-history-repo\/blob\/4c37048d6dd7b8f65481c8c86ef8cede2e782bb3\/usr\/src\/cmd\/yes.c\">very first version of the program<\/a>, released with Version 7 Unix and famously authored by Ken Thompson on <nobr>Jan 10, 1979<\/nobr>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>argc<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> argv<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">char<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-2 z-d-5\">*<\/span><span>argv<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  for<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">    printf<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">%s<\/span><span class=\"z-l-15 z-d-13\">\\n<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> argc<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-2 z-d-5\">?<\/span><span> argv<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>No magic here.<\/p>\n<p>Compare that to the <a rel=\"external\" href=\"https:\/\/github.com\/coreutils\/coreutils\/blame\/master\/src\/yes.c\">128-line-version from the GNU coreutils, which is mirrored on Github<\/a>. After 25 years, <em>it is still under active development!<\/em>\nThe last code change happened around a <a rel=\"external\" href=\"https:\/\/github.com\/coreutils\/coreutils\/commit\/4cdb1703aff044de44d27e0558714542197f6dad\">year ago<\/a>.\nThat\u2019s quite fast:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># brew install coreutils<\/span><\/span>\n<span class=\"giallo-l\"><span>gyes | pv -r &gt; \/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span>[854MiB\/s]<\/span><\/span><\/code><\/pre>\n<p>The important part is at the end:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> Repeatedly output the buffer until there is a write error; then fail.  <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">while<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">full_write<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>STDOUT_FILENO<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> buf<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> bufused<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span> bufused<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  continue<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span><\/code><\/pre>\n<p>Aha! So they simply use a buffer to make write operations faster.\nThe buffer size is defined by a constant named <code>BUFSIZ<\/code>, which gets chosen on each system so as to make I\/O efficient (see <a rel=\"external\" href=\"https:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/Controlling-Buffering.html\">here<\/a>).\nOn my system, that was defined as 1024 bytes. I actually had better performance with 8192 bytes.<\/p>\n<p>I\u2019ve extended my Rust program:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> BufWriter<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Write<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">const<\/span><span class=\"z-l-16 z-d-16\"> BUFSIZE<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 8192<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span> expletive<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap_or<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> writer<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> BufWriter<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">with_capacity<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">BUFSIZE<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-d-15\"> io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">stdout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    loop<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">        writeln!<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>writer<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> expletive<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">unwrap<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>The important part is, that the buffer size is a multiple of four, to ensure <a rel=\"external\" href=\"https:\/\/stackoverflow.com\/a\/381368\/270334\">memory alignment<\/a>.<\/p>\n<p>Running that gave me 51.3MiB\/s.\nFaster than the version, which comes with my system, but still way slower than the results from <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/unix\/comments\/6gxduc\/how_is_gnu_yes_so_fast\/\">this Reddit post<\/a> that I found, where the author talks about 10.2GiB\/s.<\/p>\n<h2 id=\"update\"><a class=\"anchor\" href=\"#update\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Update<\/h2>\n<p>Once again, the Rust community did not disappoint.<br \/>\nAs soon as this post <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/rust\/comments\/75fll1\/a_little_story_about_the_yes_unix_command\/\">hit the Rust subreddit<\/a>, user <a rel=\"external\" href=\"https:\/\/www.reddit.com\/user\/nwydo\">nwydo<\/a> pointed out a <a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/rust\/comments\/4wde08\/optimising_yes_any_further_ideas\/\">previous discussion<\/a> on the same topic.\nHere\u2019s their optimized code, that breaks the 3GB\/s mark on my machine:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>env<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-8 z-d-4\">{<\/span><span class=\"z-l-10 z-d-12\">self<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Write<\/span><span class=\"z-l-8 z-d-4\">}<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span>process<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">borrow<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">Cow<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ffi<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">OsString<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> const<\/span><span class=\"z-l-16 z-d-16\"> BUFFER_CAPACITY<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> usize<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-d-16\"> 64<\/span><span class=\"z-l-2 z-d-5\"> *<\/span><span class=\"z-l-16 z-d-16\"> 1024<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> to_bytes<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">os_str<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> OsString<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Vec<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  use<\/span><span class=\"z-l-13 z-d-15\"> std<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">os<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">unix<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-d-15\">ffi<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\">OsStringExt<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>  os_str<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">into_vec<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> fill_up_buffer<\/span><span class=\"z-l-1 z-d-3\">&lt;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">a<\/span><span class=\"z-l-1 z-d-3\">&gt;<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">buffer<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">a<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span class=\"z-l-14 z-d-10\"> output<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">a<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">a<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  if<\/span><span> output<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-1 z-d-3\"> &gt;<\/span><span> buffer<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> \/<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    return<\/span><span> output<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> buffer_size<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> output<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>  buffer<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>buffer_size<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone_from_slice<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>output<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  while<\/span><span> buffer_size<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span> buffer<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">len<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> \/<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    let<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span>left<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> right<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> buffer<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">split_at_mut<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>buffer_size<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    right<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>buffer_size<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">clone_from_slice<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>left<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span>    buffer_size<\/span><span class=\"z-l-2 z-d-5\"> *=<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &amp;<\/span><span>buffer<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>buffer_size<\/span><span class=\"z-l-8 z-d-4\">]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> write<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">output<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-2 z-d-5\"> &amp;<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> stdout<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-13 z-d-15\"> io<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">stdout<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> locked<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> stdout<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">lock<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span class=\"z-l-9 z-d-9\"> mut<\/span><span> buffer<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-8 z-d-4\"> [<\/span><span class=\"z-l-16 z-d-16\">0<\/span><span class=\"z-l-9 z-d-9\">u8<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span class=\"z-l-16 z-d-16\"> BUFFER_CAPACITY<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  let<\/span><span> filled<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> fill_up_buffer<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span> buffer<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> output<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  while<\/span><span> locked<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">write_all<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>filled<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">is_ok<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">  write<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">&amp;<\/span><span class=\"z-l-13 z-d-15\">env<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">args_os<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">nth<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>to_bytes<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">map_or<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">    Cow<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Borrowed<\/span><span class=\"z-l-8 z-d-4\">(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">      &amp;<\/span><span class=\"z-l-5 z-d-7\">b<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">y<\/span><span class=\"z-l-15 z-d-13\">\\<\/span><span class=\"z-l-15 z-d-13\">n<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    )<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    |<\/span><span class=\"z-l-9 z-d-9\">mut<\/span><span> arg<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>      arg<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">push<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">b<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-15 z-d-13\">\\<\/span><span class=\"z-l-15 z-d-13\">n<\/span><span class=\"z-l-8 z-d-4\">&#39;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">      Cow<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">Owned<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>arg<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  )<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-13 z-d-15\">  process<\/span><span class=\"z-l-2 z-d-5\">::<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">exit<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Now that\u2019s a whole different ballgame!<\/p>\n<ul>\n<li>We prepare a filled string buffer, which will be reused for each loop.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/io\/struct.Stdout.html#method.lock\">Stdout is protected by a lock<\/a>. So, instead of constantly acquiring and releasing it, we keep it all the time.<\/li>\n<li>We use the platform-native <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.OsString.html\"><code>std::ffi::OsString<\/code><\/a> and <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/borrow\/enum.Cow.html\"><code>std::borrow::Cow<\/code><\/a> to avoid unnecessary allocations.<\/li>\n<\/ul>\n<p>The only thing that I could contribute was <a rel=\"external\" href=\"https:\/\/github.com\/cgati\/yes\/pull\/3\/files\">removing an unnecessary <code>mut<\/code><\/a>. \ud83d\ude05<\/p>\n<h2 id=\"lessons-learned\"><a class=\"anchor\" href=\"#lessons-learned\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Lessons Learned<\/h2>\n<p>The trivial program <code>yes<\/code> turns out not to be so trivial after all.\nIt uses output buffering and memory alignment to improve performance.\nRe-implementing Unix tools is fun and makes me appreciate the nifty tricks,\nwhich make our computers fast.<\/p>\n"},{"title":"Lightning Fast Image Previews with Pure CSS and LQIP","pubDate":"Mon, 18 Sep 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/image-previews\/","guid":"https:\/\/endler.dev\/2017\/image-previews\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/image-previews\/factory.svg\" alt=\"Adapted from <a href='https:\/\/www.freepik.com\/free-vector\/industrial-machine-vector_753558.htm'>Freepik<\/a> \" width=\"800\" height=\"500\"\n    \/>\n    <figcaption>\n        Source: Adapted from <a href='https:\/\/www.freepik.com\/free-vector\/industrial-machine-vector_753558.htm'>Freepik<\/a>\n    <\/figcaption>\n<\/figure>\n<p>My website is reasonably fast.<\/p>\n<p>I hope that every page load feels snappy, no matter your device or location.\nThat should not come as a surprise. After all, I\u2019m just using plain HTML and CSS.\nJavaScript is avoided whenever possible.<\/p>\n<p>There was one thing left, which really annoyed me: layout reflow after images got loaded.<\/p>\n<p>The problem is, that the image dimensions are not known when the text is ready to be displayed.\nAs a result, the text will be pushed down on the screen as soon as an image is loaded above.<\/p>\n<p>Also, while an image is loading, there is no preview, just blank space.\nHere\u2019s what that looks like on a slower connection:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/image-previews\/fout.png\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/image-previews\/fout.png\" alt=\"Illustration of a flash of unstyled content\" width=\"543\" height=\"220\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Illustration of a flash of unstyled content\n    <\/figcaption>\n<\/figure>\n<p>I could fix that, by hardcoding the image width and height, but that would be tedious and error-prone.\nAnd there would be no preview.\nSo I was wondering, what others were doing. \ud83e\udd14<\/p>\n<h2 id=\"tiny-image-thumbnails\"><a class=\"anchor\" href=\"#tiny-image-thumbnails\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Tiny Image Thumbnails<\/h2>\n<p>I vaguely remembered, that <a rel=\"external\" href=\"https:\/\/code.fb.com\/uncategorized\/the-technology-behind-preview-photos\/\">Facebook uses tiny preview thumbnails in their mobile app<\/a>.\nThey extract the quantization table from the JPEG header to render the preview. This information\nis stored on the client, so it doesn\u2019t need to be downloaded every time.\nUnfortunately, this approach requires full control over the image encoder.\nIt works for apps, but hardly for websites.<\/p>\n<p>The search continued.<\/p>\n<p>Until my colleague <a rel=\"external\" href=\"https:\/\/tobias.is\/\">Tobias Baldauf<\/a> introduced me to <a rel=\"external\" href=\"https:\/\/www.guypo.com\/introducing-lqip-low-quality-image-placeholders\">LQIP (Low-Quality Image Placeholders)<\/a>.<\/p>\n<p>Here\u2019s the idea:<\/p>\n<ul>\n<li>Load the page including inlined, low-quality image thumbnails.<\/li>\n<li>Once the page is fully loaded (e.g. when the <a rel=\"external\" href=\"https:\/\/www.w3schools.com\/jsref\/event_onload.asp\"><code>onload<\/code> event<\/a> is fired), lazy load full quality images.<\/li>\n<\/ul>\n<p>Unfortunately, this technique requires JavaScript.\nNevertheless, I liked the idea, so I started experimenting with different image sizes and formats. My goal was to create the smallest thumbnails using any standard image format.<\/p>\n<h2 id=\"benchmark\"><a class=\"anchor\" href=\"#benchmark\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Benchmark<\/h2>\n<p>Here are 15 pixel wide thumbnails encoded in different file formats:<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/image-previews\/thumbnails.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/image-previews\/thumbnails.jpg\" alt=\"Comparison of different image formats when creating thumbnails\" width=\"600\" height=\"604\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Comparison of different image formats when creating thumbnails\n    <\/figcaption>\n<\/figure>\n<p>I used different tools to create the thumbnails.\nFor JPEG and PNG encoding, I used <a rel=\"external\" href=\"https:\/\/github.com\/shakiba\/svgexport\">svgexport<\/a>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">svgexport<\/span><span class=\"z-l-5 z-d-7\"> img.svg<\/span><span class=\"z-l-5 z-d-7\"> img.png<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">svg{background:white;}<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\"> 15:<\/span><span class=\"z-l-5 z-d-7\"> 1%<\/span><\/span><\/code><\/pre>\n<p>For webp, I used <a rel=\"external\" href=\"https:\/\/developers.google.com\/speed\/webp\/docs\/cwebp\">cwebp<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">cwebp<\/span><span class=\"z-l-5 z-d-7\"> img.png<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">o<\/span><span class=\"z-l-5 z-d-7\"> img.webp<\/span><\/span><\/code><\/pre>\n<p>The gif was converted using an online tool and optimized using <a rel=\"external\" href=\"https:\/\/github.com\/kohler\/gifsicle\">gifsicle<\/a>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">gifsicle<\/span><span class=\"z-l-5 z-d-7\"> -<\/span><span class=\"z-l-5 z-d-7\">O3<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span class=\"z-l-5 z-d-7\"> img.gif<\/span><span class=\"z-l-2 z-d-5\"> &gt;<\/span><span class=\"z-l-5 z-d-7\"> img_mini.gif<\/span><\/span><\/code><\/pre><h2 id=\"comparison\"><a class=\"anchor\" href=\"#comparison\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Comparison<\/h2>\n<p>WebP is the smallest, but it\u2019s <a rel=\"external\" href=\"https:\/\/caniuse.com\/?search=webp\">not supported by all browsers<\/a>.<br \/>\nGif was second, but when resizing the image and applying the blur filter, I was not happy with the result.<br \/>\nIn the end, I settled for PNG, which provided an excellent tradeoff between size and quality.\nI optimized the images even further using <a rel=\"external\" href=\"https:\/\/github.com\/shssoichiro\/oxipng\">oxipng<\/a>, which supports zopfli compression.\nWith that, I end up with thumbnails of around 300-400 bytes in size.<\/p>\n<p>I integrated the thumbnail creation process into my build toolchain for the blog.\nThe actual code to create the images is rather boring.\nIf you <em>really<\/em> want to have a look, <a rel=\"external\" href=\"https:\/\/github.com\/mre\/lqip\/\">it\u2019s on Github<\/a>.<\/p>\n<h2 id=\"avoiding-javascript\"><a class=\"anchor\" href=\"#avoiding-javascript\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Avoiding JavaScript<\/h2>\n<p>Here is the skeleton HTML for the image previews:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"html\"><span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;<\/span><span class=\"z-l-3 z-d-2\">figure<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;<\/span><span class=\"z-l-3 z-d-2\">div<\/span><span class=\"z-l-13 z-d-15\"> class<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">loader<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">object<\/span><span class=\"z-l-13 z-d-15\"> data<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">image.svg<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> type<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">image\/svg+xml<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">object<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">    &lt;<\/span><span class=\"z-l-3 z-d-2\">img<\/span><span class=\"z-l-13 z-d-15\"> class<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">frozen<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-13 z-d-15\"> src<\/span><span class=\"z-l-2 z-d-5\">=<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">data:image\/png;base64,...<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-2 z-d-5\"> \/&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">  &lt;\/<\/span><span class=\"z-l-3 z-d-2\">div<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-5\">&lt;\/<\/span><span class=\"z-l-3 z-d-2\">figure<\/span><span class=\"z-l-2 z-d-5\">&gt;<\/span><\/span><\/code><\/pre>\n<p>The trick is to wrap both the full-size image and the preview image into a <code>loader<\/code> div,\nwhich gets a <code>width: auto<\/code> CSS attribute:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"css\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-13 z-d-15\">loader<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  position<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> relative<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  overflow<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> hidden<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  width<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> auto<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>I wrap the SVG into an <code>object<\/code> tag instead of using an <code>img<\/code> element.\nThis has the benefit, that I can show a placeholder in case the SVG can\u2019t be loaded.\nI position the <code>object<\/code> at the top left of the <code>loader<\/code> div.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"css\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-13 z-d-15\">loader<\/span><span class=\"z-l-3 z-d-2\"> object<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  position<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> absolute<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-13 z-d-15\">loader<\/span><span class=\"z-l-3 z-d-2\"> img<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-13 z-d-15\">loader<\/span><span class=\"z-l-3 z-d-2\"> object<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  display<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> block<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  top<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  left<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  width<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-16 z-d-16\">%<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Here\u2019s the placeholder <em>hack<\/em> including some references:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"css\"><span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> https:\/\/stackoverflow.com\/a\/29111371\/270334 <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">\/*<\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\"> https:\/\/stackoverflow.com\/a\/32928240\/270334 <\/span><span class=\"z-l-8 z-l-i z-d-4 z-d-i\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">object<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  position<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> relative<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  float<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> left<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  display<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> block<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>  &amp;<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span>:after {<\/span><\/span>\n<span class=\"giallo-l\"><span>    position: <\/span><span>absolute<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    top<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    left<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    display<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> block<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    width<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 1000<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    height<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 1000<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    content<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    background<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-8 z-d-4\"> #<\/span><span>efefef<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>The last part is the handling of the thumbnails.\nLike most other sites, I decided to apply a blur filter.\nIn a way, it looks like the image is <em>frozen<\/em>, so that\u2019s what I called the CSS selector.\nI also applied a scaling transformation to achieve sharp borders.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"css\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-13 z-d-15\">frozen<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-l-i z-d-3 z-d-i\">  -webkit-filter<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> blur<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">8<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-l-i z-d-3 z-d-i\">  -moz-filter<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> blur<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">8<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-l-i z-d-3 z-d-i\">  -o-filter<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> blur<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">8<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-l-i z-d-3 z-d-i\">  -ms-filter<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> blur<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">8<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  filter<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> blur<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">8<\/span><span class=\"z-l-9 z-d-9\">px<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  transform<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> scale<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">1.04<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  animation<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0.2<\/span><span class=\"z-l-9 z-d-9\">s<\/span><span> ease-in<\/span><span class=\"z-l-16 z-d-16\"> 0.4<\/span><span class=\"z-l-9 z-d-9\">s<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span> forwards<\/span><span> fade<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">  width<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 100<\/span><span class=\"z-l-16 z-d-16\">%<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">@<\/span><span class=\"z-l-9 z-d-9\">keyframes<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> fade<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>  0%<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    opacity<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 1<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span>  100%<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-2\">    opacity<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>I use CSS animations instead of JavaScript.<br \/>\nThe duration of the animation is based on the 95% percentile load time of all visitors of the page. Although it\u2019s just an approximation, this should work for most readers.<\/p>\n<h2 id=\"result\"><a class=\"anchor\" href=\"#result\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Result<\/h2>\n<ul>\n<li>No JavaScript needed<\/li>\n<li>Works on all modern browsers<\/li>\n<li>Supports a fallback in case the main image can\u2019t be loaded<\/li>\n<li>Tiny overhead<\/li>\n<\/ul>\n<h2 id=\"resources\"><a class=\"anchor\" href=\"#resources\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Resources<\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/www.guypo.com\/introducing-lqip-low-quality-image-placeholders\">Introducing LQIP \u2013 Low Quality Image Placeholders<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/jmperezperez.com\/medium-image-progressive-loading-placeholder\/\">How Medium does progressive image loading<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/axe312ger\/sqip\">SQIP, a new preview technique using pure SVG<\/a><\/li>\n<\/ul>\n"},{"title":"Go vs Rust? Choose Go.","pubDate":"Fri, 15 Sep 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/go-vs-rust\/","guid":"https:\/\/endler.dev\/2017\/go-vs-rust\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/go-vs-rust\/hero.svg\" alt=\"Gopher designed with <a href='https:\/\/gopherize.me'>Gopherize.me<\/a>. Gears designed by <a href='https:\/\/www.freepik.com\/free-vector\/gear-background-with-pieces-different-colors_966124.htm'>Freepik<\/a>.\" width=\"809\" height=\"400\"\n    \/>\n    <figcaption>\n        Source: Gopher designed with <a href='https:\/\/gopherize.me'>Gopherize.me<\/a>. Gears designed by <a href='https:\/\/www.freepik.com\/free-vector\/gear-background-with-pieces-different-colors_966124.htm'>Freepik<\/a>.\n    <\/figcaption>\n<\/figure>\n<div class=\"info\">\n    <p>I wrote this article a long time ago. In the meantime,\nmy opinion on some aspects has changed.<\/p>\n<p>In order to give a more balanced perspective on the pros and cons, I suggest to\nread this comparison on Go vs Rust instead, which I wrote in collaboration with\nShuttle \ud83d\ude80<\/p>\n<p><a rel=\"external\" href=\"https:\/\/www.shuttle.rs\/blog\/2023\/09\/27\/rust-vs-go-comparison\">Rust vs Go: A Hands-On Comparison<\/a><\/p>\n<\/div>\n<p>\u201cRust or Go, which one should I choose?\u201d is a question I get quite often.\nBoth languages seem to be competing for the same user base and they both seem to be\n<em>systems programming<\/em> languages, so there must be a clear winner, right?<\/p>\n<h2 id=\"go-practical-pragmatic-plain\"><a class=\"anchor\" href=\"#go-practical-pragmatic-plain\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Go: Practical, Pragmatic, Plain<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/go-vs-rust\/go.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/go-vs-rust\/go.jpg\" alt=\"The Golang learning curve over time, a straight line.\" width=\"504\" height=\"412\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The Golang learning curve over time, a straight line.\n    <\/figcaption>\n<\/figure>\n<p>I don\u2019t think Go is an elegant language. Its biggest feature is <del>simplicity<\/del> <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=SxdOUGdseq4\">easiness<\/a>.\nGo is not even a systems programming language. While it\u2019s great for writing microservices and tooling around backend infrastructure, I would not want to write a kernel or a memory allocator with it.<\/p>\n<p>But with Go, you <em>get things done<\/em> \u2014 fast.<br \/>\nGo is one of the most productive languages I\u2019ve ever worked with.\nThe mantra is: solve real problems today.<\/p>\n<h2 id=\"rust-s-strong-guarantees-come-at-a-cost\"><a class=\"anchor\" href=\"#rust-s-strong-guarantees-come-at-a-cost\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Rust\u2019s Strong Guarantees Come at a Cost<\/h2>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/go-vs-rust\/rust.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/go-vs-rust\/rust.jpg\" alt=\"The Rust learning curve over time, a bumpy ride.\" width=\"505\" height=\"419\"\n    \/>\n    <\/picture>\n    <figcaption>\n        The Rust learning curve over time, a bumpy ride.\n    <\/figcaption>\n<\/figure>\n<p>Rust in comparison is <strong>hard<\/strong>. It took me many months to become somewhat productive.\nYou need to invest a serious amount of time to see any benefit.\nRust is already a powerful language and it gets stronger every day.\nIt feels much more like a <em>pragmatic Haskell<\/em> to me than a <em>safer C<\/em>.<\/p>\n<p>Don\u2019t get me wrong: <a rel=\"external\" href=\"https:\/\/www.youtube.com\/channel\/UCZ_EWaQZCZuGGfnuqUoHujw\">I love Rust<\/a>, and it helped me become a better programmer. It is certainly a nice language to learn. The big question is, if it is the right choice for your next major project.<\/p>\n<p>Here\u2019s the thing: if you choose Rust, usually you need the guarantees, that the language provides:<\/p>\n<ul>\n<li>Safety against <code>Null<\/code> pointers, race conditions and all sorts of low-level threats.<\/li>\n<li>Predictable runtime behavior (zero cost abstractions and no garbage collector).<\/li>\n<li>(Almost) total control over the hardware (memory layout, processor features).<\/li>\n<li>Seamless interoperability with other languages.<\/li>\n<\/ul>\n<p>If you don\u2019t <em>require<\/em> any of these features, Rust might be a poor choice for your next project.\nThat\u2019s because these guarantees come with a cost: ramp-up time.\nYou\u2019ll need to unlearn bad habits and learn new concepts.\nChances are, you will <a rel=\"external\" href=\"https:\/\/m-decoster.github.io\/2017\/01\/16\/fighting-borrowchk\/\">fight with the borrow checker<\/a> a lot when you start out.<\/p>\n<h2 id=\"case-study-primality-by-trial-division\"><a class=\"anchor\" href=\"#case-study-primality-by-trial-division\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Case-Study: Primality by Trial Division<\/h2>\n<p>Let\u2019s say, you want to check if a number is <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Prime_number\">prime<\/a>.\nThe easiest way is to check if we can divide the number by any smaller natural number (without a remainder). If not, we found a prime number! This approach is called <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Trial_division\">trial division<\/a>.<\/p>\n<p>Here\u2019s how to do that in Golang (courtesy of <a rel=\"external\" href=\"https:\/\/rosettacode.org\/wiki\/Primality_by_trial_division#Go\">Rosetta Code<\/a>):<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">func<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> IsPrime<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\">n<\/span><span class=\"z-l-9 z-d-9\"> int<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-9 z-d-9\"> bool<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tif<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tn<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-2 z-d-5\"> -<\/span><span>n<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tswitch<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tcase<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\treturn<\/span><span class=\"z-l-16 z-d-16\"> false<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\tdefault<\/span><span class=\"z-l-8 z-d-4\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\tfor<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\"> :=<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\"> &lt;<\/span><span> n<\/span><span class=\"z-l-8 z-d-4\">;<\/span><span> i<\/span><span class=\"z-l-2 z-d-5\">++<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\tif<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\">%<\/span><span>i<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t\t\t\treturn<\/span><span class=\"z-l-16 z-d-16\"> false<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\treturn<\/span><span class=\"z-l-16 z-d-16\"> true<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>And here\u2019s the same thing in Rust:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">pub<\/span><span class=\"z-l-9 z-d-9\"> fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> is_prime<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">n<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u64<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> bool<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    match<\/span><span> n<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">        0<\/span><span class=\"z-l-2 z-d-5\">...<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-10 z-d-12\"> false<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>        _<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            for<\/span><span> d<\/span><span class=\"z-l-9 z-d-9\"> in<\/span><span class=\"z-l-16 z-d-16\"> 2<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>n<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">                if<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span> d<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">                    return<\/span><span class=\"z-l-10 z-d-12\"> false<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">                }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-10 z-d-12\">            true<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>At first sight, both solutions look pretty similar.\nBut if we look closer, we can spot some differences.<\/p>\n<ul>\n<li>In Go, we use a simple switch-case statement. In Rust, we use a <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/1.2.0\/book\/match.html\"><code>match<\/code><\/a> statement, which is much more powerful.<\/li>\n<li>In Go, we use a simple for-loop to iterate over the numbers 2 to n. In Rust, we use a range expression (<code>2..n<\/code>).<\/li>\n<li>In Go, we use two <code>return<\/code> statements, in Rust we have one <code>return<\/code> <em>expression<\/em>. In general, most things in Rust are expressions, which can be returned and assigned to a variable. Read more about expressions <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/beta\/reference\/expressions.html\">here<\/a>.<\/li>\n<\/ul>\n<p>In many areas, Rust is more functional than Golang. You could rewrite the above code using the <a rel=\"external\" href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html#method.any\"><code>any<\/code><\/a> method, which is implemented for <code>Range<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"rust\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">fn<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> is_prime<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-14 z-d-10\">n<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span class=\"z-l-9 z-d-9\"> u64<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> -&gt;<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> bool<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    match<\/span><span> n<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-d-16\">        0<\/span><span class=\"z-l-2 z-d-5\">...<\/span><span class=\"z-l-16 z-d-16\">1<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-10 z-d-12\"> false<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span>        _<\/span><span class=\"z-l-2 z-d-5\"> =&gt;<\/span><span class=\"z-l-2 z-d-5\"> !<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-16 z-d-16\">2<\/span><span class=\"z-l-2 z-d-5\">..<\/span><span>n<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">any<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span>d<\/span><span class=\"z-l-2 z-d-5\">|<\/span><span> n<\/span><span class=\"z-l-2 z-d-5\"> %<\/span><span> d<\/span><span class=\"z-l-2 z-d-5\"> ==<\/span><span class=\"z-l-16 z-d-16\"> 0<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>It might seem a little alien at first, but it will become second-nature after a while.<\/p>\n<p>This was just a quick example, of course. I suggest, you browse some code on <a rel=\"external\" href=\"https:\/\/rosettacode.org\/wiki\/Rosetta_Code\">Rosetta Code<\/a> to get a better feeling for both languages.<\/p>\n<h2 id=\"case-study-finding-duplicate-words-in-text-files\"><a class=\"anchor\" href=\"#case-study-finding-duplicate-words-in-text-files\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Case Study: Finding Duplicate Words in Text Files<\/h2>\n<p>If you\u2019re more like a visual type, here is a video where I write a simple\nconcurrent program in Go and Rust to compare both languages:<\/p>\n<link rel=\"stylesheet\" href=\"https:\/\/endler.dev\/css\/video.css\" \/>\n<script defer src=\"\/video.js\"><\/script>\n<div class=\"light-video-embed\" data-url=\"https:\/\/www.youtube.com\/embed\/B5xYBrxVSiE\"\n>\n  <picture>\n    <source srcset=\"maxresdefault.avif\" type=\"image\/avif\" \/>\n    <img src=\"maxresdefault.jpg\"\n    \/>\n  <\/picture>\n  <div class=\"play\"><\/div>\n<\/div>\n<script>\n  document.addEventListener(\"DOMContentLoaded\", function() {\n    lightEmbedInit();\n  });\n<\/script>\n<h2 id=\"some-things-i-prefer-in-go\"><a class=\"anchor\" href=\"#some-things-i-prefer-in-go\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Some Things I Prefer in Go<\/h2>\n<ul>\n<li>Fast compile times<\/li>\n<li>Pragmatic problem-solving approach<\/li>\n<li>Nice ecosystem for typical <em>DevOps<\/em> tasks<\/li>\n<li>Batteries-included standard-library<\/li>\n<li>IDE support<\/li>\n<li>Simple error handling<\/li>\n<li>The mascot \ud83d\ude09<\/li>\n<\/ul>\n<h2 id=\"some-things-i-prefer-in-rust\"><a class=\"anchor\" href=\"#some-things-i-prefer-in-rust\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Some Things I Prefer in Rust<\/h2>\n<ul>\n<li>Safety: No null pointers, no data races,\u2026<\/li>\n<li>Fine-grained system control<\/li>\n<li>Incredible runtime speed (comparable with C\/C++)<\/li>\n<li>Zero-cost abstractions<\/li>\n<li>Awesome, open-minded community<\/li>\n<li>Simple package management with cargo<\/li>\n<li>Support for Generics in form of traits<\/li>\n<li>C interop and FFI<\/li>\n<\/ul>\n<h2 id=\"conclusion\"><a class=\"anchor\" href=\"#conclusion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Conclusion<\/h2>\n<p>99% of the time, Go is \u201cgood enough\u201d and that 1% where it isn\u2019t, you\u2019ll know.\nAnd then take a look at Rust, because the two languages complement each other pretty well.\nIf you\u2019re interested in <strong>hands-on Rust consulting<\/strong>, <a rel=\"external\" href=\"https:\/\/github.com\/sponsors\/mre?frequency=one-time&amp;sponsor=mre\">pick a date from my\ncalendar<\/a> and we can talk about how I can help.<\/p>\n<p>After all is said and done, <a rel=\"external\" href=\"https:\/\/dave.cheney.net\/2015\/07\/02\/why-go-and-rust-are-not-competitors\">Rust and Go are not really competitors<\/a>.<\/p>\n"},{"title":"Afraid of Makefiles? Don't Be!","pubDate":"Tue, 15 Aug 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/makefiles\/","guid":"https:\/\/endler.dev\/2017\/makefiles\/","description":"<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/makefiles\/clothes.svg\" alt=\"What do clothes have to do with Makefiles? Find out in this post!\" width=\"1232\" height=\"563\"\n    \/>\n    <figcaption>\n        What do clothes have to do with Makefiles? Find out in this post!\n        <br \/>\n        Source: <a rel=\"external\" href=\"https:\/\/www.freepik.com\/free-photos-vectors\/background\">Illustration by Anindyanfitri - Freepik.com<\/a>\n    <\/figcaption>\n<\/figure>\n<p>In the last few years, I\u2019ve had the pleasure to work with a lot of talented Software Engineers.\nOne thing that struck me is that many of them did not have any working knowledge of <code>Makefiles<\/code>\nand why they are useful.<\/p>\n<p>When faced with the task to automate a build process, they often roll their own shell scripts.\nCommon culprits are called <code>build.sh<\/code>, <code>run.sh<\/code> or <code>doall.sh<\/code> in a project folder.<\/p>\n<p>They implement the same basic functionality over and over again:<\/p>\n<ul>\n<li>Parsing input parameters and environment variables.<\/li>\n<li>Manually managing dependencies between build steps.<\/li>\n<li>Error handling (\u2026maybe).<\/li>\n<\/ul>\n<p>Along the way, they keep making the same basic mistakes:<\/p>\n<ul>\n<li>Incorrectly handling <a rel=\"external\" href=\"https:\/\/www.pixelbeat.org\/programming\/shell_script_mistakes.html\">input parameters<\/a> and <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Shellshock_(software_bug)\">environment variables<\/a>.<\/li>\n<li>Missing dependencies between build steps.<\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.davidpashley.com\/articles\/writing-robust-shell-scripts\/\">Forgetting to handle errors<\/a> and \u2014 even worse \u2014 carrying on with the program execution.<\/li>\n<\/ul>\n<p>These are issues Makefiles were invented to solve.<\/p>\n<h2 id=\"makefiles-are-scary\"><a class=\"anchor\" href=\"#makefiles-are-scary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Makefiles Are Scary!<\/h2>\n<p>If you think that <code>make<\/code> is scary, you probably think of complicated build machinery for <a rel=\"external\" href=\"https:\/\/community.kde.org\/Guidelines_and_HOWTOs\/Build_from_source\">big<\/a> <a rel=\"external\" href=\"https:\/\/chromium.googlesource.com\/chromium\/src\/+\/master\/docs\/linux\/build_instructions.md\">software<\/a> projects.\nIt doesn\u2019t need to be that way. Let\u2019s hear from the author of <code>make<\/code>, <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Stuart_Feldman\">Stuart Feldman<\/a> himself:<\/p>\n<blockquote>\n<p>It began with an elaborate idea of a dependency analyzer, boiled down to something much simpler, and turned into Make that weekend. Use of tools that were still wet was part of the culture. Makefiles were text files, not magically encoded binaries because <strong>that was the Unix ethos: printable, debuggable, understandable stuff.<\/strong><\/p>\n<p>\u2014 <a rel=\"external\" href=\"https:\/\/nakamotoinstitute.org\/static\/docs\/taoup.pdf\">The Art of Unix Programming (2003)<\/a><\/p>\n<\/blockquote>\n<p>Make was built in <em>one weekend<\/em> to solve a reoccurring problem in a simple way.<\/p>\n<h2 id=\"makefiles-are-simple\"><a class=\"anchor\" href=\"#makefiles-are-simple\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Makefiles Are Simple!<\/h2>\n<p>Before I leave the house, I need to get dressed.\nI use the same simple routine every time:\nUnderpants, trousers, shirt, pullover, socks, shoes, jacket.\nMost likely you also have a routine, even though yours might be different.<\/p>\n<p>Some of these steps depend on each other.<br \/>\n<code>Make<\/code> is useful for handling dependencies.<br \/>\nLet\u2019s try to express my routine as a <code>Makefile<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"make\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">dress<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> trousers shoes jacket<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;All done. Let&#39;s go outside!<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">jacket<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> pullover<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on jacket.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">pullover<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> shirt<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on pullover.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">shirt<\/span><span class=\"z-l-2 z-d-5\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on shirt.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">trousers<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> underpants<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on trousers.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">underpants<\/span><span class=\"z-l-2 z-d-5\">:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on underpants.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">shoes<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> socks<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on shoes.<\/span><span>&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">socks<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> pullover<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">\t@<\/span><span>echo &quot;Putting on socks.<\/span><span>&quot;<\/span><\/span><\/code><\/pre>\n<p>If we execute the <code>Makefile<\/code>, we get the following output:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>$ make dress<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on underpants.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on trousers.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on shirt.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on pullover.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on socks.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on shoes.<\/span><\/span>\n<span class=\"giallo-l\"><span>Putting on jacket.<\/span><\/span>\n<span class=\"giallo-l\"><span>All done. Let&#39;s go outside!<\/span><\/span><\/code><\/pre><h2 id=\"what-just-happened\"><a class=\"anchor\" href=\"#what-just-happened\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What Just Happened?<\/h2>\n<p>Noticed how the steps are in the correct order?\nBy plainly writing down the dependencies between the steps, <code>make<\/code> helps us to execute them correctly.<\/p>\n<p>Each build step has the following structure:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"make\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">target<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> [dependencies]<\/span><\/span>\n<span class=\"giallo-l\"><span>\t&lt;shell command to execute<\/span><span>&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span>\t&lt;shell command to execute<\/span><span>&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span>\t..<\/span><span>.<\/span><\/span><\/code><\/pre>\n<ul>\n<li>\n<p>The first target in a <code>Makefile<\/code> will be executed by default when we call <code>make<\/code>.<\/p>\n<\/li>\n<li>\n<p>The order of the targets does not matter.<\/p>\n<\/li>\n<li>\n<p>Shell commands must be indented with a tab.<\/p>\n<\/li>\n<li>\n<p>Add an <code>@<\/code> sign to suppress output of the command that is executed.<\/p>\n<\/li>\n<li>\n<p>If <code>target<\/code> isn\u2019t a file you want to build, please add <code>.PHONY &lt;target&gt;<\/code> at the end of the build step.\nCommon phony targets are: clean, install, run,\u2026\nOtherwise, if somebody creates an <code>install<\/code> directory, <code>make<\/code> will silently fail, because the build target already exists.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"make\"><span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">.PHONY<\/span><span class=\"z-l-2 z-d-5\">:<\/span><span> install<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">install<\/span><span class=\"z-l-2 z-d-5\">:<\/span><\/span>\n<span class=\"giallo-l\"><span>\tnpm instal<\/span><span>l<\/span><\/span><\/code><\/pre><\/li>\n<\/ul>\n<p>Congratulations! You\u2019ve learned 90% of what you need to know about <code>make<\/code>.<\/p>\n<h2 id=\"next-steps\"><a class=\"anchor\" href=\"#next-steps\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Next Steps<\/h2>\n<p>Real <code>Makefiles<\/code> can do much more! They will <a rel=\"external\" href=\"https:\/\/stackoverflow.com\/a\/3798609\/270334\">only build the files that have changed<\/a> instead of doing a full rebuild.\nAnd they will do <a rel=\"external\" href=\"https:\/\/stackoverflow.com\/a\/3841803\/270334\">as much as possible in parallel<\/a>.\nJust try to keep them simple please.<\/p>\n"},{"title":"Of Boxes and Trees - Smart Pointers in Rust","pubDate":"Sat, 12 Aug 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/boxes-and-trees\/","guid":"https:\/\/endler.dev\/2017\/boxes-and-trees\/","description":"<p>Recently, I tried to implement a binary tree data structure in Rust.\nEach binary tree has a root value, a left, and a right subtree.\nI started from this Python implementation, which is quite straightforward.<\/p>"},{"title":"Why Type Systems Matter","pubDate":"Mon, 10 Jul 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/why-type-systems-matter\/","guid":"https:\/\/endler.dev\/2017\/why-type-systems-matter\/","description":"<p>I\u2019ve written most of my code in dynamically typed languages such as Python or PHP; but ever since dabbling with <a rel=\"external\" href=\"https:\/\/www.rust-lang.org\">Rust<\/a>, I\u2019ve developed a passion for static type systems.<br \/>\nIt began to feel very natural to me; like a totally new way to express myself.<\/p>"},{"title":"Being a Professional Programmer","pubDate":"Thu, 18 May 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/professional-programming\/","guid":"https:\/\/endler.dev\/2017\/professional-programming\/","description":"<p>When I was around 12, I set myself the goal to become a professional programmer.<br \/>\nI can tell, because at this time I made the conscious decision to use my right hand to control the mouse \u2014 even though I\u2019m left-handed.<\/p>\n<p>My reasoning was, that if I ever had to help out a colleague with a computer problem I sure did not want to move her mouse to the other side before getting started. That would be awkward.\n(Of course I did not foresee the advent of the wireless mouse\u2026 As a matter of fact, I still use the right hand out of habit.)<\/p>\n<p>One thing I always wanted to know is how a typical workday of a programmer looked like.\nWas I wasting my time by pursuing this career?\nOnly later I found the answer \u2014 but I had to become a professional programmer myself.\nThis article aims to save you from a few years of uncertainty.<\/p>\n<p>Before you dig into this, be sure to read the first part of this series titled <a href=\"https:\/\/endler.dev\/2017\/why-i-love-programming\/\">\u201cWhy I love Programming\u201d<\/a>.<\/p>\n<h2 id=\"what-s-the-difference-between-professional-and-hobby-programming\"><a class=\"anchor\" href=\"#what-s-the-difference-between-professional-and-hobby-programming\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>What\u2019s the Difference between \u201cprofessional\u201d and \u201chobby\u201d Programming?<\/h2>\n<p>In one word: <em>accountability<\/em>.<br \/>\nYou are expected to be responsible.<\/p>\n<p>Programming in your free time is like throwing a party without having to clean up: pure fun!\nIf you get bored you\u2019re free to move on.\nNot so in professional programming, where you\u2019re expected to get the job done.<\/p>\n<p>Every application requires constant bug fixing, refactoring and sometimes even monkey patching. Maintaining code is no amusement park; especially if it\u2019s not your own.<\/p>\n<h2 id=\"being-a-junior-developer\"><a class=\"anchor\" href=\"#being-a-junior-developer\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Being a Junior Developer<\/h2>\n<p>Fresh out of school you might think you\u2019re a pretty kick-ass programmer. Let me tell you: you\u2019re not.\nYou wouldn\u2019t guess what talented people can do with these blinking machines.\nYou\u2019ll have tons of things to learn in the first few years.<\/p>\n<p>Professional software development is a lengthy process. Writing readable, well-tested, well-documented code is a substantial effort. You will need patience, lots of it. Both, with yourself and with others.<\/p>\n<p>As a junior, you only think in black and white. You look at some code, and it\u2019s all wrong. Who in their right mind created this horrible monstrosity?!\nAs you become more experienced, you\u2019ll see the shades of grey.<\/p>\n<p>Eventually, you\u2019ll understand that those neckbeards were not slower than you, but\nmore careful. You learn how to test your code, how to document it. You even begin to\nappreciate UML diagrams.<\/p>\n<h2 id=\"becoming-obsolete\"><a class=\"anchor\" href=\"#becoming-obsolete\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Becoming Obsolete<\/h2>\n<p>\u201cThe world is moving too fast. What you learned today is obsolete tomorrow. Why bother?\u201d.\nI\u2019ve heard that saying countless times throughout my career.\nIt\u2019s both, popular and wrong.<\/p>\n<p>If a skill becomes obsolete, it\u2019s not a skill.\nThroughout your career you don\u2019t want to be known as \u201cthe Jenkins guy\u201d, you want to be the\nexpert in Software Quality. Hint: If you don\u2019t know what Jenkins is, that\u2019s the\nwhole point. You should not narrow down your scope too much.\nThe right skills never become obsolete.<\/p>\n<p>From time to time it happens, that due to some new company policy your beautiful creation will become obsolete.\nAs depressing as it sounds: it\u2019s a regular part of the software business.\nYou need to adapt.\nOne advice I can give you is not to take it too seriously.\nDrop the project, keep the wisdom.\nEmbrace change.<\/p>\n<h2 id=\"writing-software-in-a-non-perfect-world\"><a class=\"anchor\" href=\"#writing-software-in-a-non-perfect-world\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Writing Software in a Non-Perfect World<\/h2>\n<p>A professional programmer has to deal with deficiencies all the time. The game is called \u201cbalancing constraints\u201d. Deadlines, budgets, and code quality are just a few competing constraints we have to consider.\nElegant designs fade away in the face of reality.\nIn the end you want to earn money with your software, so you have to ship it!<\/p>\n<p>The best developers I know, keep the balance between pragmatism and elegance.\nThey know which parts matter and which don\u2019t. Those who don\u2019t will be replaced\nwhen there\u2019s a need.<\/p>\n<p>For me, I was always leaning more towards elegance.\nThat\u2019s just a nicer way to say I was a perfectionist.\nI needed to learn the pragmatic part through hard work.<\/p>\n<h2 id=\"mentoring-less-experienced-programmers\"><a class=\"anchor\" href=\"#mentoring-less-experienced-programmers\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Mentoring Less Experienced Programmers<\/h2>\n<blockquote>\n<p>The better you become at programming, the less you code.<\/p>\n<\/blockquote>\n<p>Instead, you will spend more time thinking about Software Architecture,\nhigh-level designs and splitting up the work into smaller chunks for other developers to consume.\nYou will start mentoring Junior Developers. Recruiting will require a lot of your\nattention. You will spend your time in Meetings, discussing project goals with\nbusiness people.\nOne might say, you take the role of a mediator. Others might call you a manager.<\/p>\n<p>Once you know the ins and outs of the business, you are an essential asset for\nthe company. You might get asked to become a manager, or at least managing projects will slowly feel like a natural extension of your responsibilities.\nBut beware! This slow and gradual process is dangerous.\nMoving back to being a full-time programmer is not easy.\nDuring the time you were busy with project management, others were busy improving their\ncoding skills.\nYou can try to keep up-to-date in your free time but that\u2019s hard.<\/p>\n<p>I\u2019ve seen excellent developers become great managers. At some point in your career\nit\u2019s a decision you need to make for yourself.<\/p>\n<p>However you decide, it pays off to invest some time into learning how to\ncommunicate. Empathy plays a prominent role in that.\nDeveloping software as a team is so complicated that a lot of time is spent on aligning goals and communicating problems. In fact, communication is what you get paid for. This includes documentation, tests and the code itself.<\/p>\n<p>Talk to others, listen to their problems. Read books about Software Project\nManagement, even though you don\u2019t want to be a manager yourself. It will help\nyou understand the role of your boss.<\/p>\n<h2 id=\"a-word-about-money\"><a class=\"anchor\" href=\"#a-word-about-money\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>A Word about Money<\/h2>\n<p>There are many good reasons to work in IT, but money is not one of them.<\/p>\n<p>While it can be tempting to base your career decisions on prospective salary,\ndon\u2019t do it. You will be very unhappy. You will spend eight hours or more each day sitting in front of a blinking cursor.\nThat\u2019s a lot of time, and time is much more valuable than money.<\/p>\n<p>Don\u2019t get me wrong. There\u2019s plenty of jobs that pay well.\nYou will most likely not get rich, though. If you want\nto make it big, I can\u2019t help you. Maybe look into Real Estate or so\u2026\nThe only way to get rich as a developer is to work on something really hard, put in lots of hours and get\nlucky. Startups, basically. Keep in mind: One Bill Gates takes a thousand failed\nattempts.\nAnother way is to stop being a programmer and become a manager instead.\nI\u2019ve already shared my opinion on that in the last section.<\/p>\n<h2 id=\"final-words\"><a class=\"anchor\" href=\"#final-words\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Final Words<\/h2>\n<p>While you should learn to read (and maybe write) code, working as a professional programmer is not for everyone.\nYou might ask: \u201cIs it worth it?\u201d.\nFor me it was the right decision. Hopefully I could help you to make your own.<\/p>\n"},{"title":"The Future of Rust","pubDate":"Thu, 27 Apr 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/future-of-rust\/","guid":"https:\/\/endler.dev\/2017\/future-of-rust\/","description":"<p>Let me first point out the obvious: yes, the title is a little sensationalist. Also\nyou might be asking why I should be entitled to talk about the future of Rust. After\nall, I\u2019m neither part of the Rust core team, nor a major contributor to the Rust\necosystem. To that I answer: why not? It\u2019s fun to think about the future of\nsystems programming in general and Rust in particular.<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/future-of-rust\/crab.svg\" alt=\"Ferris is the inofficial Rust mascot\" width=\"639\" height=\"429\"\n    \/>\n    <figcaption>\n        Ferris is the inofficial Rust mascot\n        <br \/>\n        Source: Illustration provided by <a rel=\"external\" href=\"https:\/\/www.freepik.com\">FreePik.com<\/a>\n    <\/figcaption>\n<\/figure>\n<p>You might have heard of the <a rel=\"external\" href=\"https:\/\/internals.rust-lang.org\/t\/setting-our-vision-for-the-2017-cycle\/3958\">near-term goals<\/a> that the core team has committed itself to. Faster compile times and a more gentle learning curve come to mind.\nThis post is not about that.\nInstead, I want to explore some more exotic areas where Rust could shine in\nfive to ten years from now. To make it big, we need both, <a rel=\"external\" href=\"https:\/\/www.goodreads.com\/quotes\/726646-there-are-two-things-children-should-get-from-their-parents\">roots and wings<\/a>.<\/p>\n<h2 id=\"data-science\"><a class=\"anchor\" href=\"#data-science\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Data Science<\/h2>\n<p>Right now, the most popular languages for Data Science are Python, Java, R, and C++.<\/p>\n<figure>\n  <img src=\"\/2017\/future-of-rust\/data-science-languages.png\" alt=\"Programming language popularity for data science\" \/>\n  <figcaption>Programming language popularity for data science (<a href=\"https:\/\/web.archive.org\/web\/20170311030523\/https:\/\/www.ibm.com\/developerworks\/community\/blogs\/jfp\/entry\/What_Language_Is_Best_For_Machine_Learning_And_Data_Science?lang=en\">Source<\/a>).\n  <\/figcaption>\n<\/figure>\n<p>We\u2019ve observed that while prototypes are mostly written in dynamically typed\nlanguages like Python and R, once an algorithm reaches production level quality\nit is often <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20170311030523\/https:\/\/www.ibm.com\/developerworks\/community\/blogs\/jfp\/entry\/What_Language_Is_Best_For_Machine_Learning_And_Data_Science?lang=en\">rewritten in faster languages such as C++<\/a> for scalability.\nIt is not unthinkable that Rust is going to be some healthy competition for C++ in the near future.\nThe benchmarks of <a rel=\"external\" href=\"https:\/\/github.com\/autumnai\/leaf\">leaf<\/a>, a machine learning library written in Rust, are already nothing short of\nimpressive.<\/p>\n<h2 id=\"blockbuster-games\"><a class=\"anchor\" href=\"#blockbuster-games\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Blockbuster Games<\/h2>\n<p><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/rust_gamedev\/comments\/4qlftu\/look_our_game_writen_entirely_in_rust\/d4tz4r3\/\">Games<\/a> are another area where Rust might shine.\nIt\u2019s financially attractive for Game Studios to support multiple platforms without much\neffort. <code>Cargo<\/code> and <code>rustup<\/code> make cross-compiling easy.\nModern libraries slowly fill the tooling gaps for large-scale game development.\n<a rel=\"external\" href=\"https:\/\/github.com\/tomaka\/vulkano\">Rust\u2019s support for the Vulkan 3D graphics API<\/a> might already be the best of class.\nThe killer feature though is the unique combination of safety and performance.\nIf you ship a game to a million players and they throw money at you, you\u2019ll better make sure that it doesn\u2019t crash\u2026 <a rel=\"external\" href=\"https:\/\/gamingbolt.com\/15-buggiest-games-ever-released\">right?<\/a><\/p>\n<p>That said, the first AAA Rust game might still be far in the future. <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=Az5F4lwSljI&amp;feature=youtu.be&amp;t=23m50s\">Here\u2019s Blizzard\u2019s standpoint on Rust in 2017<\/a>.<\/p>\n<h2 id=\"systems-engineering\"><a class=\"anchor\" href=\"#systems-engineering\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Systems Engineering<\/h2>\n<p>Maybe \u2014 eventually \u2014 we will also see formal verification of the Rust core. Projects like <a rel=\"external\" href=\"https:\/\/plv.mpi-sws.org\/rustbelt\/\">RustBelt<\/a> would then open new opportunities in safety-focused industries like the Space industry. Wouldn\u2019t it be nice to safely land a Spacecraft on Mars that is controlled by Rust? (Or by one of its spiritual successors.)\nI wonder if <a rel=\"external\" href=\"https:\/\/www.spacex.com\/\">SpaceX<\/a> is experimenting with Rust already\u2026<\/p>\n<h2 id=\"integrating-with-other-languages\"><a class=\"anchor\" href=\"#integrating-with-other-languages\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Integrating with Other Languages<\/h2>\n<p>There are many other areas I haven\u2019t even mentioned yet. For example, financial and medical software or Scientific Computing, just to name a few.\nIn all cases, Rust might be a good fit. Right now the biggest barrier to entry\nis probably the huge amount of legacy code. Many industries maintain large codebases in Cobol,\nC or Fortran that are not easily rewritten.<\/p>\n<p>Fortunately, Rust has been proven to work very nicely with other languages.\nPartly because of strong C-compatibility and partly because there is no Runtime or Garbage Collector.\nA typical pattern is to optimize some core part of an application in Rust that has hard safety\/performance\nrequirements, while leaving the rest untouched.\nI think this symbiosis will only become stronger in the long run.\nThere are even ambitious projects like <a rel=\"external\" href=\"https:\/\/archive.fosdem.org\/2017\/schedule\/event\/mozilla_translation_from_c_to_rust\/\">Corrode<\/a> which attempt to translate C code to Rust automatically.<\/p>\n<h2 id=\"summary\"><a class=\"anchor\" href=\"#summary\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Summary<\/h2>\n<p>Overall I see huge potential for Rust in areas where safety, performance or total control over the machine are essential. With languages like Rust and <a rel=\"external\" href=\"https:\/\/crystal-lang.org\/\">Crystal<\/a>, a whole class of errors is a thing of the past. No null pointers, no segmentation faults, no memory leaks, no data races.\nI find it encouraging that future generations of programmers will take all that for granted.<\/p>\n"},{"title":"Launching a URL Shortener in Rust Using Rocket","pubDate":"Sun, 09 Apr 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/rust-url-shortener\/","guid":"https:\/\/endler.dev\/2017\/rust-url-shortener\/","description":"<p>One common systems design task in interviews is to sketch the software architecture of a URL shortener (a <a rel=\"external\" href=\"https:\/\/bitly.com\/\">bit.ly<\/a> clone, if you may).\nSince I was playing around with <a rel=\"external\" href=\"https:\/\/rocket.rs\/\">Rocket<\/a> \u2013 a web framework for Rust \u2013 why not give it a try?<\/p>"},{"title":"The Essence of Information","pubDate":"Sat, 18 Mar 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/the-essence-of-information\/","guid":"https:\/\/endler.dev\/2017\/the-essence-of-information\/","description":"<p>People look confused when I tell them about my passion for algorithms and data-structures.\nMost of them understand what a Programmer is doing, but not what Computer Science is good for.\nAnd even if they do, they think it has no practical relevance.\nLet me show you with a simple example, that applied Computer Science can be found everywhere.<\/p>\n<p>Imagine a pile of socks that need to get sorted.\nNot exactly the most exciting pastime.\nYou\u2019ve put off this task for so long, that it will inevitably take an hour to be done.<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/big_pile.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/big_pile.jpg\" alt=\"Yes, there is a game about sorting socks.\" width=\"590\" height=\"391\"\n    \/>\n    <\/picture>\n    <figcaption>\n        Yes, there is a game about sorting socks.\n        <br \/>\n        Source: It\u2019s called <a rel=\"external\" href=\"https:\/\/apps.apple.com\/app\/sort-the-socks\/id438108346\">Sort the Socks<\/a> and you can get it for free on the App Store.\n    <\/figcaption>\n<\/figure>\n<p>Considering your options, you decide to get some help.\nTogether with a friend you get to work. You finish in roughly half the time.<\/p>\n<p>A Computer Scientist might call this pile of socks a <em>resource<\/em>.\nYou and your friend get bluntly degraded to <em>workers<\/em>.\nBoth of you can work on the problem at the same time \u2014 or <em>in parallel<\/em>.\nThis is the gist of <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Parallel_computing\">Parallel Computing<\/a>.<\/p>\n<p>Now, some properties make sock-sorting a good fit for doing in parallel.<\/p>\n<ul>\n<li>The work can be nicely split up. It takes about the same time for every worker to find a pair of socks.<\/li>\n<li>Finding a different pair is a completely separate task that can happen at the same time.<\/li>\n<\/ul>\n<p>The more workers you assign to this task, the faster you\u2019re done.<\/p>\n<ul>\n<li>1 worker takes 60 minutes.<\/li>\n<li>2 workers take 30 minutes.<\/li>\n<\/ul>\n<p>How long will 3 workers take? Right! Around 20 minutes. We could write down\na simple formula for this relationship:<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/equation.svg\" alt=\"The formula for the sorting time.\" width=\"22\" height=\"5\"\n    \/>\n    <figcaption>\n        The formula for the sorting time.\n    <\/figcaption>\n<\/figure>\n<p>Well, that is not quite correct. We forgot to consider the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Overhead_(computing)\">overhead<\/a>: When Mary\ntries to pick up a sock, Stephen might reach for the same.\nThey both smile and one of them picks another sock.\nIn computing, a worker might do the same. Well, not smiling but picking another\ntask. When lots of workers share resources, these situations occur quite\nfrequently. And resolving the situation always takes a little extra time. So we are a\nbit away from our optimal sorting speed because of that.<\/p>\n<p>But it gets worse! Let\u2019s say you have 100 workers for 100 socks.\nIn the beginning, every worker might take one sock and try to find a match for\nit. Here\u2019s the problem: As soon as they pick up one sock each, there are no\nsocks left. All workers are in a waiting state. The sorting takes forever.\nThat\u2019s a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Deadlock\">deadlock<\/a>, and it\u2019s one of the most frightening scenarios of parallel computing.<\/p>\n<p>In this case, a simple solution is to put down the sock again and wait for some time until trying to get a new sock.\nAnother way out of the dilemma would be, to enforce some kind of \u201cprotocol\u201d for sorting.\nThink of a protocol as a silent agreement between the workers on how to achieve a common goal.<\/p>\n<p>So, in our case, each worker might only be responsible for one color of socks.\nWorker one takes the green socks, worker two the gray ones and so on.\nWith this simple trick, we can avoid a deadlock, because we work on completely\nseparate tasks.<\/p>\n<p>But there\u2019s still a catch. What if there are only four green socks and 4000 gray socks?\nWorker one would get bored fairly quickly. He would sort the two pairs of socks in\nno time and then watch worker two sort the rest.\nThat\u2019s not really team spirit, is it?<\/p>\n<p>Splitting up the work like this makes most sense, if we can assume that we\nhave around the same number of socks for every color.\nThis way we achieve roughly the same workload for\neveryone.<\/p>\n<p>The following histogram gives you an idea of what I mean:<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/socks_even.svg\" alt=\"Even piles of socks.\" width=\"160\" height=\"90\"\n    \/>\n    <figcaption>\n        Even piles of socks.\n    <\/figcaption>\n<\/figure>\n<p>In this case, we have about equally sized piles for each color. Looks\nlike a fair workload for every worker to me.<\/p>\n<figure>\n    <img src=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/socks_uneven.svg\" alt=\"Uneven piles of socks.\" width=\"160\" height=\"90\"\n    \/>\n    <figcaption>\n        Uneven piles of socks.\n    <\/figcaption>\n<\/figure>\n<p>In the second case, we don\u2019t have an equal distribution. I don\u2019t want to sort the\ngray socks in this example. We need to think a little harder here.<\/p>\n<p>What can we do?<\/p>\n<p>Most of the time it helps to think of other ways to split up work.\nFor example, we could have <em>two<\/em> workers sort the big gray pile together. One\nsorts the large socks; the other one sorts the small ones. We run into another problem, though: Who decides what \u201clarge\u201d and \u201csmall\u201d means in this case?<\/p>\n<p>So, instead of thinking too hard about a smarter approach, we decide to be\npragmatic here. Everyone just grabs an equally sized pile of socks \u2014 no\nmatter the color or the size \u2014 and gets\nto work.<\/p>\n<p>Most likely, there will be some remaining socks in each pile, which have no match.\nThat\u2019s fine. We just throw them all together, mix the socks, create new piles from\nthat, and sort them again. We do so until we\u2019re done.\nWe call that a <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Scheduling_(computing)#task_queue\">task queue<\/a>. It has two advantages: First, you don\u2019t need any additional agreements between the workers and second, it scales reasonably\nwell with the number of workers without thinking too hard about the problem\ndomain.<\/p>\n<p>The tricky part about distributed systems is, that seemingly straightforward solutions can fail\nmiserably in practice.<\/p>\n<p>What if our small piles look like this?<\/p>\n<figure>\n    <picture>\n        <source srcset=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/random_pile.avif\" type=\"image\/avif\" \/>\n    <img src=\"https:\/\/endler.dev\/2017\/the-essence-of-information\/random_pile.jpg\" alt=\"A random pile of socks.\" width=\"590\" height=\"392\"\n    \/>\n    <\/picture>\n    <figcaption>\n        A random pile of socks.\n    <\/figcaption>\n<\/figure>\n<p>The number of pairs in each pile is\u2026 sobering.\nWhat we could do is run a very quick presorting step to increase the number of matches. Or maybe you come up with an even better idea?<br \/>\nThe cool thing is, once you have found a faster approach, it works for similar tasks, too.<\/p>\n<p>Problems like this have their roots in Computer Science, and they can be found everywhere.\nPersonally, I don\u2019t like the term Computer Science too much. I prefer\nthe German term \u201cInformatik\u201d, which I would roughly translate as \u201cInformation Science\u201d.\nBecause the real essence of what we\u2019re doing here is to find a general way to solve a\nwhole <em>class<\/em> of problems. We think of the nature of objects and their properties.\nWe don\u2019t sort socks; we try to answer the <a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=2Op3QLzMgSY\">fundamental questions of information<\/a>. Maybe now you can understand why I\u2019m so passionate about this subject.<\/p>\n<p>Oh, and here\u2019s a related post about <a href=\"https:\/\/endler.dev\/2017\/why-i-love-programming\/\">why I love programming<\/a>.<\/p>\n"},{"title":"Why I Love Programming","pubDate":"Wed, 15 Mar 2017 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2017\/why-i-love-programming\/","guid":"https:\/\/endler.dev\/2017\/why-i-love-programming\/","description":"<p>Programming has many faces. It is the science of structured thinking.\nIt is the art of eloquent expression.\nIt teaches you to be humble when you look at other peoples\u2019 fascinating work.\nMost of all, it teaches you a lot about yourself.<br \/>\nWhile the syntax may change, the concepts will not.<\/p>"},{"title":"Tools","pubDate":"Sun, 30 Oct 2011 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2011\/tools\/","guid":"https:\/\/endler.dev\/2011\/tools\/","description":"<p>For as long as I can think, religious flamewars have infected computer science.<\/p>\n<p>Having arguments about technical topics can be healthy, but flamewars are not. I\u2019m sick of it.\nI\u2019m fed up with people telling me that their work environment is oh-so better,\nfaster and so on. That\u2019s fine, but it doesn\u2019t matter. Your equipment only plays a supporting role. You don\u2019t even need\na computer to do programming. Donald Knuth wrote algorithms on a\nnotepad. Alan Turing wrote the first chess computer on a piece of\npaper. And it worked. Beat that!<\/p>\n<p>For an average user, the next best system is probably good enough. Just a few bucks and you get an excellent piece of hardware which is completely sufficient to surf the web, chat, archive photos, write documents, listen to music and watch movies. You can do that with a Pentium IV, 256 MB RAM and any recent Operating System (you will likely get that one for free). Heck, you can use your old Commodore for most of that. Computers have been mature and reliable enough to do all that for ages. There\u2019s no need to upgrade your system for Farmville, just like there\u2019s no reason to buy a new car if the old one works perfectly fine. When it comes to software, many of us still use Office 2000 or Photoshop 8 or VisiCalc without feeling the urge to upgrade.<\/p>\n<p>Professionals find themselves in a similar situation. Well, maybe we invest a bit more money, but still, our hardware is incredibly cheap compared to our salary (hopefully). Nothing is perfect, but most of the time <em>it\u2019s good enough<\/em>. That compiler you were using a decade ago? Still does the job. We are still using slightly modified descendants of programming languages from computing stone-age. Even if you\u2019re doing numerical computing for NASA, your primary work environment is a black box running a text editor or an IDE.<\/p>\n<p>I don\u2019t care what <em>you<\/em> are using to get things done. Find an environment that suits <em>your<\/em> needs and be happy with it. Maybe you use Emacs on a Lemote Yeelong netbook (hello Richard Stallman) or Vim on your workstation. It\u2019s the same thing: A text editor running on a piece of metal.\nYou\u2019re not a worse programmer for using Nano, ed or TextMate. Notepad works just fine, too. It loads files, saves files and lets you edit them in between. That\u2019s a hell lot more functionality than Bill Gates and Paul Allen had when they wrote a BASIC interpreter for the Altair. If you find something you\u2019re happy with, just stick with it but don\u2019t start arguing. It isn\u2019t worth your time.<\/p>\n<p>Don\u2019t feed the trolls. When it comes to software, don\u2019t fall into the old FreeBSD vs. Linux vs. Windows vs. mum cliche. Instead, talk about your code. Let\u2019s look at your problem-solving skills. Let\u2019s be pragmatic here.<\/p>\n<blockquote>\n<p>Talk is cheap. Show me the code. - <a rel=\"external\" href=\"https:\/\/lkml.org\/lkml\/2000\/8\/25\/132\">Linus Torvalds<\/a><\/p>\n<\/blockquote>\n<p>I don\u2019t care which programming language you are using. Java? Fine. Visual Basic? Great! Scala, Cobol, PHP, C++? All fine. Write in Assembler or lolcode. Don\u2019t moan about the fact that language X is missing feature Y. Write a library or use something different. Stop saying JavaScript is a toy language. It just doesn\u2019t fit your needs. Instead, show me your Lisp adventure game. Write an interpreter for Brainfuck. Do something. Move things.<\/p>\n<p>Concerning PHP, <a rel=\"external\" href=\"https:\/\/news.ycombinator.com\/item?id=2282523\">nir wrote on Hacker News<\/a>:<\/p>\n<blockquote>\n<p>Any idiot can write a snarky comment about PHP. Very few get to write code that has anywhere near the impact it had.<\/p>\n<\/blockquote>\n<p>Will you fall off your chair when I admit that I <em>like<\/em> the PHP syntax?\nOK, it has its rough edges (do we really need the $ sign?) but what\u2019s\nmore important is how much I can get done with it. PHP was my long time\ngo-to language for off the hook, one time scripts. It looks a bit ugly\nbut it runs on any server and comes with an enormous amount of built-in\nfunctionality. It\u2019s great for rapid prototyping and gluing things together.\nIn fact, when you write a piece of software, what you should strive for is to produce <em>quite good<\/em> software and what you really need to accomplish is <em>good enough<\/em> software to make your users happy.<\/p>\n<p>Zed A. Shaw puts it quite nicely in the afterword to <a rel=\"external\" href=\"https:\/\/learnpythonthehardway.org\/\">Learn Python the hard way<\/a><\/p>\n<blockquote>\n<p>I have been programming for a very long time. So long that it is incredibly boring to me. At the time that I wrote this book I knew about 20 programming languages and could learn new ones in about a day to a week depending on how weird they were. Eventually though this just became boring and couldn\u2019t hold my interest. What I discovered after this journey of learning was that the languages didn\u2019t matter, it was what you did with them. Actually, I always knew that, but I\u2019d get distracted by the languages and forget it periodically. The programming language you learn and use does not matter. Do not get sucked into the religion surrounding programming languages as that will only blind you to their real purpose of being your tool for doing interesting things.<\/p>\n<\/blockquote>\n<p>Don\u2019t get emotional for any tool you use. An iPhone - I\u2019m sorry to disappoint you - is just a phone. No magic. No \u201cthink different\u201d. \u201cBut it\u2019s evil!\u201d, the ether says, \u201cit\u2019s not open source\u201d. Well, Android just exists because Google needed to rapidly develop a mobile platform. It\u2019s simply part of their business. There is no moral behind that. Google is a yet another company just like Microsoft or Apple.<\/p>\n<p>My MacBook serves me as a solid tool, but if something \u201cbetter\u201d comes around, I will happily kick it out. I\u2019ve ditched Firefox after five years just because Chrome is faster and I will get rid of Chrome when I find a worthy successor.\nVim is <em>quite good<\/em> in my opinion but if there\u2019s a faster way to do things I\u2019m not afraid to dump it. Instead get your hands dirty and fix the problems or craft something new.<\/p>\n"},{"title":"Are You a Programmer?","pubDate":"Thu, 20 Oct 2011 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2011\/are-you-a-programmer\/","guid":"https:\/\/endler.dev\/2011\/are-you-a-programmer\/","description":"<p>My geography teacher once told the story of her first lecture at University.\nAs an introduction, her professor asked the class to draw\na map of Germany without any help and as accurate as possible. To her surprise, she was not\nable to fill the map with much detail. Even the shape of the country was a bit vague.<\/p>\n<p>She had seen thousands of images of Germany (her mother country) but\nwasn\u2019t able to reproduce it from her blurry memory. She would have to look it up.<\/p>\n<p>Doesn\u2019t this sound familiar? We rely on machines to manage large portions\nof our knowledge. There\u2019s <a href=\"https:\/\/endler.dev\/2011\/on-hard-work\/\">hard work<\/a> involved to learn something by heart.<\/p>\n<p>Here is a similar test for programmers:<\/p>\n<blockquote>\n<p>Using a programming language of your choice, write a correct sorting\nalgorithm with an average runtime complexity of O(n*log n) (Heapsort,\nQuicksort, Bucketsort, you name it) on a piece of paper without the help of any\nexternal tools.<\/p>\n<\/blockquote>\n<p>And by <em>correct<\/em> I mean it must be free of bugs without any modifications when you type it in.<\/p>\n<p>You would be surprised by the large percentage of professional software\nengineers who <a rel=\"external\" href=\"https:\/\/blog.codinghorror.com\/why-cant-programmers-program\/\">can\u2019t pull this off<\/a>.<\/p>\n<p>Some might argue that knowledge about details of programming language\nsyntax is unimportant: \u201cWhy learn all the little nitpicks when you know\nhow to use a search engine? Why start with a clean slate when you can easily\ncopy, paste and modify an example from a tutorial?\nEvery few years\/months I have to completely relearn the syntax for a different language anyway.\u201d<\/p>\n<p>But that is a myth. If you know only\none programming language <strong>really<\/strong> well - even if it is something\noutdated like Fortran or COBOL - you could easily earn a fortune with\nthat knowledge. Suppose you started with C in 1975. You could still\nuse the same syntax today - almost four decades later.\nSame for text editors. Emacs and Vim are both decades\nold. They are battle-hardened. I don\u2019t care which one you prefer, but you\nwill spend a large part of your life with your tools so invest the time to master them.<\/p>\n<p>As a side note, it appears that very few people strive for perfection in anything they do.\nThey happily settle for \u201cgood enough\u201d. This can have many different reasons, and I\u2019m not\nblaming anybody for not doing his homework but maybe I\u2019m not alone with\nthat observation.<\/p>\n<p>If you don\u2019t know how to use your tools without a manual, you are a lousy craftsman.\nIf you need a dictionary to write a simple letter, you will have a hard\ntime becoming a writer because it would already be challenging for you to form elegant, fluent\nsentences \u2014 let alone engaging and original stories.\nI don\u2019t want to read these books.<\/p>\n<p>What makes a programmer?<\/p>\n<ul>\n<li>She has at least one programming language she knows inside out.<\/li>\n<li>She can implement standard algorithms (i.e. for sorting, searching)\nand data-structures (i.e. trees, linked lists) which are robust and\nreasonably fast on the fly.<\/li>\n<li>She has at least a basic understanding of complexity theory and\nprogramming concepts like recursion and pointers.<\/li>\n<\/ul>\n<p>But, to be a good programmer, you should<\/p>\n<ul>\n<li>Be able to code in at least two fundamentally different programming\nparadigms (i.e. declarative, functional).<\/li>\n<li>Have experience with big software architectures.<\/li>\n<li>Be familiar with your programming environment like the operating system and a sophisticated text editor of your choice. Preferably one, that is\neasily extendable.<\/li>\n<\/ul>\n<p>And that is just the tip of the iceberg.\n\u201cThere\u2019s too much to learn!\u201d, I hear some of you say.\nStart slowly.\nYou need only three commands to start with Vim: <code>i<\/code>, <code>ESC<\/code>, <code>:wq<\/code>.\nThat\u2019s enough for day one.<\/p>\n<p>I realize that most of these essentials won\u2019t be taught during lectures.\nYou have to learn a vast portion on your own.\nBut let\u2019s face it: If you don\u2019t know this stuff, you are <em>not<\/em> a programmer, you\u2019re a freshman.<\/p>\n"},{"title":"On Hard Work","pubDate":"Thu, 13 Oct 2011 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2011\/on-hard-work\/","guid":"https:\/\/endler.dev\/2011\/on-hard-work\/","description":"<p>Great people get shaped by their achievements<\/p>\n<ul>\n<li>There\u2019s Thomas Edison who developed countless prototypes before selling a single light bulb.<\/li>\n<li>The unemployed Joanne K. Rowling writing Harry Potter in a Cafe while caring for her child.<\/li>\n<li>Steve Wozniak creating the first personal computer in his spare time while working at HP.<\/li>\n<\/ul>\n<p>What do they have in common?<\/p>\n<p>They all lived through frustration and contempt but still reached their goals, even though the chances for success were\nlow. These people are stemming their strong will from an intrinsic curiosity.<\/p>\n<h2 id=\"dedication\"><a class=\"anchor\" href=\"#dedication\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Dedication<\/h2>\n<p>Sure, I love what I do. I want to be a programmer for the rest of my life, but sometimes it seems simply too hard to finish a project.\nI get scared by the big picture and fear that I won\u2019t finish on time. What I need is a different mindset.<\/p>\n<p>Dhanji R. Prasanna, a former Google Wave team member <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20150717074857\/https:\/\/rethrick.com\/p\/mmm\/\">made this observation<\/a><\/p>\n<blockquote>\n<p>And this is the essential broader point\u2013as a programmer you must have a series of wins, every single day. It is the Deus Ex Machina of hacker success. It is what makes you eager for the next feature, and the next after that.<\/p>\n<\/blockquote>\n<p>While Google Wave has not been commercially successful, it sure was a\ntechnical breakthrough \u2014 and it was a drag to push it out into public.\nWe always have to see our goal right in front of us, as we take a billion baby steps to reach it.\nThis is true for any profession. Winners never give up.<\/p>\n<h2 id=\"direction\"><a class=\"anchor\" href=\"#direction\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Direction<\/h2>\n<p>Today it is easier to accomplish something meaningful than ever before.<\/p>\n<p>If you are reading this, you have access to a powerful instrument \u2014 a\ncomputer with an Internet connection. We live in a time where a single\nperson can accomplish miracles without hard physical labor.\nA time where billions of people can grow a business from their desk, get famous in minutes,\npublish books in seconds and have instant access to large amounts of\ndata. The most potent development over the last 100\nyears has been the reduction of communication costs. Transferring a bit of\ninformation to the other end of the world is virtually free and takes\nfractions of a second. While proper education was a privilege of a lucky few\nwell into the 20th century, learning new things is now mostly a question of\nwill.<\/p>\n<p>Nevertheless, learning is still a tedious task,\nrequiring patience and determination.\nAs the amount of information has increased, so have the ways of distraction.\nLosing focus is just a click away.<\/p>\n<h2 id=\"devotion\"><a class=\"anchor\" href=\"#devotion\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Devotion<\/h2>\n<p>Everybody can start something. Few will finish anything.\nThat\u2019s because getting things done is hard, even if you love what\nyou\u2019re doing. (Watch the beginnings of <a rel=\"external\" href=\"https:\/\/www.amazon.de\/gp\/product\/B08QDFDRVY?ie=UTF8&amp;tag=matthiasendle-21&amp;camp=1638&amp;linkCode=xm2&amp;creativeASIN=B08QDFDRVY\"><em>There Will Be Blood<\/em><\/a> and <a rel=\"external\" href=\"https:\/\/www.amazon.de\/gp\/product\/B08D5H2QTY\/ref=as_li_tl?ie=UTF8&amp;tag=matthiasendle-21&amp;camp=1638&amp;creative=6742&amp;linkCode=as2&amp;creativeASIN=B08D5H2QTY&amp;linkId=5dc5fa7545b60138290abe114d7c527ehttps:\/\/www.amazon.de\/gp\/product\/B08D5H2QTY\/ref=as_li_tl?ie=UTF8&amp;tag=matthiasendle-21&amp;camp=1638&amp;creative=6742&amp;linkCode=as2&amp;creativeASIN=B08D5H2QTY&amp;linkId=5dc5fa7545b60138290abe114d7c527e\"><em>Primer<\/em><\/a> for a\ndefinition of <em>hard work<\/em>.)<\/p>\n<p>No matter what they tell you, achieving anything sustainable means hustling. It means making\nsacrifices. It means pushing through.\nIt means selling something even though it isn\u2019t perfect. Your beautiful project might turn into an ugly groundhog in\nthe end. Put makeup on it and get it out the door.<\/p>\n<p>On a report about <a rel=\"external\" href=\"https:\/\/www.bluesnews.com\/abrash\/chap70.shtml\">Quake\u2019s 3D-Engine<\/a>, developer Michael Abrash says:<\/p>\n<blockquote>\n<p>By the end of a project, the design is carved in stone, and most of the work involves fixing bugs, or trying to figure out how to shoehorn in yet another feature that was never planned for in the original design. All that is a lot less fun than starting a project, and often very hard work\u2013but it has to be done before the project can ship. As a former manager of mine liked to say, \u201cAfter you finish the first 90% of a project, you have to finish the other 90%.\u201d It\u2019s that second 90% that\u2019s the key to success.<\/p>\n<\/blockquote>\n<blockquote>\n<p>A lot of programmers get to that second 90%, get tired and bored and frustrated, and change jobs, or lose focus, or find excuses to procrastinate. There are a million ways not to finish a project, but there\u2019s only one way to finish: Put your head down and grind it out until it\u2019s done. Do that, and I promise you the programming world will be yours.<\/p>\n<\/blockquote>\n<p>That last part has influenced me a lot.\nThe dedication, the urgency to reach your aims must come from within you.\nIt\u2019s your raw inner voice speaking \u2014 don\u2019t let it fade away.\nAnd when you are close to giving up, stop thinking so hard. Just try to\npush forward and make a tiny step in the right direction.\nShip it!<\/p>\n"},{"title":"Overkill \u2013 Java as a First Programming Language","pubDate":"Fri, 12 Feb 2010 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2010\/overkill-java-as-a-first-programming-language\/","guid":"https:\/\/endler.dev\/2010\/overkill-java-as-a-first-programming-language\/","description":"<p>I recently talked to a student in my neighborhood about his first programming\nexperiences. They started learning <em>Java<\/em> at school, and it soon turned out to\nbe horrible.<\/p>\n<p>A lot of us learned to code in languages like <em>BASIC<\/em> or <em>Pascal<\/em>. There was no\nobject orientation, no sophisticated file I\/O and almost no modularization\u2026\nand it was great. In <em>BASIC<\/em> you could just write<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span>PRINT<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">HELLO WORLD<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><\/span><\/code><\/pre>\n<p>and you were done. This was actually a running program solving a basic and\nreoccurring problem: Output some text on a screen.<\/p>\n<p>If you wanted to do the same thing in <em>Java<\/em> you just write:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"java\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">public<\/span><span class=\"z-l-9 z-d-9\"> class<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> Main<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">  public<\/span><span class=\"z-l-9 z-d-9\"> static<\/span><span class=\"z-l-9 z-d-9\"> void<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">String<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> args<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    System<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>out<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello, world!<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">  }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>Do you see how much knowledge about programming you must have to achieve the\neasiest task one could think of? Describing the program to a novice programmer\nmay sound like this:<\/p>\n<blockquote>\n<p>Create a Main class containing a main-method returning void expecting a string\narray as a single argument using the <code>println<\/code> method of the <code>out<\/code> object of\nclass <code>PrintStream<\/code> passing your text as a single argument.<\/p>\n<\/blockquote>\n<p>\u2014 please just don\u2019t forget your brackets. This way your first programming\nhours are guaranteed to be great fun.<\/p>\n<p>OK. So what are the alternatives? I admit that nobody wants to write <em>BASIC<\/em>\nanymore because of its lack of a sophisticated standard library for graphics\n(<em>Java<\/em> doesn\u2019t have one either) and its weak scalability. The language has to\nbe clean and straightforward. It should be fast enough for numerical tasks but\nnot as wordy as the rigid C-type bracket languages (sorry C++ guys). It should\nhave a smooth learning curve and provide direct feedback (compiled languages\noften suck at that point). It should encourage clean code and reward best\npractices. One language that provides all that is <em><em>Python<\/em><\/em>.<\/p>\n<p>And <em>Python<\/em> has even more: hundreds of libraries that help you with almost\neverything, good integration into common IDEs (PyDev in Eclipse, IDLE\u2026), a\nprecise and elegant syntax.<\/p>\n<p>Here is our program from above written in <em>Python<\/em>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">print<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">Hello World<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span><\/code><\/pre>\n<p>There\u2019s no need to know about object orientation, scopes and function arguments\nat this point. No householding or book-keeping. Yes, it\u2019s an interpreted\nlanguage, but that\u2019s not a deal breaker for beginners.<\/p>\n<p>If you aren\u2019t convinced yet, printing and formatting text output in <em>Java<\/em> is\nrelatively easy for an advanced programmer but the gruesome stuff begins with\nfile input:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"java\"><span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">import<\/span><span> java<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>io<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>BufferedReader<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">import<\/span><span> java<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>io<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>FileNotFoundException<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">import<\/span><span> java<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>io<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>FileReader<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">import<\/span><span> java<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>io<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>IOException<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">public<\/span><span class=\"z-l-9 z-d-9\"> class<\/span><span class=\"z-l-13 z-l-i z-d-15 z-d-i\"> fileIO<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">    public<\/span><span class=\"z-l-9 z-d-9\"> static<\/span><span class=\"z-l-9 z-d-9\"> void<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> main<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">String<\/span><span class=\"z-l-8 z-d-4\">[<\/span><span class=\"z-l-8 z-d-4\">]<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> args<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        String<\/span><span> filename<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-5 z-d-7\"> &quot;<\/span><span class=\"z-l-5 z-d-7\">test.txt<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">,<\/span><span> line<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">        try<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            BufferedReader<\/span><span> myFile<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">                new<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> BufferedReader<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-9 z-d-9\">new<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\"> FileReader<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>filename<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-9\">            while<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span> line <\/span><span class=\"z-l-2 z-d-5\">=<\/span><span> myFile<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">readLine<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-2 z-d-5\"> !=<\/span><span class=\"z-l-10 z-d-12\"> null<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>                System<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span>out<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">println<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>line<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">            }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><span class=\"z-l-9 z-d-9\"> catch<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">FileNotFoundException<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>            e<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">printStackTrace<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><span class=\"z-l-9 z-d-9\"> catch<\/span><span class=\"z-l-8 z-d-4\"> (<\/span><span class=\"z-l-9 z-d-9\">IOException<\/span><span class=\"z-l-14 z-l-i z-d-10 z-d-i\"> e<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\"> {<\/span><\/span>\n<span class=\"giallo-l\"><span>            e<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-l-i z-d-2 z-d-i\">printStackTrace<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span class=\"z-l-8 z-d-4\">;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-4\">}<\/span><\/span><\/code><\/pre>\n<p>I hear you say: \u201cDude, file I\/O is pretty complex. It\u2019s just the way it is\u201d.\nThat\u2019s true\u2026 <em>internally<\/em> . But a beginner should get an easy interface.\n<em>Python<\/em> shows how it\u2019s done:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span>file<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span class=\"z-l-16 z-l-i z-d-16 z-d-i\"> open<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-5 z-d-7\">test.txt<\/span><span class=\"z-l-5 z-d-7\">&quot;<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span>text<\/span><span class=\"z-l-2 z-d-5\"> =<\/span><span> file<\/span><span class=\"z-l-8 z-d-4\">.<\/span><span class=\"z-l-3 z-d-2\">read<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span class=\"z-l-8 z-d-4\">)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-16 z-l-i z-d-16 z-d-i\">print<\/span><span class=\"z-l-8 z-d-4\">(<\/span><span>text<\/span><span class=\"z-l-8 z-d-4\">)<\/span><span>;<\/span><\/span><\/code><\/pre>\n<p>The code goes hand in hand with the natural understanding of how the process\nworks: \u201cThe computer opens a file, reads it and prints it\u201d. Even a five-year-old\nkid can understand that. Nobody would start to explain: \u201cBefore you can read a\nfile you need a BufferedReader that works on a FileReader\u2026\u201d even if this is\nprecisely how it works <em>internally<\/em>. You want to explain the big picture at\nfirst. The elementary principles of teaching a computer how to do useful stuff.\nOtherwise, you will start frustrating beginners and fool them into thinking that\nthey are not bright enough for programming. Programming is fun and starting with\nit is the most crucial step. So don\u2019t spoil that experience with layers of\nunneeded abstraction.<\/p>\n<h2 id=\"links\"><a class=\"anchor\" href=\"#links\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Links<\/h2>\n<ul>\n<li>Response to this article (almost ten years later): <a rel=\"external\" href=\"https:\/\/dev.to\/dzh\/why-kotlin-may-be-better-than-java-and-python-as-the-first-programming-language-37d5\">Why Kotlin may be better than Java and Python as the first programming language<\/a><\/li>\n<\/ul>\n"},{"title":"How to Sort a Vector or a List in C++ Using STL","pubDate":"Wed, 27 Jan 2010 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2010\/howto-sort-a-vector-or-a-list-in-c-using-stl\/","guid":"https:\/\/endler.dev\/2010\/howto-sort-a-vector-or-a-list-in-c-using-stl\/","description":"<p>A little code snippet that people need very often.<\/p>"},{"title":"Why I Love Text Files","pubDate":"Sun, 10 Jan 2010 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2010\/why-i-love-text-files\/","guid":"https:\/\/endler.dev\/2010\/why-i-love-text-files\/","description":"<p>Text files are the single most important way we can communicate with computers. It\u2019s no coincidence that they are also the most vital way to interact with other human beings. What we can achieve with text files is invaluable: Write it once and refer to it whenever you want to get the message across in the future. Write a program (it\u2019s just text), save it and let the machine execute it whenever you like. Write another text file which contains the rules for the execution of your program and the computer runs your application exactly as you specified (<code>cron<\/code> files do that on Unix).<\/p>\n<p>Text files can be structured in any way you can imagine. Some flavours are <a rel=\"external\" href=\"https:\/\/www.json.org\/\">JSON<\/a>, <a rel=\"external\" href=\"https:\/\/daringfireball.net\/projects\/markdown\/\">Markdown<\/a> and <a rel=\"external\" href=\"https:\/\/www.w3.org\/Graphics\/SVG\/\">SVG<\/a>. It\u2019s all just text. There exist a billion of programs and algorithms to access, modify and distribute text files. You can write them with <em>Emacs<\/em>, print them on a terminal, pipe them through <em>sed<\/em> and send them via email to a friend who publishes them on the web. Because text files are so important we have good support for them on any computing system. On Unix, everything is a file and <em>HTML<\/em> is just structured text. It\u2019s a simple and powerful tool to make a contribution to society that outlasts our lives.<\/p>\n<p>I have a single text file in my mac dock bar which is called <code>TODO.txt<\/code>. I open it every day, and after years of experimenting with different task management apps from simple command line tools to sophisticated online information storage systems, I always come back to plain text files. And the explanation is simple: If humanity will still be around a thousand years from now, chances are that plain text files are one of the very few file formats that will still be readable.<\/p>\n<p>Text files are an incremental part of how we can modify our environment without even leaving our desk. They have no overhead and can contain a single thought or the complete knowledge of our species. Distributing textual information is so vital for us that we permanently develop faster distribution networks \u2013 the fastest by now being the internet.<\/p>\n<p>On the web, you have instant access to a virtually endless amount of information and data distributed as plain text files. New web services made accessing the data even easier, offering <code>APIs<\/code> and <code>feeds<\/code>. You can pull down the data from their servers and make statistics with a programming language of your choice. As you may have noticed, my affinity to text files partially comes from my programming background. As <a rel=\"external\" href=\"http:\/\/matt.might.net\/articles\/console-hacks-exploiting-frequency\/\">Matt Might<\/a> correctly points out on his blog:<\/p>\n<blockquote>\n<p>The continued dominance of the command line among experts is a testament to the power of linguistic abstraction: when it comes to computing, a word is worth a thousand pictures.<\/p>\n<\/blockquote>\n<p>Whenever you like a text on the web, just link to it and create a wonderful chain of ideas. Want to read it later or recommend it to a friend? Just share the text or print it on paper. The fact that we all take such things for granted is a testament for the power of text files and their importance for the <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Information_Age\">information age<\/a>.<\/p>\n"},{"title":"Running Legacy Code","pubDate":"Sun, 08 Nov 2009 00:00:00 +0000","author":"matthias@endler.dev (Matthias Endler)","link":"https:\/\/endler.dev\/2009\/running-legacy-code\/","guid":"https:\/\/endler.dev\/2009\/running-legacy-code\/","description":"<p>This short article deals with a severe problem in software development: bit rot.\nWhen switching to a new platform (for instance from Windows XP to Windows Vista\/7), the programmers need to make sure that old bits of code run flawlessly. There are several ways to achieve this goal that will be discussed in the next paragraphs:<\/p>\n<h2 id=\"porting-the-code\"><a class=\"anchor\" href=\"#porting-the-code\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Porting the Code<\/h2>\n<p>This is generally considered a hard path to follow. For non-trivial legacy code-blocks, chances are high that they contain side-effects and hacks to make them work in different environments. Porting code means replacing parts of the program that use functions and methods that don\u2019t exist anymore with new ones which make use of the modern libraries\u00a0 and routines of the new platform. The significant advantages are maintainable software and sometimes faster running programs. But it may be needed to hack the new platform libraries in order to preserve the whole functionality of an old application. When changing an algorithm inside legacy code, the ported version may become unstable. Thus there may be better ways of maintaining obsolete code today.<\/p>\n<h2 id=\"emulators\"><a class=\"anchor\" href=\"#emulators\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Emulators<\/h2>\n<p>Emulators work much the same like porting the code. You replace old function calls with new ones to make everything work again. <br \/>However you don\u2019t alter the old codebase itself (because you may not have the source code available) but you create a new compatibility layer that \u201ctranslates\u201d the communication between the underlying operating system and software (our new platform) and our old software. Emulation can also be very fast and run stable for many years but writing an emulator can be even harder than porting the code because an educational guess may be needed to figure out how the program works internally. Additionally, the emulator itself may become obsolete in the future and might eventually\u00a0 be replaced by a new one.<\/p>\n<h2 id=\"virtual-machines\"><a class=\"anchor\" href=\"#virtual-machines\">\n    <svg height=\"22\" viewbox=\"0 0 24 24\" width=\"22\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n        <path d=\"M0 0h24v24H0z\" fill=\"none\"><\/path>\n        <path d=\"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z\"><\/path>\n    <\/svg>\n<\/a>Virtual Machines<\/h2>\n<p>During the last years, a new approach was gaining popularity. The idea is simple: Don\u2019t touch anything. Take the whole platform and copy it in order to run old software. The old software runs on top of the old operating system within a virtual machine that runs on the new platform.<\/p>\n<p>From a sane software developers view, this method is ridiculous. A lot of resources are wasted along the way. The system is busier switching contexts from an old platform to the new one and back than running the actual legacy program. However, with cheap and capable hardware everywhere this idea gets more and more interesting. As <a rel=\"external\" href=\"https:\/\/blog.codinghorror.com\/hardware-is-cheap-programmers-are-expensive\/\">Steve Atwood coined it<\/a>:<\/p>\n<blockquote>\n<p>Always try to spend your way out of a performance problem first by throwing faster hardware at it.<\/p>\n<\/blockquote>\n<p>And he\u2019s right. The Microsoft developers did the same on their new NT 6.0 platform (Vista, Windows 7, Windows Server 2008\u2026): Windows XP is running on a virtual machine. This way everything behaves just like one would run the software on the old system. And by optimizing the performance bottlenecks (input\/output, context switches), one gets a fast and stable, easy to maintain product.<\/p>\n<p>Every method has its major advantages and disadvantages. It\u2019s on the developer to select the appropriate strategy.<\/p>\n"}]}}