<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joe Clay</title>
    <description>The latest articles on DEV Community by Joe Clay (@17cupsofcoffee).</description>
    <link>https://dev.to/17cupsofcoffee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F20080%2F298dad64-3d9d-4bee-9fa8-022f0daa3557.jpg</url>
      <title>DEV Community: Joe Clay</title>
      <link>https://dev.to/17cupsofcoffee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/17cupsofcoffee"/>
    <language>en</language>
    <item>
      <title>Why Did Rust Pick the 'If Let' Syntax?</title>
      <dc:creator>Joe Clay</dc:creator>
      <pubDate>Tue, 12 Jan 2021 21:46:30 +0000</pubDate>
      <link>https://dev.to/17cupsofcoffee/why-did-rust-pick-the-if-let-syntax-bea</link>
      <guid>https://dev.to/17cupsofcoffee/why-did-rust-pick-the-if-let-syntax-bea</guid>
      <description>&lt;p&gt;One of my favourite features of Rust is that it has excellent support for pattern matching. This is usually done through &lt;code&gt;match&lt;/code&gt; expressions, but there is also a shorter syntax that can be used if you only need a single branch, which is called &lt;code&gt;if let&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you're unfamiliar, a &lt;code&gt;match&lt;/code&gt; expression looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;           &lt;span class="c"&gt;// This matches if `x` is `Some`.&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// This prints '123'.&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="mi"&gt;_&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;                &lt;span class="c"&gt;// This matches all other values.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the equivalent &lt;code&gt;if let&lt;/code&gt; expression looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   &lt;span class="c"&gt;// This matches if `x` is `Some`.&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// This prints '123'.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shortcut syntax, useful as it is, can be quite confusing to new Rust developers. I commonly see people asking things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why is that &lt;code&gt;if&lt;/code&gt; statement 'backwards'?&lt;/li&gt;
&lt;li&gt;Why is there a &lt;code&gt;let&lt;/code&gt; in that conditional?&lt;/li&gt;
&lt;li&gt;Why do I have to use &lt;code&gt;=&lt;/code&gt; instead of &lt;code&gt;==&lt;/code&gt;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I had similar questions when I started learning Rust, and to answer them, we need to take a step back and look at the plain old &lt;code&gt;let&lt;/code&gt; syntax. It's relevant, I promise!&lt;/p&gt;

&lt;p&gt;In most cases, you see &lt;code&gt;let&lt;/code&gt; being used to declare a simple named variable, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What might not be apparent at first glance is that the left side of a &lt;code&gt;let&lt;/code&gt; isn't &lt;em&gt;just&lt;/em&gt; a name - it's a pattern, the same as what you'd use in the arm of a &lt;code&gt;match&lt;/code&gt; expression!&lt;/p&gt;

&lt;p&gt;This means that we can actually do pattern matching when declaring variables, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// Wrap the data.&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c"&gt;// Unwrap ('destructure') the data via a pattern.&lt;/span&gt;

&lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;          &lt;span class="c"&gt;// This prints '123'.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is, however, one important restriction here compared to when you're using &lt;code&gt;match&lt;/code&gt; - in a &lt;code&gt;let&lt;/code&gt; statement, you can only use patterns that are 'irrefutable'. In simpler terms, this means that you can only use a pattern which will match for every possible value of the type that you're matching against.&lt;/p&gt;

&lt;p&gt;We can see what happens when this &lt;em&gt;isn't&lt;/em&gt; the case by adding an extra variant to our &lt;code&gt;Example&lt;/code&gt; enum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;Oops&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives us an error which looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;E0005&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="n"&gt;refutable&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt; &lt;span class="n"&gt;binding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Oops&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;covered&lt;/span&gt;
 &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="py"&gt;.rs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;     &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;         &lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;         &lt;span class="n"&gt;Oops&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;         &lt;span class="o"&gt;----&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;covered&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;     &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="mi"&gt;_____&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Example&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;defined&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;       &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;^^^^^^^^^^^^^^^^&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Oops&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;covered&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt;
  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;bindings&lt;/span&gt; &lt;span class="n"&gt;require&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="s"&gt;"irrefutable pattern"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;variant&lt;/span&gt;
  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;information&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;visit&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c"&gt;//doc.rust-lang.org/book/ch18-02-refutability.html&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if we can't use &lt;code&gt;let&lt;/code&gt; for this pattern, what can we use? This is where we circle back to &lt;code&gt;if let&lt;/code&gt;!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;Oops&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nn"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that this example is almost identical to the previous one that didn't compile - the only changes are the extra &lt;code&gt;if&lt;/code&gt;, and the extra block to mark which code should only be run if the pattern matched.&lt;/p&gt;

