<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://rachelcarmena.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://rachelcarmena.github.io/" rel="alternate" type="text/html" /><updated>2022-11-22T15:02:01+00:00</updated><id>https://rachelcarmena.github.io/feed.xml</id><title type="html">Rachel M. Carmena</title><subtitle>:clubs: Our profession is a card game.</subtitle><entry><title type="html">Confused am I</title><link href="https://rachelcarmena.github.io/2021/08/10/confused-am-i.html" rel="alternate" type="text/html" title="Confused am I" /><published>2021-08-10T10:00:00+00:00</published><updated>2021-10-24T12:00:00+00:00</updated><id>https://rachelcarmena.github.io/2021/08/10/confused-am-i</id><content type="html" xml:base="https://rachelcarmena.github.io/2021/08/10/confused-am-i.html">&lt;p&gt;Some things can be prone to misunderstandings in this profession.&lt;/p&gt;

&lt;p&gt;I think I didn’t realize about some of them until mentoring or receiving a question.&lt;/p&gt;

&lt;h2 id=&quot;continuous-delivery-and-continuous-deployment&quot;&gt;Continuous delivery and continuous deployment&lt;/h2&gt;

&lt;p&gt;The reason for this post.&lt;/p&gt;

&lt;p&gt;I made this mistake during a presentation in 2013:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/confused-am-i/wrong-slides.png&quot; alt=&quot;Wrong slides: continuous deployment appears before continuous delivery&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It could sound good: deployment on a staging environment and delivering when publishing on a production environment. No, I was wrong!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous delivery&lt;/strong&gt; should be the next step after &lt;strong&gt;continuous integration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous deployment&lt;/strong&gt; just happens when the automated pipeline doesn’t stop on the staging environment: every change follows the entire pipeline to the production environment automatically.&lt;/p&gt;

&lt;p&gt;Martin Fowler warned about this misunderstanding in &lt;a href=&quot;https://www.martinfowler.com/bliki/ContinuousDelivery.html&quot;&gt;Continuous Delivery&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;401-and-403&quot;&gt;401 and 403&lt;/h2&gt;

&lt;p&gt;Let’s see these HTTP status code that are used to represent errors on the client side:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;401 Unauthorized&lt;/li&gt;
  &lt;li&gt;403 Forbidden&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;According to &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7235&quot;&gt;Hypertext Transfer Protocol (HTTP/1.1): Authentication&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7231&quot;&gt;Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content&lt;/a&gt; provides the description for the second one:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first one is related to authentication and the second one to authorization.&lt;/p&gt;

&lt;p&gt;So I would have preferred &lt;strong&gt;401 Failed Authentication&lt;/strong&gt; and &lt;strong&gt;403 Unauthorized&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;406-and-415&quot;&gt;406 and 415&lt;/h2&gt;

&lt;p&gt;Another possible misunderstanding with HTTP status codes on the client side:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;406 Not Acceptable&lt;/li&gt;
  &lt;li&gt;415 Unsupported Media Type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;According to &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7231&quot;&gt;Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The 406 (Not Acceptable) status code indicates that the target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request (Section 5.3), and the server is unwilling to supply a default representation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I would have preferred &lt;strong&gt;406 Unsupported Requested Media Type&lt;/strong&gt; and &lt;strong&gt;415 Unprocessable Request&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;put-and-post&quot;&gt;PUT and POST&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;PUT for updating, POST for creating&lt;/em&gt; is repeated like a mantra mistakenly.&lt;/p&gt;

&lt;p&gt;PUT is also used for creating a new resource.&lt;/p&gt;

&lt;p&gt;According to &lt;a href=&quot;https://www.ietf.org/rfc/rfc2616.txt&quot;&gt;Hypertext Transfer Protocol - HTTP/1.1&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. (…) In contrast, the URI in a PUT request identifies the entity enclosed with the request (…).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I also talked about it in &lt;a href=&quot;/2019/07/23/restful-thinking.html&quot;&gt;RESTful thinking&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;true-and-false-on-the-command-line&quot;&gt;True and false on the command line&lt;/h2&gt;

&lt;p&gt;Look at this format of command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$&amp;gt; &amp;lt;command&amp;gt; || &amp;lt;command-if-failure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It works in this way:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If the first command finishes successfully (it returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;), a short-circuit happens and the second command won’t be executed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If the first command fails (it returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;), the second command will be executed.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I realized about the following fact when explaining it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The first command will return &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; if it finishes successfully.&lt;/li&gt;
  &lt;li&gt;When a command finishes successfully, it returns 0 exit code.&lt;/li&gt;
  &lt;li&gt;0 usually represents &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oh!&lt;/p&gt;

&lt;p&gt;Shells include built-in commands like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; which is playing in this case:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; returns a status of 0 (true) or 1 (false) depending on the evaluation of the conditional expression &lt;em&gt;expr&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$&amp;gt; &amp;lt;command-1&amp;gt; || &amp;lt;command-2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;would be equivalent to:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if &amp;lt;command-1&amp;gt;; then
    exit 0
else
    &amp;lt;command-2&amp;gt;
fi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On the other hand:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$&amp;gt; &amp;lt;command-1&amp;gt; &amp;amp;&amp;amp; &amp;lt;command-2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;would be equivalent to:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if &amp;lt;command-1&amp;gt;; then
    &amp;lt;command-2&amp;gt;
fi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;int-is-not-the-only-integer-data-type&quot;&gt;int is not the only integer data type&lt;/h2&gt;

&lt;p&gt;If a programming language provides a data type named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;, it can be thought as the only integer data type. I realized this when mentoring a friend.&lt;/p&gt;

&lt;p&gt;Let’s see the integer data types for different programming languages.&lt;/p&gt;

&lt;p&gt;C provides &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt; and a list of modifiers: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;short&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;long&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unsigned&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;signed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;JVM-based programming languages like Java, Kotlin, and Scala provide these integer data types:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;strong&gt;Integer data type&lt;/strong&gt;&lt;/th&gt;
      &lt;th&gt;&lt;strong&gt;Range of values&lt;/strong&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Byte&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;From -2^7 to 2^7-1.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Short&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;From -2^15 to 2^15-1.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;From -2^31 to 2^31-1.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Long&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;From -2^63 to 2^63-1.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The data type names start with lowercase in Java.&lt;/p&gt;

&lt;p&gt;What about CLI-based programming languages?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;C# provides &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sbyte&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byte&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;short&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ushort&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;long&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ulong&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nint&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nuint&lt;/code&gt;. More details in &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types#characteristics-of-the-integral-types&quot;&gt;C#: Characteristics of the integral types&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;F# provides &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byte&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sbyte&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int64&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint64&lt;/code&gt;. More details in &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/basic-types&quot;&gt;F#: Basic types&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I like the second one when the number of bits is added together &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see Rust: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i8&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u8&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i32&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u32&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i64&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u64&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i128&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u128&lt;/code&gt;. I love it! There is no room for error. More details in &lt;a href=&quot;https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-types&quot;&gt;Rust: Integer types&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It’s also clear with Go: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int8&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int32&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int64&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint8&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint32&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint64&lt;/code&gt;. And &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byte&lt;/code&gt; is provided as an alias for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint8&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;code-smell-primitive-obsession&quot;&gt;Code Smell: Primitive obsession&lt;/h2&gt;

&lt;p&gt;When I learned this code smell that appeared in &lt;a href=&quot;https://www.refactoring.com&quot;&gt;Refactoring&lt;/a&gt; book, I received an example of a function with several &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; parameters:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The code was “polluted” with the choice of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; type for those cases. What if it was necessary to use a different type?&lt;/li&gt;
  &lt;li&gt;The compiler couldn’t know if the arguments were being properly provided in a call. The meaning was just on the parameter names.&lt;/li&gt;
  &lt;li&gt;Those parameters had a related behavior that wasn’t being encapsulated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix consisted on replacing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; type with user-defined types for those parameters.&lt;/p&gt;

&lt;p&gt;However, the code smell is called &lt;strong&gt;primitive obsession&lt;/strong&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; is not a primitive type:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The String class is not technically a primitive data type, but considering the special support given to it by the language, you’ll probably tend to think of it as such. &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html&quot;&gt;Java: Primitive Data Types&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single. &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/api/system.type.isprimitive&quot;&gt;C#: Type.IsPrimitive Property&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And this code smell is widely explained with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; type. Even &lt;a href=&quot;https://wiki.c2.com&quot;&gt;WikiWikiWeb&lt;/a&gt; relates &lt;a href=&quot;https://wiki.c2.com/?PrimitiveObsession&quot;&gt;primitive obsession&lt;/a&gt; with &lt;a href=&quot;https://wiki.c2.com/?NoStrings&quot;&gt;NoStrings&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On the other hand, this code smell could apply to any built-in type of a programming language. For instance, it could happen with a built-in collection type.&lt;/p&gt;

&lt;p&gt;So I would have preferred the name &lt;strong&gt;obsession with built-in types&lt;/strong&gt;, primitive or non-primitive.&lt;/p&gt;

&lt;h2 id=&quot;db-views&quot;&gt;DB views&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE VIEW&lt;/code&gt; doesn’t actually create a view as could be expected but a query that will be run every time it’s referrenced.&lt;/p&gt;

&lt;p&gt;A view is actually created by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE MATERIALIZED VIEW&lt;/code&gt;, when supported by the DBMS, or other SQL sentences to materialize the view.&lt;/p&gt;

&lt;p&gt;I would have preferred &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE QUERY&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE VIEW&lt;/code&gt;, respectively.&lt;/p&gt;

&lt;h2 id=&quot;editing-a-comment-or-a-message&quot;&gt;Editing a comment or a message&lt;/h2&gt;

&lt;p&gt;Did this situation happen to you? Receiving a notification about a comment or a message, reading the text, thinking about it, opening the corresponding tool to answer and finding an entirely different text. The user edited the text after submitting it. And sometimes the message was edited more than 5 times afterwards.&lt;/p&gt;

&lt;p&gt;What about this other one? Reading a message, coming back after a few minutes and that message was edited with a long list of items. There is no guarantee that those additional data will be read.&lt;/p&gt;

&lt;p&gt;I’m always warning people around me about it.&lt;/p&gt;

&lt;p&gt;Should communication tools allow us to edit the messages?&lt;/p&gt;

&lt;p&gt;It seems they are doing their best in this sense:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Sending just one notification with the first version of the text.&lt;/li&gt;
  &lt;li&gt;Allowing an option to preview the text if it’s not a WYSIWYG editor.&lt;/li&gt;
  &lt;li&gt;Noting that the text was edited.&lt;/li&gt;
  &lt;li&gt;Allowing to see the editions history in some cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Could they do anything else to avoid these misunderstandings?&lt;/p&gt;

&lt;p&gt;Maybe adding a warning message when a user is going to edit an existing message:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The initial message has already been read and notified. Please, consider writing a new message to avoid possible misunderstandings.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I think I understand that a tool like Twitter doesn’t allow to edit the submitted tweets:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A reply could be obsolete after editing a tweet.&lt;/li&gt;
  &lt;li&gt;The users that retweeted it or liked it might disagree with the updated content.&lt;/li&gt;
  &lt;li&gt;The updated content might not be read by those users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, it’s one of the most requested features.&lt;/p&gt;

&lt;p&gt;Why not delete the tweet and create a new one?&lt;/p&gt;

&lt;p&gt;Maybe too many steps: copy, delete, new, paste, edit the text, and submit.&lt;/p&gt;

&lt;p&gt;Ok, why not add a Fix button to simplify that task?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The initial tweet will be deleted and a new tweet will be created when submitting it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just three steps: fix, edit the text, and submit. Internally, it would be like creating a new tweet from a template and keeping the id of the initial tweet to delete it. In other words, deleting and creating at the same time instead of updating.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You retweeted, liked or replied these fixed tweets:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Could the communication or project management tools follow the same idea?&lt;/p&gt;

&lt;p&gt;Does this issue come from developers because we are always thinking about CRUD operations? What if one of them isn’t appropriate for a certain tool?&lt;/p&gt;</content><author><name></name></author><category term="[&quot;coding&quot;, &quot;reflections&quot;]" /><summary type="html">Some things can be prone to misunderstandings in this profession.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/confused-am-i/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/confused-am-i/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Rereading The Cathedral and The Bazaar</title><link href="https://rachelcarmena.github.io/2021/07/16/rereading-the-cathedral-and-the-bazaar.html" rel="alternate" type="text/html" title="Rereading The Cathedral and The Bazaar" /><published>2021-07-16T10:00:00+00:00</published><updated>2021-07-16T10:00:00+00:00</updated><id>https://rachelcarmena.github.io/2021/07/16/rereading-the-cathedral-and-the-bazaar</id><content type="html" xml:base="https://rachelcarmena.github.io/2021/07/16/rereading-the-cathedral-and-the-bazaar.html">&lt;p&gt;A few weeks ago, I found a paper copy of the essay &lt;a href=&quot;http://www.catb.org/~esr/writings/cathedral-bazaar/&quot;&gt;The Cathedral and The Bazaar&lt;/a&gt; by Eric S. Raymond from my first year of University degree, the subject Computing and Society. The essay had been published one year before and it would become a book one year later. It was very popular then.&lt;/p&gt;

&lt;p&gt;So many years on, it deserved a rereading given what happened with &lt;a href=&quot;/2018/03/31/rereading-the-mythical-man-month.html&quot;&gt;The Mythical Man-Month&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I think it’s a recommended reading for anyone who wants to know more about the called bazaar style and the lessons learnt when applying it on an open-source product.&lt;/p&gt;

&lt;p&gt;The essay is available on &lt;a href=&quot;http://www.catb.org/~esr/writings/cathedral-bazaar/&quot;&gt;Eric S. Raymond’s website&lt;/a&gt;. I’m just including a few comments here.&lt;/p&gt;

&lt;h2 id=&quot;continuous-delivery&quot;&gt;Continuous delivery&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;I had been preaching the Unix gospel of small tools, rapid prototyping and evolutionary programming for years.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On the other hand, one chapter is entitled:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Release early, release often.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And one of the lessons in that chapter adds:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;And listen to your customers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those things are widely mentioned nowadays. However, I’m wondering whether it would happen in 1997.&lt;/p&gt;

