<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Snir David</title>
    <description>The latest articles on DEV Community by Snir David (@snird).</description>
    <link>https://dev.to/snird</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%2F54800%2F0eafe7f7-6db7-4907-9f09-a1a96388395c.jpg</url>
      <title>DEV Community: Snir David</title>
      <link>https://dev.to/snird</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/snird"/>
    <language>en</language>
    <item>
      <title>How to become a data engineer? Complete learning path</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Sat, 17 Oct 2020 13:29:27 +0000</pubDate>
      <link>https://dev.to/snird/how-to-become-a-data-engineer-complete-learning-path-46be</link>
      <guid>https://dev.to/snird/how-to-become-a-data-engineer-complete-learning-path-46be</guid>
      <description>&lt;p&gt;Becoming a data engineer is not an easy path.&lt;/p&gt;

&lt;p&gt;There are so many different subjects to control, with knowledge dependency between them that is overwhelming for someone who isn't already proficient in the area.&lt;/p&gt;

&lt;p&gt;When I got into the subject, I struggled with that too even though I'm a senior engineer in the Fullstack development area.&lt;/p&gt;

&lt;p&gt;Where do I start? SQL is obvious. Then I need to know how to manage a data warehouse? How should the data look in there? OLAP schema design is a subject in and of itself?&lt;/p&gt;

&lt;p&gt;That's why I create the site &lt;a href="https://awesomedataengineering.com" rel="noopener noreferrer"&gt;awesome data engineering - learning path to become a data engineer&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8asx5slxp0fvze1bbaqj.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%2Fi%2F8asx5slxp0fvze1bbaqj.png" alt="Awesome data engineering screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The resources index is open source and up for community contribution!&lt;/p&gt;

&lt;p&gt;The site makes it easy to see the different subjects, the complete learning path, and then to filter by the type of resources you prefer on each subject.&lt;/p&gt;

&lt;p&gt;Hope you'll find this project useful (:&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>python</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Data warehouse schema design - dimensional modeling and star schema</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Tue, 25 Aug 2020 12:13:59 +0000</pubDate>
      <link>https://dev.to/snird/data-warehouse-schema-design-dimensional-modeling-and-star-schema-53h5</link>
      <guid>https://dev.to/snird/data-warehouse-schema-design-dimensional-modeling-and-star-schema-53h5</guid>
      <description>&lt;p&gt;&lt;a href="https://snir.dev/talks/data-warehouse-schema-design"&gt;Original post for Data warehouse schema design - dimensional modeling and star schema in my blog&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Introduction to data warehouse schema design: In this talk, I walk through the basics of dimensional design using the kimball group approach.&lt;/p&gt;

&lt;p&gt;Amongst other things, I cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OLAP systems vs OLTP systems&lt;/li&gt;
&lt;li&gt;Third normal form of operational DB&lt;/li&gt;
&lt;li&gt;What is a dimension&lt;/li&gt;
&lt;li&gt;What is a fact&lt;/li&gt;
&lt;li&gt;Star schema&lt;/li&gt;
&lt;li&gt;Dimension grain&lt;/li&gt;
&lt;li&gt;Surrogate keys&lt;/li&gt;
&lt;li&gt;Slowly changing dimensions&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>database</category>
      <category>aws</category>
      <category>tutorial</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Pragmatic weekend project - apartments bot</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Thu, 04 Jun 2020 17:37:29 +0000</pubDate>
      <link>https://dev.to/snird/pragmatic-weekend-project-apartments-bot-1d0k</link>
      <guid>https://dev.to/snird/pragmatic-weekend-project-apartments-bot-1d0k</guid>
      <description>&lt;p&gt;Originally posted in my blog at: &lt;a href="https://snir.dev/blog/apartments-bot/" rel="noopener noreferrer"&gt;https://snir.dev/blog/apartments-bot/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting and completing a weekend project, is often challenging. Feature creep, tech stack choices and unwaranted tech excelency (100% test coverage for a weekend project anyone?) are your enemies, making the project timeline go beyond one weekend, which in turn usually results in the project never being done.&lt;/p&gt;

&lt;p&gt;After countless such projects, I got to a place where I can confidently estimate a small project, define its features and use tech as a tool to complete my project. Preventing some ideological concepts and unnecessary perfection from getting in my way.&lt;/p&gt;

&lt;p&gt;I've built a small project this weekend that will help me find my next apartment. And it is a great case study to demonstrate all lessons learned.&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%2Fi%2Fyqw0nz0ax474aq8swrea.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyqw0nz0ax474aq8swrea.gif" alt="apartment bot demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;I'm looking for a new apartment to rent. In my local market, most land lords only advertise in private facebook groups. Each group is dedicated to another city/area. Which for me resulted in 7 different groups to cover my search area.&lt;/p&gt;

&lt;p&gt;Going through the ads in facebook groups is a mess:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to individually visit several group pages in every "scan".&lt;/li&gt;
&lt;li&gt;Posts with recent comments are bumped up, making you go through posts you already saw.&lt;/li&gt;
&lt;li&gt;There is no easy way to filter posts.&lt;/li&gt;
&lt;li&gt;This is tiresome, which might lead to me missing great opportunities that are time constrained (as these are high demand locations).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;Before we dive in, if you are interested in the end result, my code is freely available at Github: &lt;a href="https://github.com/snird/apartments_bot" rel="noopener noreferrer"&gt;https://github.com/snird/apartments_bot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Manually scanning multiple facebook groups every few hours is a long error-prone process. My automated solution had these requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visit all groups manually and receive all ads.&lt;/li&gt;
&lt;li&gt;Remember which ads it already sent me, and filter those out.&lt;/li&gt;
&lt;li&gt;Filter ads by some text, in my case "3 rooms", to get only relevant ads.&lt;/li&gt;
&lt;li&gt;Send it to me in a way easily shareable with my partner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wanted to solve each of these requirements in the most pragmatic way possible. My top priority was to make it work, and be done with it within the span of a weekend. In the rest of this article I will share with you my technical decisions, reflecting on why I made them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Facebook groups scanning
&lt;/h2&gt;