&lt;p&gt;This is the reason that &lt;code&gt;if let&lt;/code&gt; looks the way it does - it's an extension of the existing &lt;code&gt;let&lt;/code&gt; syntax (which only supports irrefutable patterns) to support all kinds of patterns!&lt;/p&gt;

&lt;p&gt;Once I started thinking about it this way, the syntax started to feel a lot more natural, and I hope this post helps make the relationship between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;if let&lt;/code&gt; click for other people too.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>languagedesign</category>
    </item>
    <item>
      <title>Simple HTTPS Domain Redirects with Netlify</title>
      <dc:creator>Joe Clay</dc:creator>
      <pubDate>Tue, 07 Jul 2020 11:23:14 +0000</pubDate>
      <link>https://dev.to/17cupsofcoffee/simple-https-domain-redirects-with-netlify-5efc</link>
      <guid>https://dev.to/17cupsofcoffee/simple-https-domain-redirects-with-netlify-5efc</guid>
      <description>&lt;p&gt;This week, a website that I help maintain ran into some issues with their domain names. I stumbled upon a quick (and free!) solution which I thought was worth sharing, in case it helps anyone else out of a jam.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; You can use a Netlify &lt;a href="https://docs.netlify.com/routing/redirects"&gt;&lt;code&gt;_redirects&lt;/code&gt;&lt;/a&gt; file to redirect both HTTP and HTTPS traffic from one domain to another, without paying for server hosting or an SSL certificate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://arewegameyet.rs/"&gt;Are We Game Yet?&lt;/a&gt; is a website which lists resources for game developers in the Rust community. It's hosted on Github Pages, and historically it's been available via &lt;code&gt;https://arewegameyet.com&lt;/code&gt;. We also had simple HTTP redirects set up on &lt;code&gt;http://arewegameyet.rs&lt;/code&gt; and &lt;code&gt;http://arewegameyet.org&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Since the &lt;code&gt;.rs&lt;/code&gt; domain makes it a bit clearer that the website is Rust-related, we decided that it'd be good to make this the new primary URL. But that led us to a bit of a conundrum: pretty much all of the existing links to the site, including the ones on Google, point at &lt;code&gt;https://arewegameyet.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;GitHub Pages doesn't support multiple domains, and our domain providers only support simple HTTP redirects unless we pay through the nose for a VPS and/or a SSL certificate. So for a while, it looked like we wouldn't be able fix these URLs without moving our hosting or increasing our expenditure, neither of which would be ideal.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; is a web hosting service that's targeted at static sites. They have an extremely generous free tier, which I'm currently using to host both this blog and &lt;a href="https://tetra.seventeencups.net/"&gt;Tetra's documentation&lt;/a&gt;, and I'll basically tell anyone who'll listen about how they're the best thing since sliced bread.&lt;/p&gt;

&lt;p&gt;One of the really cool features of Netlify is that they allow you to specify &lt;a href="https://docs.netlify.com/routing/redirects/#syntax-for-the-redirects-file"&gt;redirect rules&lt;/a&gt; as part of your static deployment. You provide a file called &lt;code&gt;_redirects&lt;/code&gt;, and their servers will handle mapping the URLs. It's similar to an Apache &lt;code&gt;.htaccess&lt;/code&gt; file, but without having to actually manage the server itself.&lt;/p&gt;

&lt;p&gt;I've seen a lot of cool tricks done with &lt;code&gt;_redirects&lt;/code&gt; files before; for example, &lt;a href="https://kentcdodds.com/"&gt;Kent C. Dodds&lt;/a&gt; has used them to create his own &lt;a href="https://github.com/kentcdodds/netlify-shortener"&gt;URL shortener&lt;/a&gt;. So I was curious whether they could be applied to this problem - and as it turned out, thanks to &lt;a href="https://docs.netlify.com/routing/redirects/redirect-options/#splats"&gt;splat redirects&lt;/a&gt;, they can!&lt;/p&gt;

&lt;p&gt;First, we created a dummy &lt;code&gt;index.html&lt;/code&gt; file, as Netlify didn't seem to want to deploy a site without one present. Then, alongside it, we created a &lt;code&gt;_redirects&lt;/code&gt; file with only two lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* https://arewegameyet.rs/:splat 301!
/  https://arewegameyet.rs        301!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;!&lt;/code&gt; at the end is important, as it prevents files in the deployment from &lt;a href="https://docs.netlify.com/routing/redirects/rewrites-proxies/#shadowing"&gt;shadowing&lt;/a&gt; the redirects.&lt;/p&gt;