&lt;h2 id=&quot;make-it-work-make-it-right-and-make-it-fast&quot;&gt;Make it work, make it right and make it fast&lt;/h2&gt;

&lt;p&gt;Eric explains how Linux started reusing code and ideas from Minix:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Eventually all the Minix code went away or was completely rewritten—but while it was there, it provided scaffolding for the infant that would eventually become Linux.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Find &lt;a href=&quot;https://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast&quot;&gt;more details about make it work, make it right and make it fast&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;problem-vs-solution&quot;&gt;Problem vs. Solution&lt;/h2&gt;

&lt;p&gt;I witnessed a lot of discussions in terms of the solution before having a clear understanding of the problem. Eric talks about the importance of understanding the problems (please, take a look at the essay to get more context about it):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;you often don’t really understand the problem until after the first time you implement a solution&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Often, the most striking and innovative solutions come from realizing that your concept of the problem was wrong.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;pygmalion-effect&quot;&gt;Pygmalion effect&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you treat your beta-testers as if they’re your most valuable resource, they will respond by becoming your most valuable resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;simplicity&quot;&gt;Simplicity&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Don’t hesitate to throw away superannuated features when you can do it without loss of effectiveness.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;When your code is getting both better and simpler, that is when you know it’s right.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;brooks-law&quot;&gt;Brooks’ law&lt;/h2&gt;

&lt;p&gt;The author tries to understand how an open-source product can be made by so many people because that fact contradicts Brooks’ law.&lt;/p&gt;

&lt;p&gt;However, I find some differences between a team in a company and a community of an open-source product:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Target: People that are part of a community are usually users of the product.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Context: People that are part of a community decide freely their contributions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Communication: Teams in a company usually have a biased view of a product. However, Eric explained how he dealt with the communication of the design decisions for the whole community.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Motivation: Sometimes it’s easier to find more recognition in a community than in a company.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;Finally, it includes a small but interesting &lt;a href=&quot;http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s15.html&quot;&gt;bibliography&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I would add &lt;a href=&quot;http://www.catb.org/~esr/writings/taoup/html/ch01s06.html&quot;&gt;Basics of the Unix Philosophy&lt;/a&gt; from the book The Art of Unix Programming by Eric S. Raymond. Some of the rules continue being discussed even nowadays.&lt;/p&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/majaranda-13272204/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=5473076&quot;&gt;Majaranda&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=5473076&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="reading" /><summary type="html">A few weeks ago, I found a paper copy of the essay The Cathedral and The Bazaar by Eric S. Raymond from my first year of University degree, the subject Computing and Society. The essay had been published one year before and it would become a book one year later. It was very popular then.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/rereading-the-cathedral-and-the-bazaar/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/rereading-the-cathedral-and-the-bazaar/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Awareness</title><link href="https://rachelcarmena.github.io/2021/07/14/awareness.html" rel="alternate" type="text/html" title="Awareness" /><published>2021-07-14T10:00:00+00:00</published><updated>2021-09-05T12:00:00+00:00</updated><id>https://rachelcarmena.github.io/2021/07/14/awareness</id><content type="html" xml:base="https://rachelcarmena.github.io/2021/07/14/awareness.html">&lt;p&gt;Reading books and articles, watching talks and documentary films, and listening to stories with &lt;a href=&quot;https://wiki.c2.com/?CriticalThinking&quot;&gt;critical thinking&lt;/a&gt; can help us to raise our awareness and to become better people personally and professionally.&lt;/p&gt;

&lt;p&gt;Let’s see some books that helped me in this profession.&lt;/p&gt;

&lt;h2 id=&quot;when-learning&quot;&gt;When learning&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning/&quot;&gt;Pragmatic Thinking and Learning. Refactor your wetware&lt;/a&gt; by Andy Hunt&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;when-programming&quot;&gt;When programming&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://leanpub.com/4rulesofsimpledesign&quot;&gt;Understanding the Four Rules of Simple Design&lt;/a&gt; by Corey Haines&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/44919.Working_Effectively_with_Legacy_Code&quot;&gt;Working Effectively with Legacy Code&lt;/a&gt; by Michael C. Feathers&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/85009.Design_Patterns&quot;&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;/a&gt; (known as &lt;em&gt;GoF Patterns&lt;/em&gt;) by Erich Gamma, Ralph Johnson, John Vlissides, and Richard Helm&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/4845.Code_Complete&quot;&gt;Code Complete. A practical handbook of software construction&lt;/a&gt; by Steve McConnell&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/44936.Refactoring&quot;&gt;Refactoring: Improving the Design of Existing Code&lt;/a&gt; by Martin Fowler&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/3735293-clean-code&quot;&gt;Clean Code&lt;/a&gt; by Robert C. Martin&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.oreilly.com/library/view/the-art-of/9781449318482/&quot;&gt;The Art of Readable Code&lt;/a&gt; by Dustin Boswell and Trevor Foucher&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://www.growing-object-oriented-software.com/&quot;&gt;Growing Object-Oriented Software, Guided by Tests&lt;/a&gt; (known as &lt;em&gt;GooS book&lt;/em&gt;) by Steve Freeman and Nat Pryce&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://sandimetz.com/99bottles&quot;&gt;99 Bottles of OOP. A Practical Guide to Object-Oriented Design&lt;/a&gt; by Sandi Metz and Katrina Owen&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://leanpub.com/codingdojohandbook&quot;&gt;The Coding Dojo Handbook. A practical guide to creating a space where good programmers can become great programmers&lt;/a&gt; by Emily Bache&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://leanpub.com/whattolookforinacodereview&quot;&gt;What to Look for in a Code Review. Effective tips for reviewing code&lt;/a&gt; by Trisha Gee&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/17974534-the-mikado-method&quot;&gt;The Mikado Method&lt;/a&gt; by Ola Ellnestam and Daniel Brolund&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.oreilly.com/library/view/97-things-every/9780596809515/&quot;&gt;97 Things Every Programmer Should Know&lt;/a&gt; by Kevlin Henney&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://blog.codinghorror.com/coding-horror-the-book/&quot;&gt;Effective Programming: More Than Writing Code&lt;/a&gt; by Jeff Atwood&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/387190.Test_Driven_Development&quot;&gt;Test Driven Development: By Example&lt;/a&gt; by Kent Beck&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://fiftyquickideas.com/fifty-quick-ideas-to-improve-your-tests/&quot;&gt;Fifty quick ideas to improve your tests&lt;/a&gt; by Gojko Adzic, David Evans, and Tom Roden&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/34921689-domain-modeling-made-functional&quot;&gt;Domain Modeling Made Functional: Tackle Software Complexity with Domain-Driven Design and F#&lt;/a&gt; by Scott Wlaschin&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.enterpriseintegrationpatterns.com&quot;&gt;Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions&lt;/a&gt; by Gregor Hohpe and Bobby Woolf&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;when-versioning-source-code&quot;&gt;When versioning source code&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/367720.Software_Configuration_Management_Patterns&quot;&gt;Software Configuration Management Patterns: Effective Teamwork, Practical Integration&lt;/a&gt; by Stephen P. Berczuk and Brad Appleton&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;when-creating-products&quot;&gt;When creating products&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/07/16/rereading-the-cathedral-and-the-bazaar.html&quot;&gt;The Cathedral and The Bazaar&lt;/a&gt; by Eric S. Raymond&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.wiley.com/en-us/Handbook+of+Usability+Testing%3A+How+to+Plan%2C+Design%2C+and+Conduct+Effective+Tests%2C+2nd+Edition-p-9781118080405&quot;&gt;Handbook of usability testing: how to plan, design, and conduct effective tests&lt;/a&gt; by Jeff Rubin and Dana Chisnell&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/18197267-don-t-make-me-think-revisited&quot;&gt;Don’t make me think&lt;/a&gt; by Steve Krug&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/13252534-pretotype-it&quot;&gt;Pretotype it. Make sure you are building the right it before you build it right&lt;/a&gt; by Alberto Savoia&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;when-releasing&quot;&gt;When releasing&lt;/h2&gt;

&lt;p&gt;From my point of view, an interesting book for any technical profile in this profession:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://pragprog.com/titles/mnee2/release-it-second-edition/&quot;&gt;Release It!&lt;/a&gt; by Michael Nygard&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;when-working-in-a-team&quot;&gt;When working in a team&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2018/03/31/rereading-the-mythical-man-month.html&quot;&gt;The Mythical Man-Month&lt;/a&gt; by Fred Brooks&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/67825.Peopleware&quot;&gt;Peopleware&lt;/a&gt; by Tom DeMarco and Timothy R. Lister&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/5608045-apprenticeship-patterns&quot;&gt;Apprenticeship Patterns&lt;/a&gt; by Dave Hoover and Adewale Oshineye&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/23215733-the-software-craftsman&quot;&gt;The Software Craftsman: Professionalism, Pragmatism, Pride&lt;/a&gt; by Sandro Mancuso&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/4099.The_Pragmatic_Programmer&quot;&gt;The Pragmatic Programmer: From Journeyman to Master&lt;/a&gt; by David Thomas and Andrew Hunt&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.goodreads.com/book/show/67833.Extreme_Programming_Explained&quot;&gt;Extreme Programming Explained: Embrace Change&lt;/a&gt; by Kent Beck and Cynthia Andres&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.quickglance.at/agile_antipatterns&quot;&gt;Quick glance at: Agile Anti-patterns&lt;/a&gt; by David Tanzer&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://leanpub.com/agiletechnicalpracticesdistilled&quot;&gt;Agile Technical Practices Distilled&lt;/a&gt; by Pedro Moreira Santos, Marco Consolaro, and Alessandro Di Gioia&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;an-idea&quot;&gt;An idea&lt;/h2&gt;

&lt;p&gt;If you have a book library in your company, add a poster with some advice:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;No hurry.&lt;/li&gt;
  &lt;li&gt;Rereading is allowed.&lt;/li&gt;
  &lt;li&gt;Enjoy: if it’s not the right moment for a particular book, take another one and try it again later.&lt;/li&gt;
  &lt;li&gt;Take regular breaks for assimilation and reflection.&lt;/li&gt;
  &lt;li&gt;Share what you read (conversations, posts, small talks, drawings, etc).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://thebooksbywomen.com&quot;&gt;Books by women&lt;/a&gt; by Kalina Zografska&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.codinghorror.com/recommended-reading-for-developers/&quot;&gt;Recommended Reading for Developers&lt;/a&gt; by Jeff Atwood&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/viscious-speed-1744878/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=1084082&quot;&gt;Speedy McVroom&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=1084082&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="reading" /><summary type="html">Reading books and articles, watching talks and documentary films, and listening to stories with critical thinking can help us to raise our awareness and to become better people personally and professionally.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/awareness/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/awareness/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">A dream</title><link href="https://rachelcarmena.github.io/2021/07/12/a-dream.html" rel="alternate" type="text/html" title="A dream" /><published>2021-07-12T10:00:00+00:00</published><updated>2021-07-14T10:00:00+00:00</updated><id>https://rachelcarmena.github.io/2021/07/12/a-dream</id><content type="html" xml:base="https://rachelcarmena.github.io/2021/07/12/a-dream.html">&lt;p&gt;Have you tried to contribute with forums or any platform about Q&amp;amp;A?&lt;/p&gt;

&lt;p&gt;New questions are appearing continuously.&lt;/p&gt;

&lt;p&gt;They are endless lists of questions and questions.&lt;/p&gt;

&lt;p&gt;After taking a look, some kinds of questions can be found:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Looking for an opinion.&lt;/li&gt;
  &lt;li&gt;Looking for a tool to do something.&lt;/li&gt;
  &lt;li&gt;Trying to understand a concept.&lt;/li&gt;
  &lt;li&gt;Knowing the reason for a message error and how to solve it.&lt;/li&gt;
  &lt;li&gt;Knowing how to do something with a programming language or a tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I understand the first two types of questions. However, what about the rest of the types?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are the reasons for those questions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They could be a signal about poor content in the official documentation.&lt;/p&gt;

&lt;p&gt;Or maybe the official documentation is not properly organized or indexed and it’s not easy to find something.&lt;/p&gt;

&lt;p&gt;Or perhaps the reason is our contemporary world where we’re getting used to achieving things immediately with “one-click” and there is no patience to read the documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anyway, what if …&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The platform allows a way to provide one or more links when the answer can be found in the related documentation.&lt;/li&gt;
  &lt;li&gt;Otherwise, the platform would greatly recognize when someone provides the answer and at the same time makes a contribution to improve the related documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do you imagine how the technical documentation would improve?&lt;/p&gt;

&lt;p&gt;Other things could happen afterwards: the use of technical documentation would increase and the number of questions would decrease.&lt;/p&gt;

&lt;p&gt;If I think about the programming languages and tools that I learnt, I found it difficult to find “a single source of truth”. One of my dreams in this profession would be having better documentation (content, organization and indexation) and fewer questions on other platforms.&lt;/p&gt;

&lt;h2 id=&quot;corollary&quot;&gt;Corollary&lt;/h2&gt;

&lt;p&gt;It’s about “listening to the signals”, using the questions as feedback to identify improvement points.&lt;/p&gt;

&lt;p&gt;For instance, I usually talk about “preparing a demo” or “preparing docs” moments. When doing it, I realize things that could be enhanced to make it easier to explain.&lt;/p&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/bogitw-851103/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=2485544&quot;&gt;Gerhard Bögner&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=2485544&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="reflections" /><summary type="html">Have you tried to contribute with forums or any platform about Q&amp;amp;A?</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/a-dream/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/a-dream/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Some topics in a nutshell</title><link href="https://rachelcarmena.github.io/2021/06/07/some-topics-in-a-nutshell.html" rel="alternate" type="text/html" title="Some topics in a nutshell" /><published>2021-06-07T10:00:00+00:00</published><updated>2021-06-07T10:00:00+00:00</updated><id>https://rachelcarmena.github.io/2021/06/07/some-topics-in-a-nutshell</id><content type="html" xml:base="https://rachelcarmena.github.io/2021/06/07/some-topics-in-a-nutshell.html">&lt;p&gt;This profession allows me to meet a lot of good people. One of them is the reason for this post.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.carlosble.com&quot;&gt;Carlos Blé&lt;/a&gt; talked to me about his podcasts and the opportunity of participating with one-minute audios. That’s a good idea for me to think about the content previously and, at the same time, to make the effort to find the key points.&lt;/p&gt;

