<?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>Forem: JoelBonetR 🥇</title>
    <description>The latest articles on Forem by JoelBonetR 🥇 (@joelbonetr).</description>
    <link>https://forem.com/joelbonetr</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%2F158311%2F710853e1-8e11-49e3-b0d2-daf27340df52.jpg</url>
      <title>Forem: JoelBonetR 🥇</title>
      <link>https://forem.com/joelbonetr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joelbonetr"/>
    <language>en</language>
    <item>
      <title>Design Patterns demystified with examples</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Wed, 30 Oct 2024 16:14:41 +0000</pubDate>
      <link>https://forem.com/joelbonetr/demystifying-design-patterns-45m3</link>
      <guid>https://forem.com/joelbonetr/demystifying-design-patterns-45m3</guid>
      <description>&lt;p&gt;So the AI era is here, the huge leap forward that, at the moment, spits Node code with &lt;code&gt;const fetch = require('node-fetch')&lt;/code&gt; 😳 (true for both ChatGPT and Gemini as of today) and feeds yet another spin of the cyclic machine that is Internet and its content.&lt;/p&gt;

&lt;p&gt;In that amalgamation of content, design patterns are appearing again &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%2Ffuhxqxhcc9nfc18hwy8h.gif" 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%2Ffuhxqxhcc9nfc18hwy8h.gif" alt="Image description" width="498" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From posts explaining how to apply design patterns in Node(???) to posts explaining with all detail obsolete stuff like how to apply the factory pattern in Java (Java 8 released in March &lt;strong&gt;2014&lt;/strong&gt; added Lambdas).&lt;/p&gt;

&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;p&gt;Ever stumbled upon &lt;a href="https://refactoring.guru/" rel="noopener noreferrer"&gt;Refactoring guru&lt;/a&gt;?&lt;br&gt;
It is a website you probably visited in your learning journey through computer science, specially in programming. It's design patterns section is quite well explained and one of the most shared through different forums over the years.&lt;/p&gt;

&lt;p&gt;If we go to the &lt;a href="https://refactoring.guru/design-patterns/what-is-pattern" rel="noopener noreferrer"&gt;definition of what design patterns are&lt;/a&gt;, we find:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Design patterns are typical solutions to common problems&lt;br&gt;
in software design. Each pattern is like a blueprint&lt;br&gt;
that you can customize to solve a particular&lt;br&gt;
design problem in your code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Why this post, then? I mean, there's plenty of information on the website linked above; this could be all.&lt;/p&gt;

&lt;p&gt;The thing is, I always struggled with accepting this definition... "to solve a particular design problem &lt;strong&gt;in my code&lt;/strong&gt;"... in my code? Does my code have a problem that I need to solve?&lt;/p&gt;
&lt;h3&gt;
  
  
  Definition, reimagined
&lt;/h3&gt;

&lt;p&gt;What happens really, is that I need to code a certain "something" &lt;strong&gt;for which the programming language used in the project is lacking abstractions for&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Plain and simply. Just in case that doesn't resonate with you yet, lets see some examples with code.&lt;/p&gt;

&lt;p&gt;This is a really simple implementation of the Factory Pattern in Java (primarily an Object Oriented programming language).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ShapeFactory&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="nf"&gt;createShape&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"CIRCLE"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SQUARE"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Square&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Java 8 &lt;em&gt;(March 2014, just in case you forgot)&lt;/em&gt; added Lambdas (a concept from functional programming) so we can do this instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Supplier&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;shapeFactory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;shapeFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"CIRCLE"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;Circle:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;shapeFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SQUARE"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;Square:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="n"&gt;circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;shapeFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"CIRCLE"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No need for the factory design pattern ever again (at least in Java).&lt;/p&gt;

&lt;p&gt;Yes I know the factory pattern is the example most people use all the time, but what happens with the others? And what happens in other programming languages?&lt;/p&gt;

&lt;p&gt;This is the visitor pattern in Typescript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;visitor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShapeVisitor&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 

  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&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="s2"&gt;Drawing a circle&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="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;visitor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShapeVisitor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;visitor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;visitCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;sideLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sideLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sideLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sideLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&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="s2"&gt;Drawing a square&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="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;visitor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ShapeVisitor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;visitor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;visitSquare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ShapeVisitor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;visitCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;visitSquare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AreaCalculator&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;ShapeVisitor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;visitCircle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;radius&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="s2"&gt;`Circle area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;visitSquare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sideLength&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sideLength&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="s2"&gt;`Square area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;getArea&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;area&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;// Using the Visitor&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AreaCalculator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following code is doing exactly the same but using &lt;strong&gt;reflection&lt;/strong&gt; (the ability of a language to examine and manipulate its own objects at runtime) instead of the Visitor pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="c1"&gt;// ... (same as before)&lt;/span&gt;
  &lt;span class="nl"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ... (same as before)&lt;/span&gt;
  &lt;span class="nl"&gt;sideLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&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;shape&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;)&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;circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shape&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Type assertion&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;radius&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="s2"&gt;`Circle area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;shape&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;)&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shape&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Type assertion&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sideLength&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sideLength&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="s2"&gt;`Square area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the observer pattern, also in TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NewsPublisher&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&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="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
 &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;news&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NewsletterSubscriber&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&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="s2"&gt;`Received news: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;// Using the Observer&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;publisher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NewsPublisher&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;subscriber1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NewsletterSubscriber&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;subscriber2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NewsletterSubscriber&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscriber1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscriber2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New product launched!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same but using the built-in (in the Node API) EventEmitter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&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;EventEmitter&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;events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NewsPublisher&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;news&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;news&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;publisher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NewsPublisher&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;news&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="nx"&gt;news&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="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="s2"&gt;`All subscribers received the news: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New product launched!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At that point, you might have realized that the "problem" is the OOP implementation, and you would be quite right, but not fully.&lt;/p&gt;

&lt;p&gt;Every programming paradigm, specially when taken in its most pure form, has its quirks, difficulties or "things that can't be achieved in a straight line", if you will.&lt;/p&gt;

&lt;p&gt;Let's get ourselves to the functional programming realm. You've probably heard of Monads.&lt;/p&gt;

&lt;p&gt;Whether you fell for the mathematical definition mind trap or not, we -software developers- could understand Monads as design patterns as well. This is because in a world of pure functions, where nothing unexpected happens, it's difficult to conceive a side effect, but most software products need side effects, so how do we...?&lt;/p&gt;

&lt;p&gt;This is an example of the IO Monad in Haskell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;IO&lt;/span&gt; &lt;span class="nb"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;fileContent&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;readFile&lt;/span&gt; &lt;span class="s"&gt;"myFile.txt"&lt;/span&gt; 
  &lt;span class="n"&gt;putStrLn&lt;/span&gt; &lt;span class="n"&gt;fileContent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The side effect (reading a file) is contained in the IO monad.&lt;/p&gt;

&lt;p&gt;Let's add a monadic example using typescript;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Maybe&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;just&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Maybe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;nothing&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;U&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;U&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;U&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&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;Maybe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nothing&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;U&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;Maybe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;just&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;just&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;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&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;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;u&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="c1"&gt;// Maybe&amp;lt;string&amp;gt; with value "Alice"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;noUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Maybe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nothing&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;noUserName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;noUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;u&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A classic one, I've seen the maybe monad like 50 times all over the Internet, but what is it, really?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem&lt;/strong&gt; it's trying to solve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We forgot to define the properties of our object! 😩 &lt;/p&gt;

&lt;p&gt;&lt;em&gt;in a real use-case this would be the input from a side-effect mostly, like reading from a database or a file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So now if we do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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="c1"&gt;// Uncaught TypeError: Cannot read properties of undefined (reading 'value')&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the program explodes. &lt;/p&gt;

&lt;p&gt;The solution without the Maybe monad:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;value&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="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program does not explode.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;maybe monad&lt;/strong&gt; is not necessary in JavaScript or typescript due to the optional chaining operator but if you're using a language that does not implement it... well, you can apply the maybe monad or shall I say design pattern?&lt;/p&gt;