&lt;p&gt;My initial thought was to use the facebook API to retrieve the posts in an easy to consume way. Unfortunately, some of the groups I needed are defined as "secret" and you cannot get their posts using the API.&lt;/p&gt;

&lt;p&gt;With API usage out of the question, I had to resort to web scraping. I have strong experience with nodejs so it was no brainer for me to go that route. For node ecosystem Puppeteer came up and I started using it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Facebook authentication
&lt;/h3&gt;

&lt;p&gt;Puppeteers default is a headless browser. Every run is a clean start with no prior state (cookies, sessions etc'). Which means that I would have to authenticate to facebook every time. Handling authentication seemed out of my scope, and it is a one-time thing: connect to facebook.&lt;/p&gt;

&lt;p&gt;Puppeteer also allows for a full regular Chrome session, connected through the debug socket. This allowed me to open Chrome, connect to my facebook account manually and then let my script use this Chrome instance. Not everything has to be solved by programming. I have goals I want to keep - functionality and time constraints.&lt;/p&gt;




&lt;p&gt;Interested in reading the rest of the article?&lt;br&gt;
Its available in my blog: &lt;a href="https://snir.dev/blog/apartments-bot/" rel="noopener noreferrer"&gt;https://snir.dev/blog/apartments-bot/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>productivity</category>
      <category>node</category>
      <category>opensource</category>
    </item>
    <item>
      <title>The difference between mocks and stubs, explained with JS</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Thu, 22 Aug 2019 20:25:17 +0000</pubDate>
      <link>https://dev.to/snird/the-difference-between-mocks-and-stubs-explained-with-js-kkc</link>
      <guid>https://dev.to/snird/the-difference-between-mocks-and-stubs-explained-with-js-kkc</guid>
      <description>&lt;p&gt;Stubs and Mocks are two foundational concepts in testing that are often misunderstood. So much so, that we have the famous &lt;a href="https://martinfowler.com/articles/mocksArentStubs.html"&gt;Martin Fowler article&lt;/a&gt; on the subject, alongside numerous stackoverflow questions on the matter.&lt;br&gt;
Martins article is a long read for the modern impatient reader, get somewhat sidetracked and doesn't have example in the current hype language, JS.&lt;br&gt;
I'll try to be more concise in my explanations here.&lt;/p&gt;

&lt;p&gt;I'll start with the headline definition:&lt;br&gt;
&lt;strong&gt;Stubs and mocks are both dummy objects for testing, while stubs only implement a pre-programmed response, mocks also pre-program specific expectations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To put it into a workflow:&lt;/p&gt;
&lt;h3&gt;
  
  
  Stubs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Setup&lt;/strong&gt; - define the stub itself, what object in the program you are stubbing and how&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exercise&lt;/strong&gt; - run the functionality you want to test&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify&lt;/strong&gt; - check the stub for values that ran through it, that they fit expectations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teardown&lt;/strong&gt; - if needed, clean up. e.g Time stubs are usually global, you need to yield control back&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Mocks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Setup object&lt;/strong&gt; - define the mock, what object you are mocking and how (similar to stubs)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setup expectations&lt;/strong&gt; - define what you expect will happen to this mock internally&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exercise&lt;/strong&gt; - run the functionality you want to test&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify mock&lt;/strong&gt; - verify that the mock expectations are met. In some JS libraries this happens automatically without additional call, the mock expectations are verifying themselves and will throw if needed. (Used mostly when async testing).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify&lt;/strong&gt; - verify any additional expectations for results on the mock&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teardown&lt;/strong&gt; - if needed, clean up.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Mocks &amp;amp; Stubs in the JS community
&lt;/h3&gt;

&lt;p&gt;Before we get into code, since my examples will be in JS, there is an important note to be said here.&lt;/p&gt;

&lt;p&gt;One of the most successful testing libraries in the JS community is &lt;a href="https://jestjs.io"&gt;jest&lt;/a&gt;. But I will not use it for my examples, for the simple reason that jest is opinionated and does not implement mocks.&lt;br&gt;
What they call a &lt;code&gt;mock&lt;/code&gt; in the library, is actually a stub by definition. You cannot make expectations on the mock itself, rather just look at its behavior and call and make expectations on that.&lt;/p&gt;

&lt;p&gt;I will demonstrate the concept using &lt;code&gt;sinon.js&lt;/code&gt; that does implement the concepts of both mocks and stubs.&lt;/p&gt;
&lt;h3&gt;
  
  
  Stubs example
&lt;/h3&gt;

&lt;p&gt;For our example, we will unit test an imaginary function for purchasing items in an eCommerce site. We will try to pay and get the payment status, and if we are successful we will send a mail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;purchaseItemsFromCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;payStatus&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;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cartItems&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;payStatus&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sendSuccessMail&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="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;payment_error_page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;when purchase payed successfully user should receive a mail&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Setup&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;paymentStub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sinon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mailStub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sinon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;paymentStub&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sendSuccessMail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mailStub&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Exercise&lt;/span&gt;
  &lt;span class="nx"&gt;purchaseItemsFromCart&lt;/span&gt;&lt;span class="p"&gt;([],&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Verify&lt;/span&gt;
  &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mailStub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;called&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;h3&gt;
  
  
  Mocks example
&lt;/h3&gt;

&lt;p&gt;Now lets do the same, using mocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;when purchase payed successfully user should receive a mail&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Setup objects&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userMock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sinon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&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="na"&gt;sendSuccessMail&lt;/span&gt;&lt;span class="p"&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="p"&gt;})&lt;/span&gt;

  &lt;span class="c1"&gt;// Setup expectations&lt;/span&gt;
  &lt;span class="nx"&gt;userMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;userMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sendSuccessMail&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;once&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="c1"&gt;// Exercise&lt;/span&gt;
  &lt;span class="nx"&gt;purchaseItemsFromCart&lt;/span&gt;&lt;span class="p"&gt;([],&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Verify mocks&lt;/span&gt;
  &lt;span class="nx"&gt;userMock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verify&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;h2&gt;
  
  
  Great. When should I use each?
&lt;/h2&gt;

&lt;p&gt;Now this is the interesting question here.&lt;br&gt;
And there is much debate - there is a reason the guys behind &lt;code&gt;jest&lt;/code&gt; decided not to implement classic mock functionality.&lt;/p&gt;

&lt;p&gt;Mocks can do whatever stubs can do, plus setting expectations directly on the objects they are faking.&lt;br&gt;
This creates readability problems for large tests as well as tendency to start expecting and testing fake objects within the test that are not the sole purpose of the test, making it a white-box test that is too aware of internals.&lt;/p&gt;

&lt;p&gt;That is even mentioned as a guideline in sinon documentation for when to use a mock:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mocks should only be used for the method under test.
In every unit test, there should be one unit under test.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So to not overuse this functionality and create a confusing, and maybe mispurposed test, you should limit your mocks usage in tests to one object.&lt;/p&gt;

&lt;p&gt;Or, you know, you could just use jest that took this decision away from you by not implementing these kind of mocks in the first place.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
      <category>tdd</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Breadth first traversal for binary trees in JS</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Mon, 19 Aug 2019 13:12:50 +0000</pubDate>
      <link>https://dev.to/snird/breadth-first-traversal-for-binary-trees-in-js-h9m</link>
      <guid>https://dev.to/snird/breadth-first-traversal-for-binary-trees-in-js-h9m</guid>
      <description>&lt;p&gt;Breath first traversal of binary trees is a basic thing to do.&lt;br&gt;
So why do I write this post?&lt;br&gt;
Because there is a gap if you try to quickly look for implementation in google.&lt;/p&gt;

&lt;p&gt;Most of the articles cover generic trees, not binary tress. Thus have no concept of "left" and "right" nodes, but just unordered children.&lt;br&gt;
&lt;a href="https://medium.com/@kenny.hom27/breadth-first-vs-depth-first-tree-traversal-in-javascript-48df2ebfc6d1" rel="noopener noreferrer"&gt;https://medium.com/@kenny.hom27/breadth-first-vs-depth-first-tree-traversal-in-javascript-48df2ebfc6d1&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@stephaniewo/understanding-breadth-first-tree-traversal-with-javascript-9b8fe670176d" rel="noopener noreferrer"&gt;https://medium.com/@stephaniewo/understanding-breadth-first-tree-traversal-with-javascript-9b8fe670176d&lt;/a&gt;&lt;br&gt;
&lt;a href="https://gist.github.com/thinkphp/1440007" rel="noopener noreferrer"&gt;https://gist.github.com/thinkphp/1440007&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this might confuse a beginner.&lt;br&gt;
Others, like &lt;a href="https://hackernoon.com/breadth-first-search-in-javascript-e655cd824fa4" rel="noopener noreferrer"&gt;this great article at hackernoon&lt;/a&gt; do a perfect job explaining the concept, but not presenting the code for it.&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%2Fmiro.medium.com%2Fmax%2F1400%2F1%2A3NKvODZparRFVKEwtVmrkw.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%2Fmiro.medium.com%2Fmax%2F1400%2F1%2A3NKvODZparRFVKEwtVmrkw.gif" alt="bft-tree"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;gif by by Stephanie Wong&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, assuming you'll read the concept of how we use queues to do the breadth first traversal at &lt;a href="https://hackernoon.com/breadth-first-search-in-javascript-e655cd824fa4" rel="noopener noreferrer"&gt;this great article at hackernoon&lt;/a&gt;, here is a modern implementation, specific to binary trees with &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;right&lt;/code&gt; nodes.&lt;br&gt;
(And as in the gif above, it will always go from left to right)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tree&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;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;left&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;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;right&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;breadthFirstTraversal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tree&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="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;let&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="nf"&gt;callback&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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;continue&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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="nx"&gt;queue&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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="nx"&gt;queue&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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="nx"&gt;t&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;Tree&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Tree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Tree&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Tree&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="kc"&gt;null&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="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="nf"&gt;breadthFirstTraversal&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Will print "1,2,3,4"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>interview</category>
    </item>
    <item>
      <title>Recursion optimization in JS - where is it? PTC, TCO and FUD</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Sun, 18 Aug 2019 21:43:10 +0000</pubDate>
      <link>https://dev.to/snird/recursion-optimization-in-js-where-is-it-ptc-tco-and-fud-4fka</link>
      <guid>https://dev.to/snird/recursion-optimization-in-js-where-is-it-ptc-tco-and-fud-4fka</guid>
      <description>&lt;p&gt;ES6 is old news by now. It's fully implemented across all modern browsers. Nothing to see here.&lt;br&gt;
The compat-table of ES6 by kangax that we used to check to see progress should be all green by now, right?&lt;/p&gt;

&lt;p&gt;Well, it's not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwdk8tparph1j8ej0dgob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwdk8tparph1j8ej0dgob.png" alt="ES6 compat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The proper tails call section, (tail call optimization) is red.&lt;/p&gt;

&lt;p&gt;Why? is it a feature that can't be implemented for JS?&lt;br&gt;
Well, no. There is one browser that implemented this feature. Safari.&lt;/p&gt;

&lt;p&gt;Then it is possible, and it is out for large audience in Safari. Why does chrome and firefox lagging behind?&lt;/p&gt;

&lt;p&gt;The answer is complicated. And as it seems from my browsing in many many bug trackers comments for V8, Firefox JS engine, github issues, TC39 committee discussions and more - also very political and opinionated.&lt;/p&gt;

&lt;p&gt;I'll try to give here a bit of background on the subject, that may hopefully leave you knowing more why is this so hard.&lt;/p&gt;
&lt;h3&gt;
  
  
  PTC? TCO?
&lt;/h3&gt;

&lt;p&gt;PTC - proper tail call&lt;br&gt;
TCO - tail code optimization&lt;br&gt;
These 2 terms are not the same. And it is important to understand the difference between them for the discussion ahead.&lt;/p&gt;
&lt;h3&gt;
  
  
  Assumptions moving forward
&lt;/h3&gt;

&lt;p&gt;I don't want to make this article a primer on recursions and call stacks.&lt;br&gt;
I will assume you already know about that part. In case you don't, &lt;a href="https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/" rel="noopener noreferrer"&gt;freecodecamp&lt;/a&gt; have a great article regarding this.&lt;/p&gt;
&lt;h3&gt;
  
  
  Proper Tail Call
&lt;/h3&gt;

&lt;p&gt;I'll say before starting, proper tail call is what should have been implemented in ES6, and not tail code optimization (which we will talk about later).&lt;br&gt;
It is in the &lt;a href="https://www.ecma-international.org/ecma-262/6.0/" rel="noopener noreferrer"&gt;ES6 Standard document&lt;/a&gt; and if you can't read the &lt;a href="https://www.ecma-international.org/ecma-262/6.0/#sec-tail-position-calls" rel="noopener noreferrer"&gt;Formal definitions&lt;/a&gt; of it (don't worry, neither can I) you can just look at the introduction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Goals for ECMAScript 2015 include providing better support for [...].
Some of its major enhancements include modules, class declarations, [..]
and proper tail calls.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Proper tail call is a technique where the program will not create additional stack frames for a recursion that fits the tail call definition.&lt;br&gt;
This, and this only is the proper tail call value proposition.&lt;/p&gt;

