<?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: Nimmo</title>
    <description>The latest articles on DEV Community by Nimmo (@nimmo).</description>
    <link>https://dev.to/nimmo</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%2F497%2F3ffb6ca2-abcc-47f4-9878-6d504396b805.png</url>
      <title>DEV Community: Nimmo</title>
      <link>https://dev.to/nimmo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nimmo"/>
    <language>en</language>
    <item>
      <title>A monad is a thing you put things in so you can do things with them.</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Sun, 03 Apr 2022 10:15:08 +0000</pubDate>
      <link>https://dev.to/nimmo/a-monad-is-a-thing-you-put-things-in-so-you-can-do-things-with-them-2f35</link>
      <guid>https://dev.to/nimmo/a-monad-is-a-thing-you-put-things-in-so-you-can-do-things-with-them-2f35</guid>
      <description>&lt;p&gt;You can skip reading this post now, if you like - it's all there in the title. But if you want to hear a little more, okay, I won't deprive you. &lt;/p&gt;

&lt;p&gt;Think of a time when you've needed to process some inconsistent data. You won't have to think very far before you realise that you've had to do this any time you've had an optional/nullable value somewhere - something in JS that may or may not be &lt;code&gt;truthy&lt;/code&gt;, something in Java that may or may not be &lt;code&gt;null&lt;/code&gt;, something in Haskell that is a &lt;code&gt;Maybe something&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's say in JavaScript, I have an array of values (&lt;em&gt;things&lt;/em&gt;) which I know may include &lt;code&gt;undefined&lt;/code&gt; values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myJsArray = 
  [value1, value2, value3]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I want iterate over (&lt;em&gt;do something with&lt;/em&gt;) this array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const double = x =&amp;gt; x * 2

const myNewArray = myJsArray.map(double)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You probably don't want to end up with an array that contains a series of &lt;code&gt;NaN&lt;/code&gt; values; you already know that that's the first step on many paths that can lead to confusion for your users. &lt;/p&gt;

&lt;h2&gt;
  
  
  You've got your &lt;em&gt;things&lt;/em&gt;, and you want to &lt;em&gt;do something with&lt;/em&gt; those &lt;em&gt;things&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;So what do you need? A &lt;em&gt;thing you put those things in, so you can do something with them&lt;/em&gt;. You need a monad!&lt;/p&gt;

&lt;p&gt;Earlier I mentioned Haskell's &lt;a href="https://hackage.haskell.org/package/base-4.16.1.0/docs/Data-Maybe.html"&gt;Maybe&lt;/a&gt; type. This type can store one of two variants: &lt;code&gt;Just something&lt;/code&gt;, or &lt;code&gt;Nothing&lt;/code&gt;. This means that even if you can't be sure whether something contains a value or not, you can still perform consistent operations anyway - the operation that you're trying to perform is required to handle what to do in either scenario, and then you can't end up with unexpected junk data somewhere else in your application. Or to put it another way - you know you can &lt;em&gt;do the thing&lt;/em&gt; you wanted to on your &lt;em&gt;thing&lt;/em&gt; because it was &lt;em&gt;in a thing&lt;/em&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why did I write this?
&lt;/h2&gt;

&lt;p&gt;I've heard lots of different explanations of monads over the years. People tend to like using fancy words in their explanations, and I've seen lots of people shy away from Functional Programming altogether as soon as someone has mentioned monads to them. In fact, the Elm community &lt;em&gt;doesn't even like to say the word monad&lt;/em&gt; (opting for &lt;code&gt;Custom Types&lt;/code&gt; instead, which I agree is a simpler term), because it is so commonly linked with unnecessary confusion. &lt;/p&gt;

&lt;p&gt;Google &lt;a href="https://www.google.com/search?q=what+is+a+monad&amp;amp;rlz=1C5CHFA_enGB998GB998&amp;amp;oq=what+is+a+monad"&gt;"What is a monad?"&lt;/a&gt; and you'll probably see the same thing explained in lots of ways, but I bet none are quite as simple as the explanation you read before even reading this post. Although if you happen to get this post in your results...you're now also one step away from understanding &lt;a href="https://www.google.com/search?q=recursion"&gt;recursion&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>types</category>
      <category>simpleexplainations</category>
      <category>functional</category>
    </item>
    <item>
      <title>Elm: A short example of the development experience on a real code change (video)</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Wed, 23 Dec 2020 16:46:00 +0000</pubDate>
      <link>https://dev.to/nimmo/elm-a-short-example-of-the-development-experience-on-a-real-code-change-video-6m</link>
      <guid>https://dev.to/nimmo/elm-a-short-example-of-the-development-experience-on-a-real-code-change-video-6m</guid>
      <description>&lt;p&gt;I love working with Elm, but it can be hard to explain what the development experience is really like compared to JavaScript-based tools. I thought a short video might help.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/J4n40TKAvww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>elm</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Take a day off</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Sat, 21 Nov 2020 18:12:52 +0000</pubDate>
      <link>https://dev.to/nimmo/take-a-day-off-1g9b</link>
      <guid>https://dev.to/nimmo/take-a-day-off-1g9b</guid>
      <description>&lt;p&gt;I'm usually pretty good at knowing what I do and what I do not give a fuck about, but recently the lines have been a little blurred. Far too much of my energy has been spent on things that would ordinarily be in my "don't give a fuck" list.&lt;/p&gt;

&lt;p&gt;Why have I found myself with a lack of patience?&lt;/p&gt;

&lt;p&gt;Why have I found myself unable to sleep most nights? &lt;/p&gt;

&lt;p&gt;Why have I found myself losing motivation?&lt;/p&gt;

&lt;p&gt;Maybe the answer to these questions wasn't really important. But having taken a single day off last week to do things I genuinely love doing, I can at least tell you that a little perspective has made all the difference. &lt;/p&gt;