&lt;p&gt;Yes I know, there's people that just learnt the Maybe thingy and eagerly applied it to 6 side-projects all at once and now I'm being the giggle at the party for telling you "you don't need it". You can still use it though, in fact I invite you to do so if you feel it's cool &lt;em&gt;(at the end of the day it's your code + with that pretty face you can do whatever you want! 🤭)&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;But back to basics. What about other paradigms? If you're thinking outside the OOP/FP box, I like it! &lt;/p&gt;

&lt;p&gt;All paradigms definitely have their own recurring solutions and techniques, even if they aren't always formally called "design patterns." &lt;/p&gt;

&lt;p&gt;Here are a few examples (thanks Gemini for avoiding me thinking, thanks me for the pretty formatting and added value 😁):&lt;/p&gt;

&lt;h5&gt;
  
  
  Logic Programming:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Constraint Logic Programming&lt;/strong&gt;: This paradigm involves defining constraints and relationships between variables, and then letting the system find solutions that satisfy those constraints. Techniques like &lt;strong&gt;backtracking&lt;/strong&gt; and &lt;strong&gt;constraint propagation&lt;/strong&gt; are crucial for efficient problem-solving in this paradigm. (Quite useful when dealing with AI).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deductive Databases&lt;/strong&gt;: These databases use logical rules and inference to derive new information from existing data. Techniques like &lt;strong&gt;forward/backward chaining&lt;/strong&gt; are fundamental to how these databases operate and could be considered patterns within this paradigm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Concurrent Programming:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Message Passing&lt;/strong&gt;: In concurrent systems, where multiple processes execute simultaneously, message passing is a common technique for communication and coordination. Patterns like &lt;strong&gt;producer-consumer&lt;/strong&gt; and &lt;strong&gt;reader-writer&lt;/strong&gt; provide established solutions for managing concurrent access to resources and ensuring data consistency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synchronization Primitives&lt;/strong&gt;: These are low-level constructs like &lt;strong&gt;mutexes&lt;/strong&gt;, &lt;strong&gt;semaphores&lt;/strong&gt;, and &lt;strong&gt;condition variables&lt;/strong&gt; that are used to control access to shared resources in concurrent programs. While not "patterns" in the traditional sense, they represent well-defined solutions to common concurrency challenges.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Data-Oriented Programming:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Transformation Pipelines&lt;/strong&gt;: This paradigm emphasizes transforming data through a series of operations. Techniques like &lt;strong&gt;map&lt;/strong&gt;, &lt;strong&gt;filter&lt;/strong&gt;, and &lt;strong&gt;reduce&lt;/strong&gt; (common in functional programming as well, and used A LOT in javascript since its addition) are fundamental building blocks for constructing these pipelines, and could be considered patterns within this paradigm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Entity-Component-System (ECS)&lt;/strong&gt;: This architectural pattern is popular in game development and other data-intensive applications. It involves breaking down entities into components (data) and systems (logic), promoting data locality and efficient processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a lot of "techniques" and "patterns", this list is just to give you threads to pull if you're curious.&lt;/p&gt;

&lt;p&gt;Hope you find this useful, read you rather soon!&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%2Fpabifeog8sqt6e1bxam5.gif" 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%2Fpabifeog8sqt6e1bxam5.gif" alt="Image description" width="498" height="498"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  🔖 Summary, for the hurry ones!
&lt;/h3&gt;

&lt;p&gt;While the term "design patterns" is most closely associated with OOP, other paradigms have their own sets of recurring solutions and techniques. These techniques address the specific challenges and constraints of those paradigms, providing established approaches to common problems. So, even if they aren't always formally labeled as "design patterns," they serve a similar purpose in guiding developers towards effective and maintainable solutions.&lt;/p&gt;

&lt;p&gt;We can understand design patterns as &lt;strong&gt;well-known workarounds to patch features that the programming language we're using lacks abstractions for&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;small&gt;This post has been written almost entirely by me, specified examples by Gemini 1.5 Pro&lt;/small&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tech Lead Software Setup - 2024 Edition</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Sat, 09 Mar 2024 18:08:56 +0000</pubDate>
      <link>https://forem.com/joelbonetr/tech-lead-software-setup-2024-edition-8lk</link>
      <guid>https://forem.com/joelbonetr/tech-lead-software-setup-2024-edition-8lk</guid>
      <description>&lt;p&gt;Have you asked yourself what do you really need? Without the noise, without the hassle.&lt;/p&gt;

&lt;p&gt;Here's &lt;/p&gt;

&lt;h1&gt;
  
  
  My software development setup for this 2024
&lt;/h1&gt;

&lt;p&gt;and some extras!&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;br&gt;
&lt;strong&gt;!important;&lt;/strong&gt; The links of this post contain NO referral links and I've got zero monies to create this list. Everything you're about to read is my experience and opinion, enjoy! 😊 &lt;br&gt;
&lt;/small&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  BYE BYE VSCode. Hello &lt;a href="https://vscodium.com" rel="noopener noreferrer"&gt;VSCodium&lt;/a&gt;!
&lt;/h2&gt;

&lt;p&gt;Straight to the point; Why would I want to send telemetry and tracking data to Microsoft all the time? &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuvp9kzrffedc3qo5fyo.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuvp9kzrffedc3qo5fyo.png" alt="VSCodium VSCode open source binaries"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VSCodium contains the community-driven Open Source, freely-licensed binaries of VSCode with a beautiful icon that suits my desktop better! 😁&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjth5w98fuasz514rvmi.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjth5w98fuasz514rvmi.png" alt="Mac launchpad apps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Companion AI Autocompletion
&lt;/h2&gt;

&lt;p&gt;Apparently, Github Copilot requires Microsoft's distributed version of VSCode (wondering why 😇) and that led me to seek alternatives, now I'm glad I did!&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4hh69j88t4lzqr0bttm.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4hh69j88t4lzqr0bttm.png" alt="Codeium"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's &lt;a href="https://codeium.com" rel="noopener noreferrer"&gt;Codeium&lt;/a&gt;, which has a FREE individual plan, and has proven more useful to me than copilot, honestly. &lt;/p&gt;

&lt;p&gt;The context awareness amongst the project is quite superior and I'm now using the paid version instead the Copilot paid one. &lt;/p&gt;

&lt;p&gt;&lt;small&gt;I assume they might train the model further if you use the free version but didn't read the Terms &amp;amp; Conditions. It was sunday morning. I apologize. Shall you do please tell me 🙃&lt;/small&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  VSCodium plugins
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Less is more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;VSCode/VSCodium has improved on every update, linkedEditing settings drove "Auto rename tag" extension obsolete, "bracket pair colorizer" is now the default behaviour in VSCodium, so it's yet another extension that you no longer need and so on and so forth.&lt;/p&gt;

&lt;p&gt;On the other hand certain extensions like Codeium made others obsolete, like anything related to "code snippets".&lt;/p&gt;

&lt;p&gt;Now here's the full list of extensions I really use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=Codeium.codeium" rel="noopener noreferrer"&gt;&lt;strong&gt;Codeium&lt;/strong&gt;&lt;/a&gt; explained before&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments" rel="noopener noreferrer"&gt;&lt;strong&gt;Better comments&lt;/strong&gt;&lt;/a&gt; it adds visual and mental order for me 😂&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" rel="noopener noreferrer"&gt;&lt;strong&gt;GitLens&lt;/strong&gt;&lt;/a&gt; the Good Ol' Git Lens, if you didn't tested it yet, give it a shot!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme" rel="noopener noreferrer"&gt;&lt;strong&gt;Material Icon Theme&lt;/strong&gt;&lt;/a&gt; Having the proper icon for each thingy, is it too much to ask? This icon theme solves that for you. It even helps by adding easy to grasp icons for common directories like &lt;code&gt;core&lt;/code&gt;, &lt;code&gt;utils&lt;/code&gt;, &lt;code&gt;dist&lt;/code&gt; and much more!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;&lt;strong&gt;Prettier&lt;/strong&gt;&lt;/a&gt; Undoubtedly one of the most beloved extensions, specially when you enable "formatOnSave" along prettier as default formatter.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=bierner.markdown-preview-github-styles" rel="noopener noreferrer"&gt;&lt;strong&gt;Markdown Preview Github Styling&lt;/strong&gt;&lt;/a&gt; which name is self-explanatory I guess. A nice to have one, not the only one, though. I've used others during the time, don't have a favourite as for now, it just happens that I'm using this one at the moment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that's been the entire plugins list I'm afraid. &lt;br&gt;
It's not that I've suddenly become lazy and don't want to write any more I promise, this is really the extensions I'm using right now.&lt;/p&gt;

