<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Sebastian Wilzbach</title>
    <description>A blog covering science, technology and more from Sebastian Wilzbach.
</description>
    <link>https://seb.wilzba.ch/</link>
    <atom:link href="https://seb.wilzba.ch/rss.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 18 Dec 2023 00:13:39 +0100</pubDate>
    <lastBuildDate>Mon, 18 Dec 2023 00:13:39 +0100</lastBuildDate>
    <generator>Jekyll v3.9.2</generator>
    
      <item>
        <title>The Expressive C++17 Coding Challenge in D</title>
        <description>&lt;p&gt;You might have seen that I have been coding a lot in D lately and as a few weeks ago there was the
&lt;a href=&quot;https://www.fluentcpp.com/2017/09/25/expressive-cpp17-coding-challenge/&quot;&gt;Expressive C++17 Coding Challenge&lt;/a&gt;
with its &lt;a href=&quot;http://www.bfilipek.com/2017/10/expressive-cpp17-results.html&quot;&gt;winner&lt;/a&gt; in &lt;a href=&quot;https://www.fluentcpp.com/2017/10/23/results-expressive-cpp17-coding-challenge/&quot;&gt;C++&lt;/a&gt; now being public, I thought this is an excellent opportunity to show why I like D so much.&lt;/p&gt;

&lt;h2 id=&quot;the-requirements&quot;&gt;The requirements&lt;/h2&gt;

&lt;p&gt;Let me first recap the requirements of this challenge:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This command line tool should accept the following arguments:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;the filename of a CSV file,&lt;/li&gt;
    &lt;li&gt;the name of the column to overwrite in that file,&lt;/li&gt;
    &lt;li&gt;the string that will be used as a replacement for that column,&lt;/li&gt;
    &lt;li&gt;the filename where the output will be written.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./program &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;example-input&quot;&gt;Example input&lt;/h3&gt;

&lt;p&gt;Given this simple CSV as input&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csv&quot; data-lang=&quot;csv&quot;&gt;name,surname,city,country
Adam,Jones,Manchester,UK
Joe,Doe,Cracow,Poland
Michael,Smith,Paris,France
Alex,McNeil,Gdynia,Poland&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;the program called with:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./program input.csv city London output.csv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;should write:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csv&quot; data-lang=&quot;csv&quot;&gt;name,surname,city,country
Adam,Jones,London,UK
Joe,Doe,London,Poland
Michael,Smith,London,France
Alex,McNeil,London,Poland&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Sounds fairly trivial, right?
Please have a short look first at the “best” &lt;a href=&quot;http://coliru.stacked-crooked.com/a/70f762ee7f9c2606&quot;&gt;C++&lt;/a&gt; and &lt;a href=&quot;https://gist.github.com/steveklabnik/ad0a33acc82e21ca3f763e4278ad31a5#file-main-rs-L36&quot;&gt;Rust&lt;/a&gt; solutions before you look at the D solution.&lt;/p&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The solution&lt;/h2&gt;

&lt;p&gt;Okay, so here’s one way to solve this in D.
If you are scared at the moment - don’t worry. I will explain it line by line below.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;usr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rdmd&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid args\n&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;./tool &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;columName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;byLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countUntil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid column. Valid columns: %(%s, %)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writefln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%-(%s,%)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dropOne&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// iterate with an (index, value) tuple&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;joiner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;so-how-does-this-compare-to-c17-and-rust&quot;&gt;So how does this compare to C++17 and Rust?&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Language&lt;/th&gt;
      &lt;th&gt;LoC&lt;/th&gt;
      &lt;th&gt;Words&lt;/th&gt;
      &lt;th&gt;Characters&lt;/th&gt;
      &lt;th&gt;Time&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;C++&lt;/td&gt;
      &lt;td&gt;125&lt;/td&gt;
      &lt;td&gt;365&lt;/td&gt;
      &lt;td&gt;2724&lt;/td&gt;
      &lt;td&gt;15s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Rust&lt;/td&gt;
      &lt;td&gt;83&lt;/td&gt;
      &lt;td&gt;231&lt;/td&gt;
      &lt;td&gt;1703&lt;/td&gt;
      &lt;td&gt;6s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;D&lt;/td&gt;
      &lt;td&gt;17&lt;/td&gt;
      &lt;td&gt;84&lt;/td&gt;
      &lt;td&gt;710&lt;/td&gt;
      &lt;td&gt;12s&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;D (slightly tweaked)&lt;/td&gt;
      &lt;td&gt;25&lt;/td&gt;
      &lt;td&gt;98&lt;/td&gt;
      &lt;td&gt;794&lt;/td&gt;
      &lt;td&gt;5s (4s with LTO)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;CSV parsing &lt;a href=&quot;http://thomasburette.com/blog/2014/05/25/so-you-want-to-write-your-own-CSV-code/&quot;&gt;is a lot more complicated than splitting by a delimiter&lt;/a&gt; and
in the real world &lt;a href=&quot;http://www.secretgeek.net/csv_trouble&quot;&gt;shouldn’t roll your own CSV parser&lt;/a&gt;.
However, this article aims to analyze the &lt;em&gt;expressive power&lt;/em&gt; of D in comparison to C++ and Rust by focusing on common example.
Later in this article I will also present a solution with only 12 lines
by using D’s built-in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.csv&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;I used the following D code to generate a simple CSV file with 10 fields and 10m lines:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rdmd --eval=&apos;10.iota.map!(a =&amp;gt; &quot;field&quot;.text(a)).join(&quot;,&quot;)
.repeat(10_000_000).joiner(newline).writeln&apos; &amp;gt; input_big.csv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The resulting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input_big.csv&lt;/code&gt; has a size of 668M.&lt;/p&gt;

&lt;p&gt;LTO stands for &lt;em&gt;link-time optimization&lt;/em&gt; and I included it to show that we can always tweak the performance with a few easy tricks. See the benchmarking section for more details.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Aren’t you concered that Rust is faster in this benchmark?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not at all. The challenge was to write &lt;em&gt;expressive&lt;/em&gt; code.
When performance really matters D provides the same tools as C or C++ and D even supports native interoperability with C and most of C++.&lt;/p&gt;

&lt;p&gt;In this example, however, I/O is the bottleneck and D provides a few convenience features like using locked file handles, s.t. accessing files is thread-safe by default, or supporting unicode input.
However, it’s easy to opt out of such productivity features and use other tricks like &lt;a href=&quot;https://dlang.org/phobos/std_mmfile.html&quot;&gt;memory mapped files&lt;/a&gt;.
For the interested readers I have attached a slightly optimized version at the end.&lt;/p&gt;