&lt;p&gt;Perhaps you are in need of a day off too? My advice to you is: take it.&lt;/p&gt;

</description>
      <category>wellbeing</category>
    </item>
    <item>
      <title>Deploy every Friday</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Mon, 09 Dec 2019 11:07:01 +0000</pubDate>
      <link>https://dev.to/nimmo/deploy-every-friday-42b4</link>
      <guid>https://dev.to/nimmo/deploy-every-friday-42b4</guid>
      <description>&lt;p&gt;Every Friday I see people on Twitter shouting about how it's #noDeployFriday. And every Friday, I deploy to production anyway. &lt;/p&gt;

&lt;p&gt;Do I hate quiet weekends? Not at all. I moved to full continuous deployment because I wanted quiet days, evenings, &lt;em&gt;and&lt;/em&gt; weekends. &lt;/p&gt;

&lt;p&gt;I got here by moving to continuous deployment.&lt;/p&gt;

&lt;p&gt;I once worked for a company that had a painful release cycle. Everything had to stop once a month, and everyone spent the  period immediately afterwards fixing issues. &lt;/p&gt;

&lt;p&gt;Once I was in a position to own my own team's pipelines I wanted things to be better. &lt;/p&gt;

&lt;p&gt;I started out with continuous integration (CI). Every change that we made was automatically tested and compiled, and the team was automatically notified of the build result.&lt;/p&gt;

&lt;p&gt;This saved the team a lot of time, but I wanted more. &lt;/p&gt;

&lt;h2&gt;
  
  
  Moving to continuous deployment (CD)
&lt;/h2&gt;

&lt;p&gt;How could I be sure that everything was ready to go to production all the time? My work could be categorised in two ways:&lt;/p&gt;

&lt;h3&gt;
  
  
  1: Changes to pages that were already available to users
&lt;/h3&gt;

&lt;p&gt;Feature flags were enough to ensure that these changes didn't prematurely become accessible to users.&lt;/p&gt;

&lt;h3&gt;
  
  
  2: Changes to pages that weren't yet available to users
&lt;/h3&gt;

&lt;p&gt;I decided to extend this idea a little further here. I already had a mechanism in the application to denote available pages, so I extended that to enable/disable entire pages easily based on the user's environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_Frh74iK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9gcslo7ippfn2bojvegb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Frh74iK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9gcslo7ippfn2bojvegb.png" alt="A function that returns true or false based on which page is loaded in combination with an environment type" width="820" height="1018"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I had everything I needed to turn on automatic deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  And everyone lived happily ever after, right?
&lt;/h2&gt;

&lt;p&gt;Well, sort of. There were a couple of things that we hadn't quite accounted for: &lt;/p&gt;

&lt;h3&gt;
  
  
  1: You can still make mistakes, but now your users can see them
&lt;/h3&gt;

&lt;p&gt;It only took one bug to accidentally put a page live. This taught me that I needed an extra safeguard. &lt;/p&gt;

&lt;p&gt;I added automated tests to check the status of each page. This meant a small overhead when making a new page available to users, but eliminated the possibility of users accessing pages before they were ready.&lt;/p&gt;

&lt;h3&gt;
  
  
  2: Caches can trip you up sometimes
&lt;/h3&gt;

&lt;p&gt;My application is being served by AWS Cloudfront, which is known to cache aggressively. I initially invalidated this cache manually, but this wasn't good enough after moving to CD. This was easily fixed by amending the pipeline to invalidate the cache every time it ran.&lt;/p&gt;

&lt;p&gt;I deployed over 70 times last week alone without worrying how close it was to 5pm, or what day it was. It's scary to begin with, but it's worth it. &lt;/p&gt;

&lt;p&gt;"#NoDeployFridays"? No thanks. &lt;/p&gt;

&lt;h3&gt;
  
  
  Things mentioned in this post
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.martinfowler.com/articles/feature-toggles.html"&gt;Feature flags&lt;/a&gt;&lt;/p&gt;

</description>
      <category>continuousdeployment</category>
    </item>
    <item>
      <title>Easier paths to accessibility in Elm</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Fri, 11 Oct 2019 16:19:45 +0000</pubDate>
      <link>https://dev.to/nimmo/easier-paths-to-accessibility-in-elm-4ojo</link>
      <guid>https://dev.to/nimmo/easier-paths-to-accessibility-in-elm-4ojo</guid>
      <description>&lt;p&gt;Accessibility is a big topic. It covers all sorts of things that affect people in different ways, but it's also something we can improve with some minor changes. For example, take the following element:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pF1LjkxK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ifwcj8y4olif9895iyxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pF1LjkxK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ifwcj8y4olif9895iyxm.png" alt="A select input" width="762" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looks fine, right? &lt;/p&gt;

&lt;p&gt;Well...not quite. This &lt;em&gt;looks&lt;/em&gt; like a normal select input, but it's really a div and a span, both with an onClick handler, as well as a span that has the same onClick handler. &lt;/p&gt;

&lt;p&gt;The problem is that neither &lt;code&gt;div&lt;/code&gt;s nor &lt;code&gt;span&lt;/code&gt;s should have onClick functionality.   &lt;/p&gt;

&lt;p&gt;When someone types in this field the application suggests booking statuses as they're typing. These appear in a drop-down that looks like a select:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hXeEwxDv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4vuqriyx8cc1ecb7n44v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hXeEwxDv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4vuqriyx8cc1ecb7n44v.png" alt="A dropdown showing suggested results" width="786" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The user is presented with more divs containing suggestions, each with onClick handlers. What happens when you select one of them?   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NlpbBUn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6rirpassgmk0nbb3ltys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NlpbBUn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6rirpassgmk0nbb3ltys.png" alt="The original select input, now with an item inside" width="766" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have extra buttons: one for deleting the selected item, and one for deleting &lt;em&gt;all&lt;/em&gt; the selected items. Would it surprise you to learn that these aren't buttons either? Spoiler alert: both are also spans. &lt;/p&gt;