&lt;p&gt;In certain projects I can have the &lt;strong&gt;Python&lt;/strong&gt; extensions as well, maybe Language Support for &lt;strong&gt;Java&lt;/strong&gt; or any other language I might be fiddling around with. Maybe some test-related extension if it's any good (&lt;strong&gt;Playwright&lt;/strong&gt;, &lt;strong&gt;Jest&lt;/strong&gt;...) depending on the needs of what I'm doing!!&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip:
&lt;/h3&gt;

&lt;p&gt;Remember that you can create &lt;strong&gt;profiles&lt;/strong&gt; in &lt;code&gt;VSCodium &amp;gt; Settings &amp;gt; Profiles&lt;/code&gt;, each with its very own set of extensions, this way you don't need to manually disable the heavy language/platform specific extensions when you work in other kind of projects, avoiding weird behaviours and/or crashes!&lt;/p&gt;


 
&lt;h2&gt;
  
  
  Browser
&lt;/h2&gt;

&lt;p&gt;Who would have told me that we would be talking about browsers in 2024?&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k4fw913y3fruwej6npb.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k4fw913y3fruwej6npb.png" alt="Browsers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Isn't &lt;strong&gt;Chrome&lt;/strong&gt; the king? -Despite tracking the soul out of you-&lt;/li&gt;
&lt;li&gt;Isn't &lt;strong&gt;Safari&lt;/strong&gt; so shitty that's considered the new IE? &lt;/li&gt;
&lt;li&gt;Isn't &lt;strong&gt;Firefox&lt;/strong&gt; so RAM consuming that's better to just leave it to the QA team?&lt;/li&gt;
&lt;li&gt;Isn't &lt;strong&gt;Opera&lt;/strong&gt; / &lt;strong&gt;Opera GX&lt;/strong&gt; buggy and crashy?&lt;/li&gt;
&lt;li&gt;Isn't &lt;strong&gt;Brave&lt;/strong&gt; dead after they added third party ads, trackers and crypto scams (the exact oposite of their selling point)?&lt;/li&gt;
&lt;li&gt;Is &lt;strong&gt;Epiphany&lt;/strong&gt; something more than a medium to install &lt;strong&gt;Chromium&lt;/strong&gt; in certain Linux distributions?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aren't you tired of browsers that look the same, do almost the same, each one with it's flaws? &lt;strong&gt;SO DID I&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I recently discovered &lt;a href="https://arc.net" rel="noopener noreferrer"&gt;Arc&lt;/a&gt; which I've read that "it's not a browser" somewhere even though is developed and published by "The Browser Company" 😂&lt;/p&gt;

&lt;p&gt;I'm not yet using all the features (I'm getting old, bear with me), here's what I love the most as for now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It has "&lt;strong&gt;Spaces&lt;/strong&gt;" to keep your contexts separated (e.g. job space, personal space...).&lt;/li&gt;
&lt;li&gt;You can create &lt;strong&gt;folders&lt;/strong&gt; in each space as well, which allows me to store tabs per project.&lt;/li&gt;
&lt;li&gt;Contextual &lt;strong&gt;AI&lt;/strong&gt;; honestly didn't used it that much because I'm used to the old fashioned way, but I'm slowly getting there!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Little Arc&lt;/strong&gt;. Being Arc the default browser, when you open a link from Meet/Teams/Discord, your email or any other source external to Arc, it opens it inside a "little Arc" which you can simply close when you're done (e.g. SSO login pop-up) or hit the maximise button to add it to your "Big Arc"!&lt;/li&gt;
&lt;li&gt;Two tabs at the same time! I'm currently using the split view feature, here have a look:&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqz4vsksaafyig6rwitpi.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqz4vsksaafyig6rwitpi.png" alt="Arc browser split view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also drag the separator to make one side or the other larger or set up the tabs vertically instead (useful when using my secondary monitor which I've rotated 90 degrees).&lt;/p&gt;

&lt;p&gt;Being used to other browsers it was a clunky experience the first day, not gonna lie, but an amazing one after a couple of days more, so much so that that's now my main browser!&lt;/p&gt;


 
&lt;h2&gt;
  
  
  Who asked for more AI?
&lt;/h2&gt;

&lt;p&gt;I've been testing &lt;a href="https://faraday.dev" rel="noopener noreferrer"&gt;&lt;strong&gt;Faraday&lt;/strong&gt;&lt;/a&gt; with a couple or three of different Mistral-based models, just as GPT-like helper.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhx3a5pytakrghs3k2wq.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhx3a5pytakrghs3k2wq.png" alt="Faraday AI dev"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're interested in task-specific models such improvisation, role play, long conversations and so on you can also find a ton of them in the "Manage Models" menu, so you can download and then link the one you want to test to existing or new "AI Characters".&lt;/p&gt;


 
&lt;h2&gt;
  
  
  MORE AI? REALLY?
&lt;/h2&gt;

&lt;p&gt;The previous one was for funzies, just to fiddle around but this one... oh boy, this one's a MUST!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.warp.dev" rel="noopener noreferrer"&gt;&lt;strong&gt;WARP Terminal&lt;/strong&gt;&lt;/a&gt; allows for seamless copy paste, it remembers previous commands and suggest them to you while you type and many more goodies&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk17040xfp13holz6zn8.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk17040xfp13holz6zn8.png" alt="Warp terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You won't regret checking the "Reusable Workflows" feature!&lt;/p&gt;


 

&lt;p&gt;&lt;strong&gt;&lt;em&gt;THE END&lt;/em&gt;&lt;/strong&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%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeXJodmFzdjdrOHJpcnE3Y3k5enQ0Mno1Zmwzdml2dWNqemxqanZibSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FVe1KReZyJLTakI9GRI%2Fgiphy.gif" 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%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeXJodmFzdjdrOHJpcnE3Y3k5enQ0Mno1Zmwzdml2dWNqemxqanZibSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FVe1KReZyJLTakI9GRI%2Fgiphy.gif" alt="Comment down below"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Share your favourite tools in the comment section! 👇🏻😁👇🏻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>ai</category>
    </item>
    <item>
      <title>CS fundamentals: How Data Storage actually works</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Thu, 11 Jan 2024 17:27:16 +0000</pubDate>
      <link>https://forem.com/joelbonetr/cs-fundamentals-how-data-storage-actually-works-1o4a</link>
      <guid>https://forem.com/joelbonetr/cs-fundamentals-how-data-storage-actually-works-1o4a</guid>
      <description>&lt;p&gt;Have you ever wondered how the digital files, photos, and documents you store on your devices are actually kept safe and accessible? Let's dive into it&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding Bits and Bytes:
&lt;/h1&gt;

&lt;p&gt;At the core of data storage is the concept of bits and bytes. A bit is the smallest unit of digital information, representing either a 0 or a 1. &lt;/p&gt;

&lt;h3&gt;
  
  
  Binary Code:
&lt;/h3&gt;

&lt;p&gt;Oftentimes is useful to think of it as Booleans (true/false) and, while they can represent primitive Booleans, this is true or false, by grouping them one can represent numbers, text, images and sounds.&lt;/p&gt;

&lt;p&gt;All the data you see on your screen is ultimately represented in binary code - a series of 0s and 1s. &lt;/p&gt;

&lt;p&gt;Your computer, smartphone or any other device, reads this code and translates it into the text, images, and sounds you interact with daily.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;When eight bits come together, they form a byte, which can represent a character, number, or a small piece of data.&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Fractions
&lt;/h3&gt;

&lt;p&gt;The most common method for representing fractions in computers is through floating-point representation. Floating-point numbers consist of two main components: the sign bit, which represents whether the number is positive or negative, and the fractional part, which represents the actual value of the fraction.&lt;/p&gt;

&lt;p&gt;E.g. the decimal fraction 0.75. In binary, this is represented as 0.11. &lt;br&gt;
The sign bit would indicate the sign of the fraction&lt;/p&gt;