&lt;p&gt;Here is the transcript of my audios.&lt;/p&gt;

&lt;h2 id=&quot;writing-a-blog&quot;&gt;Writing a blog&lt;/h2&gt;

&lt;p&gt;It wasn’t clear to me that having a blog was worthwhile because of thinking that posts could be obsolete very soon.&lt;/p&gt;

&lt;p&gt;Not only technical posts could be out of date but also subjective posts because we evolve and can change our mind.&lt;/p&gt;

&lt;p&gt;However, a blog helped me to organize ideas, to spend time reflecting on some topics and to spread things that had been useful when I shared them personally.&lt;/p&gt;

&lt;p&gt;At last but not least, I also learn more from the received feedback.&lt;/p&gt;

&lt;h2 id=&quot;gender-gap&quot;&gt;Gender gap&lt;/h2&gt;

&lt;p&gt;If I think about myself and the reason why I’m working in tech, the answer is my mother, that is to say, having a female reference.&lt;/p&gt;

&lt;p&gt;On the other hand, I’ve had bad experiences in this profession.&lt;/p&gt;

&lt;p&gt;So, I think it could be useful to address these things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Making women who &lt;strong&gt;were&lt;/strong&gt; in this profession visible.&lt;/li&gt;
  &lt;li&gt;Taking care of women who &lt;strong&gt;are&lt;/strong&gt; in this profession.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further reading: &lt;a href=&quot;/2019/01/19/my-reference.html&quot;&gt;My reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;test-driven-development&quot;&gt;Test-driven development&lt;/h2&gt;

&lt;p&gt;I think that learning and practicing TDD can provide us more benefits beyond the TDD cycle.&lt;/p&gt;

&lt;p&gt;It teaches us:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;To think before writing code.&lt;/li&gt;
  &lt;li&gt;To divide the problems thanks to the step by step.&lt;/li&gt;
  &lt;li&gt;The importance of continuous improvement with the step of refactoring.
    &lt;ul&gt;
      &lt;li&gt;That’s also a humbling experience because it’s really difficult to do something right at the first time.&lt;/li&gt;
      &lt;li&gt;And it also helps us to progress more quickly because of the focus on making it work as the first step.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;The value of tests because they are in the first place.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, regardless of working in a context where TDD can be difficult, I think that knowing TDD has much to offer.&lt;/p&gt;

&lt;p&gt;Further reading: &lt;a href=&quot;/2018/07/05/be-open-minded-my-friend.html#text-on-screen-tdd&quot;&gt;Be open-minded, my friend: TDD&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;code-comments&quot;&gt;Code comments&lt;/h2&gt;

&lt;p&gt;I find empathy useful. That is, thinking about someone that didn’t live my circumstances or moments of taking some decisions. What comments would be useful for others?&lt;/p&gt;

&lt;p&gt;Further reading: &lt;a href=&quot;/2018/07/05/be-open-minded-my-friend.html#text-on-screen-documentation&quot;&gt;Be open-minded, my friend: Documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;p&gt;Thank you so much again, &lt;a href=&quot;https://www.carlosble.com&quot;&gt;Carlos Blé&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://podcast.carlosble.com&quot;&gt;Carlos Blé’s podcasts (in Spanish)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/krzysztofniewolny-4120434/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=6221925&quot;&gt;Krzysztof Niewolny&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=6221925&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="reflections" /><summary type="html">This profession allows me to meet a lot of good people. One of them is the reason for this post.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/some-topics-in-a-nutshell/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/some-topics-in-a-nutshell/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Not only source code smells</title><link href="https://rachelcarmena.github.io/2020/12/29/not-only-source-code-smells.html" rel="alternate" type="text/html" title="Not only source code smells" /><published>2020-12-29T10:00:00+00:00</published><updated>2021-01-01T10:00:00+00:00</updated><id>https://rachelcarmena.github.io/2020/12/29/not-only-source-code-smells</id><content type="html" xml:base="https://rachelcarmena.github.io/2020/12/29/not-only-source-code-smells.html">&lt;p&gt;I cannot forget that project…&lt;/p&gt;

&lt;p&gt;I joined when it was almost one year old.&lt;/p&gt;

&lt;p&gt;After a few days digging deeper into the product and trying to solve some issues, I proposed to start building the product from the beginning.&lt;/p&gt;

&lt;p&gt;What?&lt;/p&gt;

&lt;p&gt;Yes, I did it ;)&lt;/p&gt;

&lt;p&gt;Oh, a young and daring person!!!&lt;/p&gt;

&lt;p&gt;There wasn’t a trend to follow Agile methodologies then and it was the characteristic Waterfall project where all the decisions were made at the beginning before the product is built.&lt;/p&gt;

&lt;p&gt;Oh, wait, that thing also happens in some “Agile” projects nowadays where all the decisions are made at the beginning to fill the backlog like there’s no tomorrow.&lt;/p&gt;

&lt;p&gt;And backlog refinement sessions for those projects are extremely chaotic.&lt;/p&gt;

&lt;p&gt;As &lt;a href=&quot;https://twitter.com/PragmaticAndy&quot;&gt;Andy Hunt&lt;/a&gt; wrote in &lt;a href=&quot;https://pragprog.com/book/ahptl/pragmatic-thinking-and-learning&quot;&gt;Pragmatic thinking and learning. Refactor your wetware&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Be comfortable with uncertainty.&lt;/strong&gt; Agile software development embraces the idea of working with uncertainty. Early on, you don’t know what the project end date will really be. You’re not 100 percent certain which features will be present in the next iteration. You don’t know how many iterations there will be. And that’s perfectly OK: that’s the sort of uncertainty you want to be comfortable with. You’ll find answers as you go along, and by the end, everything will have been answered.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s one of the reasons why we talk about evolutionary architectures, for instance.&lt;/p&gt;

&lt;p&gt;Please, let’s reflect about it. You’ll find a book about Agile Anti-Patterns at the end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s come back to the beginning of this story!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A lot of meetings were needed to defend my proposal.&lt;/p&gt;

&lt;p&gt;I didn’t have too much professional experience then and several mates were asked to share their points of view.&lt;/p&gt;

&lt;p&gt;By the end, the product was started from the beginning and we had a working product after a few weeks.&lt;/p&gt;

&lt;p&gt;No merit.&lt;/p&gt;

&lt;p&gt;I recognize that it’s easier to create a product when a huge amount of feedback exists. Likewise new products are created and work better than other competitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happened before?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In summary, a lot of time had been invested on irrelevant features and they had been thought too complex. It’s known as &lt;a href=&quot;https://wiki.c2.com/?AccidentalComplexity&quot;&gt;accidental complexity&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the same time, the most important features that gave meaning to the product, the core of the product, what defined the product, … those features hadn’t been taken care. Not only they didn’t work as expected for the client but also it was really difficult to make a change without breaking surprise things. Some Marie Kondo time was needed to organize them in a different way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How could that project have been different?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think that not only the source code has smells. All the things can have smells.&lt;/p&gt;

&lt;p&gt;Some examples from that project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;When having a complex data model in an initial step: did we add extra features that the client didn’t request? Could it be reduced to start with a simpler step for an initial working product? Imagine those scenes where a person appears with a typewriter. That person doesn’t find a good story and starts a white paper several times. A new paper into the trash and starting again. We’re lucky because we’re working in a profession where it’s easy to delete things. However, we aren’t used to deleting what we write or draw but it grows and grows.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;When having long discussions: why are they long? Every person is proposing a different solution. No agreements. It’s said that one’s ego plays in those discussions. I’m not sure about it. Maybe there are no agreements because any proposal could be right. Nobody knows it. What if we are discussing unknown things? What if we don’t have enough data to make a decision? Maybe, instead of egos, every person is looking at their crystal ball to look at the future and find the right solution. What if we wait for having more feedback to reach that point? What if we make a decision from the things that we really know right now? What would be the first small step now? &lt;em&gt;We only know that … now so it’s necessary to … To do that, we can start … and then we’ll decide next steps&lt;/em&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stop and think. Detect the smells. Detect what things are &lt;em&gt;telling&lt;/em&gt;. Why this complex design? Why this long discussion?&lt;/p&gt;

&lt;h2 id=&quot;further-knowledge&quot;&gt;Further knowledge&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.quickglance.at/agile_antipatterns.html&quot;&gt;Book: Agile Anti-Patterns&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/dtanzer&quot;&gt;David Tanzer&lt;/a&gt; - he talks about the product backlog bankruptcy among other interesting reflections - it’s also available in Spanish: &lt;a href=&quot;https://www.quickglance.at/agile_antipatterns_es&quot;&gt;Antipatrones del Desarrollo Ágil&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.eferro.net/2016/12/el-arte-del-patadon-palante-posponer.html&quot;&gt;Post and talk: El patadón pa’lante. Posponer decisiones&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/eferro&quot;&gt;Eduardo Ferro&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.eferro.net/2017/06/el-arte-del-patadon-palante-libro-de.html&quot;&gt;Post and talk: El arte del patadón pa’lante. Libro de recetas&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/eferro&quot;&gt;Eduardo Ferro&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/artolamola&quot;&gt;Luis Artola&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://pragprog.com/book/ahptl/pragmatic-thinking-and-learning&quot;&gt;Book: Pragmatic thinking and learning. Refactor your wetware&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/PragmaticAndy&quot;&gt;Andy Hunt&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2019/02/19/a-possible-next-step.html&quot;&gt;Post: A possible next step&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2018/02/27/duplication-you-are-welcome.html&quot;&gt;Post: Duplication, you’re welcome&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2019/01/23/Coding-centered-methodology.html&quot;&gt;Post: Coding-centered methodology&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/fearscare-2010330/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=4043090&quot;&gt;Fearscare&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=4043090&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="[&quot;experiences&quot;, &quot;reflections&quot;]" /><summary type="html">I cannot forget that project…</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/not-only-source-code-smells/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/not-only-source-code-smells/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Functional programming sparks joy 2</title><link href="https://rachelcarmena.github.io/2019/08/20/functional-programming-sparks-joy-2.html" rel="alternate" type="text/html" title="Functional programming sparks joy 2" /><published>2019-08-20T10:00:00+00:00</published><updated>2019-09-20T08:00:00+00:00</updated><id>https://rachelcarmena.github.io/2019/08/20/functional-programming-sparks-joy-2</id><content type="html" xml:base="https://rachelcarmena.github.io/2019/08/20/functional-programming-sparks-joy-2.html">&lt;p&gt;Previous card: &lt;a href=&quot;/2019/08/05/functional-programming-sparks-joy.html&quot;&gt;Functional programming sparks joy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before adding more concepts, I would like to share a reflection.&lt;/p&gt;

&lt;p&gt;I think that object-oriented programming and functional programming are such different paradigms that they are not comparable. However, I find a similar feeling.&lt;/p&gt;

&lt;p&gt;When I discovered object-oriented design patterns, I realized that we weren’t doing anything special. Our problems were widespread.&lt;/p&gt;

&lt;p&gt;The only difference between our development project and others could be the business domain.&lt;/p&gt;

&lt;p&gt;What if we step forward? What if we can model the domain with two kinds of pieces?&lt;/p&gt;

&lt;p&gt;When I was a child, I didn’t have LEGO bricks but TENTE with smaller pieces.&lt;/p&gt;

&lt;p&gt;I still remember my helicopter of the forest brigade:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/helicopter.png&quot; alt=&quot;Helicopter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I assembled it and disassembled it hundreds of times.&lt;/p&gt;

&lt;p&gt;However, it had more than two kinds of pieces.&lt;/p&gt;

&lt;p&gt;What if we only need two kinds of pieces for creating software?&lt;/p&gt;

&lt;p&gt;What if there is a branch of mathematics that tries to generalize things with two kinds of pieces and can be moved to computer programming?&lt;/p&gt;

&lt;p&gt;I’m talking about &lt;strong&gt;category theory&lt;/strong&gt; where a &lt;strong&gt;category&lt;/strong&gt; is a collection of:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Objects&lt;/li&gt;
  &lt;li&gt;Relationships (also known as morphisms or arrows) between the objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Functional programming&lt;/strong&gt; is based on a &lt;strong&gt;category of sets&lt;/strong&gt; where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The objects are &lt;strong&gt;types&lt;/strong&gt; (sets of values)&lt;/li&gt;
  &lt;li&gt;The arrows are &lt;strong&gt;functions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just two kinds of &lt;em&gt;pieces&lt;/em&gt; and the &lt;strong&gt;power of composition&lt;/strong&gt; with all the &lt;strong&gt;abstractions&lt;/strong&gt; defined and proved matematically.&lt;/p&gt;

&lt;p&gt;As &lt;a href=&quot;https://twitter.com/BartoszMilewski&quot;&gt;Bartosz Milewski&lt;/a&gt; wrote:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;One of the important advantages of having a mathematical model for programming is that it’s possible to perform formal proofs of correctness of software.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Imagine more than one category. And now, imagine arrows between categories:
&lt;ul&gt;
&lt;li&gt;From objects of a category to objects of another one&lt;/li&gt;
&lt;li&gt;From arrows of a category to arrows of another one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Therefore, in &lt;strong&gt;functional programming&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The objects are &lt;strong&gt;types&lt;/strong&gt; and &lt;strong&gt;functions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Remember that functions are first-class citizens and can be input and output as well.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;It’s awesome the amount of things that can be built when “playing” with only two kinds of pieces.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/BartoszMilewski&quot;&gt;Bartosz Milewski&lt;/a&gt; also wrote:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Category theory is full of simple but powerful ideas&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s review the other previous concepts (I already mentioned functions as first-class citizens):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If functions were impure, it would be very difficult to “play” with them and to compose with each other.&lt;/li&gt;
  &lt;li&gt;Mathematically, the common needs with types and functions are defined. We only have to use them, so we’ll program in a higher abstraction level.&lt;/li&gt;
  &lt;li&gt;Immutability is also essential to compose functions. Otherwise, the results couldn’t be anticipated.&lt;/li&gt;
  &lt;li&gt;Recursion will appear when defining types or functions.&lt;/li&gt;
  &lt;li&gt;Currying and partial application are some of the techniques to be able to compose functions (an output must match with the input of the following function).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, let’s consider the business domain we are working on, the state machines, the processes, the transformations, the validations, … how do types and functions fit those needs? It seems they absolutely fit them.&lt;/p&gt;