&lt;p&gt;What if all of the things that are pretending to be buttons right now really were buttons?   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VnDHbQDy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wsd2zx7tobevc0stxlt7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VnDHbQDy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wsd2zx7tobevc0stxlt7.png" alt="An input field" width="788" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This basically looks the same, but it isn't. We've changed the placeholder text to reflect what was previously hidden functionality. The arrow is now a button, which can be understood by screen-readers. Awesome.   &lt;/p&gt;

&lt;p&gt;I can hear you now: &lt;em&gt;"But I don't use a screen-reader"&lt;/em&gt;. I'm happy for you and your sightedness. But did you know that making this a button instead of a span gives us keyboard controls &lt;em&gt;for free&lt;/em&gt;? &lt;/p&gt;

&lt;p&gt;I won't bore you with screenshots of the rest of the states this element can be in, but we've changed all of them to use buttons in the same way. Now every suggestion can be navigated through solely through the keyboard. The remove buttons can be selected in the same way. And it all looks exactly as it did before. &lt;/p&gt;

&lt;h2&gt;
  
  
  But you can use ARIA to solve this, right? 
&lt;/h2&gt;

&lt;p&gt;Yes, you can. But, your application will happily let you forget. &lt;/p&gt;

&lt;p&gt;ARIA will help screen-readers understand that your elements are acting as buttons etc., but we should use HTML the way in which it was intended here. This is inherently understood by screen-readers as it has accessibility built-in by default.&lt;/p&gt;

&lt;p&gt;That said, surely there's a way we can make this easier for people. Surely we can work towards accessibility being easier to implement. Surely we can make our applications accessible to the widest possible audience? &lt;/p&gt;

&lt;h2&gt;
  
  
  Enter: Elm's accessible-html module
&lt;/h2&gt;

&lt;p&gt;Tessa Kelly is an engineer at NoRedInk. She has created an Elm module called "accessible-html" to solve this problem.  &lt;/p&gt;

&lt;p&gt;This module ensures that people can't accidentally write HTML that falls foul of accessibility rules. It achieves this by failing to compile if you accidentally do so, for example:    &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aPPLn7Wp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dtgx0zk28le4ni995n4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aPPLn7Wp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dtgx0zk28le4ni995n4o.png" alt="An error from Elm's compiler, explaining that the first argument needs to be a list of &amp;quot;Attribute Never&amp;quot; rather than &amp;quot;Attribute msg&amp;quot;" width="648" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I've tried to call a div with an "onClick", but Elm's compiler has rightly pointed out that this is not possible.&lt;/p&gt;

&lt;p&gt;Here's another example:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4m3KrNx---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/eb73161yp8th2fp2fvk6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4m3KrNx---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/eb73161yp8th2fp2fvk6.png" alt="An error from Elm's compiler, explaining that an argument needs to be a String rather than a list of &amp;quot;Attribute msg&amp;quot;" width="660" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The compiler is telling me that the "img" function needs a String as its first argument. This is because &lt;code&gt;accessible-html&lt;/code&gt; won't allow you to have an image without alternate text. This means that the image will always be described if it doesn't load for any reason, including for people using screen-readers. &lt;/p&gt;

&lt;p&gt;Here, our own tooling &lt;em&gt;makes us better engineers&lt;/em&gt; by &lt;em&gt;actively teaching us&lt;/em&gt; the rules of accessibility.&lt;/p&gt;

&lt;p&gt;Since this module extends the core &lt;code&gt;HTML&lt;/code&gt; module, it is &lt;em&gt;almost&lt;/em&gt; a drop-in replacement. The only things that need attention are where accessible-html's API differs from HTML's, as it does with the "img" function we've already looked at.&lt;/p&gt;

&lt;p&gt;As I mentioned at the start of this post, accessibility is a big topic. We need to ensure we're considering it at design &lt;em&gt;and&lt;/em&gt; implementation stages. Tools like this make it a lot easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things mentioned in this post: 
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://package.elm-lang.org/packages/tesk9/accessible-html/latest/"&gt;accessible-html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/t_kelly9"&gt;Tessa Kelly (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA"&gt;ARIA&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elm</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Some basic JS issues, and how Elm avoids them (Video)</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Mon, 24 Jun 2019 08:59:33 +0000</pubDate>
      <link>https://dev.to/nimmo/some-basic-js-issues-and-how-elm-avoids-them-part-1-video-4goo</link>
      <guid>https://dev.to/nimmo/some-basic-js-issues-and-how-elm-avoids-them-part-1-video-4goo</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/z6W4ov1rXrU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>elm</category>
      <category>javascript</category>
    </item>
    <item>
      <title>State transitions (i.e. Elm messages/React actions etc.): Past or imperative tense?</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Fri, 01 Mar 2019 09:41:17 +0000</pubDate>
      <link>https://dev.to/nimmo/state-transitions-ie-elm-messagesreact-actions-etc-past-or-imperative-tense-488i</link>
      <guid>https://dev.to/nimmo/state-transitions-ie-elm-messagesreact-actions-etc-past-or-imperative-tense-488i</guid>
      <description>&lt;p&gt;Do you have an opinion over which helps either you or your colleagues reason about your applications better? &lt;/p&gt;