&lt;p&gt;Not all fractions can be precisely represented in the binary system. This can lead to rounding errors and imprecision, especially when performing arithmetic operations involving fractions.&lt;/p&gt;

&lt;h1&gt;
  
  
  File Systems:
&lt;/h1&gt;

&lt;p&gt;Think of a file system as the organization structure for your data. It manages how data is stored, retrieved, and organized on a storage device.&lt;/p&gt;

&lt;p&gt;Without a file system, data placed on a storage medium would be a large body of data with no way of knowing where one piece of data ends and the next begins.&lt;/p&gt;

&lt;p&gt;Some examples that may ring a bell are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NTFS&lt;/strong&gt; (New Technology File System) mainly used on Windows systems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EXT4&lt;/strong&gt; (Extended File System) mainly used on Linux systems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;APFS&lt;/strong&gt; (Apple File System) mainly used on MacOSX systems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FAT32&lt;/strong&gt; (File Allocation Table) which is currently at the verge of extinction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Storage Devices:
&lt;/h1&gt;

&lt;p&gt;Your computer, smartphone, or external hard drive uses various storage devices to keep your data safe. The two main types are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard Disk Drives (HDD):&lt;/strong&gt; A stack of spinning disks with magnetic surfaces. Data is stored on these disks as magnetized areas, and a tiny arm reads or writes data as the disks spin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solid State Drives (SSD):&lt;/strong&gt; These use memory chips to store data. Since there are no moving parts, SSDs are faster and more durable than HDDs.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;SSD &lt;strong&gt;M.2&lt;/strong&gt; are just SSD that are connected to the motherboard through M.2 port, an expansion port of the PCI family&lt;/small&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Data compression:
&lt;/h1&gt;

&lt;p&gt;As the devices to store data are limited, reducing the size of our data is oftentimes useful. &lt;br&gt;
We can use two methods to achieve data compression:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lossless Compression&lt;/strong&gt; retains all the original data when decompressed. Common algorithms include &lt;strong&gt;ZIP&lt;/strong&gt; and &lt;strong&gt;GZIP&lt;/strong&gt;. It's ideal for text files and documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lossy Compression:&lt;/strong&gt; This sacrifices some data to achieve higher compression ratios. It's often used for multimedia files like images, audio, and video. Examples include &lt;strong&gt;JPEG&lt;/strong&gt; for images, &lt;strong&gt;MP3&lt;/strong&gt; for audio or &lt;strong&gt;MP4&lt;/strong&gt; for video.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  But how does data compression works?
&lt;/h3&gt;

&lt;p&gt;1- &lt;strong&gt;Identifying Redundancy:&lt;/strong&gt; Compression algorithms exploit redundancies in data, which can be either spatial (repeating patterns within the data) or temporal (repeating patterns over time).&lt;/p&gt;

&lt;p&gt;2- &lt;strong&gt;Encoding and Replacing:&lt;/strong&gt; Once redundancies are identified, the algorithm encodes them more efficiently. For example, it might replace repeated patterns with shorter codes or use mathematical representations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decompression
&lt;/h3&gt;

&lt;p&gt;If we have compression, decompression must exist as well. &lt;br&gt;
To compress and decompress data processing power is required, hence it has some cost in terms of electricity and time, for that reason not everything is compressed and not everything is compressed the same way or to the same extent.&lt;/p&gt;

&lt;p&gt;Following the same logic, we have two techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lossless Decompression:&lt;/strong&gt; In lossless compression, the original data is fully restored during decompression, ensuring no loss of information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lossy Decompression:&lt;/strong&gt; In lossy compression, some data may be lost, but the decompressed file should be perceptually similar to the original.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For developers:&lt;/strong&gt; you might decide when to GZIP a JSON from a microservice (or other) depending on the amount of data returned. Is usually a matter of minutes to enable compression in your server and some time more to benchmark if the download time of your new "gzipped" JSON has shortened more or less than the time the client device lasts in decompressing it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Cloud Storage:
&lt;/h1&gt;

&lt;p&gt;In addition to local storage on your devices, many of us use cloud storage. This involves storing your data on servers maintained by companies like Google, Dropbox, or Microsoft to mention some. &lt;/p&gt;

&lt;p&gt;Ultimately, data will be stored in devices like the ones mentioned above with filesystems like the ones mentioned above and in binary code like mentioned above. &lt;br&gt;
The difference is that you don't need the physical device but an internet connection to interact with your data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Backups and Redundancy:
&lt;/h1&gt;

&lt;p&gt;To ensure your precious data is safe, it's crucial to make backups. This involves creating &lt;strong&gt;duplicate copies&lt;/strong&gt; of your files, either on an external drive or in the cloud.&lt;br&gt;
Some storage systems also use redundancy, where data is duplicated across multiple drives for added security.&lt;/p&gt;

&lt;p&gt;If you want to configure a system with redundancy you might be interested in researching topics like RAID (Redundant Array of Independent Disks) and NAS (Network Attached Storage).&lt;/p&gt;

&lt;h1&gt;
  
  
  Closing
&lt;/h1&gt;

&lt;p&gt;Remember, every time you save a document or snap a photo, you're engaging with the intricate world of data storage. It's a mix of hardware, software, and clever organization that keeps your digital life intact and easily accessible.&lt;/p&gt;

&lt;p&gt;Feel free to ask if you have any questions or want more details on a specific aspect!&lt;/p&gt;

&lt;p&gt;Cheers,&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AI generated the 90% of this post</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Wed, 18 Jan 2023 10:07:14 +0000</pubDate>
      <link>https://forem.com/joelbonetr/ai-generated-the-90-of-this-post-3a91</link>
      <guid>https://forem.com/joelbonetr/ai-generated-the-90-of-this-post-3a91</guid>
      <description>&lt;p&gt;&lt;small&gt;The heading image has been generated with Dall·E 2&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;In the previous post &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/joelbonetr" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F158311%2F710853e1-8e11-49e3-b0d2-daf27340df52.jpg" alt="joelbonetr"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/joelbonetr/js-functional-concepts-pipe-and-compose-1mho" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JS Functional Concepts: Pipe and Compose&lt;/h2&gt;
      &lt;h3&gt;JoelBonetR 🥇 ・ Jan 2 '23&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;I explained these concepts in a way that I felt "enough understandable" for a wide range of people, though I can be wrong because it's my point of view at the end, so I've decided to try and make Chat GPT to explain what it does.&lt;/p&gt;

&lt;p&gt;The conversation went like that:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Me:&lt;/strong&gt;&lt;br&gt;
can you explain me the following function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipeAsync&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Chat GPT:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This function is creating a utility function called "pipeAsync", which allows chaining multiple asynchronous functions together in a pipeline.&lt;/p&gt;

&lt;p&gt;It takes a list of functions as input, passed as rest parameter, which are all wrapped inside a promise.&lt;/p&gt;

&lt;p&gt;It returns a new function that takes an input value as an argument. This returned function uses the Array.prototype.reduce method to iterate over the array of functions, and calls each function in sequence, passing the result of the previous function call as input to the next function.&lt;/p&gt;

&lt;p&gt;The reduce function starts with an initial value of Promise.resolve(input), which is the input passed to the returned function. This is the starting point of the pipeline.&lt;/p&gt;

&lt;p&gt;The reduce function then calls the next function in the pipeline with the result of the previous function call, and this process continues for each function in the pipeline.&lt;/p&gt;

&lt;p&gt;The result of the reduce function is a new promise that resolves with the final result of the pipeline.&lt;/p&gt;

&lt;p&gt;The "pipeAsync" function allows you to chain together multiple asynchronous functions in a way that makes the code more readable and maintainable. It is similar to the "pipe" function from functional programming, but it's adapted to work with async/await.&lt;/p&gt;