&lt;p&gt;So, instead of having a recursion with all its stack saved in memory, we will have just one level of stack saved, optimizing the recursion stack.&lt;/p&gt;

&lt;p&gt;But how can it be? Tail recursion functions basically keep passing all the necessary data it needs down the recursion, so you don't have to rely on the stack.&lt;/p&gt;

&lt;p&gt;The classic example here is the Fibbonaci function.&lt;/p&gt;

&lt;p&gt;Consider this in the classic (head) recursion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&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;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;It has to rely on the stack on each step, as each step have to be "processed up" to the &lt;code&gt;n * factorial(n - 1)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now consider this tail recursive version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&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;n&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;acc&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;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;acc&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;In this version, we have an accumulator as an argument. This keeps track of the total so far. Therefore, the stack here have no use, all the data is available all the way down the recursion call.&lt;/p&gt;

&lt;p&gt;Great! Recursive programming that is sometimes easier to grasp than the iterative alternative without the call stack problem. They are basically equivalent!&lt;/p&gt;

&lt;p&gt;Only, they are not. Not in the PTC case.&lt;br&gt;
The problems with PTC are &lt;a href="https://github.com/tc39/proposal-ptc-syntax#issues-with-ptc" rel="noopener noreferrer"&gt;described beautifully&lt;/a&gt; on a recent proposal for TCO in Ecmascript.&lt;/p&gt;