&lt;p&gt;Past tense: &lt;code&gt;DetailsUpdated&lt;/code&gt;&lt;br&gt;
Imperative tense: &lt;code&gt;UpdateDetails&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Personally I'd always gone with imperative, but I thought about it recently and realised that whenever I'm looking at a list of state transitions things felt a little strange. For example: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i6qNZBMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6gldfvabv6dmy00mdy8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i6qNZBMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/6gldfvabv6dmy00mdy8d.png" alt="A list of state transitions, all in imperative tense: StartGame, ChangeUrl, ChangeRoom, ExamineRoom, ToggleInventory"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whilst this is easy enough to follow, it's hard to describe it without reverting to past tense anyway: The user &lt;strong&gt;started&lt;/strong&gt; the game, the URL &lt;strong&gt;changed&lt;/strong&gt;, the user &lt;strong&gt;changed&lt;/strong&gt; rooms, the user &lt;strong&gt;toggled&lt;/strong&gt; the inventory...&lt;/p&gt;

&lt;p&gt;But this isn't the same when you're writing the code: "When a user opts to start the game, I want the game to start" etc.&lt;/p&gt;

&lt;p&gt;So I'm interested: what do you use? &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>elm</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Optional chaining: What is it, and how can you add it to your JavaScript application right now?</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Wed, 27 Feb 2019 16:40:51 +0000</pubDate>
      <link>https://dev.to/nimmo/optional-chaining-what-is-it-and-how-can-you-add-it-to-your-javascript-application-right-now-37ie</link>
      <guid>https://dev.to/nimmo/optional-chaining-what-is-it-and-how-can-you-add-it-to-your-javascript-application-right-now-37ie</guid>
      <description>&lt;p&gt;&lt;em&gt;This post assumes that you're already transpiling your JS applications with Babel (version 7+). If you're not, then this probably isn't the feature to convince you to add that into your build process, but it's still a proposed language feature that is worth being aware of.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You've seen these errors before, hiding in your logs, in your automated test readouts, in your console, in your devtools: &lt;code&gt;cannot read property "map" of undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You spend time tracking down the error, and find the function in question:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;someArray&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someOtherFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You spend even more time looking at the code that called this function. Sometimes that array really might be undefined. In this scenario you decide that it is &lt;code&gt;someFunction&lt;/code&gt;'s responsibility to handle that. You update your code, and leave a helpful comment so that no-one else wastes time wondering why you're accounting for this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Sometimes this is undefined: See [link to bug report]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someOtherFunction&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;This works. But, you kind of liked the implicit return from the original example. A single expression in a function makes you feel more comfortable. No way anything else can sneak in there and cause problems. I like your thinking.&lt;/p&gt;

&lt;p&gt;You try again, with a single expression this time, using a default value:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class="c1"&gt;// Sometimes this is undefined: See [link to bug report]&lt;/span&gt;
    &lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someOtherFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works. But, now your helpful comment is a bit weird. Will someone think that the &lt;em&gt;output&lt;/em&gt; of this function is undefined, and accidentally account for that possibility elsewhere, even though this will always return an array? You imagine the confusion you've potentially caused, and the accumulated (hypothetical) cost to your company as a result.&lt;/p&gt;

&lt;p&gt;You could make your comment clearer, but you want to solve this problem using JavaScript, not boring words.&lt;/p&gt;

&lt;p&gt;You could resign yourself to a ternary, but that would mean having to type &lt;code&gt;someArray&lt;/code&gt; an extra time. Let's look at a new alternative: &lt;/p&gt;

&lt;h2&gt;
  
  
  Enter &lt;code&gt;optional chaining&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;With optional chaining, you have a new operator: &lt;code&gt;?.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can use &lt;code&gt;?.&lt;/code&gt; on anything that you think might be undefined, which can save you from the most common and the most frustrating issues you see regularly in JS. For example:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withoutOptionalChaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;something&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someOtherThing&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someOtherThing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;yetAnotherThing&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withOptionalChaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;something&lt;/span&gt;
    &lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;someOtherThing&lt;/span&gt;
    &lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;yetAnotherThing&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's crucial to understand that if either &lt;code&gt;someOtherThing&lt;/code&gt; or &lt;code&gt;yetAnotherThing&lt;/code&gt; are &lt;code&gt;undefined&lt;/code&gt;, then the &lt;code&gt;withoutOptionalChaining&lt;/code&gt; example will be &lt;code&gt;false&lt;/code&gt;, where the &lt;code&gt;withOptionalChaining&lt;/code&gt; example will be &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As you're aware if you've written JS for anything more than a day, &lt;code&gt;undefined is not a function&lt;/code&gt;. But, what if that didn't matter?&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
  &lt;span class="nx"&gt;someObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;?.()&lt;/span&gt; &lt;span class="c1"&gt;// returns `undefined` rather than a runtime error if `someFunction` is undefined!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
   I'm in. But, how?
&lt;/h2&gt;

&lt;p&gt;Fortunately, there's a Babel plugin for this: &lt;a href="https://www.npmjs.com/package/@babel/plugin-proposal-optional-chaining"&gt;@babel/plugin-proposal-optional-chaining&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install that plugin with &lt;code&gt;npm&lt;/code&gt;, and &lt;a href="https://babeljs.io/docs/en/plugins"&gt;add it to your babel config&lt;/a&gt; via your chosen configuration option. &lt;/p&gt;

&lt;p&gt;Depending on the rest of your Babel config, you may also find that you end up with an error about &lt;code&gt;regenerator runtime&lt;/code&gt; not being defined. If so, you may need to add the &lt;a href="https://babeljs.io/docs/en/babel-plugin-transform-runtime"&gt;@babel/plugin-transform-runtime&lt;/a&gt; as well, and configure it like so:&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="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@babel/plugin-transform-runtime&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;regenerator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're using ESlint, you'll find that it isn't too happy about this new operator. You'll also need to add the &lt;a href="https://github.com/babel/babel-eslint"&gt;babel-eslint&lt;/a&gt; plugin to your ESlint config.&lt;/p&gt;

&lt;p&gt;And that's it. Now you ought to be able to use optional chaining as much as you want to in your application.&lt;/p&gt;