&lt;p&gt;In addition, if you are interested in performance,
Jon Degenhardt (member of eBay’s data science team),
has made an excellent &lt;a href=&quot;https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md&quot;&gt;performance benchmark&lt;/a&gt;
between eBay’s tsv-utils and existing CSV/TSV processing tools written in C, Go, and Rust.&lt;/p&gt;

&lt;h3 id=&quot;1-what-is-usrbinenv-rdmd&quot;&gt;1) What is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#!/usr/bin/env rdmd&lt;/code&gt;?&lt;/h3&gt;

&lt;p&gt;One of the favorite aspects of D is that it has a blazingly fast compiler. Period. I can compile the entire D front-end of the compiler (~200 kLoC) in less than two seconds or the entire standard library with lots and lots of compile-time function evaluation and templates and &amp;gt; 300 kLoC in 5 seconds &lt;em&gt;from scratch without any cache or incremental compilation&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This means that the compiler is almost as fast as an interpreter and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rdmd&lt;/code&gt; is the tool that allows handy usage as “pseudo-interpreted” language. You can invoke &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rdmd&lt;/code&gt; with any file and it will automatically figure out all required files based on your dependencies and pass them to the compiler.&lt;/p&gt;

&lt;p&gt;It’s very popular in the D community because for small scripts one doesn’t even notice that the program is compiled to real machine code under the hood.
Also if the shebang header is added and the file is executable, D scripts can be used as if they would be script files:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./main.d input.csv city London output.csv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2-so-you-import-a-bunch-of-libraries-what-do-they-do&quot;&gt;2) So you import a bunch of libraries. What do they do?&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import std.algorithm, std.exception, std.format, std.range, std.stdio;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In short &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.stdio&lt;/code&gt; is for input and output, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.range&lt;/code&gt; is about D’s magic streams called “ranges” and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.algorithm&lt;/code&gt; abstracts on top of them and provides generic interfaces for a lot of sophisticated algorithms.&lt;/p&gt;

&lt;p&gt;Moreover, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.exception&lt;/code&gt; offers methods for working with exceptions like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt; and finally &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.format&lt;/code&gt; bundles methods for string formatting.&lt;/p&gt;

&lt;p&gt;Don’t worry - the functionality imported from these modules will be explained soon.&lt;/p&gt;

&lt;h3 id=&quot;3-your-program-has-a-main-function-whats-so-special-about-it-compared-to-c-or-c&quot;&gt;3) Your program has a main function. What’s so special about it compared to C or C++?&lt;/h3&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;For starters, arrays in D have a length. Try:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Compared to C/C++ null-terminated strings and arrays, it won’t segfault.
It would just throw a nice Error:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;core.exception.RangeError@./main.d(10): Range violation
----------------
??:? _d_arrayboundsp [0x43b622]
prog.d:9 void main.foo(immutable(char)[][]) [0x43ac93]
prog.d:4 _Dmain [0x43ac67]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Oh so D performs automatic bounds-checking before accessing the memory.
Isn’t that expensive?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s almost negligible compared to the safety it buys, but D is a language for everyone, so the people who want to squeeze out the last cycles of their processor can do so by simply compiling with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-boundscheck=off&lt;/code&gt; (for obvious reasons this isn’t recommended).&lt;/p&gt;

&lt;p&gt;In D, strings are arrays too and there’s another nice property about D’s arrays. They are only a view on the actual memory and you don’t copy the array, but just the view of the memory (in D it’s called a slice).&lt;/p&gt;

&lt;p&gt;Consider this example:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bArr&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;..&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;$];&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bArr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// this is a vectorized operation&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [1, 4, 5]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;There many other things D has learned from C and C++.
Walter has recently written a great article on how D helps to &lt;a href=&quot;https://dlang.org/blog/2018/02/07/vanquish-forever-these-bugs-that-blasted-your-kingdom&quot;&gt;&lt;em&gt;vanquish forever these bugs that blasted your kingdom&lt;/em&gt;&lt;/a&gt; which I highly recommend if you have a C/C++ background.&lt;/p&gt;

&lt;h3 id=&quot;4-whats-up-with-this-enforce&quot;&gt;4) What’s up with this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt;?&lt;/h3&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid args.\n&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;./tool &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;I have never seen the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~&lt;/code&gt; operator before!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s the string concatenation (or more general array concatenation) operator.
How often have you encountered code like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a + b&lt;/code&gt; and needed to know the types
of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt; to know whether it’s a addition or concatenation?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Why don’t you use an if statement and terminate the program explicitly?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Invalid args.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tool &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That’s valid D too. D allows a lot of different programming styles, but this article
is intended to highlight a few specific &lt;em&gt;D styles&lt;/em&gt; like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://dlang.org/phobos/std_exception.html#enforce&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt;&lt;/a&gt; is a function defined in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.exception&lt;/code&gt; and throws an exception
if its first argument has a falsy value.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hmm, I looked at the &lt;a href=&quot;https://dlang.org/phobos/std_exception.html#enforce&quot;&gt;documentation&lt;/a&gt; and saw this monster. I thought it simply throws an exception?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Throwable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lazy&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;__LINE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I don’t have the time to fully dive into D’s syntax, but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt;
instructs the compiler infer the return type for you. This leads to the interesting
&lt;a href=&quot;https://wiki.dlang.org/Voldemort_types&quot;&gt;&lt;em&gt;Voldemort&lt;/em&gt; return types&lt;/a&gt; as they can’t be named by the user, but
that’s a good topic for another article.&lt;/p&gt;

&lt;p&gt;The next part looks a bit complicated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(E : Throwable = Exception, T)&lt;/code&gt;, but don’t worry yet.
It means that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt; is a template parameter which needs to inherit from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Throwable&lt;/code&gt; (the root of all exceptions),
and is by default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Exception&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt; is the template type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Wait. I just instantiated a template without specifying its template parameters?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, the D compiler does all the hard work for you.
The technical term is &lt;a href=&quot;https://dlang.org/spec/template.html#argument_deduction&quot;&gt;Implicit Function-Template Instantiation&lt;/a&gt; (IFTI).
Of course, we could have instructed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt; to throw a custom exception,
but more on template instantiation later.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alright. So this function takes a generic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt; and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msg&lt;/code&gt;, but a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy string msg&lt;/code&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; is a special keyword in D and tells the compiler to defer
the evaluation of an argument expression until is actually needed.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I don’t understand. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msg&lt;/code&gt; seems to be a string concatentation of two strings.
Isn’t this done &lt;em&gt;before&lt;/em&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt; is called?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;Invalid args.\n&quot; ~ &quot;./tool &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;No, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; is lazy and the string concatenation doesn’t happen at the caller site,
but can be requested explicitly by the callee.&lt;/p&gt;