&lt;p&gt;Basically, this is what they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance issues. This only optimize the call stack, not the calls themselves.&lt;/li&gt;
&lt;li&gt;Debugging. The call stack will be tempered with unnaturally, a thing that might make debugging much harder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yicks. No wonder people are so passionate about their positions on this regard.&lt;br&gt;
Some say the debugging issues is a deal breaker, and the performance issues will kill profiling. Others disregard this as FUD, since Safari implemented PTC and hell is still closed.&lt;/p&gt;

&lt;p&gt;You can find adults fight passionately for what they believe here:&lt;br&gt;
&lt;a href="https://github.com/tc39/proposal-ptc-syntax/issues/23" rel="noopener noreferrer"&gt;https://github.com/tc39/proposal-ptc-syntax/issues/23&lt;/a&gt;&lt;br&gt;
&lt;a href="https://bugs.chromium.org/p/v8/issues/detail?id=4698" rel="noopener noreferrer"&gt;https://bugs.chromium.org/p/v8/issues/detail?id=4698&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tail Call Optimization
&lt;/h3&gt;

&lt;p&gt;Tail call optimization to the rescue!&lt;br&gt;
Well, not really but I wanted to be dramatic.&lt;/p&gt;

&lt;p&gt;Tail code optimization is different by the fact that it does not simply eliminate the additional stack calls, it completely re-compiles the recursive function to be an iterative one.&lt;/p&gt;