&lt;h2 id=&quot;about-the-examples&quot;&gt;About the examples&lt;/h2&gt;

&lt;p&gt;So far, I’ve used plain JavaScript and an example with Lodash library.&lt;/p&gt;

&lt;p&gt;However, to continue explaining functional programming, I’ll include examples in &lt;a href=&quot;http://www.purescript.org&quot;&gt;PureScript&lt;/a&gt;, a strongly-typed functional programming language that compiles to JavaScript. It’s heavily influenced by Haskell.&lt;/p&gt;

&lt;p&gt;I would have had a clear choice with other non-purely programming languages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://arrow-kt.io&quot;&gt;Arrow&lt;/a&gt; for Kotlin&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://typelevel.org/cats/&quot;&gt;Cats&lt;/a&gt; for Scala&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://bow-swift.io&quot;&gt;Bow&lt;/a&gt; for Swift&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.vavr.io&quot;&gt;VAVR&lt;/a&gt; for Java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think it’s good to have libraries which add functional capabilities as a way of extending a language more quickly and with the support of the developers community.&lt;/p&gt;

&lt;p&gt;However, I had a lot of alternatives in JavaScript:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Libraries&lt;/strong&gt;: Lodash, Underscore, Rambda, etc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Languages which compile to JavaScript&lt;/strong&gt;: TypeScript, PureScript, Elm, ClojureScript, Reason, OCaml (the last two options thanks to BuckleScript), etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why PureScript? I made the decision when trying to explain composite types:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Libraries such as Lodash or Underscore don’t allow to create sum types.&lt;/li&gt;
  &lt;li&gt;Ramda library provides Either, though it’s for doing an OR of function results.&lt;/li&gt;
  &lt;li&gt;I found a library for creating sum types: &lt;a href=&quot;https://github.com/fantasyland/daggy&quot;&gt;Daggy&lt;/a&gt;. However, this alternative involved making more decisions later.&lt;/li&gt;
  &lt;li&gt;TypeScript uses the pipe to represent the choice between basic types or the intersection of properties between objects.&lt;/li&gt;
  &lt;li&gt;I found composite types in Reason, though I didn’t find other capabilities.&lt;/li&gt;
  &lt;li&gt;What about the rest of options? I reviewed PureScript and it provided the characteristics I was looking for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My only purpose is explaining functional programming. PureScript is only a choice for it.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Sometimes we think about selecting only one programming language (as I did here). However, for a real software product, we could choose different programming languages according to the needs. There are a lot of languages which compile to JavaScript, which run under JVM or which run under the CLR, among other options.
&lt;/div&gt;

&lt;h3 id=&quot;declaration-and-definition&quot;&gt;Declaration and definition&lt;/h3&gt;

&lt;p&gt;In PureScript, as in Haskell, it’s a good practice to provide type annotations as documentation though compiler is able to infer them.&lt;/p&gt;

&lt;p&gt;The function type annotation is known as the &lt;strong&gt;function declaration&lt;/strong&gt;. Its notation is influenced by &lt;a href=&quot;https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system&quot;&gt;Hindley-Milner type system&lt;/a&gt; and it has the following parts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Function name&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::&lt;/code&gt; (= “is of type” or “has the type of”)&lt;/li&gt;
  &lt;li&gt;Function type:
    &lt;ul&gt;
      &lt;li&gt;Input type&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&amp;gt;&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Output type&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;function definition&lt;/strong&gt; is where the function is actually defined.&lt;/p&gt;

&lt;p&gt;For instance, the declaration and definition of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; function:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Int&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: As in other languages such as Haskell or F#, all functions are considered curried. So the &lt;code&gt;add&lt;/code&gt; function is really:
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;
add :: Int -&amp;gt; (Int -&amp;gt; Int)
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It takes an integer (the first operand) and returns a function. That function takes the other integer (the second operand) and returns the sum.&lt;/p&gt;
&lt;p&gt;This is transparent to us because the function definition and the use work like a function of 2 parameters.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;composite-types&quot;&gt;Composite types&lt;/h2&gt;

&lt;p&gt;Types can be combined to create a new type.&lt;/p&gt;

&lt;p&gt;The new type is also known as an &lt;strong&gt;algebraic data type&lt;/strong&gt; (ADT).&lt;/p&gt;

&lt;p&gt;Why &lt;em&gt;algebraic&lt;/em&gt;? Because we can “play” with them on equations and symbols (I didn’t cover it here although it’s fun!).&lt;/p&gt;

&lt;p&gt;There are two common kinds of composite types:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Product types&lt;/li&gt;
  &lt;li&gt;Sum types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see what they are and some examples and then I’ll explain a curiosity that can be useful to understand the reason of their names.&lt;/p&gt;

&lt;h3 id=&quot;product-types&quot;&gt;Product types&lt;/h3&gt;

