<?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: Lauri Hiltunen</title>
    <description>The latest articles on DEV Community by Lauri Hiltunen (@decoeur_).</description>
    <link>https://dev.to/decoeur_</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%2F3062%2FadAcmtL6.jpg</url>
      <title>DEV Community: Lauri Hiltunen</title>
      <link>https://dev.to/decoeur_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/decoeur_"/>
    <language>en</language>
    <item>
      <title>Estimates and Anchoring When Playing Planning Poker</title>
      <dc:creator>Lauri Hiltunen</dc:creator>
      <pubDate>Sun, 10 Feb 2019 15:29:25 +0000</pubDate>
      <link>https://dev.to/decoeur_/estimates-and-anchoring-when-playing-planning-poker-3678</link>
      <guid>https://dev.to/decoeur_/estimates-and-anchoring-when-playing-planning-poker-3678</guid>
      <description>

&lt;h3&gt;
  
  
  Rudimentary Introduction to Planning Poker
&lt;/h3&gt;

&lt;p&gt;The term of planning poker is used to describe the method which utilises a group of developers to estimate the relative size of a development task, or multiple of. When a team is playing planning poker, people go through the tasks one by one, estimating  the task as they go. You can read more about the method in &lt;a href="https://en.wikipedia.org/wiki/Planning_poker"&gt;Wikipedia&lt;/a&gt;, for instance.&lt;/p&gt;

&lt;p&gt;One benefit of planning poker is including the opinion of each developer when the estimates are done. Generally the more experienced developers, who might know the system inside and out, may lean on the smaller side of the estimate spectrum. This is quite natural, as it is how that person sees the task. What he might fail to note is that not every developer in the team shares the same experience, expertise or insight on how the app works currently.&lt;/p&gt;

&lt;h4&gt;
  
  
  Before Moving on...
&lt;/h4&gt;

&lt;p&gt;Before we move on to the cool stuff, try answering these two questions. I promise it'll make sense in just a minute.&lt;br&gt;
&lt;iframe src="https://jsfiddle.net/cLah7x48/6//embedded/result//dark" width="100%" height="600"&gt; &lt;/iframe&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Cool Stuff
&lt;/h3&gt;

&lt;p&gt;Now, where the game gets interesting is the psychology behind it. The Wikipedia description includes this, sometimes overlooked rule of planning poker: "all participants show their [estimate] card at the same time". For a successful round of planning poker, I consider this quite essential part of the game. Why, you might ask...&lt;/p&gt;

&lt;p&gt;It all boils down to something called the anchoring effect. In a nutshell, anchoring means using some initial piece of information as a base on which we build our own opinion of the matter. Daniel Kahneman's Thinking Fast and Slow elaborates this by using an example:&lt;/p&gt;

&lt;p&gt;The guests at San Fransisco Exploratium were subjected to an experiment to see how the anchoring affects people's estimates. People were split into two groups, each of which two questions were asked as follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Group 1&lt;br&gt;
Is the height of the tallest redwood tree more or less than 365 meters? &lt;br&gt;
What is your best guess about the height of the tallest redwood tree?&lt;/p&gt;

&lt;p&gt;Group 2&lt;br&gt;
Is the height of the tallest redwood tree more or less than 55 meters?&lt;br&gt;
What is your best guess about the height of the tallest redwood tree?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What was noted that the first question affects how people will respond to the second question. The average estimate of height of the tallest red wood tree for the group one was ~257 meters while the group 2's average was around 85 meters. Quite a big difference just by changing one number in the first question. The anchor.&lt;/p&gt;

&lt;p&gt;So if we skip the "everyone reveals their estimate at the same time" we establish the possibility to anchoring to happen. It means that whoever speaks their mind first might affect the estimates of people coming after them. Following estimates might not necessarily become the same, but it's easier for the person to drop their original estimate of 5-7 points to 3, for instance. And that's a big difference.&lt;/p&gt;

&lt;p&gt;The lesson is this: if you're playing planning poker, go all in!&lt;/p&gt;