&lt;p&gt;While it is 100% accurate, the language and language resources it uses may require a bit of focus to understand in my opinion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do you think?&lt;/strong&gt; Is it better explained by GPT or by flesh and bones people? Let me know in the comments!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>machinelearning</category>
      <category>career</category>
    </item>
    <item>
      <title>JS Functional Concepts: Pipe and Compose</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Mon, 02 Jan 2023 10:23:34 +0000</pubDate>
      <link>https://forem.com/joelbonetr/js-functional-concepts-pipe-and-compose-1mho</link>
      <guid>https://forem.com/joelbonetr/js-functional-concepts-pipe-and-compose-1mho</guid>
      <description>&lt;p&gt;Function piping and composition are concepts from functional programming that of course are possible in JavaScript -as it's a multi-paradigm programming language-, let's deep into this concepts quickly.&lt;/p&gt;

&lt;p&gt;The concept is to execute more than a single function, in a given order and pass the result of a function to the next one.&lt;/p&gt;

&lt;p&gt;You can do it ugly like that:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;function1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialArg&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Or using function composition&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;function3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;function2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;function1&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;initialArg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;or function piping&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;function1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;function2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;function3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;initialArg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;To make it short, &lt;strong&gt;composition and piping are almost the same&lt;/strong&gt;, the only &lt;strong&gt;difference being the execution order&lt;/strong&gt;; If the functions are executed from left to right, it's a pipe, on the other hand, if the functions are executed from right to left it's called compose.&lt;/p&gt;

&lt;p&gt;A more accurate definition would be: "In Functional Programming, Compose is the mechanism that composes the smaller units (our functions) into something more complex (you guessed it, another function)".&lt;/p&gt;

&lt;p&gt;Here's an example of a pipe function:&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;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;functions&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="nx"&gt;value&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentFunction&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;currentFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;value&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;Let's add some insights into this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basics&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need to gather a N number of functions&lt;/li&gt;
&lt;li&gt;Also pick an argument&lt;/li&gt;
&lt;li&gt;Execute them in chain passing the argument received to the first function that will be executed&lt;/li&gt;
&lt;li&gt;Call the next function, adding as argument the result of the first function.&lt;/li&gt;
&lt;li&gt;Continue doing the same for each function in the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="cm"&gt;/* destructuring to unpack our array of functions into functions */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
  &lt;span class="cm"&gt;/* value is the received argument */&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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="cm"&gt;/* reduce helps by doing the iteration over all functions stacking the result */&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentFunction&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="cm"&gt;/* we return the current function, sending the current value to it */&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;currentFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;value&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;We already know that arrow functions don't need brackets nor return tag if they are returning a single statement, so we can spare on keyboard clicks by writing it like that: &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;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;functions&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="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  How to use
&lt;/h3&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;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&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="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;input&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;)([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// 64&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Remember that the first function is the one at the left (Pipe) so 3+5 = 8 and 8 squared is 64. Our test went well, everything seems to work fine, but what about having to chain &lt;code&gt;async&lt;/code&gt; functions?&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipe on Async functions
&lt;/h2&gt;

&lt;p&gt;One use-case I had on that is to have a middleware to handle requests between the client and a gateway, the process was always the same (do the request, error handling, pick the data inside the response, process the response to cook some data and so on and so forth), so having it looking like that was a charm:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&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="nf"&gt;pipeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parseData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="cm"&gt;/* 
       ... 
     */&lt;/span&gt; 


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

&lt;/div&gt;

&lt;p&gt;Let's see how to handle async function piping in both Javascript and Typescript:&lt;/p&gt;

&lt;h4&gt;
  
  
  JS Version
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipeAsync&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&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="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;JSDoc Types added to make it more understandable (I guess)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="cm"&gt;/**
 * Applies Function piping to an array of async Functions.
 * @param  {Promise&amp;lt;Function&amp;gt;[]} fns
 * @returns {Function}
 */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipeAsync&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&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="cm"&gt;/** @type {any} */&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="cm"&gt;/** @type {Promise&amp;lt;Function&amp;gt;} */&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="cm"&gt;/** @type {Function | Promise&amp;lt;Function&amp;gt; | any} */&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  TS Version
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipeAsync&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This way it will work both for async and non-async functions so it's a winner over the example above.&lt;/p&gt;

&lt;p&gt;You may be wondering what about &lt;strong&gt;function composition&lt;/strong&gt;, so let's take a gander:&lt;/p&gt;

&lt;h2&gt;
  
  
  Function Composition
&lt;/h2&gt;

&lt;p&gt;If you prefer to call the functions from right to left instead, you just need to change &lt;code&gt;reduce&lt;/code&gt; for &lt;code&gt;redureRight&lt;/code&gt; and you're good to go. Let's see the async way with function composition:&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;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;composeAsync&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&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="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduceRight&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Back to the example above, let's replicate the same but with composition:&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use
&lt;/h3&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;compose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;fns&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="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;fns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduceRight&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;input&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;)([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// 64&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Note that we reversed the function order to keep it consistent with the example at the top of the post.&lt;/p&gt;

&lt;p&gt;Now, sum (which is at the rightmost position) will be called first, hence 3+5=8 and then 8 squared is 64.&lt;/p&gt;




&lt;p&gt;If you have any question or suggestion please comment down below &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%2Fc.tenor.com%2Fc4KyoQ7BQPAAAAAC%2Fcomment-down-below-dane-manalad.gif" 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%2Fc.tenor.com%2Fc4KyoQ7BQPAAAAAC%2Fcomment-down-below-dane-manalad.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Any good OS isomorphic CRM or ERP?</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Tue, 30 Aug 2022 15:52:03 +0000</pubDate>
      <link>https://forem.com/joelbonetr/any-good-os-isomorphic-crm-or-erp-pb9</link>
      <guid>https://forem.com/joelbonetr/any-good-os-isomorphic-crm-or-erp-pb9</guid>
      <description>&lt;p&gt;I'm checking online trying to find out how many ERP and CRM are out there that implement JavaScript in both backend and frontend but couldn't find much.&lt;/p&gt;

&lt;p&gt;Do you know any open source CRM and/or ERP that's made entirely with JavaScript?&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Stages in Software Development</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Sat, 27 Aug 2022 19:58:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/stages-in-software-development-4k2k</link>
      <guid>https://forem.com/joelbonetr/stages-in-software-development-4k2k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Alpha&lt;/strong&gt; and &lt;strong&gt;Beta&lt;/strong&gt; versions are common in software, you may also have heard "&lt;strong&gt;Friends &amp;amp; Family&lt;/strong&gt;", specially in business-related development environments or &lt;strong&gt;MVP&lt;/strong&gt; if you landed a project on an initial stage. Let's deep a bit into this interconnected topics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Friends &amp;amp; Family
&lt;/h2&gt;

&lt;p&gt;have two connotations:&lt;/p&gt;

&lt;h4&gt;
  
  
  Monies
&lt;/h4&gt;

&lt;p&gt;usually in the form a loan, that a business owner gets from either family members or friends in order to help finance their startup or growing business. Investors.&lt;/p&gt;

&lt;h4&gt;
  
  
  People
&lt;/h4&gt;

&lt;p&gt;In software testing means a group of people, be in-house workers of the client or even investors that will test a software product during the development process after each deploy to UAT or User Acceptance Testing environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alpha version
&lt;/h2&gt;

&lt;p&gt;of software means that it's not thoroughly tested by the developer before it is released to customers. Alpha software may contain serious errors, and any resulting instability could cause crashes or data loss. Alpha software may not contain all of the features that are planned for the final version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beta version
&lt;/h2&gt;

&lt;p&gt;of software is one that has completed intensive internal testing, as well as often being tested by a carefully selected range of external testers in "Live" situations around the world, and we feel it is now as "bug" free as possible and is therefore ready to be safely used by a broader set of users.&lt;/p&gt;




&lt;p&gt;Not every software is suitable for all testing stages mentioned above. Friends and family is quite common in every software but on the rest, you should analyse the market and see if it's suitable for an alpha or beta version. There's also a sub-category here, both alpha and beta can be open or closed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Closed
&lt;/h4&gt;

&lt;p&gt;Only a limited group of people will have access to the software in this testing version. Think on supporters in kickstarter (e.g. 7 Days to Die) or any other platform, people that made a reservation (e.g. Call of Duty) on an early stage or a limited amount of subscribers (e.g. DALL-E 2 and Github Copilot).&lt;/p&gt;

&lt;h4&gt;
  
  
  Open