&lt;p&gt;We deployed these two files to Netlify, added our &lt;code&gt;.com&lt;/code&gt; and &lt;code&gt;.org&lt;/code&gt; domain names to the project, and activated HTTPS via Netlify's &lt;a href="https://letsencrypt.org/"&gt;Let's Encrypt&lt;/a&gt; integration.&lt;/p&gt;

&lt;p&gt;And that's it! Now both domains redirect all of their traffic on both HTTP and HTTPS to the corresponding page on &lt;code&gt;https://arewegameyet.rs&lt;/code&gt;, and we didn't have to pay a penny.&lt;/p&gt;

&lt;p&gt;Hopefully this is useful to other people who find themselves in a similar situation!&lt;/p&gt;

</description>
      <category>netlify</category>
      <category>web</category>
      <category>domain</category>
      <category>https</category>
    </item>
    <item>
      <title>How Lua Avoids Semicolons</title>
      <dc:creator>Joe Clay</dc:creator>
      <pubDate>Tue, 03 Apr 2018 19:02:17 +0000</pubDate>
      <link>https://dev.to/17cupsofcoffee/how-lua-banished-the-semicolons-225o</link>
      <guid>https://dev.to/17cupsofcoffee/how-lua-banished-the-semicolons-225o</guid>
      <description>&lt;p&gt;My current pet project outside of work is developing a little programming language called &lt;a href="https://github.com/17cupsofcoffee/ein"&gt;Ein&lt;/a&gt;. I decided fairly early on in development that I didn't want Ein to have semicolons, so I've spent a fair chunk of the past week investigating how other languages make this work.&lt;/p&gt;

&lt;p&gt;Lua's solution to this problem is (in my opinion) fairly nifty, so I thought I'd write about it on the off-chance that someone else will find it as interesting as I do 😄&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;First, some background - why is getting rid of semicolons tricky? Can't we just remove them from our language's grammar and be done with it?&lt;/p&gt;

&lt;p&gt;The answer to this question can be summed up in one snippet of pseudo-code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c"&gt;// Does the statement end here?&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;       &lt;span class="c"&gt;// Or does it end here?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How does our language's parser decide whether this should be one statement (&lt;code&gt;let x = 1 - 1&lt;/code&gt;) or two (&lt;code&gt;let x = 1&lt;/code&gt; followed by &lt;code&gt;-1&lt;/code&gt;)? In the parser's eyes, they're both perfectly valid!&lt;/p&gt;

&lt;h2&gt;
  
  
  The (Potential) Solutions
&lt;/h2&gt;

&lt;p&gt;There's several ways that languages try to get around this problem.  Some make the whitespace in their language significant, like Python. Others, like Go, try to insert the semicolons for you behind the scenes based on &lt;a href="https://golang.org/ref/spec#Semicolons"&gt;a set of rules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Personally though, I'm not a fan of those solutions. Making whitespace have meaning rubs me the wrong way for reasons I don't quite understand, and automatic semicolon insertion feels like placing too much trust in the compiler to 'guess' where I meant for the statements to end.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Lua Does It
&lt;/h2&gt;

&lt;p&gt;Lua's syntax is unambigous, even if you leave out all the semicolons and nice formatting, and the main way it achieves this is by dropping a feature a lot of us take for granted - &lt;em&gt;expressions-as-statements&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In most languages, it's perfectly valid to use an expression (a piece of code that can be evaluated to get a value, like adding two numbers together) in the same place that you would use a statement (a piece of code run for its side effects, like a variable declaration).&lt;/p&gt;

&lt;p&gt;Lua takes a much more hardline stance on this - programs are a list of statements, some statements may contain expressions (like the condition of an &lt;code&gt;if&lt;/code&gt;), but expressions are &lt;em&gt;not&lt;/em&gt; allowed to be used as statements.&lt;/p&gt;

&lt;p&gt;Let's go back to our original example, translated to Lua:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;-- Does the statement end here?&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;         &lt;span class="c1"&gt;-- Or does it end here?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Lua, a variable declaration is a statement, but &lt;code&gt;-1&lt;/code&gt; is an expression - therefore, the only valid way of interpreting this code is &lt;code&gt;local x = 1 - 1&lt;/code&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  What's The Catch?
&lt;/h2&gt;

&lt;p&gt;Ah yes, there's always a catch, and in this case it's a fairly obvious one: what if I &lt;em&gt;want&lt;/em&gt; to run an expression for its side effects?&lt;/p&gt;

&lt;p&gt;For example, a lot of the time you'll want to use the return value of a function, but sometimes you'll just want to run it. Lua caters for this scenario by  making an exception to the rule, allowing function calls to be used both in statement and expression position.&lt;/p&gt;