&lt;p&gt;P.S. Oh btw, about the answer you gave earlier, did your answer reflect with the findings described above?&lt;br&gt;
&lt;iframe src="https://jsfiddle.net/x6oscmzd/1//embedded/result//dark" width="100%" height="600"&gt; &lt;/iframe&gt;&lt;/p&gt;


</description>
      <category>planningpoker</category>
      <category>estimate</category>
      <category>anchoring</category>
      <category>interactive</category>
    </item>
    <item>
      <title>Managing State with Vuex - the Guide I Wish I'd Had</title>
      <dc:creator>Lauri Hiltunen</dc:creator>
      <pubDate>Wed, 28 Mar 2018 16:12:10 +0000</pubDate>
      <link>https://dev.to/decoeur_/managing-state-with-vuex---the-guide-i-wish-id-had-28h</link>
      <guid>https://dev.to/decoeur_/managing-state-with-vuex---the-guide-i-wish-id-had-28h</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; see the vuex flow and/or skip to see the code.&lt;/p&gt;

&lt;p&gt;Frontend apps have been growing more and more feature-rich in recent years. "It's for the web" is not a proper reason to deny desktop-like feature requests anymore. At the same time frontends are switching from the traditional MVC model to a more componentized structure, and the need for a solid state management pattern has emerged. After all, the components interacting with each other is a vital part of any bigger app.&lt;/p&gt;

&lt;p&gt;Flux is a design pattern released by Facebook, created to structure client-side, component-based applications. There are many implementations of the Flux-pattern but in this post we're going to focus on one: Vuex. This is the guide I wish I'd had when I first started reading about state management with Vuex. There will be code!&lt;/p&gt;

&lt;h3&gt;
  
  
  Concepts
&lt;/h3&gt;

&lt;p&gt;The key concepts with Vuex are: the state, actions, mutations and getters. The state object contains the application state, and is shared with all the components. Mutations change the state - and they are the only way to change it. Actions commit mutations, the key difference being that mutations can not be asynchronous. We should invoke async actions which commit mutations when the async code has completed. All state mutations must be synchronous! Finally the getters return specific parts of the state for components to use.&lt;/p&gt;

&lt;p&gt;&lt;span id="vuex-flow"&gt; &lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwu1dtt6firtg4ln5tn61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwu1dtt6firtg4ln5tn61.png" alt="The flow in a single image"&gt;&lt;/a&gt;&lt;/p&gt;
The flow of data inside store: components create actions which commit mutations, mutations alter the state and getters return parts of it.



&lt;p&gt;You can choose not to use some of the steps described above, but for the sake of completeness I'll go through the flow as it's designed to be used.&lt;/p&gt;

&lt;h3&gt;
  
  
  The sample app
&lt;/h3&gt;

&lt;p&gt;We're going to take a look at some code, which creates the store for one property, mutates it and returns it for components. The sample app is a concept of an activity calculator of some sorts. The basic idea is that you'll select an exercise you're working with and then add the amount of that exercise done, like stairs climbed, the distance you've ran or the pushups you've done. The app for this example consists of two components: one that selects the exercise and the other one that uses the selected exercise and allows you to mark the "reps" you've accomplished and send the data to a backend service for further processing.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;span id="tldr"&gt;Bring on the code&lt;/span&gt;
&lt;/h3&gt;

&lt;p&gt;Let's get going with the code - I did use the vue-cli simple webpack setup to enable ES6 features. First of all, let's create the Vuex store.&lt;/p&gt;

&lt;h4&gt;
  
  
  The state inside store.js
&lt;/h4&gt;

&lt;p&gt;The state inside the store is just another object, it can contain anything you want.&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;//store.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vue&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;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vuex&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;selectedExercise&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
We have the state object in store.js, it contains the selectedExercise which we'll mutate in a little while.





&lt;h4&gt;
  
  
  Actions
&lt;/h4&gt;