&lt;p&gt;It gets a bit clearer if we look at the second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt; as there’s runtime work involved:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid column name. Valid are: %(%s, %)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;format&lt;/code&gt; and all the expensive work of formatting the error message is never done on the default path,
but only if an exception actually gets thrown.
Ignore the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%(%s, %)&lt;/code&gt; formatting string for a bit, it will be explained soon.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Ok, but how does that work?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In short: the compiler does a few smart lowerings for you and creates an anonymous lambda.
It’s more complicated in practice, and interested readers can learn more at &lt;a href=&quot;https://dlang.org/articles/lazy-evaluation.html&quot;&gt;Walter’s advanced article D’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For now I will use a simple trick to show what’s going on under the hood.
The &lt;a href=&quot;https://run.dlang.io/is/MxHkVF&quot;&gt;AST explorer at run.dlang.io&lt;/a&gt; allows us to peek at the
internal representation of a D source file in the compiler after all semantic processing has been done.
This means we can see that for the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt; the concatenation is even done at compile-time:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5L&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delegate&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[]()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid args\x0a./tool
&amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;onlineapp.d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4L&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;As mentioned this is a representation of the internal state of the compiler.
Hence, nice aliases like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;string&lt;/code&gt; which is an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias&lt;/code&gt;
for an array of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const(char)&lt;/code&gt; elements are resolved
and numeric types are serialized with their inferred type. Similarly, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x0a&lt;/code&gt;
is the hexadecimal representation of the new line character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\n&lt;/code&gt; and
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;delegate const(char)[]() =&amp;gt;&lt;/code&gt; is a lambda function without arguments that returns a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;string&lt;/code&gt;.
Of course, D has a shorthand syntax for lambda functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;() =&amp;gt; &quot;hello&quot;&lt;/code&gt;,
but the compiler internally expands this syntax sugar.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;But there’s more magic here. What’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__FILE__&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__LINE__&lt;/code&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;__LINE__&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Remember that D is a compiled language and accessing the stack isn’t as easy as
asking the interpreter nicely.
These two default arguments are automatically set by the compiler
with the file and line number of the caller.
This is important for logging or throwing exceptions like we have done here.&lt;/p&gt;

&lt;p&gt;So, an API author can simply say “Hey, I would like to know the line number of my caller.”
and doesn’t depend on the user hacking the replacements like its done in C/C++
with preprocessor macros:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#ifdef SPDLOG_DEBUG_ON
#define SPDLOG_DEBUG(logger, ...) logger-&amp;gt;debug(__VA_ARGS__)  &amp;lt;&amp;lt; &quot; (&quot; &amp;lt;&amp;lt; __FILE__ &amp;lt;&amp;lt; &quot; #&quot; &amp;lt;&amp;lt; __LINE__ &amp;lt;&amp;lt;&quot;)&quot;;
#else
#define SPDLOG_DEBUG(logger, ...)
#endif&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In fact, D doesn’t even have a preprocessor.&lt;/p&gt;

&lt;h3 id=&quot;5-auto-and-a-statically-typed-language&quot;&gt;5) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt; and a statically typed language&lt;/h3&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;columName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hmm, but what’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt;? I thought D has a static type system?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes D is statically typed, but the compiler is pretty smart, so we can let him do all the hard work for us. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt; is a filler word for the compiler that means “whatever the type of the assignment, use this as the type of this variable”.&lt;/p&gt;

&lt;h3 id=&quot;6-what-the-heck-is-ufcs&quot;&gt;6) What the heck is UFCS?&lt;/h3&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;byLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;One of the major features of D is the Unified Function Call Syntax (UFCS). In short, the compiler will look up a function in the current namespace if it’s not found as a member function of a type,
but let’s go through this step by step.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I looked at the &lt;a href=&quot;https://dlang.org/phobos/std_stdio.html#.File&quot;&gt;documentation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File&lt;/code&gt;&lt;/a&gt; and it has a method &lt;a href=&quot;https://dlang.org/phobos/std_stdio.html#.File.byLine&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byLine&lt;/code&gt;&lt;/a&gt;. So where’s the magic?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Have another look at &lt;a href=&quot;https://dlang.org/phobos/std_algorithm_iteration.html#.map&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt;&lt;/a&gt;, it’s located in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.algorithm&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay, wait. How does this work?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The compiler internally rewrites the expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File.byLine.map&lt;/code&gt; to the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;byLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Missing parenthesis are allowed too - after all the compiler knows that the symbol is a function.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay, but what’s up with this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!(a =&amp;gt; a.splitter(&quot;,&quot;)))&lt;/code&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; is similar to C++/Java’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&amp;gt;&lt;/code&gt; and allows to instantiate a template.
In this case it’s a lambda function of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a =&amp;gt; a.splitter(&quot;,&quot;)&lt;/code&gt;.
Notice that for &lt;a href=&quot;https://dlang.org/phobos/std_algorithm_iteration.html#splitter&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;splitter&lt;/code&gt;&lt;/a&gt; UFCS is used again and your brain might be more used to reading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;splitter(a, &quot;,&quot;)&lt;/code&gt; for now.&lt;/p&gt;

&lt;h3 id=&quot;7-ranges&quot;&gt;7) Ranges&lt;/h3&gt;

&lt;p&gt;Okay to recap, we have taken the input of a file by line, splitting every line by commas &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Wouldn’t this result in a lot of unnecessary allocation?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The short answer is: D uses “iterators on steroids” which are lazy and work is only done when explicitly requested. Usually range algorithms don’t even require any heap allocation as everything is done on the stack.&lt;/p&gt;

&lt;p&gt;For example, in the next line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.front&lt;/code&gt; returns the the first line though which &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;countUntil&lt;/code&gt; explicitly iterates:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countUntil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columnName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lines.front&lt;/code&gt; looks something like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;surname&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;city&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;country&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;countUntil&lt;/code&gt; will return the of the first match or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-1&lt;/code&gt; otherwise.
It’s a bit similar to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indexOf&lt;/code&gt; function known from e.g. JavaScript, but it accepts a template.
So we could have supplied a custom predicate function:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countUntil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endsWith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;8-stdformat-and-compile-time-checking-of-parameters&quot;&gt;8) std.format: and compile-time checking of parameters&lt;/h3&gt;

