aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-01 12:55:39 +0100
committerAkshay <[email protected]>2020-08-01 12:55:39 +0100
commit70827fe44d6844528e7dd56637de2f0f3e0cf847 (patch)
tree17fd0215faa06d1583321a298047dd19c9567087
parent6dc5eb710c27a3fee4a132763c106c5ce16f72ab (diff)
update irc nick, publish post
-rw-r--r--docs/index.html19
-rw-r--r--docs/index.xml115
-rw-r--r--docs/posts/WPA_woes/index.html2
-rw-r--r--docs/posts/auto-currying_rust_functions/index.html2
-rw-r--r--docs/posts/bash_harder_with_vim/index.html2
-rw-r--r--docs/posts/bye_bye_BDFs/index.html2
-rw-r--r--docs/posts/call_to_ARMs/index.html2
-rw-r--r--docs/posts/color_conundrum/index.html2
-rw-r--r--docs/posts/font_size_fallacies/index.html2
-rw-r--r--docs/posts/get_better_at_yanking_and_putting_in_vim/index.html2
-rw-r--r--docs/posts/gripes_with_go/index.html173
-rw-r--r--docs/posts/hold_position!/index.html2
-rw-r--r--docs/posts/my_setup/index.html2
-rw-r--r--docs/posts/onivim_sucks/index.html2
-rw-r--r--docs/posts/pixel_art_in_GIMP/index.html2
-rw-r--r--docs/posts/rapid_refactoring_with_vim/index.html2
-rw-r--r--docs/posts/static_sites_with_bash/index.html2
-rw-r--r--docs/posts/termux_tandem/index.html2
-rw-r--r--docs/posts/turing_complete_type_systems/index.html2
-rwxr-xr-xgenerate.sh2
-rw-r--r--posts/gripes_with_go.md21
21 files changed, 341 insertions, 21 deletions
diff --git a/docs/index.html b/docs/index.html
index 68da119..6a70b78 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -30,12 +30,29 @@
30 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 30 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
31 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 31 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
32 </p> 32 </p>
33 <p>Send me a mail at [email protected] or a message at [email protected].</p> 33 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
34 </div> 34 </div>
35 <table> 35 <table>
36 <tr> 36 <tr>
37 <td class=table-post> 37 <td class=table-post>
38 <div class="date"> 38 <div class="date">
39 01/08 — 2020
40 </div>
41 <a href="/posts/gripes_with_go" class="post-link">
42 <span class="post-link">Gripes With Go</span>
43 </a>
44 </td>
45 <td class=table-stats>
46 <span class="stats-number">
47 4.9
48 </span>
49 <span class=stats-unit>min</span>
50 </td>
51 </tr>
52
53 <tr>
54 <td class=table-post>
55 <div class="date">
39 18/06 — 2020 56 18/06 — 2020
40 </div> 57 </div>
41 <a href="/posts/turing_complete_type_systems" class="post-link"> 58 <a href="/posts/turing_complete_type_systems" class="post-link">
diff --git a/docs/index.xml b/docs/index.xml
index 628c111..003d4d6 100644
--- a/docs/index.xml
+++ b/docs/index.xml
@@ -12,6 +12,121 @@
12 <language>en-us</language> 12 <language>en-us</language>
13 <copyright>Creative Commons BY-NC-SA 4.0</copyright> 13 <copyright>Creative Commons BY-NC-SA 4.0</copyright>
14 <item> 14 <item>
15<title>Gripes With Go</title>
16<description>&lt;p&gt;You’ve read a lot of posts about the shortcomings of the Go programming language, so what’s one more.&lt;/p&gt;
17&lt;ol type="1"&gt;
18&lt;li&gt;&lt;a href="#lack-of-sum-types"&gt;Lack of sum types&lt;/a&gt;&lt;/li&gt;
19&lt;li&gt;&lt;a href="#type-assertions"&gt;Type assertions&lt;/a&gt;&lt;/li&gt;
20&lt;li&gt;&lt;a href="#date-and-time"&gt;Date and Time&lt;/a&gt;&lt;/li&gt;
21&lt;li&gt;&lt;a href="#statements-over-expressions"&gt;Statements over Expressions&lt;/a&gt;&lt;/li&gt;
22&lt;li&gt;&lt;a href="#erroring-out-on-unused-variables"&gt;Erroring out on unused variables&lt;/a&gt;&lt;/li&gt;
23&lt;li&gt;&lt;a href="#error-handling"&gt;Error handling&lt;/a&gt;&lt;/li&gt;
24&lt;/ol&gt;
25&lt;h3 id="lack-of-sum-types"&gt;Lack of Sum types&lt;/h3&gt;
26&lt;p&gt;A “Sum” type is a data type that can hold one of many states at a given time, similar to how a boolean can hold a true or a false, not too different from an &lt;code&gt;enum&lt;/code&gt; type in C. Go lacks &lt;code&gt;enum&lt;/code&gt; types unfortunately, and you are forced to resort to crafting your own substitute.&lt;/p&gt;
27&lt;p&gt;A type to represent gender for example:&lt;/p&gt;
28&lt;div class="sourceCode" id="cb1"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb1-1"&gt;&lt;a href="#cb1-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;type&lt;/span&gt; Gender &lt;span class="dt"&gt;int&lt;/span&gt;&lt;/span&gt;
29&lt;span id="cb1-2"&gt;&lt;a href="#cb1-2" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
30&lt;span id="cb1-3"&gt;&lt;a href="#cb1-3" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;const&lt;/span&gt; (&lt;/span&gt;
31&lt;span id="cb1-4"&gt;&lt;a href="#cb1-4" aria-hidden="true"&gt;&lt;/a&gt; Male Gender = &lt;span class="ot"&gt;iota&lt;/span&gt; &lt;span class="co"&gt;// assigns Male to 0&lt;/span&gt;&lt;/span&gt;
32&lt;span id="cb1-5"&gt;&lt;a href="#cb1-5" aria-hidden="true"&gt;&lt;/a&gt; Female &lt;span class="co"&gt;// assigns Female to 1&lt;/span&gt;&lt;/span&gt;
33&lt;span id="cb1-6"&gt;&lt;a href="#cb1-6" aria-hidden="true"&gt;&lt;/a&gt; Other &lt;span class="co"&gt;// assigns Other to 2&lt;/span&gt;&lt;/span&gt;
34&lt;span id="cb1-7"&gt;&lt;a href="#cb1-7" aria-hidden="true"&gt;&lt;/a&gt;)&lt;/span&gt;
35&lt;span id="cb1-8"&gt;&lt;a href="#cb1-8" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
36&lt;span id="cb1-9"&gt;&lt;a href="#cb1-9" aria-hidden="true"&gt;&lt;/a&gt;fmt.Println(&lt;span class="st"&gt;&amp;quot;My gender is &amp;quot;&lt;/span&gt;, Male)&lt;/span&gt;
37&lt;span id="cb1-10"&gt;&lt;a href="#cb1-10" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// My gender is 0&lt;/span&gt;&lt;/span&gt;
38&lt;span id="cb1-11"&gt;&lt;a href="#cb1-11" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// Oops! We have to implement String() for Gender ...&lt;/span&gt;&lt;/span&gt;
39&lt;span id="cb1-12"&gt;&lt;a href="#cb1-12" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
40&lt;span id="cb1-13"&gt;&lt;a href="#cb1-13" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;func&lt;/span&gt; (g Gender) String() &lt;span class="dt"&gt;string&lt;/span&gt; {&lt;/span&gt;
41&lt;span id="cb1-14"&gt;&lt;a href="#cb1-14" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;switch&lt;/span&gt; (g) {&lt;/span&gt;
42&lt;span id="cb1-15"&gt;&lt;a href="#cb1-15" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="dv"&gt;0&lt;/span&gt;: &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="st"&gt;&amp;quot;Male&amp;quot;&lt;/span&gt;&lt;/span&gt;
43&lt;span id="cb1-16"&gt;&lt;a href="#cb1-16" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt;: &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="st"&gt;&amp;quot;Female&amp;quot;&lt;/span&gt;&lt;/span&gt;
44&lt;span id="cb1-17"&gt;&lt;a href="#cb1-17" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;default&lt;/span&gt;: &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="st"&gt;&amp;quot;Other&amp;quot;&lt;/span&gt;&lt;/span&gt;
45&lt;span id="cb1-18"&gt;&lt;a href="#cb1-18" aria-hidden="true"&gt;&lt;/a&gt; }&lt;/span&gt;
46&lt;span id="cb1-19"&gt;&lt;a href="#cb1-19" aria-hidden="true"&gt;&lt;/a&gt;}&lt;/span&gt;
47&lt;span id="cb1-20"&gt;&lt;a href="#cb1-20" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
48&lt;span id="cb1-21"&gt;&lt;a href="#cb1-21" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// You can accidentally do stupid stuff like:&lt;/span&gt;&lt;/span&gt;
49&lt;span id="cb1-22"&gt;&lt;a href="#cb1-22" aria-hidden="true"&gt;&lt;/a&gt;gender := Male + &lt;span class="dv"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
50&lt;p&gt;The Haskell equivalent of the same:&lt;/p&gt;
51&lt;div class="sourceCode" id="cb2"&gt;&lt;pre class="sourceCode haskell"&gt;&lt;code class="sourceCode haskell"&gt;&lt;span id="cb2-1"&gt;&lt;a href="#cb2-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;data&lt;/span&gt; &lt;span class="dt"&gt;Gender&lt;/span&gt; &lt;span class="ot"&gt;=&lt;/span&gt; &lt;span class="dt"&gt;Male&lt;/span&gt;&lt;/span&gt;
52&lt;span id="cb2-2"&gt;&lt;a href="#cb2-2" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="op"&gt;|&lt;/span&gt; &lt;span class="dt"&gt;Female&lt;/span&gt;&lt;/span&gt;
53&lt;span id="cb2-3"&gt;&lt;a href="#cb2-3" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="op"&gt;|&lt;/span&gt; &lt;span class="dt"&gt;Other&lt;/span&gt;&lt;/span&gt;
54&lt;span id="cb2-4"&gt;&lt;a href="#cb2-4" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;deriving&lt;/span&gt; (&lt;span class="dt"&gt;Show&lt;/span&gt;)&lt;/span&gt;
55&lt;span id="cb2-5"&gt;&lt;a href="#cb2-5" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
56&lt;span id="cb2-6"&gt;&lt;a href="#cb2-6" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="fu"&gt;print&lt;/span&gt; &lt;span class="op"&gt;$&lt;/span&gt; &lt;span class="st"&gt;&amp;quot;My gender is &amp;quot;&lt;/span&gt; &lt;span class="op"&gt;++&lt;/span&gt; (&lt;span class="fu"&gt;show&lt;/span&gt; &lt;span class="dt"&gt;Male&lt;/span&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
57&lt;h3 id="type-assertions"&gt;Type Assertions&lt;/h3&gt;
58&lt;p&gt;A downcast with an optional error check? What could go wrong?&lt;/p&gt;
59&lt;p&gt;Type assertions in Go allow you to do:&lt;/p&gt;
60&lt;div class="sourceCode" id="cb3"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb3-1"&gt;&lt;a href="#cb3-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;var&lt;/span&gt; x &lt;span class="kw"&gt;interface&lt;/span&gt;{} = &lt;span class="dv"&gt;7&lt;/span&gt;&lt;/span&gt;
61&lt;span id="cb3-2"&gt;&lt;a href="#cb3-2" aria-hidden="true"&gt;&lt;/a&gt;y, goodToGo := x.(&lt;span class="dt"&gt;int&lt;/span&gt;)&lt;/span&gt;
62&lt;span id="cb3-3"&gt;&lt;a href="#cb3-3" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;if&lt;/span&gt; goodToGo {&lt;/span&gt;
63&lt;span id="cb3-4"&gt;&lt;a href="#cb3-4" aria-hidden="true"&gt;&lt;/a&gt; fmt.Println(y)&lt;/span&gt;
64&lt;span id="cb3-5"&gt;&lt;a href="#cb3-5" aria-hidden="true"&gt;&lt;/a&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
65&lt;p&gt;The error check however is optional:&lt;/p&gt;
66&lt;div class="sourceCode" id="cb4"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb4-1"&gt;&lt;a href="#cb4-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;var&lt;/span&gt; x &lt;span class="kw"&gt;interface&lt;/span&gt;{} = &lt;span class="dv"&gt;7&lt;/span&gt;&lt;/span&gt;
67&lt;span id="cb4-2"&gt;&lt;a href="#cb4-2" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;var&lt;/span&gt; y := x.(&lt;span class="dt"&gt;float64&lt;/span&gt;)&lt;/span&gt;
68&lt;span id="cb4-3"&gt;&lt;a href="#cb4-3" aria-hidden="true"&gt;&lt;/a&gt;fmt.Println(y)&lt;/span&gt;
69&lt;span id="cb4-4"&gt;&lt;a href="#cb4-4" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// results in a runtime error:&lt;/span&gt;&lt;/span&gt;
70&lt;span id="cb4-5"&gt;&lt;a href="#cb4-5" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// panic: interface conversion: interface {} is int, not float64&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
71&lt;h3 id="date-and-time"&gt;Date and Time&lt;/h3&gt;
72&lt;p&gt;Anyone that has written Go previously, will probably already know what I am getting at here. For the uninitiated, parsing and formatting dates in Go requires a “layout”. This “layout” is based on magical reference date:&lt;/p&gt;
73&lt;pre&gt;&lt;code&gt;Mon Jan 2 15:04:05 MST 2006&lt;/code&gt;&lt;/pre&gt;
74&lt;p&gt;Which is the date produced when you write the first seven natural numbers like so:&lt;/p&gt;
75&lt;pre&gt;&lt;code&gt;01/02 03:04:05 &amp;#39;06 -0700&lt;/code&gt;&lt;/pre&gt;
76&lt;p&gt;Parsing a string in &lt;code&gt;YYYY-MM-DD&lt;/code&gt; format would look something like:&lt;/p&gt;
77&lt;div class="sourceCode" id="cb7"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb7-1"&gt;&lt;a href="#cb7-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;const&lt;/span&gt; layout = &lt;span class="st"&gt;&amp;quot;2006-01-02&amp;quot;&lt;/span&gt;&lt;/span&gt;
78&lt;span id="cb7-2"&gt;&lt;a href="#cb7-2" aria-hidden="true"&gt;&lt;/a&gt;time.Parse(layout, &lt;span class="st"&gt;&amp;quot;2020-08-01&amp;quot;&lt;/span&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
79&lt;p&gt;This so-called “intuitive” method of formatting dates doesn’t allow you to print &lt;code&gt;0000 hrs&lt;/code&gt; as &lt;code&gt;2400 hrs&lt;/code&gt;, it doesn’t allow you to omit the leading zero in 24 hour formats. It is rife with inconveniences, if only there were a &lt;a href="https://man7.org/linux/man-pages/man3/strftime.3.html"&gt;tried and tested&lt;/a&gt; date formatting convention …&lt;/p&gt;
80&lt;h3 id="statements-over-expressions"&gt;Statements over Expressions&lt;/h3&gt;
81&lt;p&gt;Statements have side effects, expressions return values. More often than not, expressions are easier to understand at a glance: evaluate the LHS and assign the same to the RHS.&lt;/p&gt;
82&lt;p&gt;Rust allows you to create local namespaces, and treats blocks (&lt;code&gt;{}&lt;/code&gt;) as expressions:&lt;/p&gt;
83&lt;div class="sourceCode" id="cb8"&gt;&lt;pre class="sourceCode rust"&gt;&lt;code class="sourceCode rust"&gt;&lt;span id="cb8-1"&gt;&lt;a href="#cb8-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;let&lt;/span&gt; twenty_seven &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
84&lt;span id="cb8-2"&gt;&lt;a href="#cb8-2" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;let&lt;/span&gt; three &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="dv"&gt;2&lt;/span&gt;&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
85&lt;span id="cb8-3"&gt;&lt;a href="#cb8-3" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;let&lt;/span&gt; nine &lt;span class="op"&gt;=&lt;/span&gt; three &lt;span class="op"&gt;*&lt;/span&gt; three&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
86&lt;span id="cb8-4"&gt;&lt;a href="#cb8-4" aria-hidden="true"&gt;&lt;/a&gt; nine &lt;span class="op"&gt;*&lt;/span&gt; three&lt;/span&gt;
87&lt;span id="cb8-5"&gt;&lt;a href="#cb8-5" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="op"&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
88&lt;p&gt;The Go equivalent of the same:&lt;/p&gt;
89&lt;div class="sourceCode" id="cb9"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb9-1"&gt;&lt;a href="#cb9-1" aria-hidden="true"&gt;&lt;/a&gt;twenty_seven := &lt;span class="ot"&gt;nil&lt;/span&gt;&lt;/span&gt;
90&lt;span id="cb9-2"&gt;&lt;a href="#cb9-2" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
91&lt;span id="cb9-3"&gt;&lt;a href="#cb9-3" aria-hidden="true"&gt;&lt;/a&gt;three := &lt;span class="dv"&gt;1&lt;/span&gt; + &lt;span class="dv"&gt;2&lt;/span&gt;&lt;/span&gt;
92&lt;span id="cb9-4"&gt;&lt;a href="#cb9-4" aria-hidden="true"&gt;&lt;/a&gt;nine := three * three&lt;/span&gt;
93&lt;span id="cb9-5"&gt;&lt;a href="#cb9-5" aria-hidden="true"&gt;&lt;/a&gt;twenty_seven = nine * three&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
94&lt;h3 id="erroring-out-on-unused-variables"&gt;Erroring out on unused variables&lt;/h3&gt;
95&lt;p&gt;Want to quickly prototype something? Go says no! In all seriousness, a warning would suffice, I don’t want to have to go back and comment each unused import out, only to come back and uncomment them a few seconds later.&lt;/p&gt;
96&lt;h3 id="error-handling"&gt;Error handling&lt;/h3&gt;
97&lt;div class="sourceCode" id="cb10"&gt;&lt;pre class="sourceCode go"&gt;&lt;code class="sourceCode go"&gt;&lt;span id="cb10-1"&gt;&lt;a href="#cb10-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;if&lt;/span&gt; err != &lt;span class="ot"&gt;nil&lt;/span&gt; { ... }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
98&lt;p&gt;Need I say more? I will, for good measure:&lt;/p&gt;
99&lt;ol type="1"&gt;
100&lt;li&gt;Error handling is optional&lt;/li&gt;
101&lt;li&gt;Errors are propagated via a clunky &lt;code&gt;if&lt;/code&gt; + &lt;code&gt;return&lt;/code&gt; statement&lt;/li&gt;
102&lt;/ol&gt;
103&lt;p&gt;I prefer Haskell’s “Monadic” error handling, which is employed by Rust as well:&lt;/p&gt;
104&lt;div class="sourceCode" id="cb11"&gt;&lt;pre class="sourceCode rust"&gt;&lt;code class="sourceCode rust"&gt;&lt;span id="cb11-1"&gt;&lt;a href="#cb11-1" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// 1. error handling is compulsory&lt;/span&gt;&lt;/span&gt;
105&lt;span id="cb11-2"&gt;&lt;a href="#cb11-2" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="co"&gt;// 2. errors are propagated with the `?` operator&lt;/span&gt;&lt;/span&gt;
106&lt;span id="cb11-3"&gt;&lt;a href="#cb11-3" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;fn&lt;/span&gt; foo() &lt;span class="op"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="dt"&gt;Result&lt;/span&gt;&lt;span class="op"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dt"&gt;String&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; &lt;span class="pp"&gt;io::&lt;/span&gt;&lt;span class="bu"&gt;Error&lt;/span&gt;&lt;span class="op"&gt;&amp;gt;&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
107&lt;span id="cb11-4"&gt;&lt;a href="#cb11-4" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;let&lt;/span&gt; &lt;span class="kw"&gt;mut&lt;/span&gt; f &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="pp"&gt;File::&lt;/span&gt;open(&lt;span class="st"&gt;&amp;quot;foo.txt&amp;quot;&lt;/span&gt;)&lt;span class="op"&gt;?;&lt;/span&gt; &lt;span class="co"&gt;// return if error&lt;/span&gt;&lt;/span&gt;
108&lt;span id="cb11-5"&gt;&lt;a href="#cb11-5" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;let&lt;/span&gt; &lt;span class="kw"&gt;mut&lt;/span&gt; s &lt;span class="op"&gt;=&lt;/span&gt; &lt;span class="dt"&gt;String&lt;/span&gt;&lt;span class="pp"&gt;::&lt;/span&gt;new()&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
109&lt;span id="cb11-6"&gt;&lt;a href="#cb11-6" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
110&lt;span id="cb11-7"&gt;&lt;a href="#cb11-7" aria-hidden="true"&gt;&lt;/a&gt; f&lt;span class="op"&gt;.&lt;/span&gt;read_to_string(&lt;span class="op"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kw"&gt;mut&lt;/span&gt; s)&lt;span class="op"&gt;?;&lt;/span&gt; &lt;span class="co"&gt;// return if error&lt;/span&gt;&lt;/span&gt;
111&lt;span id="cb11-8"&gt;&lt;a href="#cb11-8" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
112&lt;span id="cb11-9"&gt;&lt;a href="#cb11-9" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="cn"&gt;Ok&lt;/span&gt;(s) &lt;span class="co"&gt;// all good, return a string inside a `Result` context&lt;/span&gt;&lt;/span&gt;
113&lt;span id="cb11-10"&gt;&lt;a href="#cb11-10" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
114&lt;span id="cb11-11"&gt;&lt;a href="#cb11-11" aria-hidden="true"&gt;&lt;/a&gt;&lt;/span&gt;
115&lt;span id="cb11-12"&gt;&lt;a href="#cb11-12" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="kw"&gt;fn&lt;/span&gt; main() &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
116&lt;span id="cb11-13"&gt;&lt;a href="#cb11-13" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="co"&gt;// `contents` is an enum known as Result:&lt;/span&gt;&lt;/span&gt;
117&lt;span id="cb11-14"&gt;&lt;a href="#cb11-14" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;let&lt;/span&gt; contents &lt;span class="op"&gt;=&lt;/span&gt; foo()&lt;span class="op"&gt;;&lt;/span&gt;&lt;/span&gt;
118&lt;span id="cb11-15"&gt;&lt;a href="#cb11-15" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="kw"&gt;match&lt;/span&gt; contents &lt;span class="op"&gt;{&lt;/span&gt;&lt;/span&gt;
119&lt;span id="cb11-16"&gt;&lt;a href="#cb11-16" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="cn"&gt;Ok&lt;/span&gt;(c) &lt;span class="op"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="pp"&gt;println!&lt;/span&gt;(c)&lt;span class="op"&gt;,&lt;/span&gt;&lt;/span&gt;
120&lt;span id="cb11-17"&gt;&lt;a href="#cb11-17" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="cn"&gt;Err&lt;/span&gt;(e) &lt;span class="op"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="pp"&gt;eprintln!&lt;/span&gt;(e)&lt;/span&gt;
121&lt;span id="cb11-18"&gt;&lt;a href="#cb11-18" aria-hidden="true"&gt;&lt;/a&gt; &lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;
122&lt;span id="cb11-19"&gt;&lt;a href="#cb11-19" aria-hidden="true"&gt;&lt;/a&gt;&lt;span class="op"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
123&lt;h3 id="conclusion"&gt;Conclusion&lt;/h3&gt;
124&lt;p&gt;I did not want to conclude without talking about stylistic choices, lack of metaprogramming, bizzare export rules, but, I am too busy converting my &lt;code&gt;interface{}&lt;/code&gt; types into actual generic code for Go v2.&lt;/p&gt;</description>
125<link>https://peppe.rs/posts/gripes_with_go/</link>
126<pubDate>Sat, 01 Aug 2020 11:55:00 +0000</pubDate>
127<guid>https://peppe.rs/posts/gripes_with_go/</guid>
128</item>
129<item>
15<title>Turing Complete Type Systems</title> 130<title>Turing Complete Type Systems</title>
16<description>&lt;p&gt;Rust’s type system is Turing complete:&lt;/p&gt; 131<description>&lt;p&gt;Rust’s type system is Turing complete:&lt;/p&gt;
17&lt;ul&gt; 132&lt;ul&gt;
diff --git a/docs/posts/WPA_woes/index.html b/docs/posts/WPA_woes/index.html
index 0c50385..5121434 100644
--- a/docs/posts/WPA_woes/index.html
+++ b/docs/posts/WPA_woes/index.html
@@ -76,7 +76,7 @@ $ sudo sv restart dhcpcd</code></pre>
76 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 76 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
77 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 77 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
78 </p> 78 </p>
79 <p>Send me a mail at [email protected] or a message at [email protected].</p> 79 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
80 </div> 80 </div>
81 81
82 <a href="/" class="post-end-link">⟵ Back</a> 82 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/auto-currying_rust_functions/index.html b/docs/posts/auto-currying_rust_functions/index.html
index a86667c..62f92bc 100644
--- a/docs/posts/auto-currying_rust_functions/index.html
+++ b/docs/posts/auto-currying_rust_functions/index.html
@@ -540,7 +540,7 @@ test tests::works ... ok</code></pre>
540 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 540 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
541 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 541 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
542 </p> 542 </p>
543 <p>Send me a mail at [email protected] or a message at [email protected].</p> 543 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
544 </div> 544 </div>
545 545
546 <a href="/" class="post-end-link">⟵ Back</a> 546 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/bash_harder_with_vim/index.html b/docs/posts/bash_harder_with_vim/index.html
index 7c9e5d6..303880d 100644
--- a/docs/posts/bash_harder_with_vim/index.html
+++ b/docs/posts/bash_harder_with_vim/index.html
@@ -86,7 +86,7 @@ Press ENTER or type command to continue</code></pre>
86 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 86 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
87 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 87 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
88 </p> 88 </p>
89 <p>Send me a mail at [email protected] or a message at [email protected].</p> 89 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
90 </div> 90 </div>
91 91
92 <a href="/" class="post-end-link">⟵ Back</a> 92 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/bye_bye_BDFs/index.html b/docs/posts/bye_bye_BDFs/index.html
index a2e410d..43d2dfd 100644
--- a/docs/posts/bye_bye_BDFs/index.html
+++ b/docs/posts/bye_bye_BDFs/index.html
@@ -58,7 +58,7 @@
58 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 58 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
59 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 59 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
60 </p> 60 </p>
61 <p>Send me a mail at [email protected] or a message at [email protected].</p> 61 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
62 </div> 62 </div>
63 63
64 <a href="/" class="post-end-link">⟵ Back</a> 64 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html
index f882e6b..a05ed38 100644
--- a/docs/posts/call_to_ARMs/index.html
+++ b/docs/posts/call_to_ARMs/index.html
@@ -83,7 +83,7 @@ Reading symbols from main... # yay!</code></pre>
83 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 83 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
84 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 84 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
85 </p> 85 </p>
86 <p>Send me a mail at [email protected] or a message at [email protected].</p> 86 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
87 </div> 87 </div>
88 88
89 <a href="/" class="post-end-link">⟵ Back</a> 89 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/color_conundrum/index.html b/docs/posts/color_conundrum/index.html
index 0ba7aa5..c7db8cd 100644
--- a/docs/posts/color_conundrum/index.html
+++ b/docs/posts/color_conundrum/index.html
@@ -60,7 +60,7 @@
60 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 60 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
61 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 61 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
62 </p> 62 </p>
63 <p>Send me a mail at [email protected] or a message at [email protected].</p> 63 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
64 </div> 64 </div>
65 65
66 <a href="/" class="post-end-link">⟵ Back</a> 66 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/font_size_fallacies/index.html b/docs/posts/font_size_fallacies/index.html
index c91eba5..af55661 100644
--- a/docs/posts/font_size_fallacies/index.html
+++ b/docs/posts/font_size_fallacies/index.html
@@ -82,7 +82,7 @@ Dimensions: 1920x1080 @ 13&quot; (29.5x16.5 sq. cm)
82 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 82 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
83 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 83 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
84 </p> 84 </p>
85 <p>Send me a mail at [email protected] or a message at [email protected].</p> 85 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
86 </div> 86 </div>
87 87
88 <a href="/" class="post-end-link">⟵ Back</a> 88 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html b/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html
index a009a15..e02f5d2 100644
--- a/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html
+++ b/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html
@@ -69,7 +69,7 @@ nnoremap gb `[v`] &quot; &quot;a quick map to perform the above</code></pre><
69 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 69 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
70 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 70 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
71 </p> 71 </p>
72 <p>Send me a mail at [email protected] or a message at [email protected].</p> 72 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
73 </div> 73 </div>
74 74
75 <a href="/" class="post-end-link">⟵ Back</a> 75 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/gripes_with_go/index.html b/docs/posts/gripes_with_go/index.html
new file mode 100644
index 0000000..b527b4a
--- /dev/null
+++ b/docs/posts/gripes_with_go/index.html
@@ -0,0 +1,173 @@
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <link rel="stylesheet" href="/style.css">
5 <link rel="stylesheet" href="/syntax.css">
6 <meta charset="UTF-8">
7 <meta name="viewport" content="initial-scale=1">
8 <meta content="#ffffff" name="theme-color">
9 <meta name="HandheldFriendly" content="true">
10 <meta property="og:title" content="Gripes With Go">
11 <meta property="og:type" content="website">
12 <meta property="og:description" content="a static site {for, by, about} me ">
13 <meta property="og:url" content="https://peppe.rs">
14 <link rel="icon" type="image/x-icon" href="/favicon.png">
15 <title>Gripes With Go · peppe.rs</title>
16 <body>
17 <div class="posts">
18 <div class="post">
19 <a href="/" class="post-end-link">⟵ Back</a>
20 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/gripes_with_go.md
21">View Raw</a>
22 <div class="separator"></div>
23 <div class="date">
24 01/08 — 2020
25 <div class="stats">
26 <span class="stats-number">
27 76.71
28 </span>
29 <span class="stats-unit">cm</span>
30 &nbsp
31 <span class="stats-number">
32 4.9
33 </span>
34 <span class="stats-unit">min</span>
35 </div>
36 </div>
37 <h1>
38 Gripes With Go
39 </h1>
40 <div class="post-text">
41 <p>You’ve read a lot of posts about the shortcomings of the Go programming language, so what’s one more.</p>
42<ol type="1">
43<li><a href="#lack-of-sum-types">Lack of sum types</a></li>
44<li><a href="#type-assertions">Type assertions</a></li>
45<li><a href="#date-and-time">Date and Time</a></li>
46<li><a href="#statements-over-expressions">Statements over Expressions</a></li>
47<li><a href="#erroring-out-on-unused-variables">Erroring out on unused variables</a></li>
48<li><a href="#error-handling">Error handling</a></li>
49</ol>
50<h3 id="lack-of-sum-types">Lack of Sum types</h3>
51<p>A “Sum” type is a data type that can hold one of many states at a given time, similar to how a boolean can hold a true or a false, not too different from an <code>enum</code> type in C. Go lacks <code>enum</code> types unfortunately, and you are forced to resort to crafting your own substitute.</p>
52<p>A type to represent gender for example:</p>
53<div class="sourceCode" id="cb1"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">type</span> Gender <span class="dt">int</span></span>
54<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a></span>
55<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a><span class="kw">const</span> (</span>
56<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a> Male Gender = <span class="ot">iota</span> <span class="co">// assigns Male to 0</span></span>
57<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a> Female <span class="co">// assigns Female to 1</span></span>
58<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a> Other <span class="co">// assigns Other to 2</span></span>
59<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>)</span>
60<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a></span>
61<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>fmt.Println(<span class="st">&quot;My gender is &quot;</span>, Male)</span>
62<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a><span class="co">// My gender is 0</span></span>
63<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a><span class="co">// Oops! We have to implement String() for Gender ...</span></span>
64<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a></span>
65<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a><span class="kw">func</span> (g Gender) String() <span class="dt">string</span> {</span>
66<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a> <span class="kw">switch</span> (g) {</span>
67<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a> <span class="kw">case</span> <span class="dv">0</span>: <span class="kw">return</span> <span class="st">&quot;Male&quot;</span></span>
68<span id="cb1-16"><a href="#cb1-16" aria-hidden="true"></a> <span class="kw">case</span> <span class="dv">1</span>: <span class="kw">return</span> <span class="st">&quot;Female&quot;</span></span>
69<span id="cb1-17"><a href="#cb1-17" aria-hidden="true"></a> <span class="kw">default</span>: <span class="kw">return</span> <span class="st">&quot;Other&quot;</span></span>
70<span id="cb1-18"><a href="#cb1-18" aria-hidden="true"></a> }</span>
71<span id="cb1-19"><a href="#cb1-19" aria-hidden="true"></a>}</span>
72<span id="cb1-20"><a href="#cb1-20" aria-hidden="true"></a></span>
73<span id="cb1-21"><a href="#cb1-21" aria-hidden="true"></a><span class="co">// You can accidentally do stupid stuff like:</span></span>
74<span id="cb1-22"><a href="#cb1-22" aria-hidden="true"></a>gender := Male + <span class="dv">1</span></span></code></pre></div>
75<p>The Haskell equivalent of the same:</p>
76<div class="sourceCode" id="cb2"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">data</span> <span class="dt">Gender</span> <span class="ot">=</span> <span class="dt">Male</span></span>
77<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a> <span class="op">|</span> <span class="dt">Female</span></span>
78<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a> <span class="op">|</span> <span class="dt">Other</span></span>
79<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a> <span class="kw">deriving</span> (<span class="dt">Show</span>)</span>
80<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a></span>
81<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a><span class="fu">print</span> <span class="op">$</span> <span class="st">&quot;My gender is &quot;</span> <span class="op">++</span> (<span class="fu">show</span> <span class="dt">Male</span>)</span></code></pre></div>
82<h3 id="type-assertions">Type Assertions</h3>
83<p>A downcast with an optional error check? What could go wrong?</p>
84<p>Type assertions in Go allow you to do:</p>
85<div class="sourceCode" id="cb3"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">var</span> x <span class="kw">interface</span>{} = <span class="dv">7</span></span>
86<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>y, goodToGo := x.(<span class="dt">int</span>)</span>
87<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a><span class="kw">if</span> goodToGo {</span>
88<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a> fmt.Println(y)</span>
89<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>}</span></code></pre></div>
90<p>The error check however is optional:</p>
91<div class="sourceCode" id="cb4"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">var</span> x <span class="kw">interface</span>{} = <span class="dv">7</span></span>
92<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="kw">var</span> y := x.(<span class="dt">float64</span>)</span>
93<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>fmt.Println(y)</span>
94<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a><span class="co">// results in a runtime error:</span></span>
95<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a><span class="co">// panic: interface conversion: interface {} is int, not float64</span></span></code></pre></div>
96<h3 id="date-and-time">Date and Time</h3>
97<p>Anyone that has written Go previously, will probably already know what I am getting at here. For the uninitiated, parsing and formatting dates in Go requires a “layout”. This “layout” is based on magical reference date:</p>
98<pre><code>Mon Jan 2 15:04:05 MST 2006</code></pre>
99<p>Which is the date produced when you write the first seven natural numbers like so:</p>
100<pre><code>01/02 03:04:05 &#39;06 -0700</code></pre>
101<p>Parsing a string in <code>YYYY-MM-DD</code> format would look something like:</p>
102<div class="sourceCode" id="cb7"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">const</span> layout = <span class="st">&quot;2006-01-02&quot;</span></span>
103<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>time.Parse(layout, <span class="st">&quot;2020-08-01&quot;</span>)</span></code></pre></div>
104<p>This so-called “intuitive” method of formatting dates doesn’t allow you to print <code>0000 hrs</code> as <code>2400 hrs</code>, it doesn’t allow you to omit the leading zero in 24 hour formats. It is rife with inconveniences, if only there were a <a href="https://man7.org/linux/man-pages/man3/strftime.3.html">tried and tested</a> date formatting convention …</p>
105<h3 id="statements-over-expressions">Statements over Expressions</h3>
106<p>Statements have side effects, expressions return values. More often than not, expressions are easier to understand at a glance: evaluate the LHS and assign the same to the RHS.</p>
107<p>Rust allows you to create local namespaces, and treats blocks (<code>{}</code>) as expressions:</p>
108<div class="sourceCode" id="cb8"><pre class="sourceCode rust"><code class="sourceCode rust"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">let</span> twenty_seven <span class="op">=</span> <span class="op">{</span></span>
109<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a> <span class="kw">let</span> three <span class="op">=</span> <span class="dv">1</span> <span class="op">+</span> <span class="dv">2</span><span class="op">;</span></span>
110<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a> <span class="kw">let</span> nine <span class="op">=</span> three <span class="op">*</span> three<span class="op">;</span></span>
111<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a> nine <span class="op">*</span> three</span>
112<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="op">};</span></span></code></pre></div>
113<p>The Go equivalent of the same:</p>
114<div class="sourceCode" id="cb9"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a>twenty_seven := <span class="ot">nil</span></span>
115<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a></span>
116<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>three := <span class="dv">1</span> + <span class="dv">2</span></span>
117<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>nine := three * three</span>
118<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>twenty_seven = nine * three</span></code></pre></div>
119<h3 id="erroring-out-on-unused-variables">Erroring out on unused variables</h3>
120<p>Want to quickly prototype something? Go says no! In all seriousness, a warning would suffice, I don’t want to have to go back and comment each unused import out, only to come back and uncomment them a few seconds later.</p>
121<h3 id="error-handling">Error handling</h3>
122<div class="sourceCode" id="cb10"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="kw">if</span> err != <span class="ot">nil</span> { ... }</span></code></pre></div>
123<p>Need I say more? I will, for good measure:</p>
124<ol type="1">
125<li>Error handling is optional</li>
126<li>Errors are propagated via a clunky <code>if</code> + <code>return</code> statement</li>
127</ol>
128<p>I prefer Haskell’s “Monadic” error handling, which is employed by Rust as well:</p>
129<div class="sourceCode" id="cb11"><pre class="sourceCode rust"><code class="sourceCode rust"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co">// 1. error handling is compulsory</span></span>
130<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="co">// 2. errors are propagated with the `?` operator</span></span>
131<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a><span class="kw">fn</span> foo() <span class="op">-&gt;</span> <span class="dt">Result</span><span class="op">&lt;</span><span class="dt">String</span><span class="op">,</span> <span class="pp">io::</span><span class="bu">Error</span><span class="op">&gt;</span> <span class="op">{</span></span>
132<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> f <span class="op">=</span> <span class="pp">File::</span>open(<span class="st">&quot;foo.txt&quot;</span>)<span class="op">?;</span> <span class="co">// return if error</span></span>
133<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a> <span class="kw">let</span> <span class="kw">mut</span> s <span class="op">=</span> <span class="dt">String</span><span class="pp">::</span>new()<span class="op">;</span></span>
134<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a></span>
135<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a> f<span class="op">.</span>read_to_string(<span class="op">&amp;</span><span class="kw">mut</span> s)<span class="op">?;</span> <span class="co">// return if error</span></span>
136<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a></span>
137<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a> <span class="cn">Ok</span>(s) <span class="co">// all good, return a string inside a `Result` context</span></span>
138<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a><span class="op">}</span></span>
139<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a></span>
140<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a><span class="kw">fn</span> main() <span class="op">{</span></span>
141<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a> <span class="co">// `contents` is an enum known as Result:</span></span>
142<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a> <span class="kw">let</span> contents <span class="op">=</span> foo()<span class="op">;</span></span>
143<span id="cb11-15"><a href="#cb11-15" aria-hidden="true"></a> <span class="kw">match</span> contents <span class="op">{</span></span>
144<span id="cb11-16"><a href="#cb11-16" aria-hidden="true"></a> <span class="cn">Ok</span>(c) <span class="op">=&gt;</span> <span class="pp">println!</span>(c)<span class="op">,</span></span>
145<span id="cb11-17"><a href="#cb11-17" aria-hidden="true"></a> <span class="cn">Err</span>(e) <span class="op">=&gt;</span> <span class="pp">eprintln!</span>(e)</span>
146<span id="cb11-18"><a href="#cb11-18" aria-hidden="true"></a> <span class="op">}</span></span>
147<span id="cb11-19"><a href="#cb11-19" aria-hidden="true"></a><span class="op">}</span></span></code></pre></div>
148<h3 id="conclusion">Conclusion</h3>
149<p>I did not want to conclude without talking about stylistic choices, lack of metaprogramming, bizzare export rules, but, I am too busy converting my <code>interface{}</code> types into actual generic code for Go v2.</p>
150
151 </div>
152
153 <div class=intro>
154 Hi.
155 <div class=hot-links>
156 <a href=https://peppe.rs/index.xml class=feed-button>Subscribe</a>
157 <a href=https://liberapay.com/nerdypepper/donate class=donate-button>Donate</a>
158 </div>
159 <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p>
160 <p>
161 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
162 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
163 </p>
164 <p>Send me a mail at [email protected] or a message at [email protected].</p>
165 </div>
166
167 <a href="/" class="post-end-link">⟵ Back</a>
168 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/gripes_with_go.md
169">View Raw</a>
170 </div>
171 </div>
172 </body>
173</html>
diff --git a/docs/posts/hold_position!/index.html b/docs/posts/hold_position!/index.html
index 61e4768..8948370 100644
--- a/docs/posts/hold_position!/index.html
+++ b/docs/posts/hold_position!/index.html
@@ -60,7 +60,7 @@ winrestview(view) &quot; restore our original view!</code></pre>
60 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 60 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
61 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 61 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
62 </p> 62 </p>
63 <p>Send me a mail at [email protected] or a message at [email protected].</p> 63 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
64 </div> 64 </div>
65 65
66 <a href="/" class="post-end-link">⟵ Back</a> 66 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/my_setup/index.html b/docs/posts/my_setup/index.html
index 996a459..c24c765 100644
--- a/docs/posts/my_setup/index.html
+++ b/docs/posts/my_setup/index.html
@@ -58,7 +58,7 @@
58 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 58 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
59 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 59 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
60 </p> 60 </p>
61 <p>Send me a mail at [email protected] or a message at [email protected].</p> 61 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
62 </div> 62 </div>
63 63
64 <a href="/" class="post-end-link">⟵ Back</a> 64 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/onivim_sucks/index.html b/docs/posts/onivim_sucks/index.html
index ded6fd9..1549e3e 100644
--- a/docs/posts/onivim_sucks/index.html
+++ b/docs/posts/onivim_sucks/index.html
@@ -57,7 +57,7 @@
57 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 57 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
58 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 58 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
59 </p> 59 </p>
60 <p>Send me a mail at [email protected] or a message at [email protected].</p> 60 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
61 </div> 61 </div>
62 62
63 <a href="/" class="post-end-link">⟵ Back</a> 63 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/pixel_art_in_GIMP/index.html b/docs/posts/pixel_art_in_GIMP/index.html
index e6661b2..f767de8 100644
--- a/docs/posts/pixel_art_in_GIMP/index.html
+++ b/docs/posts/pixel_art_in_GIMP/index.html
@@ -101,7 +101,7 @@
101 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 101 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
102 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 102 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
103 </p> 103 </p>
104 <p>Send me a mail at [email protected] or a message at [email protected].</p> 104 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
105 </div> 105 </div>
106 106
107 <a href="/" class="post-end-link">⟵ Back</a> 107 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/rapid_refactoring_with_vim/index.html b/docs/posts/rapid_refactoring_with_vim/index.html
index ee05dc0..b0ed0ad 100644
--- a/docs/posts/rapid_refactoring_with_vim/index.html
+++ b/docs/posts/rapid_refactoring_with_vim/index.html
@@ -141,7 +141,7 @@ BUFFER: json!( ... );</code></pre>
141 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 141 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
142 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 142 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
143 </p> 143 </p>
144 <p>Send me a mail at [email protected] or a message at [email protected].</p> 144 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
145 </div> 145 </div>
146 146
147 <a href="/" class="post-end-link">⟵ Back</a> 147 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/static_sites_with_bash/index.html b/docs/posts/static_sites_with_bash/index.html
index b2a90a7..80bfe37 100644
--- a/docs/posts/static_sites_with_bash/index.html
+++ b/docs/posts/static_sites_with_bash/index.html
@@ -79,7 +79,7 @@
79 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 79 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
80 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 80 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
81 </p> 81 </p>
82 <p>Send me a mail at [email protected] or a message at [email protected].</p> 82 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
83 </div> 83 </div>
84 84
85 <a href="/" class="post-end-link">⟵ Back</a> 85 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/termux_tandem/index.html b/docs/posts/termux_tandem/index.html
index b4818cf..37088bb 100644
--- a/docs/posts/termux_tandem/index.html
+++ b/docs/posts/termux_tandem/index.html
@@ -70,7 +70,7 @@ mtZabXG.jpg p8d5c584f2841.jpg vjUxGjq.jpg</code></pre>
70 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 70 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
71 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 71 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
72 </p> 72 </p>
73 <p>Send me a mail at [email protected] or a message at [email protected].</p> 73 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
74 </div> 74 </div>
75 75
76 <a href="/" class="post-end-link">⟵ Back</a> 76 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/docs/posts/turing_complete_type_systems/index.html b/docs/posts/turing_complete_type_systems/index.html
index 3e572e3..cc51210 100644
--- a/docs/posts/turing_complete_type_systems/index.html
+++ b/docs/posts/turing_complete_type_systems/index.html
@@ -61,7 +61,7 @@
61 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 61 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
62 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 62 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
63 </p> 63 </p>
64 <p>Send me a mail at [email protected] or a message at [email protected].</p> 64 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
65 </div> 65 </div>
66 66
67 <a href="/" class="post-end-link">⟵ Back</a> 67 <a href="/" class="post-end-link">⟵ Back</a>
diff --git a/generate.sh b/generate.sh
index 9504d6a..86a5a40 100755
--- a/generate.sh
+++ b/generate.sh
@@ -55,7 +55,7 @@ intro() {
55 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. 55 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
56 I write open-source stuff to pass time. I also design fonts: scientifica, curie. 56 I write open-source stuff to pass time. I also design fonts: scientifica, curie.
57 </p> 57 </p>
58 <p>Send me a mail at [email protected] or a message at [email protected].</p> 58 <p>Send me a mail at [email protected] or a message at nerdypepper@irc.rizon.net.</p>
59 </div> 59 </div>
60 " 60 "
61} 61}
diff --git a/posts/gripes_with_go.md b/posts/gripes_with_go.md
index 60aabc8..9bcaabc 100644
--- a/posts/gripes_with_go.md
+++ b/posts/gripes_with_go.md
@@ -166,12 +166,27 @@ employed by Rust as well:
166// 1. error handling is compulsory 166// 1. error handling is compulsory
167// 2. errors are propagated with the `?` operator 167// 2. errors are propagated with the `?` operator
168fn foo() -> Result<String, io::Error> { 168fn foo() -> Result<String, io::Error> {
169 let mut f = File::open("foo.txt")?; // return here if error 169 let mut f = File::open("foo.txt")?; // return if error
170 let mut s = String::new(); 170 let mut s = String::new();
171 171
172 f.read_to_string(&mut s)?; // return here if error 172 f.read_to_string(&mut s)?; // return if error
173 173
174 Ok(s) // all good, return the value inside a `Result` context 174 Ok(s) // all good, return a string inside a `Result` context
175}
176
177fn main() {
178 // `contents` is an enum known as Result:
179 let contents = foo();
180 match contents {
181 Ok(c) => println!(c),
182 Err(e) => eprintln!(e)
183 }
175} 184}
176``` 185```
177 186
187### Conclusion
188
189I did not want to conclude without talking about stylistic
190choices, lack of metaprogramming, bizzare export rules, but,
191I am too busy converting my `interface{}` types into actual
192generic code for Go v2.