&lt;p&gt;Then we're having the action methods, they get the context as their first parameter and the possible payload as the second param. This action creates a mutation by calling context.commit with the name of the mutation and passing possible payload to go with it.&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;//store.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;selectActiveExercise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exercise&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selecting exercise action, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;exercise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selectExercise&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exercise&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="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Actions commit mutations





&lt;h4&gt;
  
  
  Mutations
&lt;/h4&gt;

&lt;p&gt;And then there are the mutations. Mutations get the state as first parameter and an optional payload as second. The action from previous step committed a mutation which calls the selectExercise method which in turn changes the state for real.&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;//store.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;selectExercise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;exercise&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selecting exercise mutation, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;exercise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedExercise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;exercise&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Mutations altering the state





&lt;h4&gt;
  
  
  Getters
&lt;/h4&gt;

&lt;p&gt;The last missing part - the getters exposed by the store. You can call the selectedExercise getter from any of your components and it'll return you that specific portion of the state.&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;//store.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;selectedExercise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;getting selected exercise&lt;/span&gt;&lt;span class="dl"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedExercise&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Getter returning a part of the state





&lt;h4&gt;
  
  
  Exporting the Vuex store
&lt;/h4&gt;

&lt;p&gt;Build up the store and export it so we can use it.&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;//store.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getters&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Import the store and use it in your app
&lt;/h4&gt;

&lt;p&gt;Initialising the app with the store.&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;// your app.js/main.js, some code omitted&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;store&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;./store/store.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;router&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;App/&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;App&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;
We're importing the store from newly-created store.js and assigning it as a store to our app.





&lt;h3&gt;
  
  
  Using the store inside components
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Running actions and mutating the state
&lt;/h4&gt;

&lt;p&gt;Now that we've set up the store, we can use it in our components. First of all the exercise-selector component, which triggers the action that selects the active exercise for our context by running the select exercise action which in turn runs the mutation that commits the change to state.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mapActions&lt;/span&gt; &lt;span class="p"&gt;}&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exercise-selector&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;methods&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="nf"&gt;mapActions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;selectActiveExercise&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selectActiveExercise&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="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// code omitted...    &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Exercise selector vue component, it maps the selectActiveExercise action for use in our Vue component







&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"exercise-row"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"selectActiveExercise"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ exercise.name }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"pointsPerUnit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;{{ exercise.pointsPerUnit }} points per {{ exercise.unit }}&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Using the mapped "selectActiveExercise" method inside the template





&lt;h4&gt;
  
  
  Getters
&lt;/h4&gt;

&lt;p&gt;After taking care of mutating the state, we're mapping the getters defined in the store to our other component. This effectively creates a computed getter method with the name "selectedExercise" for our component.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mapGetters&lt;/span&gt; &lt;span class="p"&gt;}&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exercise-input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;computed&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="nf"&gt;mapGetters&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;selectedExercise&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="c1"&gt;//...    &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Mapping the getter "selectedExercise" from vuex store for use as computed properties





&lt;p&gt;When the getter is in our component's context, we can use it in our template as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"selectedExercise"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Add exercise&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-selected-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ selectedExercise.name }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;in-put&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-number"&lt;/span&gt; &lt;span class="na"&gt;v-on:keyup.enter=&lt;/span&gt;&lt;span class="s"&gt;"addExercise"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"units"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/in-put&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-unit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ selectedExercise.unit }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"input-details"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Points {{ selectedExercise.pointsPerUnit}} per {{ selectedExercise.unit }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"addExercise"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add to your exercises record&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"forward"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Mapping the getter "selectedExercise" from vuex store for use as a computed property





&lt;p&gt;So we are using the mapped getter method inside our template. This effectively gets the data from store and is updated automatically when any component commits the mutation that changes the selected exercise.&lt;/p&gt;

&lt;p&gt;And that's it, Vuex with a couple of lines of code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Afterword
&lt;/h3&gt;