&lt;p&gt;Behind the scenes, tail code optimization takes a recursive function and generate an iterative function, using &lt;code&gt;goto&lt;/code&gt; internally, and then runs it.&lt;/p&gt;

&lt;p&gt;It does not limit the stack calls, because there are none once the function is actually not recursive behind the scenes.&lt;/p&gt;

&lt;p&gt;This solves the performance issues perfectly.&lt;br&gt;
&lt;a href="http://lua-users.org/lists/lua-l/2010-02/msg00582.html" rel="noopener noreferrer"&gt;Lua actually has this implemented long ago&lt;/a&gt; and it works perfectly. A recursive function is identical in performance to its equivalent iterative function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alright, so why not just implement TCO?
&lt;/h3&gt;

&lt;p&gt;Well... There is much debate about that too.&lt;br&gt;
There are people who want "implicit" TCO - that is, when it recognizes a fit function for tail optimization - just do it in place.&lt;/p&gt;

&lt;p&gt;And there are people who want "explicit" TCO - do this only if it is the developer intent by purpose.&lt;/p&gt;

&lt;p&gt;This is what the &lt;a href="https://github.com/tc39/proposal-ptc-syntax" rel="noopener noreferrer"&gt;current proposal for Syntactic Tail Calls&lt;/a&gt; is all about.&lt;/p&gt;

&lt;p&gt;It introduces new syntax and new keyword for tail calls optimizations, namely the &lt;code&gt;continue&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;And, again, much controversy here too it seems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Will we have to beg third-party library owners to re-write their code?&lt;/li&gt;
&lt;li&gt;The new syntax required will basically kill the feature before anyone will use it.&lt;/li&gt;
&lt;li&gt;etc' etc'.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, that's the story of tail call optimization in JS as it stands right now.&lt;br&gt;
I didn't go too deep on the details, ofcourse, but I feel like this should give you a basic understanding on why this subject is complicated and hard to get right.&lt;br&gt;
And as always - thank you to all the guys working on this subject and the Ecmascript proposals. Your work and passion-full discussions ends up benefit us all.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>ecmascript</category>
    </item>
    <item>
      <title>Functors from first principle - explained with JS</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Sat, 17 Aug 2019 14:02:02 +0000</pubDate>
      <link>https://dev.to/snird/functors-from-first-principle-37lh</link>
      <guid>https://dev.to/snird/functors-from-first-principle-37lh</guid>
      <description>&lt;p&gt;In this post, I will explain what functors are and why they are useful in a different way than I was taught.&lt;br&gt;
When I tried to learn about the functors concept I usually got to one of those explanations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is something you can map over (But what exactly does map means?)&lt;/li&gt;
&lt;li&gt;It's like lists that you can map over (So, is mapping just looping through elements?)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those weren't very useful for me. And I ended up reading very very long explanations, and reading many lines of real world code to get all the gotchas and the real meaning.&lt;br&gt;
I will try to spare you, by explaining as fast as possible the concepts.&lt;/p&gt;

&lt;p&gt;I will start with the general concept and some demos in JavaScript to make is accessible as possible, but I will end up going to Haskell here as there are things only Haskell can do that are important for your understanding.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lists are functors - as you can map over them
&lt;/h2&gt;

&lt;p&gt;Let's start with an anecdotal example and expand from there.&lt;br&gt;
Lists as you know them from many languages are functors, as you can map over them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;myList&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;2&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;4&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;addTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&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;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;myList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addTwo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [3,4,5,6,7]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Map is applying a function to a structure
&lt;/h3&gt;

&lt;p&gt;So what we saw above, is basic map function for a list where we apply the &lt;code&gt;addTwo&lt;/code&gt; function to every item in the list.&lt;br&gt;
But mapping a bit more generic definitions is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Applying a function over *or* around some structure while keeping the structure intact.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In lists, the structure is the list itself. We apply a function, &lt;code&gt;addTwo&lt;/code&gt;, that has no otherwise knowledge of the existence of lists, &lt;em&gt;over&lt;/em&gt; every item in the structure, the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Got it. Mapping over structure. What are structures?
&lt;/h2&gt;

&lt;p&gt;It is a bit hard to grasp the concept of structures as first, when you only have the &lt;code&gt;list&lt;/code&gt; example.&lt;br&gt;
But this is where the important generic concept of functors come in play.&lt;br&gt;
Think of the "structure" at play as a box, holding some kind of value in it. When mapping, you apply a function to a potential value within that box, while leaving the box intact.&lt;/p&gt;

