<?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: Gustavo Gomes</title>
    <description>The latest articles on DEV Community by Gustavo Gomes (@gustavogomesdev).</description>
    <link>https://dev.to/gustavogomesdev</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%2F790711%2F772afec0-d15c-4bab-909d-8309c23f59d4.png</url>
      <title>DEV Community: Gustavo Gomes</title>
      <link>https://dev.to/gustavogomesdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gustavogomesdev"/>
    <language>en</language>
    <item>
      <title>Functional Programming with Javascript</title>
      <dc:creator>Gustavo Gomes</dc:creator>
      <pubDate>Mon, 12 Jun 2023 23:51:26 +0000</pubDate>
      <link>https://dev.to/gustavogomesdev/functional-programming-with-javascript-4jk7</link>
      <guid>https://dev.to/gustavogomesdev/functional-programming-with-javascript-4jk7</guid>
      <description>&lt;h2&gt;
  
  
  What is Functional Programming ?
&lt;/h2&gt;

&lt;p&gt;Functional Programming is a programming paradigm, where functions reign. Function programming is also a coding styles, code organization, code writing and a project approach style. Also is a mindset type that you can use, a way of thinking about a problem, a way to solve a task. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Functional Programming Javascript ?
&lt;/h2&gt;

&lt;p&gt;Safer, easier to debug and maintain. To help us write the Javascript function there are several libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can you do that ?
&lt;/h2&gt;

&lt;p&gt;So, the main thing and maybe it seems obvious is that you want to do everything using functions, so we want express everything in our program in functions terms. And a function, of course, is just something that takes an input and returns an output. So, we want thinking about the type of flow of datas of input and output of program, instead of thinking about objects and how they interact and how they handle or think about steps in a recipe as in an imperative style, here we are really thinking about how you express everything in functions terms, get input's, return output's. &lt;/p&gt;

&lt;h2&gt;
  
  
  Exemple
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Not functional:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name = "Gustavo";
var greeting = "Hi, i'm ";
console.log(greeting + name);

=&amp;gt; "Hi, i'm Gustavo"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the example above i could specify a variable, I call it "name" and make it store the text "Gustavo", i could have a greeting with "Hi, i'm" or "Hello, i'm", whatever and then i could log that to the console. This is sort of an imperative style, first do this then do that then do this other thing we don't have function, here we're not expressing this in terms of how inputs transformed into outputs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Functional&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name) {
    return "Hi, i'm" + name;
}
greet("Gustavo");

=&amp;gt; "Hi, i'm Gustavo"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So maybe a more functional way of doing the same thing and this is a really simples example just for the sake of it is to define a function called greet which takes a parameter name and returns a string which adds "Hi, i'm ". If I pass the name Maria as input, I get the output "Hi i'm Maria". &lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid side effects
&lt;/h2&gt;

&lt;p&gt;So, the main thing  about functional programming is avoid side effects, and what is side effects ? Is when a function relies on, or modifies, something outside its parameters to do something, for exemple, If you have a function that use some globally defined variable to calculate its output that does not depend  just of input for this function, so this does not is pure, is to take something from outside the function and wrap it in some way. So this is just a explanation very simple and fast about side effects. &lt;br&gt;
The goal is for your function to do nothing except take its input and use that to compute an output and after returned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Side effects example
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Function with side effects (Not pure)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name = "Gustavo"; 
function greet() {
    console.log("Hi, i'm" + name)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example we have a name variable that is defined global that is used in function, how you can you see. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Correct function (Pure)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name) {
    return "Hi, i'm" + name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example the only thing that matters for this function is its input, and the only thing she does is return her exit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Think in the pure possible way
&lt;/h2&gt;

&lt;p&gt;One of the main parts of functional programming is thinking about things as pure as possible. &lt;/p&gt;

&lt;p&gt;Thanks so much for getting here, this is a simple article about Functional Programming. In the next articles I will talk about "Use higher-order function" and "Data Structures" in functional programming with javascript of course.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Setup your env to start working w/ the blockchain</title>
      <dc:creator>Gustavo Gomes</dc:creator>
      <pubDate>Tue, 11 Jan 2022 23:08:03 +0000</pubDate>
      <link>https://dev.to/gustavogomesdev/configuring-your-machine-to-work-with-ethereum-smart-contracts-1h04</link>
      <guid>https://dev.to/gustavogomesdev/configuring-your-machine-to-work-with-ethereum-smart-contracts-1h04</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First you'll need to get node/npm. If you don't have it click &lt;a href="https://hardhat.org/tutorial/setting-up-the-environment.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;br&gt;
Warning: Recommend you install at least node v15.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now go to the terminal and type the following commands:&lt;br&gt;
Warning: Do not use the GitBash terminal&lt;br&gt;
&lt;code&gt;mkdir my-first-smart-contract&lt;/code&gt;&lt;br&gt;
&lt;code&gt;cd my-first-smart-contract&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm init -y&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm install --save-dev hardhat&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now let's install the Hardhat with the command: &lt;br&gt;
&lt;code&gt;npx hardhat&lt;/code&gt;&lt;br&gt;
Warning: In case od error, use this command: &lt;code&gt;yarn add hardhat&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the option create a sample project and agree with all the questions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The sample project will ask you to install hardhat-waffle and hardhat-ethers. Install the dependencies with the command:&lt;br&gt;
&lt;code&gt;npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After that, you will run the command: &lt;code&gt;npx hardhat accounts&lt;/code&gt; and it should print a lot of addresses like this: &lt;br&gt;
&lt;code&gt;0xa0Ee7A142d267C1f36714E4a8F75612F20a79720&lt;/code&gt;&lt;br&gt;
These are addresses that Hardhat generates to simulate users on the Blockchain. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After that we will see if everything is working, run the command: &lt;br&gt;
&lt;code&gt;npx hardhat compile&lt;/code&gt;&lt;br&gt;
Then this command: &lt;br&gt;
&lt;code&gt;npx hardhat test&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once this is done, you will see something like this: &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0o6lmzbvs2cwe5de69g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0o6lmzbvs2cwe5de69g.png" alt="Image description" width="520" height="145"&gt;&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it, your project is  configured to create Smart Contracts with Ethereum! 🎉🎉&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