&lt;p&gt;I got into Vuex a couple of weeks ago during a get-together with my colleagues. At first all the talk about actions and mutations seemed a bit confusing and complicated, but to see it in a few lines of code makes it quite clear and understandable. And in the end using centralized state does make application development easier as the size of the application gets bigger. When the state changes are reactively rendered in every component, you can focus on the key features which alter the state instead of doing something like emitting events or updating your views manually.&lt;/p&gt;

&lt;p&gt;I like it, it beats all the manual scripting and event-based solutions I've seen before. By a mile!&lt;/p&gt;

</description>
      <category>vuex</category>
      <category>vue</category>
      <category>flux</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What Is Null? (Baby Don't Hurt Me)</title>
      <dc:creator>Lauri Hiltunen</dc:creator>
      <pubDate>Wed, 22 Nov 2017 17:31:08 +0000</pubDate>
      <link>https://dev.to/decoeur_/what-is-null-baby-dont-hurt-me-a8j</link>
      <guid>https://dev.to/decoeur_/what-is-null-baby-dont-hurt-me-a8j</guid>
      <description>

&lt;p&gt;There are two kinds of programmers out there. Those that have had null-related errors in their programs and those that are just starting their careers. The dreaded null, nil, undefined… Most programming languages have a concept for “nothing”. But what is nothing? Have you ever thought about null, what is it really? And what is it not? Let’s see what null means in Java.&lt;/p&gt;

&lt;p&gt;To get things started, null in Java is not an instance of any type. Java’s type comparison operator, instanceof, &lt;a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.20.2"&gt;is defined as follows&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At run time, the result of the instanceof operator is true if the &lt;b&gt;value&lt;/b&gt; of the RelationalExpression &lt;b&gt;is not null&lt;/b&gt; and the reference could be cast to the ReferenceType without raising a ClassCastException. Otherwise the result is false.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So by definition null is not an instance of anything.&lt;/p&gt;

&lt;p&gt;However, the Java Language Specification, or JLS, defines a special &lt;a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.1"&gt;null type&lt;/a&gt;. The null type has no name, and as such you can’t declare a variable of the null type. You can’t cast anything to the null type either. The only possible value ever to exist (or not?) for null type is the null reference itself. For every other &lt;a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.3"&gt;reference type&lt;/a&gt;, you can always assign the value as null. As JLS states:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Java, null equals null. Meaning “null == null”. Also, by contract, the equals method from java.lang.Object states that for any non-null reference “ref” of type TYPE, ref.equals(null) should return false. So while null equals null, it is not equal to anything else.&lt;/p&gt;

&lt;p&gt;How do you use null then? Propably the most common use-case is to denote the fact that the reference requested does not exist or is unavailable. For instance, Java’s System.console() method returns null, if no console is available.&lt;/p&gt;

&lt;p&gt;Null is also the default value for all reference variables. This means that for every reference variable, if you won’t assign a value, it’ll be null. This fact can be used, among other things, to implement lazy initialization of your fields, where you populate the possibly expensive fields only when you need them for the first time. In cases like these null is used to represent an uninitialized state.&lt;/p&gt;

&lt;p&gt;In addition to referring to non-existing object or uninitialized state, general use-cases for null include signifying termination condition (see BufferedReader.readLine();) and having an unknown value (like mapping null to certain key in a Map).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Tony_Hoare"&gt;Sir Tony Hoare&lt;/a&gt; has famously stated that inventing null has been his billion dollar mistake. There are ways to work around the concept of nullability, for instance using &lt;a href="https://en.wikipedia.org/wiki/Null_object_pattern"&gt;Null object pattern&lt;/a&gt;. Whatever you decide to do, be mindful of your code when it's even remotely possible that a reference could be null. Otherwise your app might just&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Exception in thread "main" java.lang.NullPointerException
    at to.dev.WhatIsNull.main(WhatIsNull.java:42)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




</description>
      <category>java</category>
      <category>programming</category>
      <category>null</category>
      <category>beginners</category>
    </item>
    <item>
      <title> Programming by Coincidence (Don't Do It) </title>
      <dc:creator>Lauri Hiltunen</dc:creator>
      <pubDate>Wed, 18 Oct 2017 17:41:00 +0000</pubDate>
      <link>https://dev.to/decoeur_/programming-by-coincidence-dont-do-it-7cp</link>
      <guid>https://dev.to/decoeur_/programming-by-coincidence-dont-do-it-7cp</guid>
      <description>

&lt;p&gt;The book &lt;a href="https://pragprog.com/book/tpp/the-pragmatic-programmer"&gt;Pragmatic Programmer&lt;/a&gt; introduces the concept of programming by coincidence. In a nutshell it means writing code without really understanding what you're doing, how your snippet of code or app works. While everything seems to be working just fine on the outside, it might break later on for reasons unknown to you. I will break down the issue on this post, please correct me if there are obvious (or not so obvious) errors in the text.&lt;/p&gt;

&lt;h2&gt;Accidents Waiting to Happen&lt;/h2&gt;

&lt;p&gt;The concept itself has been broken down to following "accidents".&lt;/p&gt;

&lt;h3&gt;Accident of Implementation&lt;/h3&gt;

&lt;p&gt;Accident of Implementation might happen because of the way code's written. Maybe you're relying on some undocumented feature/bug of the library you're using, or some side effect that just happens when you're making your method calls in a certain order, without properly initializing your parameters etc. etc. In the end your relying on undocumented features or boundary conditions which just work with your code, but are breaking up often/easily when something else changes.&lt;/p&gt;

&lt;h3&gt;Accident of Context&lt;/h3&gt;

&lt;p&gt;Accident of context means that you create your code for a specific scenario but there are aspects you're not thinking of. You might be programming your modules assuming there's a GUI present, while that might not always be the case. Context accidents happen when you're relying on something that's not guaranteed to be there. I would also want to include copy-pasting code as a flavor of Accident of Context; if you're copying something (do consider DRY - don't repeat yoursef - as well), you need to be aware of both contexts, what do they have in common, how are they different.&lt;/p&gt;

&lt;h2&gt;Assumption Is the Mother of All F-Ups&lt;/h2&gt;

&lt;p&gt;Basically both of these accidents have their roots in assuming things. You assume that the code needs to be written in a way it is, you assume the API does what you think it does intentionally, even if it seems odd. You assume that your clients are literate and smart, that you know the context and environment in which the software will run. You assume your assumptions are correct :)&lt;/p&gt;