&lt;p&gt;Keeping us in the realms of javascript, a non-perfect, but still good enough example will be promises.&lt;br&gt;
Promises are boxes that hold potential values, which you can apply a function over without changing the promise box.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;promise1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&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="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// `then` is the equivalent of `map` in our example.&lt;/span&gt;
&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&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="nx"&gt;log&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Will print out [object Promise]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What happened here?&lt;br&gt;
We have a Promise object, which is a box holding in future evaluation of value.&lt;br&gt;
The &lt;code&gt;then&lt;/code&gt; method applies a function to the value &lt;em&gt;within&lt;/em&gt; that structure of promise, while leaving the promise object itself intact.&lt;br&gt;
The &lt;code&gt;then&lt;/code&gt; method is equivalent to &lt;code&gt;map&lt;/code&gt; in our world.&lt;/p&gt;
&lt;h2&gt;
  
  
  Ok. Got it. But that looks pretty thin, what more is it useful for?
&lt;/h2&gt;

&lt;p&gt;I'm with you. You need more examples to explain the value in this abstraction before we move on.&lt;br&gt;
This is where I need to get out of the classic JS realm a bit, but not too far.&lt;br&gt;
Let's introduce the Maybe Monad. Don't worry, the monad part have nothing to do with our explanation. Just the maybe part.&lt;/p&gt;

&lt;p&gt;Maybe monads are a method to handle values that may or may not exists in a safe manner. Instead of having &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; values, you'll have Maybe handle the &lt;code&gt;Nothing&lt;/code&gt; case gracefully, leveraging the functors methodology.&lt;/p&gt;

&lt;p&gt;Basically, Maybe is a box for values that are optional. Let's assume we have an implementation, this is how it might look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maybeName1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Snir&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maybeName2&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="kc"&gt;undefined&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;maybeName1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// [status: "Just", value: "Snir"]&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;maybeName2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// [status: "Nothing"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, this &lt;code&gt;Maybe&lt;/code&gt; structure is a box, that implements a &lt;code&gt;map&lt;/code&gt; function, to be a functor! Let's look at a potential &lt;code&gt;map&lt;/code&gt; implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// (This is not how `this` really works, assume `this` here is the&lt;/span&gt;
&lt;span class="c1"&gt;// currently referred Maybe object itself. Just for ease of read)&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;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fun&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;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;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nothing&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="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;fun&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thus, enabling us to code this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maybeName1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Snir&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maybeName2&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="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maybes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;maybeName1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maybeName2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;maybes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;maybeObj&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;maybeObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;name&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi &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="s2"&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;// Will logs: "Hi Snir!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see, the Maybe is a box for holding a value safely, while we can apply function using map to these values (and not needing to worry about checking for "null" values, as the Maybe implementation takes care of that).&lt;/p&gt;

&lt;p&gt;In functional programming, these boxes are all over the place. And, may I say, in languages like Haskell with evolved type system, they are even more elegant.&lt;/p&gt;

&lt;h2&gt;
  
  
  There is more! one last weird example - functions.
&lt;/h2&gt;

&lt;p&gt;So we understood that structures are boxes. Lists are a box for many values, Maybes are a box for safe evaluation of optional values.&lt;br&gt;
But functions are boxes too. Boxes for code execution data.&lt;br&gt;
We can map functions over functions too!&lt;/p&gt;

&lt;p&gt;This is where it gets a bit weird, but this is the most important example IMO as it expands your view of what "structures" are.&lt;/p&gt;

&lt;p&gt;Sadly, this is also where we have to leave the natural realms of JavaScript, as JS does not hold functions as perfect boxes for implementing functors on them.&lt;/p&gt;

&lt;p&gt;The important bit here is natural partial application for functions, which exists in Haskell, Scala and many other functional-natural languages.&lt;/p&gt;

&lt;p&gt;In Haskell for example, every function get just one argument, always. So how do we pass more than one argument? well, Haskell just automatically apply the function it created from the first argument, to a function with the second argument.&lt;/p&gt;

&lt;p&gt;This creates a world where partially applied (or curried in other name) functions are a first class feature of the language.&lt;/p&gt;

&lt;p&gt;Take a look at that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- This function takes 2 arguments: name, and address&lt;/span&gt;
&lt;span class="n"&gt;printPerson&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;putStrLn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Let's apply it with 2 arguments to get a print:&lt;/span&gt;
&lt;span class="n"&gt;printPerson&lt;/span&gt; &lt;span class="s"&gt;"Snir"&lt;/span&gt; &lt;span class="s"&gt;" Tel Aviv"&lt;/span&gt;
&lt;span class="c1"&gt;-- This will print "Snir Tel Aviv"&lt;/span&gt;

&lt;span class="c1"&gt;-- We can also just partially apply, and store in another name:&lt;/span&gt;
&lt;span class="n"&gt;printShani&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;printPerson&lt;/span&gt; &lt;span class="s"&gt;"Shani"&lt;/span&gt;
&lt;span class="c1"&gt;-- This will not print anything yet. It just returns a partially applied function&lt;/span&gt;

&lt;span class="n"&gt;printShani&lt;/span&gt; &lt;span class="s"&gt;" New York"&lt;/span&gt;
&lt;span class="c1"&gt;-- This will print "Shani New York"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are javascript libraries to make this "more" natural, like Ramdajs and it's friends.&lt;br&gt;
I will demonstrate from now on with an "Imaginary" JS that naturally supports this, just so you'll have an easier time following the syntax, alongside haskell, for those who feel comfortable with it.&lt;/p&gt;

