<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henrique Gonçalves Galvão</title>
    <description>The latest articles on DEV Community by Henrique Gonçalves Galvão (@hgalvao).</description>
    <link>https://dev.to/hgalvao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1290007%2Ff2c210d2-762c-425b-b782-5a42ede26ce1.jpeg</url>
      <title>DEV Community: Henrique Gonçalves Galvão</title>
      <link>https://dev.to/hgalvao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hgalvao"/>
    <language>en</language>
    <item>
      <title>What I got from Clean Architecture as a FE... (6-11)</title>
      <dc:creator>Henrique Gonçalves Galvão</dc:creator>
      <pubDate>Mon, 04 Mar 2024 16:44:24 +0000</pubDate>
      <link>https://dev.to/hgalvao/what-i-got-from-clean-architecture-as-a-fe-6-11-4bo0</link>
      <guid>https://dev.to/hgalvao/what-i-got-from-clean-architecture-as-a-fe-6-11-4bo0</guid>
      <description>&lt;p&gt;Let's continue! In this post I will keep summarizing what I'm understanding while reading the book Clean Architecture by Robert C. Martin. If you missed the first one (Chapters 1-5), &lt;a href="https://dev.to/hgalvao/what-i-got-from-clean-architecture-as-a-fe-1-5-4lng"&gt;click here.&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 6 - Functional Programming
&lt;/h2&gt;

&lt;p&gt;In this chapter Uncle Bob talks about functional programming following the topics: Structured Programming and OOP. He mentions that in functional programming, variables are immutable, meaning that to be able to make it "functional" it is necessary to have a good amount of memory and a powerful processor. Why? Because in functional programming, since it is immutable, the state doesn't change. However, the program keeps track of the modifications. Think of a bank statement, instead of changing state whenever there is a withdraw or a deposit, we keep track of the modifications and whenever an updated state is requested, we make the calculations returning a new variable with a new state of the final value. Make sense? I don't know, to be completely honest I never heard about this. Or have I?&lt;/p&gt;

&lt;p&gt;I know this will be a big summary but it is important to mention that in Javascript, functional programming refers to the use of pure functions, immutability, and higher-order functions to create programs that are more predictable and easier to reason about.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 7 - SRP: Single Responsiblity Principle
&lt;/h2&gt;

&lt;p&gt;In this chapter we start reading more about SOLID. The 5 principles of SOLID are Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segragation Principle, and Dependency Inversion Principle.&lt;/p&gt;

&lt;p&gt;The first, is always confused with "a function should only do one thing", meaning it should only have one responsibility. I was one to think that too. However, in this chapter, the author explains that actually, a function should affect only one "actor" &lt;/p&gt;

&lt;p&gt;Single Responsibility: A class should have one and only one reason to change. This means that the class should encapsulate one aspect of functionality that might change for only one reason.&lt;/p&gt;

&lt;p&gt;"Actor" Focus: When considering responsibility, think about who or what might be affected by changes in the behavior of the class. Each class should serve a single actor or a cohesive group of actors.&lt;/p&gt;

&lt;p&gt;I like the explanation the author uses of a company using the same class to calculate hourly wage, report hours and save hours. Each of these can be assigned to different "actors" for example, CFO, COO, and CTO respectively.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 8 - OCP: Open-Closed Principle
&lt;/h2&gt;

&lt;p&gt;In chapter 8, the author mentions that the Open-Closed Principle refers to a class or function being open to extension but closed to modification. This is done by trying to modify the function as little as possible while separating concerns. This helps assure that a high level function is not impacted by low level functions. &lt;/p&gt;

&lt;p&gt;In React, we can think about componentization, where apps can be build using components that are extendable. HOCs allows you to extend, add or modify without altering the original component. Even using life-cycle methods is a way of thinking about the OCP. They allow you to hook into the lifecycle of a component without modifying its implementation. You can extend the behavior of a component by subclassing it and overriding these methods.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 9 - LSP: Liskov Substitution Principle
&lt;/h2&gt;

&lt;p&gt;Objects of a superclass should be replaceable with objects of its subclasses without breaking the application. That is it. In React, think about that components wrapped by HOCs should behave like the base component. So whenever a component uses another component, it shouldn’t break its functionality (or create any surprises).&lt;/p&gt;

&lt;p&gt;This principle, for React devs (at least for me), seems like the most complicated one to make sense. However, if you think about the use of typescript, things should make a little more sense. Lets pretend you have a modal that accepts a child (which in most cases should be a JSX component). Without using TS, we can pass a object as that child and the component or the code won't break, but we will get an error in our browser... why? Because React works like that and it wants to receive (and only can) a JSX component or a string. Using TS, and typing that child to be a JSX component, no unexpected behavior will occur. &lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 10 - ISP: Interface Segregation Principle
&lt;/h2&gt;

&lt;p&gt;From my understanding, ISP is very dependable on the language, and if it is typed. However, to summarized, thinking about React, imagine that you have a child component keeps causing the parent to rerender when it shouldn't, this is basically what ISP tries to prevent. ISP refers to not have unused or useless code causing effects on its dependents. &lt;/p&gt;