&lt;p&gt;The next lines are:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid column name. Valid are: %(%s, %)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writefln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%-(%s,%)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;I have never seen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writefln(&quot;%(%s, %)&quot;)&lt;/code&gt;. What happens here?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://dlang.org/phobos/std_stdio.html#.File.writefln&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writefln&lt;/code&gt;&lt;/a&gt; is just a handy wrapper around D’s &lt;a href=&quot;https://dlang.org/phobos/std_format.html#.format&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;format&lt;/code&gt;&lt;/a&gt; function.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;format&lt;/code&gt; itself provides a lot of options for serialization, but it’s very similar to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;printf&lt;/code&gt;, although it does provide a few goodies like the special syntax for arrays &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%(%s, %)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This syntax opens an array formatting “scope” by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%(&lt;/code&gt; and closes it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%)&lt;/code&gt;.
Within this array “scope” the elements should be formatted with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%s&lt;/code&gt; (their &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;string&lt;/code&gt; serialization)
and use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;, &lt;/code&gt; a delimiter between the element.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;%(%s, %)&quot;&lt;/code&gt; will quote the elements by default, which is useful in most cases, but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; can be used to avoid quoting.
However, as th &lt;em&gt;Expressive C++17 Coding Challenge&lt;/em&gt; has an expected output without quotes, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;%-(%s,%)&quot;&lt;/code&gt; is used to avoid quoting and concats the elements without a delimiter.
We can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rdmd&lt;/code&gt; to test this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; head -n1 input.csv | rdmd --loop=&apos;writefln(&quot;%-(%s|%)&quot;, line.splitter(&quot;,&quot;))&apos;
name|surname|city|country
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--loop&lt;/code&gt; is a simple wrapper around &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foreach (line; stdin.byLine) { … }&lt;/code&gt; and makes it even easier to use D in command-line pipes.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%( … %)&lt;/code&gt; a shorthand syntax that often comes in handy, but if you don’t like it there are many other ways to achieve the same result. For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;joiner&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;csv&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rdmd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;joiner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;|&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;surname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;country&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;Let’s get back to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enforce&lt;/code&gt;. How would such an error message look like?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;object.Exception@./main.d(9): Invalid column name. Valid are: &quot;name&quot;, &quot;surname&quot;, &quot;city&quot;, &quot;country&quot;
----------------
??:? pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x7a34b57e]
??:? pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x7a34b4f8]
??:? _Dmain [0x7a34b17f]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay, but isn’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;printf&lt;/code&gt; bad and unsafe? I heard that languages like Python are moving away from C-like formatting.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Python library can only realize that arguments and formatted string don’t fit when it’s called.
In D, the compiler knows the types of the arguments and if you pass the format string at compile-time, guess what, the format can be checked compile-time.
Try to compile a format string that tries to format strings as numbers:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;n&quot;&gt;writefln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The compiler will complain:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(3876): Error: static assert  &quot;Incorrect format specifier for range: %d&quot;
onlineapp.d(4):        instantiated from here: writefln!(&quot;%d&quot;, string)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Wow, that’s really cool. How does this work?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;D has another unique feature: compile-time function evaluation (CTFE) that allows to execute almost any function at compile-time.
All that happens is that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writefln&lt;/code&gt; is instantiated at compile-time with the string as template argument and then it calls the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;format&lt;/code&gt; function that would normally be called at run-time with the known format string.
The coolest part about this is that there’s no special casing in the compiler and everything is just a few lines of library code.&lt;/p&gt;

&lt;h3 id=&quot;9-lets-parse-the-file&quot;&gt;9) Let’s parse the file&lt;/h3&gt;

&lt;p&gt;Now that we have found the index of the replacement column, have opened the output csv file and have already written the header to it, all that’s left is to go over the input CSV file line by line and replace the specific CSV column with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replacement&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dropOne&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// remove the header&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// iterate with an (index, value) tuple&lt;/span&gt;
                   &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                   &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;joiner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;One of the cool parts of D ranges is that they are so flexible.
You want to do everything in a functional way?
D has you covered:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;csvPipe&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                      &lt;span class=&quot;n&quot;&gt;partial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reverseArgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;joiner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;_&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                     &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dropOne&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;csvPipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;There’s another cool thing about D - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.parallelism&lt;/code&gt;.
Have you ever been annoyed that a loop takes too long, but didn’t know a quick way
to parallelize your code?
Again, D has you covered with &lt;a href=&quot;https://dlang.org/phobos/std_parallelism.html#.parallel&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.parallel&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parallel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// expensive operation comes here&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;blockquote&gt;
  &lt;p&gt;No way. I don’t believe this can be so simple.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just &lt;a href=&quot;https://run.dlang.io/is/9fbtpQ&quot;&gt;try it yourself&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-garbage-collector-gc&quot;&gt;The Garbage Collector (GC)&lt;/h2&gt;

&lt;p&gt;On the internet and especially on reddit and HackerNews there’s a huge criticism of D’s decision to do use a GC. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Go&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ruby&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JavaScript&lt;/code&gt; etc. all use a GC, but I can’t better phrase it than Adam D. Ruppe:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;D is a pragmatic language aimed toward writing fast code, fast. Garbage collection has proved to be a smashing success in the industry, providing productivity and memory-safety to programmers of all skill levels. D’s GC implementation follows in the footsteps of industry giants without compromising expert’s ability to tweak even further.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, ask your question:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay, “ability to tweak even further” sounds a bit vague, what does this mean? I can tweak the memory usage?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, of course you can do that, but that’s something most languages with a GC allow you to do.
D allows you to get the benefit of both worlds, profit from the convenience of the GC and use manual allocation methods for the hot paths in your program. This is great, because you can use &lt;em&gt;the same language&lt;/em&gt; for prototyping and shipping your application.&lt;/p&gt;