&lt;p&gt;Let's look at some imaginary map implementation for functions in JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// NOTE: this is in an imaginary JS where partial application is natural. // This will not work in real life, it just for understanding the concept.&lt;/span&gt;
&lt;span class="c1"&gt;// And as with the example before, this is not really how `this` works.&lt;/span&gt;
&lt;span class="c1"&gt;// Just assume it refers to the context function, for readability.&lt;/span&gt;
&lt;span class="nb"&gt;Function&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;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fun&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;this&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fun&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;Which will theoretically enable us to do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;add10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;multiply2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;addThenMultiply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;multiply2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;addThenMultiply&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="c1"&gt;// Will result in 22&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And this is a functor too now.&lt;br&gt;
A function is a structure storing computational information, and mapping over it is changing the stored value - aka the computational information, from just "add 10" to "add 10 then multiply by 2" while not changing the structure itself, which is being the concept of function.&lt;/p&gt;

&lt;p&gt;If you got that, it's pretty safe to say you get the conceptual generic idea of functors.&lt;/p&gt;

&lt;p&gt;For brevity, and correctness (not playing with imaginary JS) here is the same thing in haskell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- The (-&amp;gt;) is what represents functions in haskell.&lt;/span&gt;
&lt;span class="c1"&gt;-- This is an instance implementation of Functors to (-&amp;gt;) - functions.&lt;/span&gt;
&lt;span class="c1"&gt;-- We implement the `fmap` here, which is just the `map` function.&lt;/span&gt;
&lt;span class="kr"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;Functor&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="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt;  
  &lt;span class="n"&gt;fmap&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;\&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;-- Intentionally avoid point-free style, for easier read.&lt;/span&gt;
&lt;span class="n"&gt;add10&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;multiply2&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="n"&gt;addThenMultiply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;add10&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;fmap&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="n"&gt;multiply2&lt;/span&gt;
&lt;span class="n"&gt;addThenMultiply&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Formality! Let's define functors formally.
&lt;/h2&gt;

&lt;p&gt;Few. You got so far.&lt;br&gt;
Let's just wrap it up with the formal definition of Functors.&lt;/p&gt;

&lt;p&gt;A functor must implement &lt;code&gt;map&lt;/code&gt; function such that it takes a function from type &lt;code&gt;a&lt;/code&gt; to type &lt;code&gt;b&lt;/code&gt;, and a Functor with value of type a, and returns Functor with type b.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Formal haskell type definition&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What does it mean? let's start easy.&lt;br&gt;
We have a list &lt;code&gt;[1,2,3]&lt;/code&gt; and a function &lt;code&gt;addOne = (n) =&amp;gt; n + 1&lt;/code&gt;&lt;br&gt;
Then the list is the Functor, which holds values of type &lt;code&gt;Number&lt;/code&gt;. Th function, is a function from &lt;code&gt;Number&lt;/code&gt; to &lt;code&gt;Number&lt;/code&gt;. So we should result again in a functor (list) of the same type (number).&lt;br&gt;
&lt;code&gt;[1,2,3] -&amp;gt; [2,3,4]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now say we have a function from Number to another type:&lt;br&gt;
&lt;code&gt;strNum =&amp;gt; (n) =&amp;gt; "num: " + n&lt;/code&gt;&lt;br&gt;
Then, going through the rule, it will be a function, from &lt;code&gt;Number&lt;/code&gt; to &lt;code&gt;String&lt;/code&gt; transforming a Functor (list) of &lt;code&gt;Number&lt;/code&gt; to Functor of &lt;code&gt;String&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;[1,2,3] -&amp;gt; ["num: 1", "num: 2", "num: 3"]&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rules
&lt;/h3&gt;

&lt;p&gt;For functors to work as expected, in any generic usage of function, we need to keep 2 basic rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functors must preserve identity morphisms
This basically means, that if I pass a no-op function for &lt;code&gt;map&lt;/code&gt;, the functor should remain intact.
Basically, &lt;code&gt;map&lt;/code&gt; shouldn't change anything by itself, without the function provided.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;noop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&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="mi"&gt;2&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="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;noop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Must return `[1,2,3]` again.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Functors preserve composition of morphisms
This means, that mapping with a composed function, should give the same result as mapping with the functions separated.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;addTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;MultiplyTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;addThenMultiply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;MultiplyTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;))&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="mi"&gt;2&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="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addTwo&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MultiplyTwo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [6,8,10]&lt;/span&gt;

&lt;span class="c1"&gt;// Must be equivalent to the use of the composition morphism:&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="mi"&gt;2&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="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addThenMultiply&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [6,8,10]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;P.S&lt;br&gt;
There are much more to be said about functors, and more variants of functors to cover.&lt;br&gt;
This should give you a good understanding of the concept, and an easy gateway to more advance topics.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>haskell</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why B2B startups shouldn't use React (or any JS framework)</title>
      <dc:creator>Snir David</dc:creator>
      <pubDate>Sat, 10 Aug 2019 17:00:25 +0000</pubDate>
      <link>https://dev.to/snird/why-b2b-startups-shouldn-t-use-react-or-any-js-framework-3j74</link>
      <guid>https://dev.to/snird/why-b2b-startups-shouldn-t-use-react-or-any-js-framework-3j74</guid>
      <description>&lt;p&gt;Before we dive in to the reasoning behind this title, let's set up some base definitions for the discussion:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Startups&lt;/strong&gt; - The startups I'm referring to are small startups. If you will, up to 8 persons in the tech team. My claims might be valid for bigger teams, or even big companies depending on their organizational structure. This will be better explained on the reasoning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Startups kind&lt;/strong&gt; - There are many kinds of startups, and my claim can't possibly be relevant to all of them. I think my claims are more relevant for the B2B startups that provide some dashboard to users, rather than B2C startups that might need to have higher priority on user experience that SPA methodology might provide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JS frameworks&lt;/strong&gt; - The important distinction here is for front-end frameworks that are fundamentally disconnected from the backend such that it requires providing the overhead of writing specific APIs to serve it. React, Vue, Angular and others are complying with this definition.&lt;/p&gt;

