<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Programming on dlow's blog</title><link>https://blog.dlow.me/tags/programming/</link><description>Recent content in Programming on dlow's blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 14 Apr 2021 10:17:36 +0100</lastBuildDate><atom:link href="https://blog.dlow.me/tags/programming/index.xml" rel="self" type="application/rss+xml"/><item><title>bubble sort and tetrahedral numbers</title><link>https://blog.dlow.me/everything/bubble-sort-and-tetrahedral-numbers/</link><pubDate>Wed, 14 Apr 2021 10:17:36 +0100</pubDate><guid>https://blog.dlow.me/everything/bubble-sort-and-tetrahedral-numbers/</guid><description>&lt;p>Today I had a very simple problem in one of my Golang side projects. I have a server that retrieves a JSON array of objects that have the same schema and I want to display them in a server side rendered HTML table on a web page&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>.
If I had unlimited time, I would probably have started a &lt;code>Create-React-App&lt;/code> project and stick in a popular table library that takes care of rendering this JSON object.
However, that workflow requires building the Single Page App and then I probably have to embed it in the server.
That&amp;rsquo;s a bit too much effort for me as I wanted something more php-esque.&lt;/p></description></item><item><title>Using the reflect package</title><link>https://blog.dlow.me/programming/golang/using-the-reflect-package/</link><pubDate>Tue, 15 Sep 2020 22:54:19 +0100</pubDate><guid>https://blog.dlow.me/programming/golang/using-the-reflect-package/</guid><description>An example of how to use reflect package to access fields of unexported structs in golang</description></item><item><title>Anti pattern: turning struct into interface</title><link>https://blog.dlow.me/programming/golang/anti-pattern-turning-struct-into-interface/</link><pubDate>Sun, 24 May 2020 12:44:55 +0100</pubDate><guid>https://blog.dlow.me/programming/golang/anti-pattern-turning-struct-into-interface/</guid><description>&lt;p>&lt;a href="../struct-embedding">Previously I wrote about using struct embedding&lt;/a> to achieve pseudo inheritance for code reuse. In this post, I want to explore an example of what I think is an anti pattern as a result of the lack of inheritance and how I think it could be better.&lt;/p>
&lt;p>In the absence of inheritance in golang, it is very tempting to turn fields into functions of an interface.&lt;/p>
&lt;p>As an motivating example, consider the following:&lt;/p></description></item><item><title>Struct embedding as implicit composition</title><link>https://blog.dlow.me/programming/golang/struct-embedding/</link><pubDate>Fri, 22 May 2020 11:26:33 +0100</pubDate><guid>https://blog.dlow.me/programming/golang/struct-embedding/</guid><description>&lt;p>In programming, the principle &amp;ldquo;don&amp;rsquo;t repeat yourself&amp;rdquo;, DRY for short, recommends that we try to reuse the same implementation where possible. In this post, I will cover what it&amp;rsquo;s like to do it in golang through struct embedding and my personal thoughts on that pattern.&lt;/p>
&lt;h1 id="golang-struct-embedding">Golang struct embedding &lt;a class="anchor" href="#golang-struct-embedding">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>One common way of code reuse is inheritance. In Java, we can do this by implementing a method on the parent class, then subclasses will inherit this implementation.&lt;/p></description></item><item><title>Monadic Boolean 2</title><link>https://blog.dlow.me/programming/scala/monadic-boolean-2/</link><pubDate>Thu, 04 Jul 2019 23:04:54 +0100</pubDate><guid>https://blog.dlow.me/programming/scala/monadic-boolean-2/</guid><description>&lt;p>&lt;a href="../monadic-boolean">Previously&lt;/a>, I concluded that using &lt;code>Either[String, Unit]&lt;/code> is quite a nice way to compose predicates. Since then I have noticed some other patterns in my code that I would argue is an improvement.&lt;/p>
&lt;p>We will still keep the &amp;ldquo;for-comprehension&amp;rdquo; style as I find that it makes the code more readable due to the shorter indentation compared to nested if else blocks.&lt;/p>
&lt;p>The main difference is rather than defining functions that take the input and produce the monad, we use implicits to turn a boolean (or any other types as we shall see) into the monad we want for composition.&lt;/p></description></item><item><title>Confusing syntax sugar</title><link>https://blog.dlow.me/programming/scala/confusing-syntax-sugar/</link><pubDate>Fri, 10 May 2019 22:15:48 +0100</pubDate><guid>https://blog.dlow.me/programming/scala/confusing-syntax-sugar/</guid><description>&lt;h1 id="a-grave-misunderstanding">A grave misunderstanding &lt;a class="anchor" href="#a-grave-misunderstanding">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>When I started using Scala, I was very confused by &amp;ldquo;for comprehensions&amp;rdquo; for a very long time. My mistake was to treat &lt;code>&amp;lt;-&lt;/code> as an &amp;ldquo;unwrapper&amp;rdquo;. For example, in the following, &lt;code>&amp;lt;-&lt;/code> &amp;ldquo;unwraps&amp;rdquo; the collection/container/monad, as expected.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-scala" data-lang="scala">&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">def&lt;/span> main&lt;span style="color:#f92672">(&lt;/span>args&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Array&lt;/span>&lt;span style="color:#f92672">[&lt;/span>&lt;span style="color:#66d9ef">String&lt;/span>&lt;span style="color:#f92672">])&lt;/span>&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Unit&lt;/span> &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#f92672">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#f92672">{&lt;/span> x &lt;span style="color:#66d9ef">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">Option&lt;/span>&lt;span style="color:#f92672">(&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#f92672">{&lt;/span> println&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#75715e">// prints 1
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#f92672">{&lt;/span> x &lt;span style="color:#66d9ef">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">List&lt;/span>&lt;span style="color:#f92672">(&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span>&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#f92672">{&lt;/span> println&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#75715e">// prints 2
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#f92672">{&lt;/span> x &lt;span style="color:#66d9ef">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">Try&lt;/span>&lt;span style="color:#f92672">(&lt;/span>&lt;span style="color:#ae81ff">3&lt;/span>&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#f92672">{&lt;/span> println&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#75715e">// prints 3
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#f92672">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We also know that for comprehension is sugar for flatMap, map and withFilter&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>. So we can combine enumerators like the following to produce very succinct and elegant code.&lt;/p></description></item><item><title>Monadic Boolean</title><link>https://blog.dlow.me/programming/scala/monadic-boolean/</link><pubDate>Mon, 25 Mar 2019 21:42:51 +0000</pubDate><guid>https://blog.dlow.me/programming/scala/monadic-boolean/</guid><description>&lt;p>The following task is quite common: do something if all given predicates are satisfied and if some predicate fails, make it obvious which failed.&lt;/p>
&lt;p>Consider the contrived scenario where we are asked to save a number to the database if it satisfy all our conditions:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-scala" data-lang="scala">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> isGood&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Int&lt;/span>&lt;span style="color:#f92672">)&lt;/span>&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Boolean&lt;/span> &lt;span style="color:#f92672">=&lt;/span> isConditionA&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> isConditionB&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#f92672">...&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> usage&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Int&lt;/span>&lt;span style="color:#f92672">)&lt;/span>&lt;span style="color:#66d9ef">:&lt;/span> &lt;span style="color:#66d9ef">Unit&lt;/span> &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#f92672">(&lt;/span>isGood&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">))&lt;/span> saveNumber&lt;span style="color:#f92672">(&lt;/span>x&lt;span style="color:#f92672">)&lt;/span> &lt;span style="color:#66d9ef">else&lt;/span> doNothing&lt;span style="color:#f92672">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Some time later, we notice that some numbers are being rejected, and we have no idea why, so we decide to add logging when a number is rejected. How should we go about it?&lt;/p></description></item><item><title>Strategy Pattern</title><link>https://blog.dlow.me/programming/java/strategy-pattern/</link><pubDate>Thu, 07 Mar 2019 20:53:55 +0000</pubDate><guid>https://blog.dlow.me/programming/java/strategy-pattern/</guid><description>&lt;h1 id="goals">Goals: &lt;a class="anchor" href="#goals">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>When the number of strategy changes, we want to minimize change.
When the implementation of a strategy changes, we want to minimize change.&lt;/p>
&lt;h1 id="case-study">Case study: &lt;a class="anchor" href="#case-study">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;ul>
&lt;li>Mode of transportation&lt;/li>
&lt;li>Representation of a data&lt;/li>
&lt;li>Behaviour of an actor&lt;/li>
&lt;li>Trading algorithm&lt;/li>
&lt;/ul>
&lt;h1 id="entitiesobjects-involved">Entities/Objects involved &lt;a class="anchor" href="#entitiesobjects-involved">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;ul>
&lt;li>There is a strategy interface encapsulating the behaviour&lt;/li>
&lt;li>There is a context which wraps the strategy and is responsible for getting the data to apply the strategy on.&lt;/li>
&lt;li>There are implementation of the strategy interface.&lt;/li>
&lt;/ul>
&lt;h1 id="motivating-problem">Motivating problem &lt;a class="anchor" href="#motivating-problem">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>Suppose you have a set of datapoints, and you want to visualize them. You can either visualze them as a frequency graph, or as a time chart.&lt;/p></description></item><item><title>8 Weeks into Java and Scala</title><link>https://blog.dlow.me/programming/8-weeks-into-java-and-scala/</link><pubDate>Sun, 15 Apr 2018 02:19:36 +0000</pubDate><guid>https://blog.dlow.me/programming/8-weeks-into-java-and-scala/</guid><description>&lt;p>This post contains some thoughts I have after working with Java and Scala professionally for 8 weeks. The content assumes the reader has some experiences writing Java/Scala code.&lt;/p>
&lt;h1 id="starting-from-scratch">Starting from scratch &lt;a class="anchor" href="#starting-from-scratch">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>There are several components a learner must understand before he/she can get productive.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>An easy installation process&lt;/strong>, preferably something along the lines of download something, extract or run an installer, modify the user path if necessary. I think anything more than that is asking too much from the user.&lt;/li>
&lt;li>&lt;strong>An intuitive package manager&lt;/strong>. Golang comes with &lt;code>go get&lt;/code> and &lt;code>go install&lt;/code>. Node has &lt;code>npm&lt;/code>, Python has &lt;code>pip&lt;/code>, and Java has maven, ant, gradle. In my opinion, Java is probably the least beginner friendly for setting up.&lt;/li>
&lt;li>&lt;strong>The syntax (literal or not) for initializing common datatypes&lt;/strong> such as list/array, map/dictionary, and for manipulating data.&lt;/li>
&lt;/ul>
&lt;h1 id="java">Java &lt;a class="anchor" href="#java">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;h2 id="java-requires-good-mastery-of-the-ide">Java requires good mastery of the IDE &lt;a class="anchor" href="#java-requires-good-mastery-of-the-ide">&lt;span>&lt;/span>&lt;/a>&lt;/h2>&lt;p>From compilation to running the program, the IDE is immensely important.&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> The IDE, I use intelliJ, have probably generated more code than I what I physically typed. I feel that half of knowing Java is knowing which shortcuts to press in the IDE. The following are the shortcuts that bring me pleasure when I use them.&lt;/p></description></item><item><title>Java variance, covariance</title><link>https://blog.dlow.me/programming/java/variance/</link><pubDate>Wed, 28 Mar 2018 23:50:26 +0000</pubDate><guid>https://blog.dlow.me/programming/java/variance/</guid><description>&lt;h1 id="introduction">Introduction &lt;a class="anchor" href="#introduction">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>Many langauges support subtyping - this allows us to express that a type Apple is a subtype of Fruit. Notationally, we say &lt;code>T &amp;lt; S&lt;/code>. Subtyping manifest itself as subclass in most programming language concepts.&lt;/p>
&lt;p>Suppose we have the following:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-java" data-lang="java">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">Fruit&lt;/span> {}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">Apple&lt;/span> &lt;span style="color:#66d9ef">extends&lt;/span> Fruit {}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">Orange&lt;/span> &lt;span style="color:#66d9ef">extends&lt;/span> Fruit {}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">GreenApple&lt;/span> &lt;span style="color:#66d9ef">extends&lt;/span> Apple {}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then we have &lt;code>Apple &amp;lt; Fruit&lt;/code>. In simple English, we can think of this as whenever we expect a type &lt;code>Fruit&lt;/code>, we can use the type &lt;code>Apple&lt;/code>. Or think of it as an &lt;code>Apple&lt;/code> &lt;strong>is a&lt;/strong> &lt;code>Fruit&lt;/code>.&lt;/p></description></item><item><title>Comprehension with filtering</title><link>https://blog.dlow.me/programming/comprehension-filter/</link><pubDate>Sun, 25 Mar 2018 18:18:09 +0000</pubDate><guid>https://blog.dlow.me/programming/comprehension-filter/</guid><description>&lt;h1 id="problem">Problem &lt;a class="anchor" href="#problem">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>From 2018 IMOK Cayley Q1:&lt;/p>
&lt;blockquote>
&lt;p>How many 6 digit numbers are there where the digits are increasing, divisible by 6, and has the digits 3, 4 and 5?&lt;/p>&lt;/blockquote>
&lt;p>Note that an increasing number is one that is not strictly decreasing. Hence, 11123 is also an increasing number.&lt;/p>
&lt;h1 id="attempt">Attempt &lt;a class="anchor" href="#attempt">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>Let&amp;rsquo;s start with a procedural code:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-py" data-lang="py">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">count1&lt;/span>():
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> res &lt;span style="color:#f92672">=&lt;/span> []
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> i &lt;span style="color:#f92672">in&lt;/span> range(&lt;span style="color:#ae81ff">100000&lt;/span>, &lt;span style="color:#ae81ff">1000000&lt;/span>):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> i &lt;span style="color:#f92672">%&lt;/span> &lt;span style="color:#ae81ff">6&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#f92672">not&lt;/span> increasing(i):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#f92672">not&lt;/span> contains345(i):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> res&lt;span style="color:#f92672">.&lt;/span>append(i)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> res
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">increasing&lt;/span>(x):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> y &lt;span style="color:#f92672">in&lt;/span> str(x):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> int(y) &lt;span style="color:#f92672">&amp;lt;&lt;/span> c:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">False&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c &lt;span style="color:#f92672">=&lt;/span> int(y)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">True&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">contains345&lt;/span>(x):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> i &lt;span style="color:#f92672">in&lt;/span> &lt;span style="color:#e6db74">&amp;#39;345&amp;#39;&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> i &lt;span style="color:#f92672">not&lt;/span> &lt;span style="color:#f92672">in&lt;/span> str(x):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">False&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">True&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="filtering">Filtering &lt;a class="anchor" href="#filtering">&lt;span>&lt;/span>&lt;/a>&lt;/h2>&lt;p>Previously we saw how to combine map into the comprehension. Now we combine filter predicates.&lt;/p></description></item><item><title>Kata: count in order</title><link>https://blog.dlow.me/programming/comprehension/</link><pubDate>Tue, 20 Mar 2018 20:36:25 +0000</pubDate><guid>https://blog.dlow.me/programming/comprehension/</guid><description>&lt;h1 id="introduction">Introduction &lt;a class="anchor" href="#introduction">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>&lt;strong>Problem&lt;/strong>: Given a list of words, return the list of numbers which represents the number of letters in that word that is the same as its position in the alphabet. &lt;a href="https://www.codewars.com/kata/alphabet-symmetry/python">Source&lt;/a>&lt;/p>
&lt;p>&lt;strong>Final solution&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">solve&lt;/span>(arr):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> [sum(i &lt;span style="color:#f92672">==&lt;/span> ord(c) &lt;span style="color:#f92672">-&lt;/span> ord(&lt;span style="color:#e6db74">&amp;#39;a&amp;#39;&lt;/span>) &lt;span style="color:#66d9ef">for&lt;/span> i, c &lt;span style="color:#f92672">in&lt;/span> enumerate(s&lt;span style="color:#f92672">.&lt;/span>lower())) &lt;span style="color:#66d9ef">for&lt;/span> s &lt;span style="color:#f92672">in&lt;/span> arr]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>First attempt&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">solve&lt;/span>(arr):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> letters &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;abcdefghijklmnopqrstuvwxyz&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">f&lt;/span>(word):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> (i, j) &lt;span style="color:#f92672">in&lt;/span> enumerate(word):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> i &lt;span style="color:#f92672">&amp;gt;&lt;/span> &lt;span style="color:#ae81ff">25&lt;/span>: &lt;span style="color:#66d9ef">return&lt;/span> c
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> letters[i] &lt;span style="color:#f92672">==&lt;/span> j: 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c&lt;span style="color:#f92672">+=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> c
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> arr &lt;span style="color:#f92672">=&lt;/span> map(&lt;span style="color:#66d9ef">lambda&lt;/span> x: x&lt;span style="color:#f92672">.&lt;/span>lower(), arr)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> res &lt;span style="color:#f92672">=&lt;/span> list(map(f, arr))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> res
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>solve([&lt;span style="color:#e6db74">&amp;#34;encode&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;abc&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;xyzD&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;ABmD&amp;#34;&lt;/span>]) &lt;span style="color:#f92672">//&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>, &lt;span style="color:#ae81ff">3&lt;/span>, &lt;span style="color:#ae81ff">1&lt;/span>, &lt;span style="color:#ae81ff">4&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>solve([&lt;span style="color:#e6db74">&amp;#34;abode&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;ABc&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;xyzD&amp;#34;&lt;/span>]) &lt;span style="color:#f92672">//&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span>, &lt;span style="color:#ae81ff">3&lt;/span>, &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="the-lessons">The lessons &lt;a class="anchor" href="#the-lessons">&lt;span>&lt;/span>&lt;/a>&lt;/h2>&lt;h3 id="get-rid-of-lambdas-and-map">Get rid of lambdas and map &lt;a class="anchor" href="#get-rid-of-lambdas-and-map">&lt;span>&lt;/span>&lt;/a>&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-py" data-lang="py">&lt;span style="display:flex;">&lt;span>arr &lt;span style="color:#f92672">=&lt;/span> map(&lt;span style="color:#66d9ef">lambda&lt;/span> x: x&lt;span style="color:#f92672">.&lt;/span>lower(), arr)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># can always be replaced by&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>arr &lt;span style="color:#f92672">=&lt;/span> [x&lt;span style="color:#f92672">.&lt;/span>lower &lt;span style="color:#66d9ef">for&lt;/span> x &lt;span style="color:#f92672">in&lt;/span> arr]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="a-counter-can-be-replaced-with-sum">A counter can be replaced with sum &lt;a class="anchor" href="#a-counter-can-be-replaced-with-sum">&lt;span>&lt;/span>&lt;/a>&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-py" data-lang="py">&lt;span style="display:flex;">&lt;span>c &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">...&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">if&lt;/span> cond: c&lt;span style="color:#f92672">+=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">...&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Can be replaced by&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sum(cond &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#f92672">...&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># e.g.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">f&lt;/span>(word):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> sum(letters[i] &lt;span style="color:#f92672">==&lt;/span> j &lt;span style="color:#66d9ef">for&lt;/span> (i,j) &lt;span style="color:#f92672">in&lt;/span> enumerate(word))
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="trick-for-finding-distance-of-letters">Trick for finding distance of letters &lt;a class="anchor" href="#trick-for-finding-distance-of-letters">&lt;span>&lt;/span>&lt;/a>&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-py" data-lang="py">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Instead of hard coding letters, or numbers&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>letters &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;abcd...&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>letters[i] &lt;span style="color:#f92672">==&lt;/span> j
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Replace it with&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>i &lt;span style="color:#f92672">==&lt;/span> Ord(j) &lt;span style="color:#f92672">-&lt;/span> Ord(&lt;span style="color:#e6db74">&amp;#34;a&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="conclusion">Conclusion &lt;a class="anchor" href="#conclusion">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>We have seen how we can use list comprehension to simplify our problem.&lt;/p></description></item><item><title>How to do common tasks in Java</title><link>https://blog.dlow.me/programming/java/java-common-tasks/</link><pubDate>Mon, 19 Mar 2018 21:49:03 +0000</pubDate><guid>https://blog.dlow.me/programming/java/java-common-tasks/</guid><description>&lt;h1 id="gulf-of-execution">Gulf of execution &lt;a class="anchor" href="#gulf-of-execution">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>In his book &lt;em>The design of everyday things&lt;/em>, Norman introduced the terms &lt;code>gulf of evaluation&lt;/code> and &lt;code>gulf of execution&lt;/code>. The latter is the difference between the intentions of the user and what the system allows them to do or how well the system supports those actions.&lt;/p>
&lt;p>This describes perfectly my experience as I moved from Golang to Java.&lt;/p>
&lt;p>I find myself asking questions like:&lt;/p>
&lt;ul>
&lt;li>What is the least painful way of iterating over a map?&lt;/li>
&lt;li>How do I make lazy functions?&lt;/li>
&lt;li>How do I run something in a different thread?&lt;/li>
&lt;li>How to get the path of folder and files?&lt;/li>
&lt;/ul>
&lt;p>This post documents my learning through my struggle.&lt;/p></description></item><item><title>Getting started with scala again</title><link>https://blog.dlow.me/programming/scala/getting-started/</link><pubDate>Thu, 01 Mar 2018 06:35:29 +0000</pubDate><guid>https://blog.dlow.me/programming/scala/getting-started/</guid><description>&lt;h1 id="introduction">Introduction &lt;a class="anchor" href="#introduction">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>I started a new job, and I have to write scala. The last time I touched the language was two years ago, for about 2 weeks. My main takeaway then was disgust at the existance of something called the &lt;a href="https://www.google.co.uk/search?q=cake+pattern+scala">cake pattern&lt;/a>.&lt;/p>
&lt;p>This series is about me having to start embracing scala, coming from a primarily golang background.&lt;/p>
&lt;h1 id="getting-started">Getting started &lt;a class="anchor" href="#getting-started">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>I started looking through my book repository, and found a book called &lt;a href="https://www.goodreads.com/book/show/17839288-atomic-scala">Atomic scala&lt;/a>. It goes through language features with example, more than &lt;a href="https://docs.scala-lang.org/tour/tour-of-scala.html">the tour&lt;/a> provides in my opinion.&lt;/p></description></item><item><title>More about struct allocation</title><link>https://blog.dlow.me/programming/golang/2016-12-14-struct-allocation/</link><pubDate>Wed, 14 Dec 2016 00:17:52 +0000</pubDate><guid>https://blog.dlow.me/programming/golang/2016-12-14-struct-allocation/</guid><description>&lt;p>In Go, instantiating a struct in a function doesn&amp;rsquo;t always result in heap allocated memory. If you create a struct and it never leaves the function, Go can stack-allocate it. If you create a struct and pass it to another function directly, Go can copy the struct in place, which means it can still be stack-allocated. If you reference it then pass the pointer, now Go has to heap-allocate it, which means more GC.&lt;/p></description></item><item><title>Getting around generics in Golang</title><link>https://blog.dlow.me/programming/golang/generics/</link><pubDate>Sat, 20 Aug 2016 10:49:30 +0100</pubDate><guid>https://blog.dlow.me/programming/golang/generics/</guid><description>&lt;h1 id="introduction">Introduction &lt;a class="anchor" href="#introduction">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>Go programmers would know about the lack of generic in the language (even at 1.7 at the point of writing). Technically, Go has generic, &lt;code>append&lt;/code>, &lt;code>make&lt;/code>, &amp;hellip; are some examples. It&amp;rsquo;s simply not accessibly to normal programmers. The &lt;a href="http://web.archive.org/web/20160727102024/https://golang.org/doc/faq#generics">website&lt;/a> says that generics are convenient but come at a cost in complexity in the type system, and that it is possible to write code that does what generics would enable. In this article, I want to explore how to replace generics.&lt;/p></description></item><item><title>The case for typed variables</title><link>https://blog.dlow.me/programming/golang/typed_var/</link><pubDate>Thu, 18 Aug 2016 23:00:00 +0100</pubDate><guid>https://blog.dlow.me/programming/golang/typed_var/</guid><description>&lt;h1 id="the-case-of-typed-variables">The case of typed variables &lt;a class="anchor" href="#the-case-of-typed-variables">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;p>Go has short assignments and the compiler can infer its type.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> &lt;span style="color:#e6db74">&amp;#34;fmt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">AddOne&lt;/span>(&lt;span style="color:#a6e22e">a&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#66d9ef">int&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">a&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">x&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Printf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;%v&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">AddOne&lt;/span>(&lt;span style="color:#a6e22e">x&lt;/span>)) &lt;span style="color:#75715e">// 2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>One could have also written&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">x&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span> = &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Printf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;%v&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">AddOne&lt;/span>(&lt;span style="color:#a6e22e">x&lt;/span>)) &lt;span style="color:#75715e">// 2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>or even&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">x&lt;/span> = &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Printf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;%v&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">AddOne&lt;/span>(&lt;span style="color:#a6e22e">x&lt;/span>)) &lt;span style="color:#75715e">// 2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>So which should we prefer?&lt;/p>
&lt;p>In normal cases, &lt;code>x := 1&lt;/code> is preferred as it is concise and clear. However, there is a case for using the latter.&lt;/p></description></item><item><title>A slice gotcha in golang</title><link>https://blog.dlow.me/programming/golang/slices-and-pointers/</link><pubDate>Mon, 28 Mar 2016 09:55:20 +0800</pubDate><guid>https://blog.dlow.me/programming/golang/slices-and-pointers/</guid><description>&lt;h1 id="slices-gotcha">Slices gotcha &lt;a class="anchor" href="#slices-gotcha">&lt;span>&lt;/span>&lt;/a>&lt;/h1>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">s&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> []&lt;span style="color:#66d9ef">int&lt;/span>{&lt;span style="color:#ae81ff">1&lt;/span>,&lt;span style="color:#ae81ff">2&lt;/span>,&lt;span style="color:#ae81ff">3&lt;/span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">s&lt;/span>[:&lt;span style="color:#ae81ff">2&lt;/span>]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">t&lt;/span> = append(&lt;span style="color:#a6e22e">t&lt;/span>, &lt;span style="color:#ae81ff">100&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>) &lt;span style="color:#75715e">// {1,2,100}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#a6e22e">s&lt;/span>) &lt;span style="color:#75715e">// ?&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If you&amp;rsquo;ve said &lt;code>{1,2,100}&lt;/code>, good on you! You can just quickly skim through this section.&lt;/p>
&lt;p>In go, an array is a contiguous piece of memory that has a fixed length. However, dynamically sized arrays are often more useful for a programmer. Go&amp;rsquo;s solution to this is slices. A slice is another datastructure that contains a pointer to the underlying array, and two values for the length and capacity.&lt;/p></description></item></channel></rss>