&lt;/h4&gt;

&lt;p&gt;Open here means "public", anyone can join this version -yet users can be filtered by stablishing a set of prerequisites- usually through a registering/subscribing process (e.g. Android Beta program and Windows Insiders program).&lt;/p&gt;



&lt;h3&gt;
  
  
  Stages in software development:
&lt;/h3&gt;

&lt;p&gt;The first version of a product is necessarily a &lt;strong&gt;PoC&lt;/strong&gt; (Proof of Concept), which is a base to test the product in a late analysis phase.&lt;/p&gt;

&lt;p&gt;The second one would be an Alpha version, in which most features are joining, the functional testing is not 100% compliant and most work on stabilization, integration and bug fixing still needs to be done.&lt;/p&gt;

&lt;p&gt;The third one is then a Beta version, in which most bugs have been solved, the software is stable and just needs a bit of polishing.&lt;/p&gt;

&lt;p&gt;At this point we reach the MVP (Minimum Viable Product) which is -usually- the V1 of the product. &lt;br&gt;
That means that we reached the minimum set of features that this software needs to have a meaning and a position in the market on a robust and stable version.&lt;/p&gt;

&lt;p&gt;From now on it's a development iteration through versions to add extra features, polishing, bug fixing, optimizations etc.&lt;/p&gt;

&lt;p&gt;Please note that the MVP is not necessarily a software that is about to be launched to the market, market changes and iterations to the market analysis can lead us to add more features or expand our understanding of what our MVP should be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Version numbers
&lt;/h3&gt;

&lt;p&gt;Versions in software have -usually- 3 numbers separated by dots.&lt;br&gt;
e.g. &lt;code&gt;4.12.9&lt;/code&gt;&lt;br&gt;
You can also see beta or alpha (pre-releases) in the version, and it can be in one of two ways:&lt;br&gt;
&lt;code&gt;a-0.1.29&lt;/code&gt; or &lt;code&gt;0.1.29-alpha&lt;/code&gt;&lt;br&gt;
&lt;code&gt;b-0.19.33 or 0.19.33-beta&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Those numbers are not arbitrary, there's some sort of a standard: &lt;code&gt;Major.Minor.Patch&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;The first number means a Major upgrade, the second one a Minor upgrade and the last one is a counter on how many Patch upgrades we did.&lt;/p&gt;

&lt;h3&gt;
  
  
  Major, Minor and Patch
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Major Version&lt;/strong&gt; means a release of a software product that contains significant changes to features or functionality or underlying technology.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;minor version&lt;/strong&gt; number is incremented when developers add new features to the product that are still compatible with former versions in the same major category.&lt;/p&gt;

&lt;p&gt;A software &lt;strong&gt;patch&lt;/strong&gt; or fix is a quick-repair job for a piece of programming designed to resolve functionality issues, improve security or add new features.&lt;/p&gt;




&lt;p&gt;If you have any suggestion or question please comment down below &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CTKk1TAD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://c.tenor.com/c4KyoQ7BQPAAAAAC/comment-down-below-dane-manalad.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CTKk1TAD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://c.tenor.com/c4KyoQ7BQPAAAAAC/comment-down-below-dane-manalad.gif" width="498" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devrel</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>testing</category>
    </item>
    <item>
      <title>Markdown Editor with JavaScript</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Tue, 23 Aug 2022 16:26:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/markdown-editor-with-javascript-2jb7</link>
      <guid>https://forem.com/joelbonetr/markdown-editor-with-javascript-2jb7</guid>
      <description>&lt;p&gt;For this little project I'm using &lt;a href="https://www.npmjs.com/package/marked" rel="noopener noreferrer"&gt;Marked&lt;/a&gt; to parse the markdown content.&lt;/p&gt;

&lt;p&gt;It's just 3 lines of JS in this case, most of the time invested here is in styling. &lt;br&gt;
You'll find a text set as a sort of placeholder that serves the purpose of a quick markdown guide. &lt;/p&gt;