&lt;p&gt;This is an example of the creation of a new type with the product of two types:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Money = Money {
    amount   :: Amount,
    currency :: Currency
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Its values will contain both a value of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Amount&lt;/code&gt; &lt;strong&gt;and&lt;/strong&gt; a value of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Currency&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why &lt;em&gt;product&lt;/em&gt;? Think about the number of different values for that type: the &lt;em&gt;product&lt;/em&gt; of the number of different values of the type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Amount&lt;/code&gt; and the number of different values of the type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Currency&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;sum-types&quot;&gt;Sum types&lt;/h3&gt;

&lt;p&gt;This is an example of the creation of a new type with the sum of two types:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data SendingMethod 
    = Email String
    | Address { street  :: String, 
                city    :: String, 
                country :: String }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The new type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SendingMethod&lt;/code&gt; represents a choice between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Email&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Address&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The values of this new type will contain a value of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Email&lt;/code&gt; &lt;strong&gt;or&lt;/strong&gt; a value of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Address&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why &lt;em&gt;sum&lt;/em&gt;? Think about the number of different values for that type: the &lt;em&gt;sum&lt;/em&gt; of the number of different values of the type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Email&lt;/code&gt; and the number of different values of the type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Address&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: I only included examples of combining two types for simplicity though there is no limit.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Initially I used &lt;em&gt;type composition&lt;/em&gt; as section title. It wasn't right because it could be confused with &lt;em&gt;composition&lt;/em&gt; from &lt;em&gt;function composition&lt;/em&gt;.
&lt;/div&gt;

&lt;h2 id=&quot;pattern-matching&quot;&gt;Pattern matching&lt;/h2&gt;

&lt;p&gt;In functional programming, pattern matching is based on constructors as patterns.&lt;/p&gt;

&lt;p&gt;Given a value, it can be disassembled down to parts that were used to construct it.&lt;/p&gt;

&lt;p&gt;This is a powerful tool to make decisions according to types:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;showSendingMethod :: SendingMethod -&amp;gt; String
showSendingMethod sendingMethod = 
    case sendingMethod of
        Email email -&amp;gt; &quot;Sent by mail to: &quot; &amp;lt;&amp;gt; email
        Address address -&amp;gt; &quot;Sent to an address&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;some-composite-types&quot;&gt;Some composite types&lt;/h2&gt;

&lt;h3 id=&quot;tuple&quot;&gt;Tuple&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; is an example of &lt;em&gt;product&lt;/em&gt; type that represents a pair of values.&lt;/p&gt;

&lt;p&gt;It’s defined in the module &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Tuple&lt;/code&gt; of PureScript:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Tuple a b = Tuple a b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The lowercase letters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt; represent any type&lt;/li&gt;
  &lt;li&gt;The first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; is the type constructor&lt;/li&gt;
  &lt;li&gt;The second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; is the value constructor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see an example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pair :: Tuple String String
pair = Tuple &quot;spam&quot; &quot;eggs&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The type constructor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; is used in the declaration: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pair&lt;/code&gt; is of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple String String&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;The value constructor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; is used in the definition: the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pair&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple &quot;spam&quot; &quot;eggs&quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s known as &lt;strong&gt;Pair&lt;/strong&gt; in other languages.&lt;/p&gt;

&lt;h3 id=&quot;maybe&quot;&gt;Maybe&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; is an example of &lt;em&gt;sum&lt;/em&gt; type that is used to define optional values.&lt;/p&gt;

&lt;p&gt;It’s defined in the module &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Maybe&lt;/code&gt; of PureScript:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Maybe a = Nothing | Just a
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The lowercase letter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; represents any type&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; is the type constructor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; of a type can represent one of these options:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A missing value: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Nothing&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;The presence of a value of that type: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Just a&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see an example of use:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;showTheValue :: Maybe Number -&amp;gt; String
showTheValue value =
    case value of
        Nothing -&amp;gt; &quot;There is no value&quot;
        Just value' -&amp;gt; &quot;The value is: &quot; &amp;lt;&amp;gt; toString value'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s known as &lt;strong&gt;Option&lt;/strong&gt; in other languages.&lt;/p&gt;

&lt;h3 id=&quot;either&quot;&gt;Either&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Either&lt;/code&gt; is another example of &lt;em&gt;sum&lt;/em&gt; type and it’s commonly use for error handling.&lt;/p&gt;

&lt;p&gt;It’s defined in the module &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Either&lt;/code&gt; of PureScript:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Either a b = Left a | Right b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The lowercase letters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt; represent any type&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Either&lt;/code&gt; is the type constructor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Either&lt;/code&gt; represents the choice between 2 types of values where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Left&lt;/code&gt; is used to carry an error value&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Right&lt;/code&gt; is used to carry a success value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see an example of use:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;showTheValue :: Either String Number -&amp;gt; String
showTheValue value =
    case value of
        Left value' -&amp;gt; &quot;Error: &quot; &amp;lt;&amp;gt; value'
        Right value' -&amp;gt; &quot;The value is: &quot; &amp;lt;&amp;gt; toString value'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;some-guidelines&quot;&gt;Some guidelines&lt;/h2&gt;

&lt;h3 id=&quot;making-things-explicit&quot;&gt;Making things explicit&lt;/h3&gt;

&lt;p&gt;It can be said that functional programming is based on making things &lt;strong&gt;explicit&lt;/strong&gt; as much as possible.&lt;/p&gt;

&lt;p&gt;For instance, let’s think about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If a function returns an integer, a missing value is not expected.&lt;/p&gt;

&lt;p&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt;, it can be made explicit that the function returns an integer or not.&lt;/p&gt;

&lt;h3 id=&quot;making-illegal-states-unrepresentable&quot;&gt;Making illegal states unrepresentable&lt;/h3&gt;

&lt;p&gt;This is a design guideline by &lt;a href=&quot;https://twitter.com/yminsky&quot;&gt;Yaron Minsky&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see an example. Imagine that we have a type Course with this content:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Course = Course {
    title           :: String,
    started         :: Boolean,
    lastInteraction :: Maybe Date
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is an illegal state that can be representable: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;started&lt;/code&gt; is false and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lastInteraction&lt;/code&gt; has a date.&lt;/p&gt;

&lt;p&gt;For instance, that illegal state could be avoided with a sum type:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Course 
    = StartedCourse { title :: String, lastInteraction :: Date }
    | UnstartedCourse { title :: String }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: This design guideline reminds me another one that has a wider application. It was formulated by &lt;strong&gt;Scott Meyers&lt;/strong&gt;:
&lt;blockquote&gt;
&lt;p&gt;Make interfaces easy to use correctly and hard to use incorrectly.&lt;/p&gt;
&lt;p&gt;Interfaces occur at the highest level of abstraction (user interfaces), at the lowest (function interfaces), and at levels in between (class interfaces, library interfaces, etc.)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;

&lt;h2 id=&quot;typeclasses&quot;&gt;Typeclasses&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;A &lt;strong&gt;typeclass&lt;/strong&gt; defines a family of types that support a common interface&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Typeclasses are useful to define concepts like &lt;strong&gt;monoids&lt;/strong&gt;, &lt;strong&gt;functors&lt;/strong&gt;, &lt;strong&gt;applicative&lt;/strong&gt; and &lt;strong&gt;monads&lt;/strong&gt; for all the types or types constructors, respectively.&lt;/p&gt;

&lt;p&gt;And then, it’s possible to create instances of those typeclasses for concrete types or types constructors.&lt;/p&gt;

&lt;p&gt;I include more details about it in following sections.&lt;/p&gt;

&lt;h2 id=&quot;monoids&quot;&gt;Monoids&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;monoid&lt;/strong&gt; is useful to explain how the values of a type are combined.&lt;/p&gt;

&lt;p&gt;Let’s see some examples with known types.&lt;/p&gt;

&lt;p&gt;For instance, natural numbers:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;They could be combined with addition, for instance.&lt;/li&gt;
  &lt;li&gt;Zero could be the starting point and then, add each number.&lt;/li&gt;
  &lt;li&gt;Given 3 numbers, the result with be the same for these operations:
    &lt;ul&gt;
      &lt;li&gt;The addition of the first 2 numbers is added with the third number.&lt;/li&gt;
      &lt;li&gt;The first number is added with the addition of the other 2 numbers.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or strings:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;They could be combined with concatenation.&lt;/li&gt;
  &lt;li&gt;An empty string could be the starting point and then, concatenate each string.&lt;/li&gt;
  &lt;li&gt;Given 3 strings, the result with be the same for these operations:
    &lt;ul&gt;
      &lt;li&gt;The concatenation of the first 2 strings is concatenated with the third string.&lt;/li&gt;
      &lt;li&gt;The first string is concatenated with the concatenation of the other 2 strings.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How to express it in an easy way?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monoids&lt;/strong&gt; to the rescue!&lt;/p&gt;

&lt;p&gt;Read the following definition together with the previous examples.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;monoid&lt;/strong&gt; is a type with a binary operation (2 elements). That operation has the following properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It has a neutral element (identity)&lt;/li&gt;
  &lt;li&gt;It’s associative&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Did you identify each part of the definition in the previous examples?&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: I included examples with simple and known types. However, think about &lt;strong&gt;any&lt;/strong&gt; kind of type and the need to define how the values of a type are combined.
&lt;/div&gt;

&lt;h3 id=&quot;typeclass-for-monoids&quot;&gt;Typeclass for monoids&lt;/h3&gt;

&lt;p&gt;Let’s see how to abstract the concept of &lt;strong&gt;monoid&lt;/strong&gt; for any type and then, how to define it for concrete types.&lt;/p&gt;

&lt;p&gt;In Haskell, the typeclass for a &lt;strong&gt;monoid&lt;/strong&gt; includes the neutral element (called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mempty&lt;/code&gt;) and the binary operation (called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mappend&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Monoid m where
    mempty :: m
    mappend :: m -&amp;gt; m -&amp;gt; m
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, PureScript has a previous abstraction and includes the binary operation in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Semigroup&lt;/code&gt; typeclass:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Semigroup a where
    append :: a -&amp;gt; a -&amp;gt; a
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So &lt;strong&gt;Monoid&lt;/strong&gt; typeclass extends the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Semigroup&lt;/code&gt; typeclass with the neutral element:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Semigroup m &amp;lt;= Monoid m where
    mempty :: m
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s the abstraction. Now, for instance, how to define the way of combining strings?&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;monoid&lt;/strong&gt; for strings in PureScript (modules &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Semigroup&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Monoid&lt;/code&gt;, respectively):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;instance semigroupString :: Semigroup String where
    append = concatString
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;instance monoidString :: Monoid String where
    mempty = &quot;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The binary operation is concatenation and the neutral element is the empty string.&lt;/p&gt;

&lt;p&gt;In this way, it’s possible to combine all the strings from an array into a single string when using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mempty&lt;/code&gt; defined for strings:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;greeting :: String
greeting = foldl append mempty [&quot;Hello,&quot;, &quot; &quot;, &quot;world!&quot;]
-- &quot;Hello, world!&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: &lt;code&gt;foldl&lt;/code&gt; folds the array from the left. In this case, the result would be the same with &lt;code&gt;foldr&lt;/code&gt;.
&lt;/div&gt;

&lt;h2 id=&quot;functors&quot;&gt;Functors&lt;/h2&gt;

&lt;p&gt;You already know a &lt;strong&gt;functor&lt;/strong&gt;!!&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;functor&lt;/strong&gt; is a type constructor which provides a mapping operation.&lt;/p&gt;

&lt;p&gt;Which &lt;strong&gt;functor&lt;/strong&gt; do you know for sure?&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; is a &lt;strong&gt;functor&lt;/strong&gt; which provides the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Let’s remember the included example in the first part (plain JavaScript):&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [4, 25, 64]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The same example in PureScript:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;square :: Int -&amp;gt; Int
square number = pow number 2

numbers = [2, 5, 8] :: Array Int

logShow (map square numbers)
-- [4,25,64]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or using an &lt;em&gt;infix&lt;/em&gt; function application (as an operator between the two arguments):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;logShow (square `map` numbers)
-- [4,25,64]

logShow (square &amp;lt;$&amp;gt; numbers)
-- [4,25,64]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Graphically:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/array_functor.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It’s said that:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; function allows the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;square&lt;/code&gt; to be &lt;em&gt;lifted&lt;/em&gt; over an array&lt;/li&gt;
  &lt;li&gt;Or just, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; function &lt;em&gt;lifts&lt;/em&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;square&lt;/code&gt; function&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-to-form-a-functor&quot;&gt;How to form a functor&lt;/h3&gt;

&lt;p&gt;Following the definition, a &lt;strong&gt;functor&lt;/strong&gt; can be formed by:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A type constructor&lt;/li&gt;
  &lt;li&gt;A mapping function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For instance, the &lt;strong&gt;functor&lt;/strong&gt; formed by:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The type constructor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; (in this case, from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;The following &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fmap&lt;/code&gt; function:
    &lt;ul&gt;
      &lt;li&gt;From a function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String -&amp;gt; String)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;To a function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(Maybe String -&amp;gt; Maybe String)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;repeat :: String -&amp;gt; String
repeat aString = aString &amp;lt;&amp;gt; aString

fmap :: (String -&amp;gt; String) -&amp;gt; Maybe String -&amp;gt; Maybe String
fmap f value =
    case value of
        Nothing -&amp;gt; Nothing
        Just value' -&amp;gt; Just (f value')

message :: Maybe String
message = fmap repeat (Just &quot; bla &quot;)
-- (Just &quot; bla  bla &quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Graphically:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/maybe_functor.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In this example, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fmap&lt;/code&gt; function &lt;em&gt;lifts&lt;/em&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;repeat&lt;/code&gt; function.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: For simplicity in the examples, I included functions like &lt;code&gt;square&lt;/code&gt; and &lt;code&gt;repeat&lt;/code&gt; which have the same type for input and output. However, that condition is &lt;strong&gt;not&lt;/strong&gt; necessary.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: What's the purpose of &lt;strong&gt;functors&lt;/strong&gt;? Let's remember the need of composing functions and the need of adapting the input and output to compose them. We've already seen some tools for it and a &lt;strong&gt;functor&lt;/strong&gt; is another one. We'll see more of them in the next sections.
&lt;/div&gt;

&lt;h3 id=&quot;typeclass-for-functors&quot;&gt;Typeclass for functors&lt;/h3&gt;

&lt;p&gt;Let’s see how to abstract the concept of &lt;strong&gt;functor&lt;/strong&gt; for any type constructor and then, how to define it for a concrete type constructor.&lt;/p&gt;

&lt;p&gt;The typeclass for a &lt;strong&gt;functor&lt;/strong&gt; appears in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Functor&lt;/code&gt; module:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Functor f where
    map :: forall a b. (a -&amp;gt; b) -&amp;gt; f a -&amp;gt; f b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Following the previous example, the &lt;strong&gt;functor&lt;/strong&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; is already defined in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data.Maybe&lt;/code&gt; module:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;instance functorMaybe :: Functor Maybe where
    map fn (Just x) = Just (fn x)
    map _  _        = Nothing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So it can be used to get the same result than before with less code:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;repeat :: String -&amp;gt; String
repeat aString = aString &amp;lt;&amp;gt; aString

logShow (map repeat (Just &quot; bla &quot;))
-- (Just &quot; bla  bla &quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or using an &lt;em&gt;infix&lt;/em&gt; function application (as an operator between the two arguments):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;logShow (repeat `map` (Just &quot; bla &quot;))
-- (Just &quot; bla  bla &quot;)

logShow (repeat &amp;lt;$&amp;gt; (Just &quot; bla &quot;))
-- (Just &quot; bla  bla &quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;functor-composition&quot;&gt;Functor composition&lt;/h3&gt;

&lt;p&gt;So far I’ve included examples of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; functor and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; functor separately.&lt;/p&gt;

&lt;p&gt;What if there are more than one functor?&lt;/p&gt;

&lt;p&gt;What if we want to apply the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;repeat&lt;/code&gt; function into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe (Array String)&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/functor_composition.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Firstly, we use the mapping function of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; and then, the mapping function of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; over the result.&lt;/p&gt;

&lt;p&gt;In other words, the mapping functions are composed (operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;logShow ((map &amp;gt;&amp;gt;&amp;gt; map) repeat (Just [&quot; bla &quot;, &quot; ha &quot;]))
-- (Just [&quot; bla  bla &quot;,&quot; ha  ha &quot;])
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;applicative&quot;&gt;Applicative&lt;/h2&gt;

&lt;p&gt;There are a lot of things about &lt;strong&gt;applicative&lt;/strong&gt;. I include the basic &lt;strong&gt;applicative&lt;/strong&gt; abstraction also known as an &lt;strong&gt;applicative functor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;applicative functor&lt;/strong&gt; is an step further than a &lt;strong&gt;functor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see what happens if we have a function with more than one parameter.&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fullName :: String -&amp;gt; String -&amp;gt; String
fullName name surname = name &amp;lt;&amp;gt; &quot; &quot; &amp;lt;&amp;gt; surname
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Functions are curried by default in PureScript, so in this case: the input is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; and the output is another function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String -&amp;gt; String&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/fullName.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;What happens if instead of two strings for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;surname&lt;/code&gt; we have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; for each of them?&lt;/p&gt;

&lt;p&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;functorMaybe&lt;/code&gt;, we get another function from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe (String -&amp;gt; String)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/fullName-map.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In other words, the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String -&amp;gt; String&lt;/code&gt; is wrapped with the type constructor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;How can we continue?&lt;/p&gt;

&lt;p&gt;How can we get another function from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt; to the rescue!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/applicative-2-params.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In PureScript, the applicative for Maybe is already defined so it’s possible to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt; with that kind of type constructor:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;logShow (apply (map fullName (Just &quot;Rachel&quot;)) (Just &quot;M. Carmena&quot;))
-- (Just &quot;Rachel M. Carmena&quot;)

logShow (apply (map fullName (Just &quot;Rachel&quot;)) Nothing)
-- Nothing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or using an &lt;em&gt;infix&lt;/em&gt; function application (in this case, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;*&amp;gt;&lt;/code&gt; is the equivalent to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;logShow (fullName &amp;lt;$&amp;gt; Just &quot;Rachel&quot; &amp;lt;*&amp;gt; Just &quot;M. Carmena&quot;)
-- (Just &quot;Rachel M. Carmena&quot;)

logShow (fullName &amp;lt;$&amp;gt; Just &quot;Rachel&quot; &amp;lt;*&amp;gt; Nothing)
-- Nothing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, if we have a function with more than two parameters, we’d use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;$&amp;gt;&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt;) for the first parameter and then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;*&amp;gt;&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt;) for the rest of parameters.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/applicative-3-params.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Another powerful tool to compose functions. Think about other type constructors like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Either&lt;/code&gt;, form validations, etc.&lt;/p&gt;

&lt;p&gt;Finally, after the examples, it could be easier to understand the difference between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; from &lt;strong&gt;functors&lt;/strong&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt; from &lt;strong&gt;applicative functors&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;map :: forall a b. (a -&amp;gt; b) -&amp;gt; f a -&amp;gt; f b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apply :: forall a b. f (a -&amp;gt; b) -&amp;gt; f a -&amp;gt; f b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Both get the same result though &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; transforms a function and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apply&lt;/code&gt; transforms a function which is wrapped.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: In this section, I didn't include the formal definition of &lt;strong&gt;applicative functors&lt;/strong&gt; in PureScript and the corresponding instance for &lt;code&gt;Maybe&lt;/code&gt;. They can be found in the modules &lt;code&gt;Control.Apply&lt;/code&gt;, &lt;code&gt;Control.Applicative&lt;/code&gt; and &lt;code&gt;Data.Maybe&lt;/code&gt;. There are also instances for &lt;code&gt;Either&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, etc. 
&lt;/div&gt;

&lt;h2 id=&quot;monad&quot;&gt;Monad&lt;/h2&gt;

&lt;p&gt;Let’s see what happens if we have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUser&lt;/code&gt; function from a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; value to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe User&lt;/code&gt; value:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/monad-initial-function.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;and we don’t have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; value available to be provided to the function but a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;Then, we can think about the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; &lt;strong&gt;functor&lt;/strong&gt; to have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; value as an input:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/monad-problem.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;However, the result will be a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe (Maybe User)&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;How can we get just a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe User&lt;/code&gt; value?&lt;/p&gt;

&lt;p&gt;Flattening &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe (Maybe User)&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe User&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/monad-solution.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Both operations are considered together by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bind&lt;/code&gt; from a &lt;strong&gt;monad&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bind :: forall a b. m a -&amp;gt; (a -&amp;gt; m b) -&amp;gt; m b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/monad-solution-details.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Following the example of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUser&lt;/code&gt; function, it’s possible to get a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe User&lt;/code&gt; value from a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe String&lt;/code&gt; value, because the instance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Monad&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Maybe&lt;/code&gt; is already available in PureScript:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;user :: Maybe User
user = bind (Just &quot;12345&quot;) getUser
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or using an &lt;em&gt;infix&lt;/em&gt; function application (in this case, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&amp;gt;=&lt;/code&gt; is the equivalent to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bind&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;user :: Maybe User
user = (Just &quot;12345&quot;) &amp;gt;&amp;gt;= getUser
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s said that &lt;strong&gt;monads&lt;/strong&gt; are useful to chain dependent functions in series:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy-2/monad-chain.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: The ability to wrap a value to a context is done by the &lt;code&gt;pure&lt;/code&gt; function from a &lt;strong&gt;functor&lt;/strong&gt;. For instance, from a &lt;code&gt;String&lt;/code&gt; value to a &lt;code&gt;Maybe String&lt;/code&gt; value.
&lt;/div&gt;

&lt;h2 id=&quot;further-knowledge&quot;&gt;Further knowledge&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=dgrucfgv2Tw&quot;&gt;Talk: Truth about Types&lt;/a&gt; by Bartosz Milewski&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.47deg.com/blog/science-behind-functional-programming/&quot;&gt;Post: The Science Behind Functional Programming&lt;/a&gt; by Rafa Paradela&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html&quot;&gt;Post: Functors, Applicatives, And Monads In Pictures&lt;/a&gt; by Aditya Bhargava&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://mitpress.mit.edu/sites/default/files/sicp/index.html&quot;&gt;Online book: Structure and Interpretation of Computer Programs&lt;/a&gt; by Harold Abelson, Gerald Jay Sussman and Julie Sussman&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/playlist?list=PLE18841CABEA24090&quot;&gt;Playlist: MIT 6.001 Structure and Interpretation, 1986&lt;/a&gt; by Hal Abelson and Gerald Jay Sussman&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/hmemcpy/milewski-ctfp-pdf&quot;&gt;Online book: Category Theory for Programmers&lt;/a&gt; by Bartosz Milewski&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/fantasyland/fantasy-land&quot;&gt;Specification: Fantasy Land Algebra&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://wiki.haskell.org/Typeclassopedia&quot;&gt;Typeclassopedia&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://haskellbook.com&quot;&gt;Book: Haskell Programming from first principles&lt;/a&gt; by Julie Moronuki and Christopher Allen&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/t0nymix-5936404/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=2532622&quot;&gt;Anthony Jarrin&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=2532622&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="coding" /><summary type="html">Previous card: Functional programming sparks joy</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/functional-programming-sparks-joy-2/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/functional-programming-sparks-joy-2/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Functional programming sparks joy</title><link href="https://rachelcarmena.github.io/2019/08/05/functional-programming-sparks-joy.html" rel="alternate" type="text/html" title="Functional programming sparks joy" /><published>2019-08-05T10:00:00+00:00</published><updated>2019-09-20T08:00:00+00:00</updated><id>https://rachelcarmena.github.io/2019/08/05/functional-programming-sparks-joy</id><content type="html" xml:base="https://rachelcarmena.github.io/2019/08/05/functional-programming-sparks-joy.html">&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;The title comes from Marie Kondo’s recommendation about feeling if an item sparks joy to keep it with you or to discard it.&lt;/p&gt;

&lt;p&gt;When I heard about functional programming I decided to continue learning about it. Why? Let’s see some reasons.&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;I agree with &lt;a href=&quot;https://twitter.com/ScottWlaschin&quot;&gt;Scott Wlaschin&lt;/a&gt; when he says that functional programming is not scary but unfamiliar. It has a mathematical basis and is full of new concepts.&lt;/p&gt;

&lt;p&gt;However, the more you know about functional programming and working examples, the more advantages you notice in the paradigm.&lt;/p&gt;

&lt;p&gt;Which programming language am I going to use for the examples? JavaScript. It’s not a purely functional programming language like Haskell but multi-paradigm, so it’s suitable for talking about it.&lt;/p&gt;

&lt;p&gt;Moreover, I think it can be interesting to start practicing with a known and non-purely functional programming language before moving to another one.&lt;/p&gt;

&lt;h2 id=&quot;pure-functions&quot;&gt;Pure functions&lt;/h2&gt;

&lt;p&gt;One of the objectives is to have pure functions.&lt;/p&gt;

&lt;p&gt;A pure function works as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It takes an input.&lt;/li&gt;
  &lt;li&gt;It works with that input and no more. It doesn’t access the outside in order to get more things, neither changes it the outside.&lt;/li&gt;
  &lt;li&gt;It returns an output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This image appears in my mind:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy/function.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So it has these properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It returns the &lt;strong&gt;same output&lt;/strong&gt; from the &lt;strong&gt;same input&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;It has &lt;strong&gt;no side effects&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;It’s &lt;strong&gt;referentially transparent&lt;/strong&gt;: a call can be replaced by the output for the present input. It’s not necessary to execute the function to preserve the semantics of the program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Referential transparency is a simple and powerful concept: Can I replace this function call by its result without altering the program behaviour? Why? Can it be simplified? Would it be necessary to compute that function call every time? Could some results be memoized?&lt;/p&gt;

&lt;h2 id=&quot;declarative-programming&quot;&gt;Declarative programming&lt;/h2&gt;

&lt;p&gt;My Dutch uncle who is now retired and always worked very near developers told me:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I’ve heard that one of the problems in software development is that source code includes a lot of details and we should program at a higher abstraction level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I think it’s useful to explain this section.&lt;/p&gt;

&lt;p&gt;Functional programming is declarative: it doesn’t reveal details of implementation.&lt;/p&gt;

&lt;p&gt;For example, imagine that we have the following function:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and we want to know if an array only contains even numbers:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;onlyContainsEvenNumbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;onlyContainsEvenNumbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onlyContainsEvenNumbers&lt;/code&gt; function is an example of imperative programming: it includes a lot of details to indicate &lt;em&gt;how&lt;/em&gt; to get the goal.&lt;/p&gt;

&lt;p&gt;However, compare it with this alternative where an expression is used to describe what to get:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;every&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Following the pointfree style:&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;every&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If fewer details are given then: less prone to error and easier to read.&lt;/p&gt;

&lt;p&gt;In this case, less tests would be needed because the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;every&lt;/code&gt; function is known to work as expected.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: The &quot;point&quot; of &lt;strong&gt;pointfree style&lt;/strong&gt; is not &lt;code&gt;.&lt;/code&gt; but a point on a space. &lt;code&gt;f(x)&lt;/code&gt; can be read as &quot;the value of f at point x&quot;. So pointfree style consists on not specifying the parameters to avoid redundancy.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: The function &lt;code&gt;isEven&lt;/code&gt; is an example of &lt;strong&gt;predicate&lt;/strong&gt;, a function that returns a boolean value.
&lt;/div&gt;

&lt;h2 id=&quot;immutability&quot;&gt;Immutability&lt;/h2&gt;

&lt;p&gt;How many times have you seen a call that modifies the arguments when only an output is expected as a result of that call?&lt;/p&gt;

&lt;p&gt;What if the immutability is ensured?&lt;/p&gt;

&lt;p&gt;For example, we have a function to calculate the square:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and we want to calculate the array of squares from an array of numbers:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;calculateSquares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;calculateSquares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [4, 25, 64]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Not only a lot of details are given again but also the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers&lt;/code&gt; array is mutated to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[4, 25, 64]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, let’s see the following code:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [4, 25, 64]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case, we get the same result and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers&lt;/code&gt; array remains with the same content at the end.&lt;/p&gt;

&lt;p&gt;This is only an example. Immutability is pursued beyond arguments.&lt;/p&gt;

&lt;p&gt;The consequences of immutability are testable and parallelizable code.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: The &lt;code&gt;map&lt;/code&gt; function doesn't only return an array with the same type of items. It accepts a function from the original type to any type.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Moore's law established that the number of transistors on integrated circuits would double every two years. However, the limit was reached for the year 2002. Later, multicore processors appeared to keep the speed increases. Parallelizable code is the only way to take advantage of them.
&lt;/div&gt;

&lt;p&gt;On the other hand, we can find impure functions in JavaScript like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sort&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; 
&lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numbers&lt;/code&gt; array is mutated.&lt;/p&gt;

&lt;p&gt;That impure function could be wrapped into a pure function:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sortArray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;compareFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arrayCopy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arrayCopy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;compareFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sortArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In production code, I would think about these questions: Where do I need to sort an array? Do I have a lot of functions with an array as a parameter? Should I have to create a new data type?&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: However, programs usually change the &lt;em&gt;outside world&lt;/em&gt;. In that case, what if mutations are isolated in a specific part of the source code?
&lt;/div&gt;

&lt;h2 id=&quot;higher-order-functions&quot;&gt;Higher-order functions&lt;/h2&gt;

&lt;p&gt;In JavaScript, a function is a first-class citizen:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It can be the argument to another function.&lt;/li&gt;
  &lt;li&gt;It can be the output of another function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;higher-order function&lt;/strong&gt; is a function that takes another function as an argument or returns another function (or both).&lt;/p&gt;

&lt;p&gt;I included examples of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;every&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; so far. Let’s see examples with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reduce&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isEven&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [4, 2, 20]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 5&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Good habit: indicating an initial value&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The power of having functions as first-class citizens and creating higher-order functions promotes the separation of responsibilities and readability.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: When &lt;code&gt;reduce&lt;/code&gt; doesn't include an initial value (second parameter), the first item from the array is used as the initial value for the accumulator and skipped. In the included example, it's not necessary to indicate an initial value, because the first item can be used as the initial value and skipped. However, I talked about a &lt;em&gt;good habit&lt;/em&gt; to avoid problems with empty lists.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Some programming languages differentiate between &lt;code&gt;reduce&lt;/code&gt; (without providing an initial value) and &lt;code&gt;fold&lt;/code&gt; (providing an initial value). Others have just &lt;code&gt;fold&lt;/code&gt; for both options.
&lt;/div&gt;

&lt;h2 id=&quot;function-composition&quot;&gt;Function composition&lt;/h2&gt;

&lt;p&gt;Functions can be composed into a new one.&lt;/p&gt;

&lt;p&gt;When following the definition of composing two functions, the functions appear from right to left because the output of the first function is the input of the following one.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy/function_composition.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For example, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sumOfSquares&lt;/code&gt; function:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sumOfSquares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;sumOfSquares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, there are other two ways of composing functions where the functions appear from left to right: pipe or chain.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/functional-programming-sparks-joy/pipe.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For example, let’s see the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sumOfSquares&lt;/code&gt; function as a pipe:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sumOfSquares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Following the pointfree style:&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sumOfSquares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or as a chain:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;accum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sumOfSquares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: I only included examples of composing two functions for simplicity though there is no limit.
&lt;/div&gt;

&lt;h2 id=&quot;tail-recursive-functions&quot;&gt;Tail recursive functions&lt;/h2&gt;

&lt;p&gt;In functional programming, iteration is usually programmed with recursion so it’s important to control the growth of the call stack.&lt;/p&gt;

&lt;p&gt;How? Reusing the call frame instead of adding a new one.&lt;/p&gt;

&lt;p&gt;It’s known as &lt;strong&gt;tail call optimization&lt;/strong&gt; or &lt;strong&gt;proper tail calls&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Given a recursive function, that optimization is possible if it calls itself as its last action. That is, it’s a &lt;strong&gt;tail recursive function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see a &lt;strong&gt;non-&lt;/strong&gt;tail recursive function:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The stack trace for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;factorial(4)&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On the other hand, the same function as a &lt;strong&gt;tail recursive function&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The stack trace for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;factorial(4)&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s the reason why it’s possible to reuse the call frame: there is no need to remember the previous calls.&lt;/p&gt;

&lt;p&gt;However, the last &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;factorial&lt;/code&gt; function could be called with an argument for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;accumulator&lt;/code&gt; parameter from the beginning:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;WRONG_ARGUMENT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;WRONG_ARGUMENT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 120&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So let’s prevent that error and create an alternative with only one parameter and a &lt;strong&gt;closure&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;factorial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fact&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fact&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;accumulator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fact&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;currying&quot;&gt;Currying&lt;/h2&gt;

&lt;p&gt;Currying consists of converting a function with several parameters into nested unary functions (&lt;em&gt;unary&lt;/em&gt; = one parameter).&lt;/p&gt;

&lt;p&gt;For example, we have this function with two parameters:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`[&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;] &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ERROR&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Undefined variable&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;[ERROR] Undefined variable&quot;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;INFO&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;New post created&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// &quot;[INFO] New post created&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It could be transformed into two nested functions:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`[&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;] &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logError&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ERROR&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;INFO&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;logError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Undefined variable&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;[ERROR] Undefined variable&quot;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;logInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;New post created&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// &quot;[INFO] New post created&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice the improvement in readability: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logError&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logInfo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Moreover, the need of writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;ERROR&quot;&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;INFO&quot;&lt;/code&gt; every single time disappears.&lt;/p&gt;

&lt;p&gt;I tried to write my own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curry&lt;/code&gt; function to convert any function into those nested unary functions automatically. The original function can only be called when having all the arguments, so I needed to accumulate the arguments recursively (&lt;em&gt;arity&lt;/em&gt; = number of arguments expected by a function):&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;curry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_curry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; 
        &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arity&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_curry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_curry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Following the previous example:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`[&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;] &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;curriedLog&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;curry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logError&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;curriedLog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ERROR&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;curriedLog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;INFO&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;logError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Undefined variable&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;[ERROR] Undefined variable&quot;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;logInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;New post created&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// &quot;[INFO] New post created&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: My own version doesn't work like the &lt;code&gt;curry&lt;/code&gt; function that can be found in libraries such as Lodash or Ramda which add more capabilities.
&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: In languages such as Haskell or F#, all functions are considered curried.
&lt;/div&gt;

&lt;h2 id=&quot;partial-application&quot;&gt;Partial application&lt;/h2&gt;

&lt;p&gt;Partial application consists of doing a &lt;em&gt;projection&lt;/em&gt;: specifying only some arguments in function application, producing another function with the remaining parameters.&lt;/p&gt;

&lt;p&gt;For example, let’s play with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;partial&lt;/code&gt; function from Lodash, using an underscore for the unknown arguments:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;lodash&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;place&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;`Hello &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; from &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;place&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;! &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greetFromWonderland&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
    &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;partial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Wonderland&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greetFromWonderlandWithWish&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;partial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greetFromWonderland&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Have a good day!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;greetFromWonderlandWithWish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Mike&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Hello Mike from Wonderland! Have a good day!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;note&quot;&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Beyond the included examples, currying and partial application are useful to be able to compose functions.
&lt;/div&gt;

&lt;h2 id=&quot;another-mindset&quot;&gt;Another mindset&lt;/h2&gt;

&lt;p&gt;Last but not least, all of these things (and many more!) make us to think in a different way:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Fewer details. We program at a higher abstraction level.&lt;/li&gt;
  &lt;li&gt;It forces ourselves to separate responsibilities in building blocks and then to combine them.&lt;/li&gt;
  &lt;li&gt;Side effects under control. We are more aware of mutations.&lt;/li&gt;
  &lt;li&gt;I didn’t talk about functional data types but I could say that &lt;a href=&quot;http://wiki.c2.com/?PrimitiveObsession&quot;&gt;Primitive Obsession smell&lt;/a&gt; can be eradicated with this paradigm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new mindset is needed to embrace functional programming.&lt;/p&gt;

&lt;h2 id=&quot;vocabulary&quot;&gt;Vocabulary&lt;/h2&gt;

&lt;p&gt;Some words which weren’t used here although they can be useful to understand other articles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Domain&lt;/strong&gt;: Set of possible inputs to a given function.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Codomain&lt;/strong&gt;: Set of possible outputs to a given function (the prefix “co” is used to refer to the opposite).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total function&lt;/strong&gt; (vs. &lt;strong&gt;partial function&lt;/strong&gt;): It returns a valid output for every possible input. They are just known as &lt;strong&gt;functions&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Polymorphic function&lt;/strong&gt;: In functional programming, polymorphism is also known as &lt;strong&gt;parametric polymorphism&lt;/strong&gt;. A polymorphic function operates on values without depending on their type. It’s valid for any type.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;next-card&quot;&gt;Next card&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;/2019/08/20/functional-programming-sparks-joy-2.html&quot;&gt;Functional programming sparks joy 2&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;further-knowledge&quot;&gt;Further knowledge&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.gotw.ca/publications/concurrency-ddj.htm&quot;&gt;Post: The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software&lt;/a&gt; by Herb Sutter&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-PX0BV9hGZY&quot;&gt;Talk: Tail Call Optimization: The Musical!!&lt;/a&gt; by Anjana Vakil &amp;amp; Natalia Margolis&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=TScwxX62uig&quot;&gt;Talk (Spanish): Better types = fewer tests&lt;/a&gt; by Raúl Raja&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Up7LcbGZFuo&quot;&gt;Talk: Domain Modeling Made Functional&lt;/a&gt; by Scott Wlaschin&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf&quot;&gt;Article: Why Functional Programming Matters&lt;/a&gt; by John Hughes&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-337-functional-programming-is-deep/&quot;&gt;Reflection: Functional programming is deep&lt;/a&gt; by Eric Normand&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://magazines.pragprog.com/2012/pragpub-2012-08.pdf&quot;&gt;Articles: PragPub Magazine #38&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;p&gt;Special thanks to these old colleagues:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://twitter.com/panavtec&quot;&gt;Christian Panadero&lt;/a&gt; for giving me the first master classes about functional programming and category theory. They were the best &lt;em&gt;ice-breaker&lt;/em&gt; classes.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://twitter.com/CarlosMChica&quot;&gt;Carlos Morera de la Chica&lt;/a&gt; for being the best travel companion together with Christian during several editions of &lt;a href=&quot;http://www.lambda.world/&quot;&gt;Lambda World Conference&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://twitter.com/richardjwild&quot;&gt;Richard Wild&lt;/a&gt; for providing me a lot of reflection moments with his series about &lt;a href=&quot;https://codurance.com/2018/08/09/the-functional-style-part-1/&quot;&gt;The Functional Style&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And thanks to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://twitter.com/esebastian&quot;&gt;Eduardo Sebastian&lt;/a&gt; for his pull request to fix some typos.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Christophe Riolo Uusivaara&lt;/strong&gt; for his valuable feedback about &lt;em&gt;tail call optimization&lt;/em&gt;. It’s not only related to recursive functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;credit&quot;&gt;Credit&lt;/h2&gt;

&lt;p&gt;Image by &lt;a href=&quot;https://pixabay.com/users/asundermeier-448808/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=4075123&quot;&gt;Anke Sundermeier&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=4075123&quot;&gt;Pixabay&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="coding" /><summary type="html">Motivation</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/functional-programming-sparks-joy/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/functional-programming-sparks-joy/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The usefulness of small ‘crazy’ ideas</title><link href="https://rachelcarmena.github.io/2019/07/25/small-crazy-ideas.html" rel="alternate" type="text/html" title="The usefulness of small ‘crazy’ ideas" /><published>2019-07-25T12:00:00+00:00</published><updated>2019-07-25T12:00:00+00:00</updated><id>https://rachelcarmena.github.io/2019/07/25/small-crazy-ideas</id><content type="html" xml:base="https://rachelcarmena.github.io/2019/07/25/small-crazy-ideas.html">&lt;h2 id=&quot;space-invader&quot;&gt;Space invader&lt;/h2&gt;

&lt;p&gt;It wasn’t the first time I met someone who was worried about GitHub contributions panel.&lt;/p&gt;

&lt;p&gt;A friend of mine was too much worried about it. Too much… and my words weren’t useful.&lt;/p&gt;

&lt;p&gt;I needed to come up with something to make an impact on him.&lt;/p&gt;

&lt;p&gt;So I programmed &lt;a href=&quot;https://github.com/rachelcarmena/space-invader/blob/master/scripts/create-space-invader.sh&quot;&gt;a small script to create a space invader in an empty year&lt;/a&gt; or whatever he liked.&lt;/p&gt;

&lt;p&gt;For example, I have a space invader in 2016:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://github.com/rachelcarmena/space-invader/raw/master/img/space-invader-in-2016.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;See the full script and all the details in &lt;a href=&quot;https://github.com/rachelcarmena/space-invader&quot;&gt;Space Invader GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: It worked! It made him reflect.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: When sharing it in Twitter, someone mentioned this project: &lt;a href=&quot;https://github.com/gelstudios/gitfiti&quot;&gt;gitfiti&lt;/a&gt;. I didn't know it though I understand my idea wasn't unique. The goal is very similar although the way to get it is different and it's based on &lt;code&gt;GIT_COMMITTER_DATE&lt;/code&gt; to change the date. 
&lt;/div&gt;

&lt;h2 id=&quot;saying-goodbye-to-an-awesome-colleague&quot;&gt;Saying goodbye to an awesome colleague&lt;/h2&gt;

&lt;p&gt;A colleague was going to leave the company and he had been a very important person for all of us.&lt;/p&gt;

&lt;p&gt;I then created a Slack channel as a tribute to write all the things we had learnt from him.&lt;/p&gt;

&lt;p&gt;That Slack channel was very beautiful and I wanted him to have it forever.&lt;/p&gt;

&lt;p&gt;So I programmed this &lt;a href=&quot;https://github.com/rachelcarmena/small-tools/tree/master/SlackChannel2PDF&quot;&gt;small tool to create a PDF from a Slack channel&lt;/a&gt; based on Slack API and Latex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: He loved the idea.&lt;/p&gt;

&lt;h2 id=&quot;simulating-user-actions-from-the-web-console&quot;&gt;Simulating user actions from the Web Console&lt;/h2&gt;

&lt;p&gt;I was helping as an event organizer and it was necessary to schedule tens of tweets.&lt;/p&gt;

&lt;p&gt;I was added to Tweetdeck and I thought that I could simulate the user actions to schedule all the tweets after being logged in.&lt;/p&gt;

&lt;p&gt;So I opened the Web Console and I created this function to schedule a tweet at 10:30 by default:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;goToNextMonth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.tweet-button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.js-compose-text&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.js-compose-text&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dispatchEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;InputEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.js-schedule-button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#amPm&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// depends on the current time&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#scheduled-hour&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#scheduled-minute&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;goToNextMonth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#next-month&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;a[href='#&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;']:not(.caldisabled):not(.caloff)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.js-send-button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And then I only had to program a script to get a list as follows:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;21000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;24000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;33000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scheduleTweet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;36000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I wrote that list in the Web Console and after 3 seconds I saw how all the tweets were scheduled in the same way I was doing that work with the web interface (maybe it wasn’t necessary to wait for 3 seconds between them).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: I had all the tweets scheduled after a couple of minutes.&lt;/p&gt;

&lt;h2 id=&quot;beyond-post-it-notes&quot;&gt;Beyond post-it notes&lt;/h2&gt;

&lt;p&gt;I was going to join another team in a client as a software craftsperson (a mix between a developer and a technical coach). It was a special situation and I wished to have a good start.&lt;/p&gt;

&lt;p&gt;I organized a meeting a few days before joining as a first contact to meet each other. I wanted to know their concerns and wanted them to have an idea of all the things that we could get together.&lt;/p&gt;

&lt;p&gt;I tried to come up with something different to the use of post-it notes in order to have a pleasant meeting and to promote the participation.&lt;/p&gt;

&lt;p&gt;Why not to write the questions and the list of things I wanted to talk about in a long paper roll?&lt;/p&gt;

&lt;p&gt;Oh no, that’s a crazy idea!&lt;/p&gt;

&lt;p&gt;Why not?&lt;/p&gt;

&lt;p&gt;I didn’t have time to buy a paper roll so I made it from five Din A4 sheets of paper.&lt;/p&gt;

&lt;p&gt;I cut each sheet of paper in three pieces and I joined them with a little of adhesive transparent tape.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/small-crazy-ideas/making-of.png&quot; alt=&quot;Making of&quot; /&gt;&lt;/p&gt;

&lt;p&gt;My thoughts again. Oh no, that’s a crazy idea!&lt;/p&gt;

&lt;p&gt;Why not?&lt;/p&gt;

&lt;p&gt;I wrote all the things in the new paper roll, leaving room to take notes.&lt;/p&gt;

&lt;p&gt;I was ready for the meeting.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/small-crazy-ideas/roll.png&quot; alt=&quot;Roll&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And the time of the meeting arrived.&lt;/p&gt;

&lt;p&gt;I unrolled the paper.&lt;/p&gt;

&lt;p&gt;More than four meters of paper.&lt;/p&gt;

&lt;p&gt;Surprised looks.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/small-crazy-ideas/meeting-agenda.png&quot; alt=&quot;Unrolling during the meeting&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As we progressed on every issue, I cut the corresponding piece of paper.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/cards/posts/small-crazy-ideas/after-the-meeting.png&quot; alt=&quot;Roll after the meeting&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And I placed it in one of the two stacks of paper: done or to review (with additional notes).&lt;/p&gt;

&lt;p&gt;The paper roll was more and more short.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: There was an agreeable atmosphere during the meeting and I got a lot of information about the team and their concerns.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Corollary&lt;/strong&gt;: It's said that sometimes we create things from our memories. My maternal grandfather stored things from his old tailoring. A lot of paper rolls for the purchase receipts, among others. I played with those rolls a lot of times when I was a child.
&lt;/div&gt;</content><author><name></name></author><category term="[&quot;experiences&quot;, &quot;coding&quot;]" /><summary type="html">Space invader</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/small-crazy-ideas/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/small-crazy-ideas/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">RESTful thinking</title><link href="https://rachelcarmena.github.io/2019/07/23/restful-thinking.html" rel="alternate" type="text/html" title="RESTful thinking" /><published>2019-07-23T10:00:00+00:00</published><updated>2021-09-05T12:00:00+00:00</updated><id>https://rachelcarmena.github.io/2019/07/23/restful-thinking</id><content type="html" xml:base="https://rachelcarmena.github.io/2019/07/23/restful-thinking.html">&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;Working for (old) banking institutions was another world for me. I remember that the only way to integrate with their software systems was based on file transfer and it was necessary to agree on filenames, formats, directories, time schedules and dependencies.&lt;/p&gt;

&lt;p&gt;In other projects, the integration was based on the database (DB): sometimes sharing the same DB and other times synchronizing DBs.&lt;/p&gt;

&lt;p&gt;However, the most common way of integration was through SOAP services. We received a huge WSDL file and we used a tool to create the client from that file. Maybe I could say that it was a &lt;em&gt;smell&lt;/em&gt;: a lot of details in a single file and a tool to hide the complexity of creating a web service consumer.&lt;/p&gt;

&lt;p&gt;Then, I knew other two ways of integration which are still commonly used: RESTful services and messaging systems. Regarding the latter, I’m referring to message queues and message brokers (I write this clarification because web services also exchange messages).&lt;/p&gt;

&lt;p&gt;Nowadays, it seems that everybody uses RESTful services although SOAP services are still used in certain contexts for enterprise services.&lt;/p&gt;

&lt;p&gt;Despite that, is REST (Representational State Transfer) architectural style really known? Do the currently called RESTful services really use the power of the Web architecture?&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;I think that there are so many differences between SOAP and RESTful services that maybe they are not comparable.&lt;/p&gt;

&lt;p&gt;SOAP services expose stateful operations which implement some business logic. The contract is specified via WSDL, the message format is only XML, there isn’t a standard failure management and SOAP messages are only sent via HTTP POST, among others.&lt;/p&gt;

&lt;p&gt;On the other hand, RESTful services expose resources through data. Those data can be represented in several formats (not only XML) and they are exchanged through a stateless communication. These services can be consumed by any client in a lightweight way.&lt;/p&gt;

&lt;p&gt;In short, RESTful services follow the benefits of the Web architecture while SOAP services only use the transport protocol.&lt;/p&gt;

&lt;p&gt;Let’s see some characteristics of RESTful services.&lt;/p&gt;

&lt;h2 id=&quot;restful-web-services&quot;&gt;RESTful Web Services&lt;/h2&gt;

&lt;h3 id=&quot;stateless&quot;&gt;Stateless&lt;/h3&gt;

&lt;p&gt;The service provider and consumers exchange representations of &lt;strong&gt;resources&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The consumer includes all the information necessary to understand the request.&lt;/p&gt;

&lt;p&gt;The provider doesn’t answer with an explicit application state.&lt;/p&gt;

&lt;p&gt;This characteristic promotes the simplicity, low coupling and scalability.&lt;/p&gt;

&lt;h3 id=&quot;resources&quot;&gt;Resources&lt;/h3&gt;

&lt;p&gt;I mentioned &lt;strong&gt;resources&lt;/strong&gt;. What are they?&lt;/p&gt;

&lt;p&gt;According to Roy Thomas Fielding:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Any information that can be named can be a resource: a document or image, a temporal service (e.g. “today’s weather in Los Angeles”), a collection of other resources, a non-virtual object (e.g. a person), and so on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Mark Massé differentiates four resource archetypes: document (singular noun), collection (plural noun), store (plural noun) and controller (verb or verb phrase in lower camel case). The last one would be used for actions that don’t correspond with the known HTTP methods.&lt;/p&gt;

&lt;h3 id=&quot;intuitive-uris&quot;&gt;Intuitive URIs&lt;/h3&gt;

&lt;p&gt;URIs don’t encode operations. URIs identify resources and the purpose of a service can be inferred from the URI.&lt;/p&gt;

&lt;p&gt;Sometimes it’s interesting to pursue the opposite for security reasons. In that case it would be necessary to have a mapping between URIs and resource handlers. We’ll see a way to provide the semantic to a hard-to-guess URI later.&lt;/p&gt;

&lt;p&gt;On the other hand, URIs can be specified through templates as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://my-card-game.com/decks/{deck-id}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{deck-id}&lt;/code&gt; can be replaced by a deck identifier.&lt;/p&gt;

&lt;p&gt;It’s an easy way to understand, validate or create URIs.&lt;/p&gt;

&lt;h3 id=&quot;only-one-uri-for-identifying-a-resource-regardless-of-the-representation-format&quot;&gt;Only one URI for identifying a resource regardless of the representation format&lt;/h3&gt;

&lt;p&gt;URIs don’t have an extension according to the representation format of the resource. For example: .json for a JSON representation or .xml for a XML representation.&lt;/p&gt;

&lt;p&gt;A resource is identified by only one URI while the desired representation format or media type is indicated in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Accept&lt;/code&gt; request header.&lt;/p&gt;

&lt;p&gt;Following the example, it’d be used, respectively:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Accept: application/json&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Accept: application/xml&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;http-methods-as-actions&quot;&gt;HTTP methods as actions&lt;/h3&gt;

&lt;p&gt;Resources can be manipulated through HTTP methods as actions.&lt;/p&gt;

&lt;p&gt;We are responsible to keep the semantics of these HTTP methods according to the specification:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GET&lt;/strong&gt; for retrieving the details of a resource. &lt;strong&gt;The request message doesn’t include a body.&lt;/strong&gt; Use the query component of the URI (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt;) to include filters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;HEAD&lt;/strong&gt; when the consumer only wants to receive the HTTP headers. &lt;strong&gt;The request message doesn’t include a body.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OPTIONS&lt;/strong&gt; for checking which HTTP methods a resource supports.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DELETE&lt;/strong&gt; for deleting a resource.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PUT&lt;/strong&gt; for &lt;strong&gt;creating&lt;/strong&gt; a resource or &lt;strong&gt;updating&lt;/strong&gt; the state of a resource.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PATCH&lt;/strong&gt; is an alternative to &lt;strong&gt;PUT&lt;/strong&gt; in order to apply partial modifications to a resource. The PATCH method requests a set of changes (called “patch document”) on the resource identified by the Request-URI.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;POST&lt;/strong&gt;. Let’s see…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As Sam Ruby and Leonard Richardson wrote:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;POST is commonly used to create subordinate resources: resources that exist in relation to some other “parent” resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Why not use PUT to create those resources?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The difference between PUT and POST is this: the client uses PUT when it’s in charge of deciding which URI the new resource should have. The client uses POST when the &lt;em&gt;server&lt;/em&gt; is in charge of deciding which URI the new resource should have. (…) The POST method is a way of creating a new resource without the client having to know its exact URI. In most cases the client only needs to know the URI of a “parent” or “factory” resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In summary:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Create a new resource: HTTP PUT to a new URI, or HTTP POST to an existing URI.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Modify an existing resource: HTTP PUT to an existing URI.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, Amazon S3 API:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html&quot;&gt;PUT for creating a bucket&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html&quot;&gt;POST for adding an object to a bucket&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: There is a common misunderstanding about PUT and POST. In the wrong way, it's said: PUT for updating and POST for creating. Nowadays, when remembering that I made the same mistake, I don't understand the reason why it's easy to embrace that belief. There isn't a clear relationship between the meaning of the words &quot;put&quot;, &quot;update&quot;, &quot;post&quot; and &quot;create&quot;. Maybe our mind deceives us because of &lt;strong&gt;pu&lt;/strong&gt;t and &lt;strong&gt;up&lt;/strong&gt;date ;)
&lt;/div&gt;

&lt;p&gt;On the other hand, it’s our responsibility to meet the HTTP method properties according to the specification:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Safe&lt;/strong&gt;: If the defined semantic is essentially read-only and a state change on the server is not expected. The GET, HEAD and OPTIONS methods are safe.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Idempotent&lt;/strong&gt;: If the intended effect on the server of multiple identical requests is the same as the effect for a single request. The PUT, DELETE and safe request methods are idempotent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cacheable&lt;/strong&gt;: When responses to a method are allowed to be stored for reuse. Mainly GET and HEAD methods are cacheable.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: There is also a common misunderstanding about an idempotent HTTP method. It's focused on the intended effect on the server. That's the reason why GET is idempotent although multiple GETs of the same URI can generate a response with different data.
&lt;/div&gt;

&lt;h3 id=&quot;http-status-codes-as-response-codes&quot;&gt;HTTP status codes as response codes&lt;/h3&gt;

&lt;p&gt;It’s not necessary to define error types or error codes. HTTP status codes are used as response codes.&lt;/p&gt;

&lt;p&gt;Let’s see some of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Successful operations (2xx status codes):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;200 OK&lt;/strong&gt;: Nonspecific success.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;201 Created&lt;/strong&gt;: Successful resource creation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;202 Accepted&lt;/strong&gt;: It’s used for asynchronous operations. The server accepts the request and provides an URI to get the result later.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;204 No Content&lt;/strong&gt;: When the server has fulfilled the request but does not need to return a payload (PUT, POST or GET with an empty representation). It’s also used to indicate a successful response for a DELETE request. If the response must indicate the final state of the deleted resource: &lt;strong&gt;200 OK&lt;/strong&gt; and a full payload with the resource representation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Errors on the client side (4xx status codes):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;400 Bad Request&lt;/strong&gt;: It’s used when returning the payload with the same received data plus a comment about the reason why it’s a bad request.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;401 Unauthorized&lt;/strong&gt;: If there is an issue with the client’s credentials (wrong or missing).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;403 Forbidden&lt;/strong&gt;: When the access is not allowed regardless of the right credentials.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;404 Not Found&lt;/strong&gt;: When the client requests a resource that doesn’t exist. It’s also used in some responses in order not to give too many details to consumers when thinking about security.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;405 Method Not Allowed&lt;/strong&gt;: The response must include the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Allow&lt;/code&gt; header in order to know which HTTP action or actions are allowed.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;409 Conflict&lt;/strong&gt;: For example, a requested update cannot be executed.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;411 Length Required&lt;/strong&gt;: If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Length&lt;/code&gt; header in a request is missing, the service cannot determine if it’s a huge payload to cause a DoS attack.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Errors on the server side (5xx status codes):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;500 Internal Server Error&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;503 Service Unavailable&lt;/strong&gt;: It’s used with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Retry-After&lt;/code&gt; header.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTTP status codes are useful to manage situations as a change of a resource URI. In that case, it can be communicated when sending the HTTP status code &lt;strong&gt;301 Moved Permanently&lt;/strong&gt; or &lt;strong&gt;303 See Other&lt;/strong&gt; in the response (3xx status codes = redirection).&lt;/p&gt;

&lt;h3 id=&quot;entity-tag-value-for-managing-the-changes-of-the-state-of-a-resource-over-its-lifetime&quot;&gt;Entity tag value for managing the changes of the state of a resource over its lifetime&lt;/h3&gt;

&lt;p&gt;The server can associate a string token with a certain state of a resource (like a version number): an entity tag value which will appear in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ETag&lt;/code&gt; header of a response.&lt;/p&gt;

&lt;p&gt;Then, the client can indicate that entity tag value in a request header to condition the request to a particular state of the resource.&lt;/p&gt;

&lt;p&gt;The conditional request headers are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;If-Match: &amp;lt;entity_tag_value&amp;gt;&lt;/code&gt; = apply the request if the resource hasn’t changed since the last received representation&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;If-None-Match: &amp;lt;entity_tag_value&amp;gt;&lt;/code&gt; = apply the request if the resource has changed since the last received representation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other uses:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;If-Match: *&lt;/code&gt; = apply the request if the resource exists&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;If-None-Match: *&lt;/code&gt; = apply the request if the resource doesn’t exist&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A related HTTP status code: &lt;strong&gt;412 Precondition Failed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Services perform less computation because they know the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ETag&lt;/code&gt; to execute the request. Higher response time from services.&lt;/li&gt;
  &lt;li&gt;Avoiding errors because of managing an out-of-sync resource.&lt;/li&gt;
  &lt;li&gt;It may be cheaper for a service to compare &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ETag&lt;/code&gt; values rather than to generate a representation.&lt;/li&gt;
  &lt;li&gt;Preventing race conditions between clients.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disadvantages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The generation of the entity tag value in the server can be computationally expensive. It’s important to select a cheap way to generate it from the state of the resource and to be unique.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;beyond-crud-services&quot;&gt;Beyond CRUD services&lt;/h3&gt;

&lt;p&gt;As URIs identify resources, there is a trend to create CRUD services. In that case, there is a high coupling with consumers as well as the services are like an interface to operate with the DB.&lt;/p&gt;

&lt;p&gt;Let’s go beyond…&lt;/p&gt;

&lt;h3 id=&quot;links-in-the-resource-state-representation&quot;&gt;Links in the resource state representation&lt;/h3&gt;

&lt;p&gt;Resource state representation can include links to related resources or next business steps.&lt;/p&gt;

&lt;p&gt;This is the basis of &lt;strong&gt;HATEOAS&lt;/strong&gt; (Hypermedia As The Engine Of Application State) from REST architectural style.&lt;/p&gt;

&lt;p&gt;The consumer receives a resource representation with links and one of them will be chosen as the next step.&lt;/p&gt;

&lt;p&gt;In this way, we can model state transitions or business processes when transiting links between resources.&lt;/p&gt;

&lt;p&gt;The consumer doesn’t have to depend on a big number of static URI templates or contracts. It’s enough with a few URIs that act as entry points.&lt;/p&gt;

&lt;p&gt;Therefore, the provider can evolve the internal business rules more easily.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Although we are used to representing relations between entities through identifiers (think about the foreign key in a database), we don't use identifiers but URIs to address the related resources in the resource representation. If we use identifiers, the consumer would have to know how to build the URI of the related resource and it's better if that knowledge is retained in the service provider.
&lt;/div&gt;

&lt;h4 id=&quot;one-step-further&quot;&gt;One step further&lt;/h4&gt;

&lt;p&gt;If we are using a JSON representation, an example of link could follow this format:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nl&quot;&gt;&quot;link&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;uri&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;rel&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The URI is together with another link, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rel&lt;/code&gt; attribute, where there is information about the meaning or purpose of the link.&lt;/p&gt;

&lt;p&gt;How could that information be understood by machines? How could computer-to-computer interactions be possible without the need of a human interaction to interpret and to consume it?&lt;/p&gt;

&lt;p&gt;That’s one of the goals of Semantic Web Technology, machine learning, machine-processable formats, directed labeled graphs, ontontologies to represent knowledge, etc.&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Links can also be used to split the resource representation into different parts. The decisions about which data to show in the representation and which data will be obtained when following a link are based on the size of the payload, performance and cacheability, among others.
&lt;/div&gt;

&lt;h2 id=&quot;other-things&quot;&gt;Other things&lt;/h2&gt;

&lt;h3 id=&quot;security&quot;&gt;Security&lt;/h3&gt;

&lt;p&gt;HTTPS provides &lt;strong&gt;confidentiality&lt;/strong&gt; and &lt;strong&gt;integrity&lt;/strong&gt; on the transport layer. Besides that, we need authentication and authorization management:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Authentication&lt;/strong&gt; to identify the consumer (for example, OpenID).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authorization&lt;/strong&gt; to control what a consumer can do (for example, OAuth).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;postels-law&quot;&gt;Postel’s Law&lt;/h3&gt;

&lt;p&gt;It’s said that it’s followed by robust services:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Be conservative in what you do; be liberal in what you accept from others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words: be strict about the generated resource representations in responses, be permissive about the received representations in requests.&lt;/p&gt;

&lt;p&gt;This law made me think a lot and I don’t know if that lesson is really useful in all cases. I’m thinking about browsers that render content although it’s wrong (lack of ending tags, lack of accessibility data, etc) or, in general, standards that are not followed.&lt;/p&gt;

&lt;p&gt;Maybe that permissiveness is helping us to progress very quickly though we are accumulating debt because of it.&lt;/p&gt;

&lt;p&gt;I remember when my old colleague &lt;a href=&quot;https://twitter.com/ertorser&quot;&gt;Erik Torres&lt;/a&gt; talked about &lt;strong&gt;responsible&lt;/strong&gt; freedom.&lt;/p&gt;

&lt;p&gt;Lots of thoughts…&lt;/p&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Update&lt;/strong&gt;: I think my reflection here addressed a different personal concern with the lack of constraints. This law is useful for robustness when preventing breaking changes.
&lt;/div&gt;

&lt;h2 id=&quot;resources-1&quot;&gt;Resources&lt;/h2&gt;

&lt;h3 id=&quot;specifications&quot;&gt;Specifications&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc7231&quot;&gt;Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc5789&quot;&gt;PATCH Method for HTTP&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc7233&quot;&gt;Hypertext Transfer Protocol (HTTP/1.1): Range Requests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.iana.org/assignments/media-types/&quot;&gt;Standard list of media types&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;api-documentation&quot;&gt;API documentation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.openapis.org&quot;&gt;OpenAPI Specification (OAS) based on the Swagger 2.0 specification&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://raml.org&quot;&gt;RESTful API Modeling Language (RAML)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;initiatives&quot;&gt;Initiatives&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://apistylebook.com&quot;&gt;API Style Book&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.crummy.com/writing/speaking/2008-QCon/act3.html&quot;&gt;Richardson Maturity Model (RMM)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.programmableweb.com/category/all/apis&quot;&gt;API Directory&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://restcookbook.com&quot;&gt;The RESTful cookbook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tools&quot;&gt;Tools&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://openapi.tools/&quot;&gt;OpenAPI Tools&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://curl.haxx.se/docs/httpscripting.html&quot;&gt;Using curl to automate HTTP jobs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.getpostman.com&quot;&gt;Postman API Development Environment&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.pact.io&quot;&gt;Pact — Consumer-driven contract testing Tool&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://dredd.org&quot;&gt;Dredd — HTTP API Testing Framework&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;note&quot;&gt;
&lt;strong&gt;Note&lt;/strong&gt;: The use of API or Web API doesn't refer only to those which conform to the REST architectural style (RESTful APIs).
&lt;/div&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm&quot;&gt;Paper: Architectural Styles and the Design of Network-based Software Architectures&lt;/a&gt; by Roy Thomas Fielding&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.enterpriseintegrationpatterns.com&quot;&gt;Book: Enterprise Integration Patterns&lt;/a&gt; by Gregor Hohpe and Bobby Woolf&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://shop.oreilly.com/product/9780596529260.do&quot;&gt;Book: RESTful Web Services&lt;/a&gt; by Sam Ruby and Leonard Richardson&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://shop.oreilly.com/product/9780596805838.do&quot;&gt;Book: REST in practice: Hypermedia and Systems Architecture&lt;/a&gt; by Jim Webber, Savas Parastatidis and Ian Robinson&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.oreilly.com/library/view/rest-api-design/9781449317904/&quot;&gt;Book: REST API Design Rulebook&lt;/a&gt; by Mark Massé&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.slideshare.net/raquelmorenocarmena/whats-the-origin-of-rest-architectural-style&quot;&gt;Slides: What’s the origin of REST architectural style?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/2021/08/10/confused-am-i.html&quot;&gt;Post: Confused am I&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="coding" /><summary type="html">Motivation</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/restful-thinking/cover.jpg%22%7D" /><media:content medium="image" url="https://rachelcarmena.github.io/%7B%22src%22=%3E%22/img/cards/posts/restful-thinking/cover.jpg%22%7D" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>