&lt;p&gt;This is one of the only places that Lua bends the rules, however. In some languages, you can use the short circuting behavior of the logical AND/OR operators as short and sweet control flow statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// JavaScript&lt;/span&gt;
&lt;span class="nx"&gt;isActive&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The equivalent in Lua isn't valid unless you &lt;a href="http://lua-users.org/wiki/ExpressionsAsStatements"&gt;assign the result to a temporary variable:&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;isActive&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;-- _ has no special meaning - just a common Lua &lt;/span&gt;
&lt;span class="c1"&gt;-- naming convention for throwing away variables!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thank you for reading! I hope I didn't bore you to death rambling on about semicolons for $x words! ❤️&lt;/p&gt;

&lt;p&gt;If you're interested in this kind of thing, I'd recommend taking a look at the &lt;a href="http://www.lua.org/manual/5.3/manual.html#9"&gt;full grammar for Lua&lt;/a&gt; from its reference manual - it's really short and really clean, and there's a lot of really interesting design decisions in there which I'm interested in digging deeper into.&lt;/p&gt;

</description>
      <category>languagedesign</category>
      <category>lua</category>
    </item>
    <item>
      <title>What makes you want to stick with a programming language?</title>
      <dc:creator>Joe Clay</dc:creator>
      <pubDate>Wed, 28 Mar 2018 15:17:05 +0000</pubDate>
      <link>https://dev.to/17cupsofcoffee/what-makes-you-want-to-stick-with-a-programming-language-2o83</link>
      <guid>https://dev.to/17cupsofcoffee/what-makes-you-want-to-stick-with-a-programming-language-2o83</guid>
      <description>

&lt;p&gt;&lt;a href="https://dev.to/17cupsofcoffee/how-do-you-feel-about-braces-and-semicolons-2bpc"&gt;My previous post&lt;/a&gt; generated a load of really interesting comments, so I'm back with another language design question - albeit this time a bit more of an abstract one!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What factors make you want to keep investing time into a programming language beyond writing "Hello, world"? Or conversely, what things make you drop a language like a ton of bricks and run back into the warm, inviting arms of &lt;code&gt;${FAVOURITE_LANGUAGE}&lt;/code&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For me, the biggest thing that keeps me motivated through the early stages is documentation - in particular, well written guides/tutorials, rather than simple API docs. I've noticed there's been a bit of a trend in recent years towards languages coming with a 'book' which goes through all the features of the language, and I'm a really big fan of that concept! The prime example of this is &lt;a href="https://doc.rust-lang.org/book/second-edition/"&gt;The Rust Programming Language&lt;/a&gt;, which is so good I might order the print copy when it comes out &amp;lt;3&lt;/p&gt;

&lt;p&gt;On the opposite end of the spectrum, I think the main thing that puts me off a language is bad tooling (package management, command line tools, editor extensions, etc.). It's enough to put a damper on my enthusiasm for otherwise wonderful languages - I love Lua's design, but I find myself really missing code completion whenever I use it!&lt;/p&gt;

&lt;p&gt;How about everyone else?&lt;/p&gt;


</description>
      <category>discuss</category>
      <category>compiler</category>
      <category>language</category>
      <category>languagedesign</category>
    </item>
    <item>
      <title>How do you feel about braces and semicolons?</title>
      <dc:creator>Joe Clay</dc:creator>
      <pubDate>Mon, 26 Mar 2018 14:08:52 +0000</pubDate>
      <link>https://dev.to/17cupsofcoffee/how-do-you-feel-about-braces-and-semicolons-2bpc</link>
      <guid>https://dev.to/17cupsofcoffee/how-do-you-feel-about-braces-and-semicolons-2bpc</guid>
      <description>&lt;p&gt;I'm (slowly) working my way through &lt;a href="http://craftinginterpreters.com/"&gt;Crafting Interpreters&lt;/a&gt;, and trying to put together a design for my little interpreted language. Thinking about the syntax has got me curious - do you prefer for a language to have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Braces and semicolons &lt;em&gt;(C, JavaScript, Rust)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Braces and no semicolons &lt;em&gt;(Go, Wren)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Semicolons and no braces &lt;em&gt;(I'm not actually sure anyone does this?)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;No braces and no semicolons, with significant whitespace &lt;em&gt;(Python)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;No braces and no semicolons, with no significant whitespace &lt;em&gt;(Lua)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Some other wacky design I've not thought of...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Personally, I tend to prefer the explicitness of option 1, but at the same time I don't really like that &lt;code&gt;{}&lt;/code&gt; has a double meaning (is it a scope, or is it an object literal?). How about everyone else?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>language</category>
      <category>compiler</category>
    </item>
  </channel>
</rss>