&lt;p&gt;Here it goes:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/joelbonetr/embed/qBogMqa?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can edit the textarea and write whatever you want in markdown and it will be translated into HTML with the preview being at the right side (or at the bottom if you're using a smartphone).&lt;/p&gt;

&lt;p&gt;That's all for today, hope you enjoyed I sure did doing that&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%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--XBXkPOUl--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_880%2Fhttps%3A%2F%2Fc.tenor.com%2FArsu0w_nD2EAAAAM%2Fbob-anakshie.gif" 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%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--XBXkPOUl--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_880%2Fhttps%3A%2F%2Fc.tenor.com%2FArsu0w_nD2EAAAAM%2Fbob-anakshie.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>markdown</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Speech Recognition with JavaScript</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Mon, 22 Aug 2022 09:23:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/speech-recognition-with-javascript-59g1</link>
      <guid>https://forem.com/joelbonetr/speech-recognition-with-javascript-59g1</guid>
      <description>&lt;p&gt;&lt;small&gt;Cover image credits: dribbble&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Some time ago, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition" rel="noopener noreferrer"&gt;speech recognition API&lt;/a&gt; was added to the &lt;a href="https://wicg.github.io/speech-api/#speechreco-section" rel="noopener noreferrer"&gt;specs&lt;/a&gt; and we got &lt;a href="https://caniuse.com/speech-recognition" rel="noopener noreferrer"&gt;partial support&lt;/a&gt; on Chrome, Safari, Baidu, android webview, iOS safari, samsung internet and Kaios browsers (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition#browser_compatibility" rel="noopener noreferrer"&gt;see browser support in detail&lt;/a&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%2Fi.pinimg.com%2Foriginals%2F0c%2Fcc%2Ff9%2F0cccf95b25a676546aaf6a3592a92476.gif" 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%2Fi.pinimg.com%2Foriginals%2F0c%2Fcc%2Ff9%2F0cccf95b25a676546aaf6a3592a92476.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; This implementation won't work in Opera (as it doesn't support the constructor) and also won't work in FireFox (because it doesn't support a single thing of it) so if you're using one of those, I suggest you to use Chrome -or any other compatible browser- if you want to take a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Speech recognition code and PoC
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/joelbonetr/embed/poLGNde?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I realised that for any reason it won't work when embedded so &lt;strong&gt;&lt;a href="https://codepen.io/joelbonetr/pen/poLGNde?editors=0000" rel="noopener noreferrer"&gt;here's the link to open it directly&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The implementation I made currently supports English and Spanish just to showcase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick instructions and feature overview:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose one of the languages from the drop down.&lt;/li&gt;
&lt;li&gt;Hit the mic icon and it will start recording (you'll notice a weird animation).&lt;/li&gt;
&lt;li&gt;Once you finish a sentence it will write it down in the box.&lt;/li&gt;
&lt;li&gt;When you want it to stop recording, simply press the mic again (animation stops).&lt;/li&gt;
&lt;li&gt;You can also hit the box to copy the text in your clipboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Speech Recognition in the Browser with JavaScript - key code blocks:
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="cm"&gt;/* Check whether the SpeechRecognition or the webkitSpeechRecognition API is available on window and reference it */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;recognitionSvc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SpeechRecognition&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webkitSpeechRecognition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Instantiate it&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;recognition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;recognitionSvc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="cm"&gt;/* Set the speech recognition to continuous so it keeps listening to whatever you say. This way you can record long texts, conversations and so on. */&lt;/span&gt;
&lt;span class="nx"&gt;recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;continuous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;span class="cm"&gt;/* Sets the language for speech recognition. It uses IETF tags, ISO 639-1 like en-GB, en-US, es-ES and so on */&lt;/span&gt;
&lt;span class="nx"&gt;recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en-GB&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Start the speech recognition&lt;/span&gt;
&lt;span class="nx"&gt;recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Event triggered when it gets a match&lt;/span&gt;
&lt;span class="nx"&gt;recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onresult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;// iterate through speech recognition results&lt;/span&gt;
  &lt;span class="k"&gt;for &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;result&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Print the transcription to the console&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;transcript&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;// Stop the speech recognition&lt;/span&gt;
&lt;span class="nx"&gt;recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This implementation currently supports the following languages for speech recognition:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;en-GB&lt;/li&gt;
&lt;li&gt;en-US&lt;/li&gt;
&lt;li&gt;es-ES&lt;/li&gt;
&lt;li&gt;de-DE&lt;/li&gt;
&lt;li&gt;de-CH&lt;/li&gt;
&lt;li&gt;fr-FR&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want me to &lt;strong&gt;add support for more languages&lt;/strong&gt; tell me in the comment sections and I'm updating it in a blink so you can test it on your own language 😁&lt;/p&gt;

&lt;p&gt;That's all for today, hope you enjoyed I sure did doing that&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%2Fc.tenor.com%2FArsu0w_nD2EAAAAM%2Fbob-anakshie.gif" 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%2Fc.tenor.com%2FArsu0w_nD2EAAAAM%2Fbob-anakshie.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Form input validation WITHOUT JavaScript</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Mon, 15 Aug 2022 18:58:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/form-input-validation-without-javascript-1m53</link>
      <guid>https://forem.com/joelbonetr/form-input-validation-without-javascript-1m53</guid>
      <description>&lt;p&gt;I promised it and here it is, &lt;/p&gt;

&lt;h2&gt;
  
  
  BEHOLD!
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/joelbonetr/embed/ZEbgQVG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Explanation
&lt;/h2&gt;

&lt;p&gt;We need 2 things here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern" rel="noopener noreferrer"&gt;pattern&lt;/a&gt; html attribute&lt;/li&gt;
&lt;li&gt;Some CSS pseudos like &lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:valid" rel="noopener noreferrer"&gt;:valid&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:invalid" rel="noopener noreferrer"&gt;:invalid&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Pattern
&lt;/h3&gt;

&lt;p&gt;The pattern attribute allows us to specify a regular expression that the inputted value must match in order to be considered valid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;!important:&lt;/strong&gt; You must avoid using the pattern attribute on fields that have a validation by default like &lt;code&gt;&amp;lt;input type="email"&amp;gt;&lt;/code&gt; as the browser will validate the input according to the &lt;a href="https://datatracker.ietf.org/doc/html/rfc5322" rel="noopener noreferrer"&gt;RFC5322&lt;/a&gt; and cast to &lt;code&gt;:valid&lt;/code&gt; or &lt;code&gt;:invalid&lt;/code&gt; consequently) on its own.&lt;/p&gt;

&lt;h3&gt;
  
  
  :valid, :invalid
&lt;/h3&gt;

&lt;p&gt;When used in an input, CSS considers it &lt;strong&gt;:valid&lt;/strong&gt; when the regex set in the pattern attribute matches the user input on it. Otherwise it's considered &lt;strong&gt;:invalid&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;html&lt;/code&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;form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"choose"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Would you prefer tea or coffee?&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"choose"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"i_like"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="na"&gt;pattern=&lt;/span&gt;&lt;span class="s"&gt;"[Tt]ea|[Cc]offee"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;css&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:valid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:invalid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;In this example, because the pattern regex &lt;code&gt;[Tt]ea|[Cc]offee&lt;/code&gt; only those 4 words will be valid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tea&lt;/li&gt;
&lt;li&gt;tea&lt;/li&gt;
&lt;li&gt;Coffee&lt;/li&gt;
&lt;li&gt;coffee&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you type any of those, the color will change to "green" on the other hand if you type anything else, it will be "red" and any attempts to submit the form will lead to a browser message.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Joelbr/embed/OJvamJy?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;h3&gt;
  
  
  ending
&lt;/h3&gt;

&lt;p&gt;If you try to submit (thats why I left that button in the codepen) while any input in the form is not valid, it will show you a message in YOUR language. Without the need of i18n or anything else, the browser will handle that for you.&lt;/p&gt;

&lt;p&gt;I feel this a nice approach for UX; whenever you need to give a quick feedback to the user.&lt;/p&gt;

&lt;p&gt;You can design it your way and extend your creativity adding other CSS pseudos like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:focus" rel="noopener noreferrer"&gt;:focus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:placeholder-shown" rel="noopener noreferrer"&gt;:placeholder-shown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:in-range" rel="noopener noreferrer"&gt;:in-range&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/CSS/:not" rel="noopener noreferrer"&gt;:not&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And last but not least, you can also edit the label or another element by using the adjacent sibling selector &lt;code&gt;+&lt;/code&gt;, which is the reason I've set the &lt;strong&gt;label after the input&lt;/strong&gt; in my first codepen, check the CSS! 😁&lt;/p&gt;

&lt;p&gt;Also bookmark this for reference whenever you need it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/joelbonetr" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F158311%2F710853e1-8e11-49e3-b0d2-daf27340df52.jpg" alt="joelbonetr"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/joelbonetr/complete-css-guide-for-beginners-1gjc" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Complete CSS Guide for beginners and not so beginners&lt;/h2&gt;
      &lt;h3&gt;JoelBonetR 🥇 ・ Jun 23 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Till the next one! &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%2Fodditymall.com%2Fincludes%2Fcontent%2Fupload%2Finflatable-jetpack-costume-2855.gif" 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%2Fodditymall.com%2Fincludes%2Fcontent%2Fupload%2Finflatable-jetpack-costume-2855.gif" alt="jetpack" title="jetpack"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>html</category>
    </item>
    <item>
      <title>Can we talk about this feature? Please</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Mon, 15 Aug 2022 09:26:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/can-we-talk-about-this-feature-please-31b0</link>
      <guid>https://forem.com/joelbonetr/can-we-talk-about-this-feature-please-31b0</guid>
      <description>&lt;p&gt;Explicitly about the &lt;strong&gt;"forgot password"&lt;/strong&gt; thingy.&lt;/p&gt;

&lt;p&gt;This little issue that appears in every single project where users can register themselves that says "Implement the forgot password feature" 😅&lt;/p&gt;

&lt;p&gt;It's so common than most of the time people even doesn't split the issue. But should we?&lt;/p&gt;

&lt;p&gt;Well, let's check the nuances on that.&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%2Fstorage.googleapis.com%2Fduckly-blog%2F2021%2F09%2Fhow-to-start.gif" 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%2Fstorage.googleapis.com%2Fduckly-blog%2F2021%2F09%2Fhow-to-start.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  workaround
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Show a message with a "forgot password?" link/button whenever the user fails to log in.&lt;/li&gt;
&lt;li&gt;Ask the server to send the "forgot password email".&lt;/li&gt;
&lt;li&gt;Catch the request on the server.&lt;/li&gt;
&lt;li&gt;Generate a token on the fly&lt;/li&gt;
&lt;li&gt;Generate a Link that includes this token&lt;/li&gt;
&lt;li&gt;Inject this link into an email template&lt;/li&gt;
&lt;li&gt;Send the email with the template&lt;/li&gt;
&lt;li&gt;When the link is clicked, we need to validate the token&lt;/li&gt;
&lt;li&gt;If it's expired, redirect to the login, showing the "forgot password?" link/button again along with a message that says "The link is expired, please try again".&lt;/li&gt;
&lt;li&gt;If it's OK, redirect the user to a view.&lt;/li&gt;
&lt;li&gt;This view has -usually- two fields. New password and Repeat password.&lt;/li&gt;
&lt;li&gt;Check that each individual password field is aligned with the required pattern (min. 8 chars, 1 uppercase, 1 lowercase, 1 special char...) and that both are equal.&lt;/li&gt;
&lt;li&gt;On submit, check the token again. Why? well, it can expire in the meantime, if this happen, return to point 9.&lt;/li&gt;
&lt;li&gt;If the token is OK, update the password for this user.&lt;/li&gt;
&lt;li&gt;Redirect to the login view with a message that says "your password has been updated successfully"&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Munching the workaround
&lt;/h3&gt;

&lt;p&gt;We can send another email once the password has been changed, that typical "Your password has been changed, if it wasn't you please, call the police, the SWAT, the marines and send us a ticket, your entire family may surrender to hackers".&lt;/p&gt;

&lt;p&gt;Yet another thing is to handle 2FA if it's implemented in your app. You may want your users to have the chance to use it to make this process easier -for them- but as the 2FA is not something mandatory, you still need to do the rest while providing this other workaround😁&lt;/p&gt;




&lt;p&gt;Answering the question I think we all can agree on that being a big YES, splitting the "forgot password" issue is a must (Just in case I mean Github, Gitlab, Jira... any issue tracker).&lt;/p&gt;

&lt;p&gt;We need definition for email templates and nuances on some of those points and splitting all this overheat into smaller chunks also reduces the procrastination.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;This entire thingy is something that I usually procrastinate or delegate. The reason why is because &lt;strong&gt;&lt;em&gt;IT IS BORING&lt;/em&gt;&lt;/strong&gt; to develop (at least to me).&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%2Fi.pinimg.com%2Foriginals%2Fd0%2F5f%2Fb7%2Fd05fb7a100d63254ec8272d7ec6efddd.gif" 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%2Fi.pinimg.com%2Foriginals%2Fd0%2F5f%2Fb7%2Fd05fb7a100d63254ec8272d7ec6efddd.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is so boring that I coded a &lt;a href="https://dev.to/joelbonetr/javascript-calculator-the-dom-way-3p22"&gt;calculator&lt;/a&gt; and an &lt;a href="https://dev.to/joelbonetr/structs-in-javascript-1p9l"&gt;NPM package&lt;/a&gt; just to avoid coding that forgot password thingy the last time I had to. &lt;/p&gt;

&lt;p&gt;And I had to code it again this week. Glad this time I split myself that bunch into several smaller issues, otherwise this post would probably be like "Mom, look what I've done" talking about whatever crazy BS I could have come up with.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;I'm still wondering&lt;/strong&gt; why in the seven seas frameworks don't implement -yet- a nice friendly way to deal with that. I mean like... call this function with a config object as param and &lt;em&gt;WOOSH&lt;/em&gt; points 5 to 10 automated!&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%2Fthedigitalprojectmanager.com%2Fwp-content%2Fuploads%2F2020%2F09%2Funnamed-7.gif" 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%2Fthedigitalprojectmanager.com%2Fwp-content%2Fuploads%2F2020%2F09%2Funnamed-7.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm even thinking on create a npm lib if nothing exists just to spend like 80h trying to automate something worth a morning and making it as dynamic as possible to fit as much projects as possible.&lt;/p&gt;




&lt;p&gt;Do you know any tool to help hundreds? If nothing exists, would you like to collaborate to bring something new?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>discuss</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>A JavaScript monolith ready to scale</title>
      <dc:creator>JoelBonetR 🥇</dc:creator>
      <pubDate>Sat, 13 Aug 2022 10:26:00 +0000</pubDate>
      <link>https://forem.com/joelbonetr/a-javascript-monolith-ready-to-scale-25o1</link>
      <guid>https://forem.com/joelbonetr/a-javascript-monolith-ready-to-scale-25o1</guid>
      <description>&lt;p&gt;In many projects I use this stack to quickly getting the things done at the lowest cost possible.&lt;/p&gt;

&lt;p&gt;Next JS provides both Node and React sweetened with built-in features like file-system based routing and much more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/yqDuymipOa9DBsM1lW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/yqDuymipOa9DBsM1lW/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I need to create a project for a client (and assuming there's no showstopper or impediment to proceed this way after the initial analysis) I'll do the following:&lt;/p&gt;

&lt;p&gt;1- Create a Next JS app.&lt;/p&gt;

&lt;p&gt;2- Create a DB instance on my VPS (or any provider).&lt;/p&gt;

&lt;p&gt;3- Add an ORM with the proper DB driver (I use &lt;a href="https://www.npmjs.com/package/sequelize" rel="noopener noreferrer"&gt;Sequelize&lt;/a&gt; -mostly- or &lt;a href="https://www.npmjs.com/package/mongoose" rel="noopener noreferrer"&gt;Mongoose&lt;/a&gt; but there are a tone out there, you can pick your favourite one).&lt;/p&gt;

&lt;p&gt;4- Define the data model.&lt;/p&gt;

&lt;p&gt;5- Add some validation library (I usually use &lt;a href="https://www.npmjs.com/package/joi" rel="noopener noreferrer"&gt;Joi&lt;/a&gt; but as the ORM, pick whichever suits best for you).&lt;/p&gt;

&lt;p&gt;6- Create a directory "api" inside "pages".&lt;/p&gt;

&lt;p&gt;7- Add a folder for each backend entity like &lt;code&gt;/pages/api/users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;index.js&lt;/code&gt; inside will look something like that:&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;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getAllUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nl"&gt;default&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;405&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Method &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; Not Allowed`&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;8- Add the view for this API inside pages, that's &lt;code&gt;/pages/users&lt;/code&gt;&lt;br&gt;
Which will use &lt;code&gt;getServerSideProps&lt;/code&gt; (&lt;a href="https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props" rel="noopener noreferrer"&gt;see the API Reference&lt;/a&gt;) to fetch desired data from this API and show related data.&lt;/p&gt;

&lt;p&gt;If you need a component instead, simply create a directory in the root like &lt;code&gt;components/users&lt;/code&gt;, then you can import your React components in your pages.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryvmd48i3krcuz02jxk7.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryvmd48i3krcuz02jxk7.png" alt="Project structure"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;br&gt;
Repeat steps 4 to 8 for each entity you need in your project.

&lt;p&gt;You can even convert it into a PWA easily with &lt;a href="https://www.npmjs.com/package/next-pwa" rel="noopener noreferrer"&gt;Next-PWA&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling the monolith
&lt;/h2&gt;

&lt;p&gt;Because it will probably grow in both code and -hopefully- customers.&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%2Fengineering.giphy.com%2Fwp-content%2Fuploads%2F2018%2F01%2Ffiking.gif" 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%2Fengineering.giphy.com%2Fwp-content%2Fuploads%2F2018%2F01%2Ffiking.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
If you already know that this project will need to handle thousands of concurrent requests you may prefer to start with a different architecture but in most cases I face you simply don't know how the project will do. That's because it depends on many factors, most of them are on the client's roof and some of them are not even under client's control.
&lt;/blockquote&gt;

&lt;p&gt;1- The first step in scaling the project would be increase the amount of resources of your VPS or cloud instance. e.g. If you started with 2 vCores and 2Gb of RAM, maybe you'll need to scale vCores, RAM or both, depending on what's your App doing and your hosting provider plans.&lt;/p&gt;

&lt;p&gt;2- When this is not enough or there are forecasts of heavy traffic, you can simply split your /api/ directory and run it on a Node server in a new instance. That change requires few changes on both /api/ code and frontend code. e.g. changing your calls from localhost for a different thingy (if you handled that with env variables congratulations! it will cost like 2 minutes) and wrapping the /api/ inside an Express plus adding some routing.&lt;br&gt;
At this point we separated the frontend from backend 😁&lt;/p&gt;

&lt;p&gt;3- If this is not enough, you can then chunk your APIs and provide them through different instances. &lt;br&gt;
Let's say we've conceptually 3 APIs inside our app &lt;code&gt;users&lt;/code&gt;, &lt;code&gt;businesses&lt;/code&gt; and &lt;code&gt;stats&lt;/code&gt; and our favourite monitoring tool shows us that &lt;code&gt;stats&lt;/code&gt; is consuming the 60% of the resources. We can move Stats following the same steps into a fresh instance, releasing a good amount of load from the other.&lt;/p&gt;




&lt;p&gt;Following this conceptual guide we add costs just when the project needs them.&lt;/p&gt;

&lt;p&gt;Please note that each step forward into a fully fledged micro-services architecture doesn't eliminate the complexity, it's moving the complexity from the code to the infrastructure thus I recommend to check &lt;a href="https://dev.to/joelbonetr/all-you-need-to-know-about-ci-cd-as-web-developer-1e19"&gt;some DevOPS concepts&lt;/a&gt; to make it less of a burden.&lt;/p&gt;




&lt;p&gt;Do you want a full tutorial on that with code, screenshots and examples? Maybe discuss some step? &lt;/p&gt;

&lt;p&gt;Let me know in the comments!&lt;br&gt;
&lt;a href="https://i.giphy.com/media/TPKTPnBZYNLx1H5Epl/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/TPKTPnBZYNLx1H5Epl/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>nextjs</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