&lt;p&gt;Let's look again at that original code:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;someArray&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class="nx"&gt;someArray&lt;/span&gt; 
      &lt;span class="c1"&gt;// Sometimes this is undefined: See [link to bug report]&lt;/span&gt;
      &lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someOtherFunction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There we have it, another option for solving our problem. Do you always want to do this? Absolutely not: there are times when you &lt;a href="https://dev.to/nimmo/sometimes-in-the-heat-of-the-moment-its-forgivable-to-cause-a-runtime-exception-2ko2"&gt;probably do want a runtime error&lt;/a&gt; after all. But for the rest of the time, optional chaining is a great addition to your toolkit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;Optional chaining is currently at Stage 1 in the proposal process, so whether or not you are willing to incorporate it right now is up to you.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>optionalchaining</category>
      <category>babel</category>
    </item>
    <item>
      <title>Sometimes, in the heat of the moment, it's forgivable to cause a runtime exception.</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Thu, 21 Feb 2019 01:32:39 +0000</pubDate>
      <link>https://dev.to/nimmo/sometimes-in-the-heat-of-the-moment-its-forgivable-to-cause-a-runtime-exception-2ko2</link>
      <guid>https://dev.to/nimmo/sometimes-in-the-heat-of-the-moment-its-forgivable-to-cause-a-runtime-exception-2ko2</guid>
      <description>&lt;p&gt;Runtime errors &lt;em&gt;suck&lt;/em&gt;. But when you're working in JS they're difficult to avoid. Fortunately though, our whole deal is problem solving; so avoid them we do. &lt;/p&gt;

&lt;p&gt;For client-side JS this seems totally necessary: We shouldn't subject users to runtime exceptions; we should be giving them appropriate feedback in the event of an error.&lt;/p&gt;

&lt;p&gt;But do we &lt;em&gt;always&lt;/em&gt; want to avoid runtime exceptions at all costs? I'm not convinced. &lt;/p&gt;

&lt;p&gt;In a perfect world, we'd have an equivalent to Elm's compiler in every language. But in the real world, we can save ourselves some time when things actually do go wrong.&lt;/p&gt;

&lt;p&gt;Take this, as an example:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;someModule&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;someModule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;someObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;someFunction&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="p"&gt;{},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;someModule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's assume that our code is being transpiled with Babel before it's deployed. In this instance, if &lt;code&gt;someObject&lt;/code&gt; didn't exist in &lt;code&gt;someModule&lt;/code&gt;, then this would transpile fine. But at runtime, &lt;code&gt;someFunction&lt;/code&gt; would be &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: someFunction is not a function.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It seems like this code is destined to fail for one of our users. &lt;/p&gt;

&lt;p&gt;Consider if we'd done it this way instead, without the default value in our destructuring:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;someModule&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;someModule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;someObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;someFunction&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="nx"&gt;someModule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if &lt;code&gt;someObject&lt;/code&gt; doesn't exist in &lt;code&gt;someModule&lt;/code&gt; we'll get a runtime error when trying to transpile instead of after it's been deployed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: Cannot destructure property `someFunction` of 'undefined' or 'null'.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not only is this feedback much faster, but it's also going to fail on &lt;em&gt;our&lt;/em&gt; machine. This particular example can only even happen in one place in any given file, which improves our ability to locate the problem quickly. With any sort of automated build pipeline in place, this error now &lt;em&gt;can't even possibly make it to production&lt;/em&gt; any more. Not bad considering that all we did was remove three characters.&lt;/p&gt;

&lt;p&gt;This example isn't indicative of every possible problem we can encounter in JS, of course. But this was a real example that I saw recently. It was the direct result of an over-zealous approach to preventing runtime exceptions: something that the original code &lt;em&gt;didn't even do&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: We ought to spend a lot more time thinking about how and where our code can fail, and we should be very careful to consider unintended consequences we introduce by trying to protect ourselves from errors.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Bothering people over [communication tool]</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Tue, 19 Feb 2019 01:27:17 +0000</pubDate>
      <link>https://dev.to/nimmo/bothering-people-over-communication-tool-234l</link>
      <guid>https://dev.to/nimmo/bothering-people-over-communication-tool-234l</guid>
      <description>&lt;p&gt;I've worked remotely for a couple of years, and I still find myself learning things about the practice.&lt;/p&gt;

&lt;p&gt;I recently suggested to a colleague that I didn't like to "bother" people by asking them questions over Slack. &lt;/p&gt;

&lt;p&gt;I described how much easier it was when working in an office; I could look and see if people seemed busy, and ask them whatever I needed to if they didn't.&lt;/p&gt;

&lt;p&gt;Knowing that my message would result in a notification put me off sending it. I didn't know what that person was doing. I wanted to avoid disturbing them. This led me to "saving up" questions that I wanted to ask people.&lt;/p&gt;

&lt;p&gt;My colleague told me that other people's management of their own notifications wasn't my problem. And she was right. &lt;/p&gt;

&lt;p&gt;I had been wasting my own time by making a decision about other people's. Even my suggestion that it's easier in an office isn't true; asking "have got a minute?" in person is a much bigger interruption.&lt;/p&gt;

&lt;p&gt;Perhaps everyone else has managed to figure this out for themselves, but in case anyone hasn't: Your colleagues are adults. They can manage their own time and alerts. &lt;/p&gt;

&lt;p&gt;Ask the question and get on with your day. &lt;/p&gt;