&lt;p&gt;Keeping interfaces focused and minimal reduces the likelihood of unintended side effects, promotes better encapsulation, and makes components easier to understand and reason about.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 11 - DIP: Dependency Inversion Principle
&lt;/h2&gt;

&lt;p&gt;In this chapter we get to know more about Dependency Inversion Principle (DIP). We can say that for DIP, high-level components don't directly depend on low-level components. Instead, both should rely on abstractions, like props or context, to foster flexibility and maintainability.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>What I got from Clean Architecture as a FE... (1-5)</title>
      <dc:creator>Henrique Gonçalves Galvão</dc:creator>
      <pubDate>Fri, 23 Feb 2024 12:51:38 +0000</pubDate>
      <link>https://dev.to/hgalvao/what-i-got-from-clean-architecture-as-a-fe-1-5-4lng</link>
      <guid>https://dev.to/hgalvao/what-i-got-from-clean-architecture-as-a-fe-1-5-4lng</guid>
      <description>&lt;p&gt;I decided to start writing about my reading experiences. I have tried to pick up the habit of reading for a while and I decided that since my goal is to become a better dev, I will read and document software development books.&lt;/p&gt;

&lt;p&gt;To give context, I am a Frontend Developer with more than 3 years of experience. I am one of those bootcamp developers. However, since the beginning, I tried to keep up with the content that is clearly missing from those bootcamps.&lt;/p&gt;

&lt;p&gt;How is this going to work... I will try to write here what I am understanding from each chapter of this book by Robert C. Martin. Keep in mind, this is something I am doing for myself. However, if you want to comment on this with your thoughts, questions or tips on better understanding this book, feel free!&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 1 - What is design and architecture?
&lt;/h2&gt;

&lt;p&gt;The first chapter, he compares design and architecture to conclude that they are the same. He makes sure to emphasize the importance of a good design and architecture of a software. Furthermore, he continues to say that without quality, performance will dramatically decrease. He uses the story from the rabbit and the turtle to explain why over confidence and coding in a rush is always a bad choice. &lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 2 - A tale of two values
&lt;/h2&gt;

&lt;p&gt;In the second chapter, Uncle Bob talks about two main values of a software, the functionality/how it works, and the architecture. He proceeds saying that most developers and tech workers tend to forget about the most important one, which is architecture, to focus on the other. We all know how it is &lt;em&gt;"if it works, don't touch it"&lt;/em&gt;. However, developing a software like this will have many implications. A good architecture permits that changes and improvements can be made to the software without impactful additional costs. He adds that the Eisenhower's matrix can be used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzljzk7pfrweccn21bjf0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzljzk7pfrweccn21bjf0.png" alt="Image description" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While architecture is both urgent and important, functionality tends to be "just" urgent...&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 3 - Paradigm Overview
&lt;/h2&gt;

&lt;p&gt;In chapter three, the differences between the three paradigms (Structured Programming, Object-Oriented Programming, and Functional Programming) get overly summarized, but with the purpose to conclude that they are all important for software architecture.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 4 - Structured Programming
&lt;/h2&gt;

&lt;p&gt;In this chapter, Uncle Bob talks about how the structured programming was proved useful. In general, he mentions that structured programming is basically separating concerns or practicing functional decomposing, which is separating big things into small modules so they are "testable". (Will have to read more about this)&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 5 - Object-Oriented Programming
&lt;/h2&gt;

&lt;p&gt;Reading chapter 5 from the perspective of a Javascript/Typescript developer, can be challenging if you have no previous experience working with classes (Why learn them if we can just "rfce" on VSCode and create our functional components, right?). However, the author gives a brief explanation of the three principles related to OOP. One is encapsulation. &lt;strong&gt;Encapsulation&lt;/strong&gt; is the method of bundling data and functions inside an object. Encapsulation helps hiding internal state of such object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;speedIncrement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;speedIncrement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;brake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;speedDecrement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;speedDecrement&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="nx"&gt;speedDecrement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;getSpeed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, while you can view the properties, they can only be controlled through 'accelarate', 'break', and 'getSpeed'.&lt;/p&gt;

&lt;p&gt;The second principle is &lt;strong&gt;inheritance&lt;/strong&gt;, which by the name should be simple to figure out. This is a mechanism that a class inherits properties and methods from other classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; makes a noise.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; barks.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Last principle is Polymorphism, considered to be the most important one. Polymorphism allows objects of different classes to be treated as objects of a common superclass. This relates to inheritance, however in the example below we can see polymorphism with the method &lt;em&gt;makeSound()&lt;/em&gt; as it behaves differently based on the type of animal object it is called upon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Some generic sound&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Woof&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Meow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will end this first portion here. Next time I will go from Chapter 6 until Chapter 10. This book has 34 chapters, let's see if I will be a better architect by then...&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>unclebob</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