&lt;h3&gt;How to Avoid Programming by Coincidence&lt;/h3&gt;

&lt;p&gt;If there's a name for the problem and people have written about it, then there's bound to be a simple cure for it as well. Right? No. There are no easy step-by-step guides on how get rid of the issue once and for all. It takes conscious effort and focus to avoid this pitfall.&lt;/p&gt;

&lt;p&gt;First and foremost, always be aware of what you're doing. Don't go on autopilot and make the easy assumptions. Look into things and how they work, test and document your assumptions for reference. Testing your assumptions and finding them wrong on the spot... That's a bullet dodged right there.&lt;/p&gt;

&lt;p&gt;You should not program "blindfolded". Try to understand the basic concepts and what your (and all the related) code's about. Also, working with legacy software it's easy to take a look at the similar implementation for reference, or even copy-pasting it to get a head start. But try asking yourself a question: is there a reason why it was made like it was? Could you possibly improve the code base? The ones who come after you might want to thank you if you do!&lt;/p&gt;

&lt;p&gt;Why am I writing this? As a reminder really, as I've recently bumped heads with hard to find bugs because of this very matter. Errors that could've been easily prevented if people would have paid attention to what they were doing. Everyone slips up sometimes, it's natural. Just try to be aware of what you're doing to minimize problems caused by programming by coincidence.&lt;/p&gt;

&lt;p&gt;If you made it to the bottom, congratulations to you! If there's one thing to take in from the post, it's this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t Program by Coincidence&lt;/p&gt;
&lt;/blockquote&gt;


</description>
      <category>coding</category>
      <category>practices</category>
      <category>quality</category>
      <category>bugs</category>
    </item>
  </channel>
</rss>