</description>
      <category>remote</category>
    </item>
    <item>
      <title>"Can't we just...?"</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Sat, 22 Dec 2018 16:34:58 +0000</pubDate>
      <link>https://dev.to/nimmo/cant-we-just-56g</link>
      <guid>https://dev.to/nimmo/cant-we-just-56g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Want to go to the moon?&lt;/strong&gt; &lt;em&gt;Just fly there&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Want to spend all of your free time doing whatever you like?&lt;/strong&gt; &lt;em&gt;Just quit your job&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Want to be in a band?&lt;/strong&gt; &lt;em&gt;Just start a band&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Want to write a blog post?&lt;/strong&gt; &lt;em&gt;Just write one&lt;/em&gt;.&lt;br&gt;
&lt;strong&gt;Want to have steak for dinner?&lt;/strong&gt; &lt;em&gt;Just do it. Two minutes' work, done.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It's easy for most people to see why you can't &lt;em&gt;just&lt;/em&gt; fly to the moon, or &lt;em&gt;just&lt;/em&gt; quit your job. &lt;/p&gt;

&lt;p&gt;But you may be thinking that you can &lt;em&gt;just&lt;/em&gt; start a band. &lt;/p&gt;

&lt;p&gt;It's reasonable to just write a blog post.&lt;/p&gt;

&lt;p&gt;And anyone can cook a steak, right?&lt;/p&gt;

&lt;p&gt;People don't like having their achievements trivialised. So why are we quick to trivialise problems that we need to solve?&lt;/p&gt;

&lt;p&gt;Perhaps it's misplaced optimism. But the word "just" is a quick way to trivialise someone else's workload, or the tasks you're asking them to complete. &lt;/p&gt;

&lt;p&gt;It's easy to accidentally increase someone's stress levels by telling them to "just do x". Consider these two questions: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Can you just write a blog post on service testing?"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This tells the other person that you don't appreciate what you're asking them to do. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Can you produce a guide on service testing?"&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's more like it. You'd never have asked Einstein to &lt;em&gt;just prove atomic theory&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;===&lt;/p&gt;

&lt;p&gt;Further info: &lt;/p&gt;

&lt;p&gt;The thing that made me think more seriously about "just" and its over-representation within our language at work was Evan Czaplicki's fantastic Strangeloop talk earlier this year, about &lt;a href="https://www.youtube.com/watch?v=o_4EX4dPppA"&gt;the hard parts of open-source&lt;/a&gt;. I highly recommend giving it a watch.&lt;/p&gt;

</description>
      <category>terminology</category>
      <category>teamwork</category>
    </item>
    <item>
      <title>A look at a small Elm application</title>
      <dc:creator>Nimmo</dc:creator>
      <pubDate>Mon, 19 Nov 2018 22:38:21 +0000</pubDate>
      <link>https://dev.to/nimmo/a-look-at-a-small-elm-application-2loh</link>
      <guid>https://dev.to/nimmo/a-look-at-a-small-elm-application-2loh</guid>
      <description>&lt;p&gt;One thing that I've found with Elm is that there are fantastic resources for learning &lt;a href="https://guide.elm-lang.org/" rel="noopener noreferrer"&gt;how to start with the language&lt;/a&gt;, and there are equally fantastic resources talking you through a &lt;a href="https://dev.to/rtfeldman/tour-of-an-open-source-elm-spa"&gt;more complicated application architecture&lt;/a&gt;, but I think it might be useful to give people a more high-level view of what you're likely to find in an Elm application. Or at least, this is something that I think would have helped me, anyway - hopefully it will help someone else!&lt;/p&gt;

&lt;p&gt;For anyone with absolutely zero knowledge of Elm: it's a functional language that compiles to JavaScript, and crucially does not allow for runtime errors. Anything that potentially could cause a runtime error has either not been included in the language, or is caught by the compiler, and results in nice friendly compiler messages instead. &lt;/p&gt;

&lt;p&gt;Like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5duzm8gypi7g48fyvsa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5duzm8gypi7g48fyvsa.png" alt="An image showing the Elm compiler helpfully suggesting that Dict.fromLast should be Dict.fromList" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Elm Architecture
&lt;/h2&gt;