&lt;p&gt;A short and simplified summary of allocation patterns in D:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://dlang.org/articles/exception-safe.html&quot;&gt;RAII&lt;/a&gt; is supported (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File&lt;/code&gt; you saw earlier is reference-counted and automatically deallocates its buffer and close the file once all references are dead)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://dlang.org/phobos/std_typecons.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.typecons&lt;/code&gt;&lt;/a&gt; provides a lot of library goodies like &lt;a href=&quot;https://dlang.org/phobos/std_typecons.html#Unique&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Unique&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://dlang.org/phobos/std_typecons.html#Scoped&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Scoped&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://dlang.org/phobos/std_typecons.html#RefCounted&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RefCounted&lt;/code&gt;&lt;/a&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@nogc&lt;/code&gt; allocation&lt;/li&gt;
  &lt;li&gt;there’s &lt;a href=&quot;https://dlang.org/phobos/std_experimental_allocator.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.experimental.allocator&lt;/code&gt;&lt;/a&gt; for everyone with custom allocation needs&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;malloc&lt;/code&gt; and friends are available in D too (everything from C is) - though if you want to use the C heap allocator I recommend its &lt;a href=&quot;https://dlang.org/phobos/std_experimental_allocator_mallocator.html&quot;&gt;high-level wrapper&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mike Parker has recently started an extensive &lt;a href=&quot;https://dlang.org/blog/the-gc-series/&quot;&gt;GC Series&lt;/a&gt; on the &lt;a href=&quot;http://blog.dlang.org/&quot;&gt;DBlog&lt;/a&gt; which I recommend to everyone who prefers performance over convenience.&lt;/p&gt;

&lt;h2 id=&quot;other-goodies&quot;&gt;Other goodies&lt;/h2&gt;

&lt;h3 id=&quot;stdcsv&quot;&gt;std.csv&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hey, I saw that there’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.csv&lt;/code&gt; in D, why didn’t you use it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Apart from the motivation to be comparable to C++ and Rust which don’t have a built-in CSV library, it felt like cheating:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;csv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;functional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;columnName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;csvReader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columnName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt;
             &lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;stdgetopt&quot;&gt;std.getopt&lt;/h3&gt;

&lt;p&gt;One of the reasons why this challenge used positional arguments and no flags is that argument parsing is pretty hard in C++. It’s not in D.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.getopt&lt;/code&gt; provides convenience for everything out of the box:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getopt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selectedColumn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;FOO&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opts&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getopt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;i|input&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;o|output&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;s|select&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Select a column to overwrite&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selectedColumn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;f|fill&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Overwrite (default: FOO)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;helpWanted&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;defaultGetoptPrinter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./program&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;dmd-ldc-and-gdc&quot;&gt;DMD, LDC and GDC&lt;/h3&gt;

&lt;p&gt;One of the things that newcomers are often getting confused by is that D has three compilers.
The short summary is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DMD (DigitalMars D compiler) - latest greatest features + fast compilation (= ideal for development)&lt;/li&gt;
  &lt;li&gt;LDC (uses the LLVM backend) - battle-tested LLVM backend + sophisticated optimizers + cross-compilation (=ideal for production)&lt;/li&gt;
  &lt;li&gt;GDC (uses the GCC backend) - similar points as LDC&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;benchmark-and-performance&quot;&gt;Benchmark and performance&lt;/h3&gt;

&lt;p&gt;Benchmarking a language compiler is a bit tricky as very often you end up benchmarking library functions.
In general, D code can be as fast as C++ and often is even faster - after all
the LDC and GDC compilers have the same backend as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clang++&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g++&lt;/code&gt; with all its optimization logic.
If you are interested to see how D programs perform against similar programs written in other languages, checkout &lt;a href=&quot;https://github.com/kostya/benchmarks&quot;&gt;Kostya’s benchmarks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There’s also an &lt;a href=&quot;https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md&quot;&gt;excellent performance benchmark&lt;/a&gt;
from Jon Degenhardt (member of eBay’s data science team) on how eBay’s &lt;a href=&quot;https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md&quot;&gt;tsv-utils&lt;/a&gt;
compare against existing CSV/TSV processing tools written in C, Go, and Rust.&lt;/p&gt;

&lt;p&gt;Apart from the typical &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O3&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-release&lt;/code&gt; flags, the performance-savvy can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-boundscheck=off&lt;/code&gt;.
Additionally LDC also makes it easy to do link-time optimization (LTO) and profile-guided optimization (PGO).
According to &lt;a href=&quot;https://github.com/eBay/tsv-utils-dlang/blob/master/docs/dlang-meetup-14dec2017.pdf&quot;&gt;Jon’s benchmarks&lt;/a&gt; LTO brings on average an additional performance gain of 10 %, just by adding the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-flto=full&lt;/code&gt; flag.
If you want to learn more about this LTO and PGO in D, checkout his superb &lt;a href=&quot;https://github.com/eBay/tsv-utils-dlang/blob/master/docs/BuildingWithLTO.md#ldc-command-lines&quot;&gt;tutorial&lt;/a&gt; or the &lt;a href=&quot;http://johanengelen.github.io/ldc/2016/11/10/Link-Time-Optimization-LDC.html&quot;&gt;in-depth technical article about LTO&lt;/a&gt; by Johan Engelen (one of the LDC developers).&lt;/p&gt;

&lt;h3 id=&quot;safe&quot;&gt;@safe&lt;/h3&gt;

&lt;p&gt;Even though D is a system programming language that allows you to mess with pointers, raw memory and even inline assembly, it provides a sane way to deal with the dirty details.
D has a &lt;a href=&quot;https://dlang.org/articles/safed.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@safe&lt;/code&gt; subset&lt;/a&gt; of the language in which the compiler will enforce that you don’t do anything stupid thing and shoot yourself in the feet with e.g. accessing undefined memory.&lt;/p&gt;

&lt;h3 id=&quot;unittest&quot;&gt;Unittest&lt;/h3&gt;

&lt;p&gt;One strategic advantage of D is that unit-testing is so easy as it’s built-in in the language and compiler. This is a valid D program:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;k&quot;&gt;unittest&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-unittest&lt;/code&gt; the compiler can be instructed to emit unittest block to the object files or binary.
Here, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rdmd&lt;/code&gt; is again a friendly tool and you can directly go ahead and test your line with you this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rdmd -main -unittest test.d
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;No advanced tooling setup required. Of course, this also means that it’s particulary easy to automatically verify all examples that are listed in the documentation, because there part of the testsuite. I even went one step further and made it possible to &lt;a href=&quot;https://dlang.org/blog/2017/03/08/editable-and-runnable-doc-examples-on-dlang-org/&quot;&gt;directly edit and run the examples on dlang.org&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;other-cool-d-features&quot;&gt;Other cool D features&lt;/h3&gt;