&lt;p&gt;With those definitions out of the way, we have a common language to talk about my claims.&lt;/p&gt;

&lt;p&gt;To be honest, I'm not having any "revolutionary" idea here. The basic principles against using an JS frameworks for front-end have been laid out by many others before me, just with different reasoning and perspectives.&lt;br&gt;
One of my favorites in this regard, is a talk by Sam Stephenson from basecamp on Turbolinks 5, which is basecamp's antidote to the JS frameworks craze. I highly recommend watching this:&lt;/p&gt;

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

&lt;p&gt;My reasoning in this post will be, as mentioned, from a perspective of a small startup and why as a startup you shouldn't go with React or any JS framework for front end.&lt;/p&gt;

&lt;h2&gt;
  
  
  If not JS framework, what then?
&lt;/h2&gt;

&lt;p&gt;This is the important stuff to begin with, that puts my reasons below into context. I'm not advocating to use vanilla JS as your framework, or any framework at all.&lt;br&gt;
What I'm advocating for is a unified tool that will reduce friction between working on your backend and your frontend, and by that empower your so precious full stack developers to make their best work of delivering value for the business.&lt;/p&gt;

&lt;p&gt;Examples for such unified tools are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby on Rails with its integrated template system&lt;/li&gt;
&lt;li&gt;Django&lt;/li&gt;
&lt;li&gt;Phoenix&lt;/li&gt;
&lt;li&gt;Spring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The basic idea is to keep the mechanisms of backend and frontend closer together in a way that will reduce overhead and personnel involved in feature delivery for communication efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eliminate friction for feature delivery
&lt;/h2&gt;

&lt;p&gt;When you are small, time to market is everything. Validating your ideas, their feasibility and their utility in the real world is important.&lt;br&gt;
When you are dealing with providing to businesses, especially at initial phases of your company, you need to focus on business value given more than anything else.&lt;/p&gt;

&lt;p&gt;To do so continuously, your need to lower the friction of providing business value quickly. And not using a JS framework might be just that.&lt;/p&gt;

&lt;p&gt;Let's take react as an example.&lt;br&gt;
To master react and be able to deliver on that platform a developer have to master:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The JS environment (npm/yarn, node, etc')

&lt;ul&gt;
&lt;li&gt;Which might be an extra load if the backend is in non-js environment.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Functional programming concepts (for pure components, why redux reducers are like they are)

&lt;ul&gt;
&lt;li&gt;Which I'm all for, I love functional. But if the developer works on Rails or Spring, he needs to now be functional and OOP at the same time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;React crazes (OMG what are those hooks things? the last library I need only demo in hooks so I have to learn either way)&lt;/li&gt;
&lt;li&gt;React ecosystem (redux or mobx? react-router)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A developer have so much focus and attention. Expecting him to be good with react comes at the cost of other things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;His mastery in backend engineering&lt;/li&gt;
&lt;li&gt;His mastery in frontend by itself, you know, the actual front CSS &amp;amp; JS&lt;/li&gt;
&lt;li&gt;And basically everything else he does not spend time with&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's alot to pay for. Just for potentially having smoother transition between routes by having a SPA. Or put on other words - too much payment for UX in a B2B environment where business value delivery matters more.&lt;/p&gt;

&lt;p&gt;P.S - even worse proposition is to not to have fullstacks on the company, and resort to Backend developer and Frontend developer separately. Thus, introducing the overhead of personnel communication for every feature when you are a small startup. Yicks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not committing to APIs internally
&lt;/h2&gt;

&lt;p&gt;When you are separating frontend and backend, you must provide APIs for the frontend to use.&lt;br&gt;
Doing so early on in a startup life might be problematic. It is another point of friction, and you might find yourself committing to APIs that should die.&lt;/p&gt;

&lt;p&gt;People also tend to use the APIs where they are not fitting, to "save" extra work.&lt;br&gt;
And don't let me get started about the API design. Even if you are an expert in this field, designing an API when you are not yet sure where your business value really is? When you are still iterating with customers? This is the fast route to legacy code and code debt where you have APIs giving you a banana attached to a gorilla and a whole jungle, while you only needed the banana but some other part on the system depends on having the gorilla in this API too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the long-term plan?
&lt;/h2&gt;

&lt;p&gt;As a CTO, I spend alot of time thinking about this kind of stuff specifically, creating strategies for the company.&lt;/p&gt;

&lt;p&gt;In short, what I would do in a B2B environment would be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start with a unified framework such as rails/django/phoenix.&lt;/li&gt;
&lt;li&gt;Iterate quickly on business value features, usually that one developer can take full responsibility for. MVP style.&lt;/li&gt;
&lt;li&gt;Keep iterating until something is a clear winner in the market.&lt;/li&gt;
&lt;li&gt;Grow it as much as possible.&lt;/li&gt;
&lt;li&gt;Be aware when you outgrew the environment - either that frontend is so important by now that you need a specialist in this field alone anyway, or that the engineering is too messy in the unified framework.&lt;/li&gt;
&lt;li&gt;Use the &lt;a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/strangler"&gt;Strangler pattern&lt;/a&gt; to move modules to an adequate JS framework.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