&lt;p&gt;Before we look at the code for this application, let's take a little detour into how the Elm runtime works.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The Elm Architecture&lt;/code&gt; is how application state managed in an Elm application. Your application has an overall model, an update function, and a view function. Your view function is capable of sending messages, which are fed into your update function along with your model, and this returns a new (updated) model, which is then used to render your new view. Diagrams for this make a lot more sense, so: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphwpw3317d1pe1i6ui8m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphwpw3317d1pe1i6ui8m.png" width="800" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
Anyone who is familiar with Redux ought to recognise this immediately (Redux was heavily influenced by Elm's state management), with some terminology changes. In short: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Elm&lt;/th&gt;
&lt;th&gt;Redux&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;model&lt;/td&gt;
&lt;td&gt;state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;message&lt;/td&gt;
&lt;td&gt;action&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;update&lt;/td&gt;
&lt;td&gt;reducer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The key difference is that this is what the Elm runtime is built on, not something you opt-in to.&lt;/p&gt;

&lt;h2&gt;
  
  
  The app we're looking at
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Project Arklay&lt;/em&gt; is a super basic text-adventure game that I've written a few times now in order to test out different tools or ideas or languages. Put simply, you (the player) navigate through various rooms, picking up items and unlocking doors, until you're ultimately met with an abrupt and disappointing ending. &lt;/p&gt;

&lt;p&gt;Now that I've saved you the time of actually playing it, let's talk about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application states
&lt;/h3&gt;

&lt;p&gt;The application can be in one of three states (at the time of writing).&lt;/p&gt;

&lt;p&gt;Either, you haven't started playing: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkouwumvjqowehdewwkv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkouwumvjqowehdewwkv.png" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or you have started playing, and the current available directions are being displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7io88yvz32h7oeigzr80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7io88yvz32h7oeigzr80.png" width="800" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or, you have started playing, and your current inventory is being displayed: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1ehgrig4b2bh6pciut6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1ehgrig4b2bh6pciut6.png" width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although these are three separate finite states, it's clear that the second and third are siblings in an overall parent view - so we have two views here. We'll refer to these as the &lt;strong&gt;Intro view&lt;/strong&gt; and the &lt;strong&gt;Game view&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Original requirements
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The player can: 

  In the Intro view:

  + Start the game

  In the Game view:
    When the state is Displaying Directions:

      + See which directions are available to move in
      + Select a direction to move in
      + Examine the room (this will pick up any items available in the current room, and add them to the inventory)
      + Open the inventory - so long as there are items in the inventory

    When the state is Displaying Inventory: 

      + See which items are available
      + Use an item
      + Close the inventory 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How this is looks in the code
&lt;/h2&gt;

&lt;p&gt;Going through this entire application line by line probably isn't going to be super helpful, but looking at the parts that have already been described should give you a decent taste for what working with Elm is like. It &lt;em&gt;is&lt;/em&gt; worth knowing at this point though that all Elm applications will have a &lt;strong&gt;Main&lt;/strong&gt; module, which will have a &lt;strong&gt;main&lt;/strong&gt; function, and will be in a file called &lt;strong&gt;Main.elm&lt;/strong&gt;. It's probably also worth knowing that every .elm file is its own module.&lt;/p&gt;

&lt;p&gt;First of all, let's look at the application state - remember I said we had two views that made up our overall possible application states? Our overall application model is a record (which is similar to an object in JavaScript), which holds two things: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fut4ft6fzrrxe8s64h5gk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fut4ft6fzrrxe8s64h5gk.png" width="376" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You don't need to worry about the "key" here - (it exists in order to allow us to navigate between different pages of the application whilst controlling what's displayed in the URL, and is generated by Elm's internals), but the state field is defined here as holding a &lt;strong&gt;State&lt;/strong&gt;, which is a custom type. In this application's case, this looks like: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscfv19wnu1hrwnfxzzoh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscfv19wnu1hrwnfxzzoh.png" width="426" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the overall application state can be either &lt;strong&gt;ViewIntro&lt;/strong&gt; (in which case it needs something that looks like whatever is defined as Model in the Intro module), or &lt;strong&gt;ViewGame&lt;/strong&gt; (in which case it needs something that looks like whatever is defined as Model in the Game module). That takes care of two of our possible application states, and we said that the there were two possible states of our ViewGame state, so let's have a look at what &lt;strong&gt;Game.Model&lt;/strong&gt; looks like: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9y9mrf5b25hf5eq4gcf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9y9mrf5b25hf5eq4gcf.png" width="592" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great, no surprises there then - Game.Model also has a &lt;strong&gt;state&lt;/strong&gt; key, which also holds a custom type of State. It's worth noting that this is actually a &lt;strong&gt;Game.State&lt;/strong&gt;, where the "State" that we looked at last was a &lt;strong&gt;Main.State&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Custom types can look a bit odd when you see them like this for the first time, so for a very quick clarification - a custom type in Elm is a type that can be enumerated. You could consider the way that Bool works as an example: it is a type that can either be True or False, and if you were to enumerate over it, you'd know in advance that you were going to be dealing with (at most) those two values. Our State here is no different. It could easily be a flag of "displayingDirections" with a boolean value, but I think there is a nice benefit of being able to look at the state here and quickly reason about what the possibilities are, which would be lost if this was a "displayingDirections" flag (since you wouldn't know what that being false would indicate). &lt;/p&gt;

&lt;h2&gt;
  
  
  How these states are rendered
&lt;/h2&gt;

&lt;p&gt;Earlier I said that the view was rendered based on the Model, and we know that in this application the state is held in the model too, and we also know that State is a custom type, so it shouldn't be a big surprise to see how this all comes together in the code: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiv3g4mav5ml7nsb7jdp0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiv3g4mav5ml7nsb7jdp0.png" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If that looks a little confusing, it might be because functions in Elm don't have parentheses around their arguments, every function in Elm has a return value, and every function in Elm is evaluated as a single expression. If the above were in JS, it would look something like this instead: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4h9txocr41wb3j90e5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4h9txocr41wb3j90e5c.png" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although you'd be relying on state in the JS example being either "ViewIntro" or "ViewGame". In our Elm implementation, we know it is one of those two things, as those are the only things it can possibly be - so no need for a default in Elm here, which we would need in the JS version.&lt;/p&gt;

&lt;p&gt;In the case of our Game states, only part of the view changes depending on &lt;strong&gt;Game.State&lt;/strong&gt;, but it works in exactly the same way - in the part of the view that changes, there's another case expression: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fki0srw7yrx4v1clgajaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fki0srw7yrx4v1clgajaf.png" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
   How updates happen
&lt;/h2&gt;

&lt;p&gt;I have a custom type of Msg which holds the possible message type in any module that has messages (this is something you'll see in basically every Elm app ever - very much the "standard" way of handling messages, since you're always going to be wanting to run a case expression on them). &lt;/p&gt;

&lt;p&gt;There is an update function in our Main module, which is the one run by Elm's runtime. My &lt;strong&gt;Intro&lt;/strong&gt; and &lt;strong&gt;Game&lt;/strong&gt; modules also have their own update functions, and whenever an &lt;strong&gt;Intro.Msg&lt;/strong&gt; or &lt;strong&gt;Game.Msg&lt;/strong&gt; is received by the runtime, it gets piped into Intro.update or Game.update, allowing the message to be handled and the model to be updated correctly. This wiring isn't automatic, but it isn't especially complicated either - Main's &lt;strong&gt;Msg&lt;/strong&gt; type looks like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsklpb8crjaosc8l6kj2v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsklpb8crjaosc8l6kj2v.png" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ChangedUrl&lt;/strong&gt; and &lt;strong&gt;ActivatedLink&lt;/strong&gt; messages are there because I need to supply the runtime with a message to call in the event of either of those things happening, but the things we're interested in here are &lt;strong&gt;Intro.Msg&lt;/strong&gt; and &lt;strong&gt;Game.Msg&lt;/strong&gt;. By this point you probably already know that we're about to look at &lt;strong&gt;Main.update&lt;/strong&gt; to see what's happening: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts74wtxckqb9buu1phyb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts74wtxckqb9buu1phyb.png" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in the event of a &lt;strong&gt;GameMsg&lt;/strong&gt;, we unpack the &lt;strong&gt;Game.Msg&lt;/strong&gt; into &lt;strong&gt;msgReceived&lt;/strong&gt;, and then we call &lt;strong&gt;Game.update&lt;/strong&gt; passing in the message along with the current &lt;strong&gt;gameModel&lt;/strong&gt; to get an &lt;strong&gt;updatedGameModel&lt;/strong&gt;, which we then use to update our state to be &lt;strong&gt;ViewGame updatedGameModel&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Now if we look at that &lt;strong&gt;Game.Msg&lt;/strong&gt; type, we can see what messages Game.update handles: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wersa457wd3fvrui0gk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wersa457wd3fvrui0gk.png" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You won't be surprised to learn that this is all as you'd expect: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Item&lt;/strong&gt; and &lt;strong&gt;Room&lt;/strong&gt; are both custom types&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ToggleInventory&lt;/strong&gt; toggles whether the inventory is being displayed or not (by checking the current Game.model.state and switching to the other possibility) &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UseItem&lt;/strong&gt; stores an Item and a Room, and checks to see if the item in question can be used in the room in question (and uses it if it's possible)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ChangeRoom&lt;/strong&gt; stores a Room and updates the Game.model to have that room stored in its Game.model.room&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ExamineRoom&lt;/strong&gt; may have an Item, and if it does, it adds it to the player's inventory. Otherwise, the inventory remains the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, that last one is technically not quite true. It should have been: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ExamineRoom&lt;/strong&gt; always has a &lt;strong&gt;Maybe&lt;/strong&gt;, and that Maybe either has an Item or it has Nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That might sound like a subtle difference, but this is how we avoid the potential headache of null or undefined - a Maybe can be enumerated with a case expression as well, and just like everything that can be enumerated in Elm, you have to handle all possibilities.&lt;/p&gt;

&lt;p&gt;Let's have a look at the ExamineRoom function in &lt;strong&gt;Game.update&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5d1pneretvxtq7j5lt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5d1pneretvxtq7j5lt3.png" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're not familiar with Elm, this might look confusing to see all at once - remember that you felt the same way about whatever every other language you've ever used at one point too though!&lt;/p&gt;

&lt;p&gt;What's happening here is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;I'm first checking to see if there's an item stored in the (Maybe Item) that is passed along with the ExamineRoom message&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if there is, I'm checking to see if the player is either currently holding that item, or if they've already used it.&lt;/li&gt;
&lt;li&gt;In either case, I want their inventory to remain the same, so I'm returning an identical copy* of the list that is stored in Game.model.inventory.&lt;/li&gt;
&lt;li&gt;If the player is neither currently holding the item, and they haven't already used it, then we're creating a new list of the current inventory, plus the new item. And then we're reversing it so that the new item appears at the end rather than the start - items are always added to the start of a list in Elm. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there was no item to begin with, then I'm returning an identical copy* of the list that is stored in &lt;strong&gt;Game.model.inventory&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(*don't worry, the compiled and deployed code is using the value stored at the original memory location - but as every function in Elm returns a value, and values in Elm can't be mutated, we're conceptually returning an identical copy here)&lt;/p&gt;

&lt;p&gt;And we can look at the functionality that was described at the start of this post, and see how it relates to the messages in Game.Msg: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Msg&lt;/th&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ToggleInventory&lt;/td&gt;
&lt;td&gt;Player can open inventory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UseItem&lt;/td&gt;
&lt;td&gt;Player can use an item&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ChangeRoom&lt;/td&gt;
&lt;td&gt;Player can select a direction to move in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ExamineRoom&lt;/td&gt;
&lt;td&gt;Player can examine the current room&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The requirements not covered by these messages are both to do with the player being able to see something (i.e. the available directions or their current items), and that's not a coincidence - things that a user can see are controlled &lt;strong&gt;Game.view&lt;/strong&gt; and not &lt;strong&gt;Game.update&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;(There is also a sole &lt;strong&gt;Intro.Msg&lt;/strong&gt; of &lt;strong&gt;StartGame&lt;/strong&gt;, which matches up to our other requirement, but it isn't worth talking about that here!)&lt;/p&gt;

&lt;p&gt;One thing that I find especially useful with an Elm application is to look at requirements and work out whether something is the responsibility of update, and then add a Msg for it if it is. &lt;/p&gt;




&lt;p&gt;Anyway, I hope that someone found this interesting - I know this hasn't been an especially deep dive into the language itself, but I feel like it should give a little flavour of how to look around an application to figure out what's happening with it. Personally, I'm always happy when I end up with something that is this easy to understand: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyt7fm5ehbuxpdwf19la.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyt7fm5ehbuxpdwf19la.png" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
If you are interested, you can look at the full repo: &lt;a href="https://github.com/dnimmo/project-arklay-v3" rel="noopener noreferrer"&gt;https://github.com/dnimmo/project-arklay-v3&lt;/a&gt; (things will change after this post is published, so the examples here may well be different in the repo than they are in this post - happy to answer questions on any of it mind, feel free to get in touch)&lt;/p&gt;

&lt;p&gt;Or you can play the game itself in its still-could-use-some-styling-tweaks state: &lt;a href="http://arklay.surge.sh" rel="noopener noreferrer"&gt;http://arklay.surge.sh&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elm</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