&lt;p&gt;There are many other cool features that D offers that didn’t make it in this article, but as a teaser for future articles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Code generation within the language (cut down your boilerplate)&lt;/li&gt;
  &lt;li&gt;Strong and easy Compile-Time introspection (Meta-programming)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias this&lt;/code&gt; for subtyping&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-betterC&lt;/code&gt; (using D without a runtime)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mixin&lt;/code&gt; for easily generating code&lt;/li&gt;
  &lt;li&gt;A module system that doesn’t suck&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debug&lt;/code&gt; attribute to break out of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pure&lt;/code&gt; code&lt;/li&gt;
  &lt;li&gt;Built-in documentation&lt;/li&gt;
  &lt;li&gt;Contracts and invariants&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scope(exit)&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scope(failure)&lt;/code&gt; for structuring creation with its destruction&lt;/li&gt;
  &lt;li&gt;Native interfacing with C (and most of C++)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;with&lt;/code&gt; for loading symbols into the current name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a full list, see the &lt;a href=&quot;https://dlang.org/overview.html&quot;&gt;Overview of D&lt;/a&gt; and don’t forget that the &lt;a href=&quot;https://dlang.org/spec/spec.html&quot;&gt;full language specification&lt;/a&gt; is readable in one evening.&lt;/p&gt;

&lt;h2 id=&quot;downsides&quot;&gt;Downsides&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay, so you say D is so great, but why hasn’t it taken off?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There’s a lot more to a programming language than just the language and compiler. D has to fight with the problems all young languages have to deal with e.g. small ecosystem, few tutorials / sparse documentation and occasional rough edges.
Languages like Kotlin, Rust or Go have it a lot easier, because they have a big corporate sponsor
which gives these language a big boost.&lt;/p&gt;

&lt;p&gt;Without such a boost, it’s a chicken/egg problem: if nobody is learning D, it also means that no one can write tutorials or better documentation.
Also many people have learnt a few languages and use them in production. There’s little incentive for them to redesign their entire stack.&lt;/p&gt;

