<?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: Stan Prokop</title>
    <description>The latest articles on DEV Community by Stan Prokop (@atomicstan).</description>
    <link>https://dev.to/atomicstan</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%2F457943%2F2d9c4040-5f54-41e7-9483-12b98f74acd6.jpeg</url>
      <title>DEV Community: Stan Prokop</title>
      <link>https://dev.to/atomicstan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/atomicstan"/>
    <language>en</language>
    <item>
      <title>All Glory to the Principle of Least Astonishment! ❤</title>
      <dc:creator>Stan Prokop</dc:creator>
      <pubDate>Tue, 29 Sep 2020 20:07:29 +0000</pubDate>
      <link>https://dev.to/atomicstan/all-glory-to-the-principle-of-least-astonishment-1378</link>
      <guid>https://dev.to/atomicstan/all-glory-to-the-principle-of-least-astonishment-1378</guid>
      <description>&lt;p&gt;The &lt;a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment"&gt;PoLA&lt;/a&gt; is one of my favorite principles and I wish it's known as much as the &lt;a href="https://en.wikipedia.org/wiki/KISS_principle"&gt;KISS principle&lt;/a&gt;, maybe even more. It's also a playful way to think about anything you want to create and is supposed to be used by others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet the PoLA
&lt;/h2&gt;

&lt;p&gt;The idea behind it is straightforward - anything you create must not astonish or negatively surprise. As little WTFs as possible, which can help you to avoid bugs introduced by humans and provide a good user experience. This basically means to follow consistency, common user expectations and user's experience. The principle is universally applicable similarly as KISS and as a software developer I use it often to define interfaces, code behavior or in software architecture discussions&lt;/p&gt;

&lt;h2&gt;
  
  
  An example
&lt;/h2&gt;

&lt;p&gt;Let me demonstrate that on the famous Javascript comparison operator &lt;code&gt;==&lt;/code&gt;. The comparison behaves this way for values &lt;code&gt;""&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt; [] == 0
true

&amp;gt;&amp;gt; "" == 0
true

&amp;gt;&amp;gt; "" == []
true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For these values it behaves like a &lt;a href="https://en.wikipedia.org/wiki/Transitive_relation#Examples"&gt;transitive relation&lt;/a&gt;. However when you replace &lt;code&gt;""&lt;/code&gt; with &lt;code&gt;"0"&lt;/code&gt;, &lt;code&gt;"0" == []&lt;/code&gt; returns actually &lt;code&gt;false&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt; [] == 0
true

&amp;gt;&amp;gt; "0" == 0
true

&amp;gt;&amp;gt; "0" == []
false
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you know all the necessary Javascript details this behavior might make sense to you, but for the rest of the humanity it, well... it totally doesn't. And that's the point. How does it break the principle of least astonishment specifically?&lt;/p&gt;

&lt;p&gt;You might say that the last statement should be &lt;code&gt;true&lt;/code&gt; so it follows the behavior of the rest of the comparisons, but I think to really follow the principle of least astonishment the rest of the comparisons shouldn't return &lt;code&gt;true&lt;/code&gt; in the first place. They should either throw an exception (comparing something which isn't really comparable), return &lt;code&gt;undefined&lt;/code&gt; (result of such comparisons shouldn't be really defined) or just return &lt;code&gt;false&lt;/code&gt; (they are not really equal). This actually shows nicely PoLA since the right solution sometimes really depends on the context.&lt;/p&gt;

&lt;p&gt;To be fair Javascript also has strict operator &lt;code&gt;===&lt;/code&gt; which has less astonishing behavior, but hey, that wouldn't really demonstrate PoLA, would it? And &lt;code&gt;==&lt;/code&gt; is the first thing which anyone coming from a different programming language would use.&lt;/p&gt;

&lt;h2&gt;
  
  
  So...
&lt;/h2&gt;

&lt;p&gt;The PoLA is a simple but really powerful principle. When designing with PoLA in mind it helps to explicitly consider more perspectives which leads to less bugs and problems.&lt;/p&gt;

&lt;p&gt;Do you have any examples of PoLA violations? They are usually great lessons learned.&lt;/p&gt;

</description>
      <category>principles</category>
      <category>tip</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