&lt;p&gt;However, things improved greatly over the last years and nowadays even companies like Netflix, eBay, or Remedy Games use D. A few examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;the &lt;a href=&quot;https://www.theregister.co.uk/2017/12/22/a_dive_into_wekaios_parallel_file_system_tech/&quot;&gt;fastest parallel file system for High Performance Computing&lt;/a&gt; is written in D&lt;/li&gt;
  &lt;li&gt;if you drive by train in Europe, chances are good that you were guided by D (&lt;a href=&quot;https://dlang.org/blog/2017/07/28/project-highlight-funkwerk/&quot;&gt;Funkwerk&lt;/a&gt; - the company that manages the transport passenger information system - develops their software in D)&lt;/li&gt;
  &lt;li&gt;if you don’t use an Adblocker, chances are good that algorithms written in D bid in real-time for showing you advertisement (two of the leading companies in digital advertising (Sociomantic and Adroll) use D)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&quot;https://dlang.org/orgs-using-d.html&quot;&gt;organizations using D page&lt;/a&gt; lists more of these success stories.&lt;/p&gt;

&lt;p&gt;Of course, D - like every other language - has its “ugly” parts, but there’s always work in progress to fix these and compared to all other languages I have worked with,
the ugly parts are relatively tiny.&lt;/p&gt;

&lt;h2 id=&quot;where-to-go-from-here&quot;&gt;Where to go from here?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Okay that sounds great, but how do I install D on my system?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use the &lt;a href=&quot;https://dlang.org/install.html&quot;&gt;install script&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl https://dlang.org/install.sh | bash -s
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or &lt;a href=&quot;https://dlang.org/download.html&quot;&gt;use your package manager&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And start hacking!&lt;/p&gt;

&lt;h2 id=&quot;acknowledgements&quot;&gt;Acknowledgements&lt;/h2&gt;

&lt;p&gt;Thanks a lot to Timothee Cour, Juan Miguel Cejuela, Jon Degenhardt, Lio Lunesu, Mike Franklin, Steven Schveighoffer, Simen Kjærås, Walter Bright, Arredondo, Martin Tschierschke, Nicholas Wilson, Arun Chandrasekaran, Per Nordlöw, John Gabriele, jmh530, Dukc, tornchi, and ketmar for their helpful feedback.&lt;/p&gt;

&lt;p&gt;A huge thanks also goes to &lt;a href=&quot;https://www.fluentcpp.com&quot;&gt;Jonathan Boccara&lt;/a&gt; and
&lt;a href=&quot;http://www.bfilipek.com/&quot;&gt;Bartłomiej Filipek&lt;/a&gt; for organizing the Expressive C++17 Coding Challenge and opening the discussion about expressiveness of modern systems programming languages.&lt;/p&gt;

&lt;h2 id=&quot;attachements&quot;&gt;Attachements&lt;/h2&gt;

&lt;p&gt;It’s possible to do three easy tweaks to make I/O faster in D:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;disabling auto-decoding with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byCodeUnit&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;non-thread-safe I/O with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lockingTextWriter&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;use of &lt;a href=&quot;https://dlang.org/phobos/std_mmfile.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std.mmfile&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-d&quot; data-lang=&quot;d&quot;&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;usr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rdmd&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mmfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid args\n&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;./tool &amp;lt;input.csv&amp;gt; &amp;lt;colum-name&amp;gt; &amp;lt;replacement-string&amp;gt; &amp;lt;output.csv&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;columName&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;byCodeUnit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;scope&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mmFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MmFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mmFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mmFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;\n&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;byCodeUnit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;splitter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countUntil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;enforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Invalid column. Valid columns: %(%s, %)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writef&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%-(%s,%)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lockingTextWriter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dropOne&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;\n&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;,&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replacement&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

</description>
        <pubDate>Tue, 13 Feb 2018 17:48:57 +0100</pubDate>
        <link>https://seb.wilzba.ch/b/2018/02/the-expressive-c17-coding-challenge-in-d/</link>
        <guid isPermaLink="true">https://seb.wilzba.ch/b/2018/02/the-expressive-c17-coding-challenge-in-d/</guid>
        
        
        <category>d</category>
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>DLang Garden - Alpha release</title>
        <description>&lt;p&gt;I have started to learn D lately and as a part of my learning process I decided
to put my insights into a new, open platform - the D Functional Garden.&lt;/p&gt;

&lt;p&gt;It maintains a variety of snippets that can be used to learn D
or help one as a quick reference.&lt;/p&gt;

&lt;p&gt;All samples are valid code and automatically tested on every run - 
it is basically one big unittest suite.&lt;/p&gt;

&lt;p&gt;So don’t hesitate, have &lt;a href=&quot;https://garden.dlang.io&quot;&gt;a look&lt;/a&gt; and let yourself get excited about the power of &lt;a href=&quot;http://dlang.org&quot;&gt;D&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://garden.dlang.io&quot; target=&quot;_blank&quot;&gt;&lt;picture&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-986by631-417907.jpg&quot; media=&quot;(min-width: 50em) and (-webkit-min-device-pixel-ratio: 2), (min-width: 50em) and (min-resolution: 192dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-986by631-417907.jpg&quot; media=&quot;(min-width: 50em) and (-webkit-min-device-pixel-ratio: 1.5), (min-width: 50em) and (min-resolution: 144dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-950by608-417907.jpg&quot; media=&quot;(min-width: 50em)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-986by631-417907.jpg&quot; media=&quot;(min-width: 40em) and (-webkit-min-device-pixel-ratio: 2), (min-width: 40em) and (min-resolution: 192dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-986by631-417907.jpg&quot; media=&quot;(min-width: 40em) and (-webkit-min-device-pixel-ratio: 1.5), (min-width: 40em) and (min-resolution: 144dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-700by448-417907.jpg&quot; media=&quot;(min-width: 40em)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-900by576-417907.jpg&quot; media=&quot;(min-width: 30em) and (-webkit-min-device-pixel-ratio: 2), (min-width: 30em) and (min-resolution: 192dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-675by432-417907.jpg&quot; media=&quot;(min-width: 30em) and (-webkit-min-device-pixel-ratio: 1.5), (min-width: 30em) and (min-resolution: 144dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-450by288-417907.jpg&quot; media=&quot;(min-width: 30em)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-650by416-417907.jpg&quot; media=&quot;(min-width: 25em) and (-webkit-min-device-pixel-ratio: 2), (min-width: 25em) and (min-resolution: 192dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-488by312-417907.jpg&quot; media=&quot;(min-width: 25em) and (-webkit-min-device-pixel-ratio: 1.5), (min-width: 25em) and (min-resolution: 144dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-325by208-417907.jpg&quot; media=&quot;(min-width: 25em)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-400by256-417907.jpg&quot; media=&quot;(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-300by192-417907.jpg&quot; media=&quot;(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)&quot; /&gt;
    &lt;source srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-200by128-417907.jpg&quot; /&gt;
    &lt;img srcset=&quot;/dimg/blog/2016/dlang_garden_alpha-200by128-417907.jpg&quot; class=&quot;blog-center&quot; itemprop=&quot;image&quot; alt=&quot;DLang Garden Alpha&quot; /&gt;
  &lt;/picture&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
        <pubDate>Thu, 25 Feb 2016 13:44:27 +0100</pubDate>
        <link>https://seb.wilzba.ch/b/2016/02/dlang-garden-alpha/</link>
        <guid isPermaLink="true">https://seb.wilzba.ch/b/2016/02/dlang-garden-alpha/</guid>
        
        
        <category>d</category>
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>Rock JS with Defaultdict</title>
        <description>&lt;p&gt;Have you ever missed any of Python’s neat packages like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultdict&lt;/code&gt; when coding
in JavaScript?
Unfortunately this reflection functionality wasn’t given in JavaScript.&lt;/p&gt;

&lt;p&gt;However now thanks to the &lt;a href=&quot;https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy&quot;&gt;Proxy API&lt;/a&gt; we can intercept &lt;em&gt;property lookups&lt;/em&gt; and build a native &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultdict&lt;/code&gt; in JS.
Proxies are part of the ECMAScript 6 standard and are already implemented in 
Edge, Firefox and Chrome (&amp;gt;= 49) (more &lt;a href=&quot;https://kangax.github.io/compat-table/es6/&quot;&gt;details&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;starting-simple&quot;&gt;Starting simple&lt;/h2&gt;

&lt;p&gt;I have built a pure &lt;a href=&quot;https://github.com/wilzbach/defaultdict2&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultdict&lt;/code&gt;&lt;/a&gt; JS/Node package for which I will show 
why it’s so pleasant to finally have &lt;em&gt;reflection&lt;/em&gt; in JavaScript.
In contrast to other implementations, one doesn’t need to use any special getter
and it really can be used like it’s Python “brother”. Detailed instructions
for its Browsers or Node.Js use are provided on &lt;a href=&quot;https://github.com/wilzbach/defaultdict2&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For a start let’s consider this very simply example:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// { a: 1, b: 1 }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And its similar Python version:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# defaultdict(&amp;lt;class &apos;int&apos;&amp;gt;, {&apos;b&apos;: 1, &apos;a&apos;: 1})&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;coding-with-defaultdict-is-fun&quot;&gt;Coding with Defaultdict is fun!&lt;/h2&gt;

&lt;p&gt;Our first example wasn’t very fascinating as we need for the direct assignment (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d.a=1&lt;/code&gt;) 
the same amount of characters (if whitespaces are removed).&lt;/p&gt;

&lt;p&gt;However coding with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultdict&lt;/code&gt; is a lot of fun!
Let’s consider building a 2-kmers counting matrix.&lt;/p&gt;

&lt;p&gt;Traditionally we would have written this in JavaScript:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;AGAGACGAG&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]][&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]][&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]][&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// { A: { G: 3, C: 1 }, G: { A: 3 }, C: { G: 1 } }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now let’s have a look at this neat version with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;defaultdict&lt;/code&gt;.
Note that we can save both ifs with which we have to check for the existence and initialization.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;AGAGACGAG&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]][&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// { A: { G: 3, C: 1 }, G: { A: 3 }, C: { G: 1 } }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Even the Python code is a bit longer!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;AGAGACGAG&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# {&apos;G&apos;: {&apos;A&apos;: 3}, &apos;C&apos;: {&apos;G&apos;: 1}, &apos;A&apos;: {&apos;G&apos;: 3, &apos;C&apos;: 1}}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;where-to-go&quot;&gt;Where to go&lt;/h2&gt;

&lt;p&gt;Proxies are already implemented in Edge, Firefox and Chrome (&amp;gt;=49) and for
Node.js one can shim them.&lt;/p&gt;

&lt;p&gt;↪ Have fun &lt;a href=&quot;https://github.com/wilzbach/defaultdict2&quot;&gt;coding&lt;/a&gt; or check out the &lt;a href=&quot;http://jsbin.com/fiqecu/edit?js,console&quot;&gt;live demo&lt;/a&gt;!&lt;/p&gt;

</description>
        <pubDate>Fri, 05 Feb 2016 06:05:43 +0100</pubDate>
        <link>https://seb.wilzba.ch/b/2016/02/defaultdict-in-js/</link>
        <guid isPermaLink="true">https://seb.wilzba.ch/b/2016/02/defaultdict-in-js/</guid>
        
        
        <category>tech</category>
        
        <category>web</category>
        
      </item>
    
      <item>
        <title>Decrypting Threema&apos;s Android database</title>
        <description>&lt;p&gt;Most people probably enjoy New Year’s eve beneath a lovely firework with some
sparkling wine. Notwithstanding here is my New Year’s eve story.&lt;/p&gt;

&lt;h2 id=&quot;my-story&quot;&gt;My story&lt;/h2&gt;

&lt;p&gt;After I upgraded from Android M dev to Android M stable, I experienced a lot
of unknown issues with the app Threema. Eventually I managed to resolve them,
however I had to encrypt their Android database and as this is quite a complicated
task without given instructions, I wanted to share my insights.&lt;/p&gt;

&lt;p&gt;You can find all detailed instructions and some helper scripts on &lt;a href=&quot;https://github.com/wilzbach/threema-decrypt&quot;&gt;github&lt;/a&gt;.
These instructions should be straightfoward, so let me present some interesting
results that I obtained.&lt;/p&gt;

&lt;h2 id=&quot;contacts&quot;&gt;Contacts&lt;/h2&gt;

&lt;p&gt;By looking at the decrypted database, one can verify what information Threema
actually saves.
As you can see below the public key of every contact is stored and Threema internally only saves information that you expected it to save e.g. first and last name or the AndroidContactId when given.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sqlite&amp;gt; .schema contacts
CREATE TABLE `contacts` (`identity` VARCHAR , `publicKey` BLOB , `firstName` VARCHAR , `lastName` VARCHAR , `publicNickName` VARCHAR , `verificationLevel` INTEGER , `state` VARCHAR DEFAULT &apos;ACTIVE&apos; NOT NULL , `androidContactId` VARCHAR , `threemaAndroidContactId` VARCHAR , `isSynchronized` SMALLINT DEFAULT 0 , `featureLevel` INTEGER DEFAULT 0 NOT NULL , `color` INTEGER , `avatarExpires` BIGINT , PRIMARY KEY (`identity`) );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;messages&quot;&gt;Messages&lt;/h2&gt;

&lt;p&gt;Messages just contain their connected &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apiMessageId&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;identity&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body&lt;/code&gt; and their interaction status (sent, delievered, read) - nothing more is tracked.
However I know that since March 2014 until 2015 I sent 16304 personal messages and received 13852 messages.&lt;/p&gt;

&lt;h2 id=&quot;groups&quot;&gt;Groups&lt;/h2&gt;

&lt;p&gt;Group messages are according to Threema’s &lt;a href=&quot;https://threema.ch/press-files/cryptography_whitepaper.pdf&quot;&gt;whitepaper&lt;/a&gt; implemented with End-to-End encryption.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In Threema, groups are managed without any involvement of the servers. That is, the servers do not know which groups exist and which users are members of which groups&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If this being true, why is there an apiGroupId saved in the local database?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;CREATE TABLE `m_group` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `apiGroupId` VARCHAR , `name` VARCHAR , `creatorIdentity` VARCHAR , `createdAt` VARCHAR , `synchronizedAt` BIGINT , `deleted` SMALLINT );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt; The developer of Threema wrote a clarification (Thanks!)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The apiGroupId is a randomly generated unique id provided by the creator of the group and not the server (the name of the column might be a little misleading).
A group is uniquely identified by the combination of apiGroupId and creatorIdentity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;ballots-aka-surveys&quot;&gt;Ballots (aka surveys)&lt;/h2&gt;

&lt;p&gt;Ballots seem also to be implemented in End-to-End - so remember that all your friends can see
your vote. I personally had a couple of unclosed ballots (the owner already closed them
on his phone), just set them to closed and your annoyance has an end.&lt;/p&gt;

&lt;h2 id=&quot;media-files&quot;&gt;Media files&lt;/h2&gt;

&lt;p&gt;All locally stored media files are encrypted with one’s static key phase. 
With this &lt;a href=&quot;https://github.com/wilzbach/threema-decrypt&quot;&gt;code&lt;/a&gt; you can decrypt them.&lt;/p&gt;

&lt;h2 id=&quot;acknowledgment&quot;&gt;Acknowledgment&lt;/h2&gt;

&lt;p&gt;A big thanks goes to the Threema developer for building this convenient end-to-end encrypted
cross-platform messenger and letting me publish the decompiled &lt;a href=&quot;https://github.com/wilzbach/threema-decrypt&quot;&gt;instructions&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;next&quot;&gt;Next&lt;/h2&gt;

&lt;p&gt;Don’t forget to read Threema’s excellent &lt;a href=&quot;https://threema.ch/press-files/cryptography_whitepaper.pdf&quot;&gt;whitepaper&lt;/a&gt; about their used
cryptography.&lt;/p&gt;

&lt;p&gt;What do you plan to with your gained access to your Threema database?
Converting your message history to csv for archiving purposes? Extracting
the identities of your Threema friends? Let me know in the comments or on github!&lt;/p&gt;

</description>
        <pubDate>Mon, 01 Feb 2016 22:08:53 +0100</pubDate>
        <link>https://seb.wilzba.ch/b/2016/02/decrypting-threema/</link>
        <guid isPermaLink="true">https://seb.wilzba.ch/b/2016/02/decrypting-threema/</guid>
        
        
        <category>hacking</category>
        
        <category>security</category>
        
      </item>
    
      <item>
        <title>Hello world</title>
        <description>&lt;p&gt;I am glad that you made it to my new website &amp;amp; blog.
I will restart to blog here, so stay tuned and subscribe via mail or the RSS/Atom feed :)&lt;/p&gt;
</description>
        <pubDate>Wed, 22 Apr 2015 17:21:49 +0200</pubDate>
        <link>https://seb.wilzba.ch/b/2015/04/welcome/</link>
        <guid isPermaLink="true">https://seb.wilzba.ch/b/2015/04/welcome/</guid>
        
        
        <category>tech</category>
        
      </item>
    
  </channel>
</rss>
