<?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: James Macapagal</title>
    <description>The latest articles on DEV Community by James Macapagal (@jmacapagal90).</description>
    <link>https://dev.to/jmacapagal90</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%2F863382%2F7b23bb9d-0412-4dfe-ba93-d43d4a2e1699.jpg</url>
      <title>DEV Community: James Macapagal</title>
      <link>https://dev.to/jmacapagal90</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jmacapagal90"/>
    <language>en</language>
    <item>
      <title>Understanding LeetCode Problem #1672: Richest Customer Wealth (JavaScript)</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Mon, 24 Oct 2022 22:51:27 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/understanding-leetcode-problem-1672-richest-customer-wealth-javascript-2i0e</link>
      <guid>https://dev.to/jmacapagal90/understanding-leetcode-problem-1672-richest-customer-wealth-javascript-2i0e</guid>
      <description>&lt;p&gt;Hey y'all!  &lt;/p&gt;

&lt;p&gt;I've been grinding LeetCode lately in preparation for Technical Interviews, and I wanted to walkthrough a solution to an algorithm that I was able to discover. &lt;/p&gt;

&lt;h1&gt;
  
  
  Algorithm
&lt;/h1&gt;

&lt;p&gt;First off, here's a screen shot of the algorithm, &lt;a href="https://dev.to/problems/richest-customer-wealth/"&gt;Richest Customer Wealth&lt;/a&gt;. &lt;/p&gt;

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

&lt;h1&gt;
  
  
  1) Talk To Yourself
&lt;/h1&gt;

&lt;p&gt;First off, in any algorithm, take a step back and ask yourself what this algorithm is &lt;em&gt;actually&lt;/em&gt; trying to solve. &lt;/p&gt;

&lt;p&gt;Take the time to speak the problem into existence, out loud, and with intent.  Yes, even in a live/coding interview! &lt;/p&gt;

&lt;p&gt;You want to showcase your ability to verbalize code, talk through it, and also indicate you didn't just memorize this (even if you maybe did ;) )&lt;/p&gt;

&lt;p&gt;Start by asking yourself: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How would I phrase this in my own words? &lt;/li&gt;
&lt;li&gt;What data or information do I know I have?&lt;/li&gt;
&lt;li&gt;What is this problem &lt;em&gt;actually&lt;/em&gt; asking me to do?
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's break down the prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are given an &lt;code&gt;m x n&lt;/code&gt; integer grid accounts where &lt;code&gt;accounts[i][j]&lt;/code&gt; is the amount of money the &lt;code&gt;i&lt;/code&gt;​​​​​​​​​​​th​​​​ customer has in the &lt;code&gt;j&lt;/code&gt;​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has.&lt;/p&gt;

&lt;p&gt;A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's a rough recreation of my own thought process: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;gt; Ok... wait, why do rich people need... ok... focus James... Ok.. Sounds like we have arrays... which could have other arrays in it... array all day amirite...focus james... and these bougie peeps, i mean banks, are asking me to find how much cheese is in their bougie peeps accounts... ahem... what's the total amount of money in each of those accounts which are those arrays... and then find out who got the most cheese... i mean moneys... i mean the maximum value...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;(End scene... sorry, we like to have fun here...amirite?)&lt;/p&gt;

&lt;h1&gt;
  
  
  Speak and it shall be known
&lt;/h1&gt;

&lt;p&gt;Just from speaking it into existence, a whole world of solutions open up for us.  &lt;/p&gt;

&lt;p&gt;Off the bat, we know:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. We are dealing with Arrays.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Which is great because maybe now we can use built-in Array methods and/or solutions that Arrays give us by default (at least thanks in Javascript). At the very least, we know we are dealing with arrays. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. We need to count that paper.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We know we need to find the sum of a numbers in an array. My first thought is a &lt;code&gt;reduce&lt;/code&gt; method or some sort of &lt;code&gt;for&lt;/code&gt; loop where we are simply taking the sum of all the elements of the array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. We need to find who got the most paper&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Aka, we need to fine the maximum number of those sums. So, if I can get those sums, I know that there's this &lt;code&gt;Math.max()&lt;/code&gt; method that JavaScript gives me that I could use which can be used on numbers... and also... arrays! #ArrayAllDay&lt;/p&gt;

&lt;p&gt;And I haven't even touched my keyboard yet.  I simply am planning my strategy and solution before I start. &lt;/p&gt;

&lt;p&gt;But from taking this quick few minutes to breathe, think, and evaluate, I already know what I probably need to do: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find a way to get the sum of the baby arrays within the big mama array (arrayception). &lt;/li&gt;
&lt;li&gt;Put those totals into another array (papa array). &lt;/li&gt;
&lt;li&gt;Find and return the maximum value of those totals (stack that cheese). &lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Jesse, Let's Code
&lt;/h1&gt;

&lt;p&gt;Ok, so the part we all want to do. The coding.  &lt;/p&gt;

&lt;p&gt;I'm going to start with my solution and walk through it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var maximumWealth = function(accounts) {
    let wealthArr = []
    accounts.forEach((account) =&amp;gt; {wealthArr.push(account.reduce((a,b)=&amp;gt; a+b,0))})
    return Math.max(...wealthArr)

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

&lt;/div&gt;



&lt;p&gt;First, I initialize an empty array.  I know I'm going to need an array to help me keep track of all the totals I'm going to sum.  &lt;/p&gt;

&lt;p&gt;Second, I use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="noopener noreferrer"&gt;&lt;code&gt;forEach&lt;/code&gt; method&lt;/a&gt;. If you're not familiar with it, I highly recommend reviewing the method (and all Array methods), as I find them extremely helpful.  &lt;/p&gt;

&lt;p&gt;While I could go on, the TL;DR is it is basically a shortcut for a &lt;code&gt;for loop&lt;/code&gt;.  In humanspeak, for each element of the array, I want to do something.   &lt;/p&gt;

&lt;p&gt;Within the context of my algorithm, "for each" account within the "accounts" array, I am going to perform a function. Each account is the individual array of the account. &lt;/p&gt;

&lt;p&gt;Which leads me to my function inside my &lt;code&gt;forEach&lt;/code&gt;: a &lt;code&gt;push&lt;/code&gt; method which is pushing a &lt;code&gt;reduce&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;First, we are going to start "pushing" elements into my empty wealth array (&lt;code&gt;wealthArr&lt;/code&gt;) with the &lt;code&gt;push&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;Inside of the push method, I am using a &lt;code&gt;reduce&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;Again, if you're unfamiliar, I highly, highly recommend reviewing the Javascript Array methods first.  But, TL;DR, it is essentially another short cut for a loop that calculates the running total of an array.  &lt;/p&gt;

&lt;p&gt;In this instance, we are reducing all the elements of an array into one single value.  We provide to the &lt;code&gt;reduce&lt;/code&gt; method a function telling it how we want to reduce. In this instance, a simple function &lt;code&gt;(a,b)=&amp;gt; a+b,0)&lt;/code&gt; where &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are elements of the baby &lt;code&gt;account&lt;/code&gt; array and we are adding them together (a + b), starting with value (0).  The &lt;code&gt;reduce&lt;/code&gt; method is going to perform that on all the elements of the baby &lt;code&gt;account&lt;/code&gt; array until there are no more elements to add.  &lt;/p&gt;

&lt;p&gt;When we get to that singular value, we will &lt;code&gt;push&lt;/code&gt; that into my &lt;code&gt;wealthArr&lt;/code&gt; array. &lt;/p&gt;

&lt;p&gt;And finally, going back to my 3rd point, I need to &lt;strong&gt;return&lt;/strong&gt; the maximum value.  So, I am taking my &lt;code&gt;wealthArr&lt;/code&gt; which should have elements populated, and then calling the &lt;code&gt;Math.max()&lt;/code&gt; method. &lt;/p&gt;

&lt;h1&gt;
  
  
  Pass The Talk Test
&lt;/h1&gt;

&lt;p&gt;If you have the time, I highly recommend talking through a test of your solution. So, let's test this!&lt;/p&gt;

&lt;p&gt;First, let's set grab one of the test &lt;code&gt;accounts&lt;/code&gt; arrays that LeetCode gives us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accounts = [[1,5],[7,3],[3,5]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, first, we are going to create an empty array called &lt;code&gt;wealthArr&lt;/code&gt;. Simple enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wealthArr = []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then we are going to call our &lt;code&gt;forEach&lt;/code&gt; method on the &lt;code&gt;accounts&lt;/code&gt; array, which is going to sum up every single value in one of those baby &lt;code&gt;account&lt;/code&gt; arrays.The &lt;code&gt;forEach&lt;/code&gt; is then going to start pushing into my empty &lt;code&gt;wealthArr&lt;/code&gt; array the &lt;code&gt;sum&lt;/code&gt; of each of those accounts, using my &lt;code&gt;reduce&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;Each of those accounts are the individual arrays. The &lt;code&gt;forEach&lt;/code&gt; is going to iterate through &lt;code&gt;each&lt;/code&gt; of the elements of my accounts array and do stuff to them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;account1 = [1,5] 
account2 = [7,3] 
account3 = [3,5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, for instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;account1 = [1,5] =&amp;gt;  1 + 5 = 6
account2 = [7,3] =&amp;gt;  7 + 3 = 10
account3 = [3,5] =&amp;gt;  3 + 5 = 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, at this point, after going through each of those accounts, I should have the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wealthArr = [6,10,8]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then finally, I return the maximum value of the newly populated &lt;code&gt;wealthArr&lt;/code&gt;. Be sure to use the &lt;code&gt;spread&lt;/code&gt; operator (&lt;code&gt;...&lt;/code&gt;)!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return Math.max(...wealthArr)
// return Math.max([6,10,8)
&amp;gt; 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! &lt;/p&gt;

&lt;p&gt;Now, you could do this without array methods, using a regular &lt;code&gt;for&lt;/code&gt; loop and creating your own running sum. There might be some interviews where they won't let you use built-in methods (which... is a discussion topic...)&lt;/p&gt;

&lt;p&gt;That said, I highly recommend utilizing every tool at your disposal, and I find array methods both easier to understand, faster to implement, and also showcase your abilities in the language. &lt;/p&gt;

&lt;p&gt;Enjoy, good luck, and please reach out if there are any questions!&lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus: Time and Space Complexity (Big O)
&lt;/h1&gt;

&lt;p&gt;The Time Complexity is O(n x m) or O (nm)&lt;br&gt;
The Space Complexity is O(1)&lt;/p&gt;

&lt;p&gt;Now, I do want to touch upon this for this algorithm, even though I am admittedly not an expert on Big O notation, since it's always important to know. &lt;/p&gt;

&lt;p&gt;I like to think of Time Complexity as asking the question: how many operations am I performing on each input?  &lt;/p&gt;

&lt;p&gt;In this instance, I know I'm performing the following: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A loop (via my &lt;code&gt;forEach&lt;/code&gt; method which is a looping method)&lt;/li&gt;
&lt;li&gt;In each element of that loop, I'm performing another looping method via my &lt;code&gt;reduce&lt;/code&gt; method. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For 1 and 2, we are performing one operation on one input (&lt;code&gt;n&lt;/code&gt;) and then performing another operation on another different input (&lt;code&gt;m&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;As &lt;code&gt;n&lt;/code&gt; grows, &lt;code&gt;m&lt;/code&gt; could grow too. As &lt;code&gt;m&lt;/code&gt; grows, this affects &lt;code&gt;n&lt;/code&gt; as well. &lt;/p&gt;

&lt;p&gt;In plain English, think of it this way:  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;The more accounts (arrays) we have, the more looping we have to do. The more numbers in each of the individual accounts we have, the more adding we have to do&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This makes the Time Complexity O (n x m)&lt;/p&gt;

&lt;p&gt;If we were doing another &lt;code&gt;forEach&lt;/code&gt; within my original &lt;code&gt;forEach&lt;/code&gt;, we'd be doing the same &lt;code&gt;n&lt;/code&gt; operation, which would lead us to O(n * n) which is (On^2). Or if we needed to find a specific account/array, that also adds more complexity. &lt;/p&gt;

&lt;p&gt;The Space complexity is O(1) which is constant.  This means we are not creating more space the more we perform this function. If we were somehow saving the &lt;code&gt;wealthArr&lt;/code&gt; into another array of arrays, then that would increase space complexity. &lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Seed Your Rails API with an External API</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Sun, 31 Jul 2022 19:15:00 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/how-to-seed-your-rails-api-with-an-external-api-4h8n</link>
      <guid>https://dev.to/jmacapagal90/how-to-seed-your-rails-api-with-an-external-api-4h8n</guid>
      <description>&lt;p&gt;As part of Phase 4 of &lt;a href="https://flatironschool.com/welcome-to-flatiron-school/?utm_source=Google&amp;amp;utm_medium=ppc&amp;amp;utm_campaign=12728169839&amp;amp;utm_content=127574231184&amp;amp;utm_term=flatiron%20school&amp;amp;uqaid=513799628798&amp;amp;Cj0KCQjw0JiXBhCFARIsAOSAKqCofvofTasylBNohCNQ-PFSQcitqLzZsMXDHlFz3Dg8CqW5ucBGpKIaAitLEALw_wcB&amp;amp;gclid=Cj0KCQjw0JiXBhCFARIsAOSAKqCofvofTasylBNohCNQ-PFSQcitqLzZsMXDHlFz3Dg8CqW5ucBGpKIaAitLEALw_wcB" rel="noopener noreferrer"&gt;Flatiron School's&lt;/a&gt; Software Engineering bootcamp, we are tasked with building a full-stack application, including standing up an API with Rails to communicate with a React client application. &lt;/p&gt;

&lt;p&gt;Up until this point, most of our test data has been using either &lt;a href="https://github.com/faker-ruby/faker" rel="noopener noreferrer"&gt;Faker&lt;/a&gt; to generate &lt;code&gt;seed&lt;/code&gt; data, or by creating our &lt;code&gt;seed&lt;/code&gt; file from scratch. &lt;/p&gt;

&lt;p&gt;But, as you can imagine, both of those strategies have their drawbacks.  &lt;/p&gt;

&lt;p&gt;With Faker, your quality of test data is limited by the ability of the stock Faker data, or &lt;a href="https://github.com/faker-ruby/faker#customization" rel="noopener noreferrer"&gt;by customizing your own Faker data&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With scratch-baking your seed data, it can get tedious and your tests are further skewed by the fact that you are creating the test data you are testing. &lt;/p&gt;

&lt;p&gt;But what if I told you that you could use an External API to seed your seed data?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0r5cg0kjnn8alk1aqfd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0r5cg0kjnn8alk1aqfd.jpeg" alt="yo dawg api meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a few other services, but I used &lt;a href="https://rapidapi.com/hub" rel="noopener noreferrer"&gt;RapidAPI&lt;/a&gt; and specifically &lt;a href="https://rawg.io/apidocs" rel="noopener noreferrer"&gt;RAWG API&lt;/a&gt; which has a ton of APIs to use. &lt;/p&gt;

&lt;p&gt;I promise it's not that hard, and it'll be fun!&lt;/p&gt;

&lt;h2&gt;
  
  
  Assumptions
&lt;/h2&gt;

&lt;p&gt;1) You have a &lt;a href="https://rapidapi.com/hub" rel="noopener noreferrer"&gt;RapidAPI&lt;/a&gt; and &lt;a href="https://rawg.io/apidocs" rel="noopener noreferrer"&gt;RAWG API&lt;/a&gt; account &lt;br&gt;
2) You are using Ruby on Rails and are using at least version &lt;code&gt;2.7.4&lt;/code&gt;&lt;br&gt;
3) You are familiar with Ruby on Rails, Ruby Gems,and &lt;code&gt;migrating&lt;/code&gt; and &lt;code&gt;seeding&lt;/code&gt; a Rails API.&lt;br&gt;
4) You have the HTTP/REST concepts.&lt;/p&gt;

&lt;p&gt;Additionally, I used the &lt;a href="https://rawg.io/apidocs" rel="noopener noreferrer"&gt;RAWG&lt;/a&gt; API, so I will show the steps I used for that API; however, other APIs may have different instructions and steps.  I would highly recommend reading the documentation for the specific API you are using as they may recommend a different process. &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Get a API key and API Endpoint
&lt;/h2&gt;

&lt;p&gt;First, I registered for a free account with RapidAPI and then RAWG.  This allowed me to get an API key, which is necessary for accessing their API. &lt;/p&gt;

&lt;p&gt;(If you don't know what an API key, I would recommend reading this &lt;a href="https://www.fortinet.com/resources/cyberglossary/api-key" rel="noopener noreferrer"&gt;article&lt;/a&gt; for a brief overview)    &lt;/p&gt;

&lt;p&gt;On RAWG, I was directed to their API homepage, which presented a big fat "GET API KEY" button.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnslnsolyvcp4f1dxmkwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnslnsolyvcp4f1dxmkwi.png" alt="RAWG API homepage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might need to enter in some basic information about why you are using the API and provide a URL (I provided our GitHub repo).  &lt;/p&gt;

&lt;p&gt;After you finishing any of these admin tasks, you should be presented with the following page (I blacked out my personal key and info for obvious reasons):&lt;/p&gt;

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

&lt;p&gt;Copy the value in the "API Key" field save that somewhere safe. &lt;strong&gt;&lt;u&gt;Do not share this with anyone&lt;/u&gt;&lt;/strong&gt;. This is the key your application will use to request data from your external API. &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Get your API Endpoint
&lt;/h2&gt;

&lt;p&gt;Next, you'll need to get your API endpoint. This is where your mileage may vary from RAWG, but RAWG gives you their endpoint straight up on the RAWGAPI homepage:&lt;/p&gt;

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

&lt;p&gt;Save that endpoint as you'll be making a &lt;code&gt;GET&lt;/code&gt; request to that URL. &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Install Gems
&lt;/h2&gt;

&lt;p&gt;You'll need to install the following gems:&lt;/p&gt;

&lt;p&gt;1) &lt;code&gt;gem rest-client&lt;/code&gt;&lt;br&gt;
2) &lt;code&gt;gem dotenv-rails&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Create ENV and Update .gitignore file
&lt;/h2&gt;

&lt;p&gt;There's some quick steps we need to take in order to let our code tap into the API. &lt;/p&gt;
&lt;h3&gt;
  
  
  1) Create an ENV file
&lt;/h3&gt;

&lt;p&gt;You'll need to create a .env file and create a variable and assign your API key to this variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//.env file
API_KEY = &amp;lt;paste your api key here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2) Update your .gitignore file
&lt;/h3&gt;

&lt;p&gt;You'll need to add the following code to your &lt;code&gt;.gitignore&lt;/code&gt; file. This file tells GitHub which files to "ignore" when tracking and pushing files to a repo. As you can imagine, we don't want to broadcast our API key to the interwebs, so this will give us a little security when we push our code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//.gitignore file
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you've done these two steps, we are now ready to update our &lt;code&gt;seeds&lt;/code&gt; file!&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5: Create your Seed File!
&lt;/h1&gt;

&lt;p&gt;In your &lt;code&gt;seeds&lt;/code&gt; file, drop the following code into your file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 require 'rest-client'
2
3 puts "Getting Games Data"
4   def api_key
5        ENV["API_KEY"]
6    end
7
8    def games_dataset
9        api_data = { key: api_key }
10        games = RestClient.get("https://api.rawg.io/api/games?key=#{api_data[:key]}")
11        games_array = JSON.parse(games)["results"]
12        games_array.each do |g|
13            Game.create(
14                title: g["name"],
15                genre: g["genres"][0]["name"],
16                platform: g["platforms"][0]["platform"]["name"],
17                image: g["background_image"]
18            )
19        end
20
21
22    end
23 games_dataset() 
24 puts "Seeding Games Data"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me break this code down line by line. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 1:&lt;/strong&gt; I am requiring the &lt;code&gt;rest-client&lt;/code&gt; &lt;a href="https://rubygems.org/gems/rest-client/versions/1.8.0" rel="noopener noreferrer"&gt;gem&lt;/a&gt;. In a nutshell, this gem gives us access to simple HTTP/REST actions, such as &lt;code&gt;GET&lt;/code&gt;, which let's us grab data from the RAWG API. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 3:&lt;/strong&gt; Next, I've added a simple &lt;code&gt;puts&lt;/code&gt; to the console to tell us what's going on (always a good practice to have!). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 4-6:&lt;/strong&gt; Next, I have a method (&lt;code&gt;api_key&lt;/code&gt;) that is grabbing my &lt;code&gt;API_KEY&lt;/code&gt; variable from my &lt;code&gt;ENV&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 8:&lt;/strong&gt; Then, the big one, my &lt;code&gt;games_dataset&lt;/code&gt; method .... Here's what is going on top down:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 9:&lt;/strong&gt; I am creating a variable and setting it to an object with &lt;code&gt;key&lt;/code&gt; as a key and my api key as it's value. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 10:&lt;/strong&gt; I am setting a variable and setting it equal to a method, &lt;code&gt;RestClient.get&lt;/code&gt;, which is a method given to me by the &lt;code&gt;rest-client&lt;/code&gt; gem that is a get to the API endpoint. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 11:&lt;/strong&gt; I am making another variable and using the &lt;a href="https://ruby-doc.org/stdlib-3.0.1/libdoc/json/rdoc/JSON.html" rel="noopener noreferrer"&gt;method&lt;/a&gt; &lt;code&gt;JSON.parse()&lt;/code&gt;. This &lt;a href="https://ruby-doc.org/stdlib-3.0.1/libdoc/json/rdoc/JSON.html" rel="noopener noreferrer"&gt;Ruby method&lt;/a&gt; turns a JSON array into a Ruby array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 12 - 19:&lt;/strong&gt;  I am then using a &lt;code&gt;.each&lt;/code&gt; &lt;a href="https://mixandgo.com/learn/ruby/each" rel="noopener noreferrer"&gt;method&lt;/a&gt; to iterate through the data and using the &lt;code&gt;.create&lt;/code&gt; method to seed my data into the appropriate attributes that I need into my Games model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- LINE 23:&lt;/strong&gt; I am then calling my method, &lt;code&gt;games_dataset()&lt;/code&gt;, so that this method runs when I run &lt;code&gt;rails db:seed&lt;/code&gt;, and then also &lt;code&gt;puts&lt;/code&gt;-ing to the console so I know when my data is finished seeding. &lt;/p&gt;

&lt;p&gt;I would highly recommend throwing in &lt;code&gt;byebug&lt;/code&gt;s everywhere during this process, especially to make sure you are pinging the API and getting data successfully in return as well when iterating through the JSON data for seeding your model. &lt;/p&gt;

&lt;p&gt;Keep testing by running &lt;code&gt;rails db:seed&lt;/code&gt; to ensure you data is seeding your db. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Throw Your Hands Up and Yell "I am Invincible!"
&lt;/h2&gt;

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

&lt;p&gt;...Because you've just seeded a database with another API! &lt;/p&gt;

&lt;p&gt;No more Lorem Ipsum's and stock cat pictures from Faker, and no more copy-pasta seeding data. &lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus Step: When You Deploy To Heroku
&lt;/h1&gt;

&lt;p&gt;When I was deploying to Heroku, I ran into an issue when trying to seed my data in Heroku (&lt;code&gt;heroku run rails db:seed&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;I was getting the error &lt;code&gt;RestClient::Unauthorized: 401 Unauthorized&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After some troubleshooting (and help from one of our awesome FI instructors), the issue was that Heroku was trying to seed data from RAWG but wasn't using my API_KEY.  &lt;/p&gt;

&lt;p&gt;My API_KEY was stored in my &lt;code&gt;.env&lt;/code&gt; file which was being ignore in my &lt;code&gt;.gitignore&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;This caused an issue because Heroku takes your latest push to your &lt;code&gt;main&lt;/code&gt; branch in GitHub. &lt;/p&gt;

&lt;p&gt;Since the &lt;code&gt;.gitignore&lt;/code&gt; file is ignored when pushing to GitHub, Heroku was not picking up my API_KEY to use when pinging RAWG. &lt;/p&gt;

&lt;p&gt;FIX: &lt;/p&gt;

&lt;p&gt;When you first deploy to Heroku, you'll need to configure Heroku to set an environment variable for your API_KEY, similar to what the &lt;code&gt;.env&lt;/code&gt; file was doing. &lt;/p&gt;

&lt;p&gt;The steps in this wonderful &lt;a href="https://devcenter.heroku.com/articles/config-vars" rel="noopener noreferrer"&gt;guide on Heroku&lt;/a&gt; should help you out! &lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;While this is obviously specific to RapidAPI and specifically RAWG API, the overall concept of this should remain the same for any external API you might use.  &lt;/p&gt;

&lt;p&gt;To recap, we are doing the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using an API key and Endpoint to fetch data from an external API&lt;/li&gt;
&lt;li&gt;Iterating over that data and throwing those values into the attributes of our model.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While the endpoint and key may differ by the different API you might use, this is the basic idea of what we are doing. &lt;/p&gt;

&lt;p&gt;There are obviously other ways to do this depending on the languages you are using, but the core concept of "hey, get me data!" remains the same. &lt;/p&gt;

&lt;p&gt;I hope this tutorial was helpful, and, from these seeds, may you grow a strong &lt;del&gt;tree&lt;/del&gt; database. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gifer.com%2F7Be1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gifer.com%2F7Be1.gif" alt="groot"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>api</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>You Down with O-O-P?</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Mon, 11 Jul 2022 23:49:28 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/you-down-with-o-o-p-1ndg</link>
      <guid>https://dev.to/jmacapagal90/you-down-with-o-o-p-1ndg</guid>
      <description>&lt;p&gt;Object-oriented Programming. &lt;/p&gt;

&lt;p&gt;Sounds so fancy, huh? &lt;/p&gt;

&lt;p&gt;It sounds like something out of Star Trek:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DATA: My neural network is fluid, whereby thoughts are attributes of a certain class and subroutines stored like methods. &lt;br&gt;
LA FORGE: Not unlike object-oriented programming?&lt;br&gt;
DATA: Precisely. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IFC--1GD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/Q7N.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IFC--1GD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/Q7N.gif" alt="data" width="400" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(I'm a huge TNG fan, so come at me with the Trek)&lt;/p&gt;

&lt;p&gt;It's a term that gets thrown around a lot, and it sounds like something super technical. &lt;/p&gt;

&lt;p&gt;(Anecdotally, my wife (who is not a programmer), listens to a Sleep Podcast which is just some dude reading Wikipedia articles.  &lt;a href="https://podcasts.apple.com/ro/podcast/object-oriented-programming/id1457402220?i=1000521718007"&gt;Object-oriented programming&lt;/a&gt; was one of them.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N7SFK4Ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2CS.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N7SFK4Ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2CS.gif" alt="sleep" width="200" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, as I wrap up Phase 3 (of 5) in Flatiron School Bootcamp, I want to attempt to explain object oriented programming to both my wife and to the five people who will invariably read this 9 years from now. &lt;/p&gt;

&lt;p&gt;An ELI5 (explain like I'm five) if you will!&lt;/p&gt;

&lt;p&gt;So, come along, stay for the memes and gifs, and really, maybe OOP was just the friends and lessons we learned along the way...&lt;/p&gt;




&lt;h2&gt;
  
  
  What the heck even is Object-oriented programming?
&lt;/h2&gt;

&lt;p&gt;At its most basic, Object-oriented program is a paradigm- a way of programming. It's a way of specifically programming objects. So, quite literally, programming that is oriented toward the programming of objects. &lt;/p&gt;

&lt;p&gt;That's it. &lt;br&gt;
Blog over.&lt;br&gt;
Pay me $150,000, Mark Zuckerberg!&lt;/p&gt;

&lt;p&gt;(Just kidding!)&lt;/p&gt;

&lt;p&gt;While this definition sounds simple, the concept of it is what is more important (and consequently harder to grasp). &lt;/p&gt;

&lt;p&gt;In layman's terms, we want to build things to build other things for us.  This is better than building something from scratch every single time we need them.&lt;/p&gt;

&lt;p&gt;Because, while we can program objects, it is what we do &lt;em&gt;with&lt;/em&gt; those objects is ultimately what's most important. &lt;/p&gt;

&lt;p&gt;Before I get deeper into the technical aspects, like my hypothesis states, I want to give ELI5 example of OOP.  &lt;/p&gt;

&lt;p&gt;So... let's begin...&lt;/p&gt;




&lt;h1&gt;
  
  
  Legos... My Favorite Toy!
&lt;/h1&gt;

&lt;p&gt;When I was a little kid (and arguably, still am...), my favorite toys were Legos (and video games, which, I'll get to!).&lt;/p&gt;

&lt;p&gt;Now, if you've never built a Lego, it's literally pieces of plastic bricks and a set of instructions in a box.  You take out the pieces and they're in no order particular order.  You read the instructions, and the instructions are neatly laid out in the following format:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An artist rendering of the final product. &lt;/li&gt;
&lt;li&gt;A page showing all the pieces included in the box.&lt;/li&gt;
&lt;li&gt;A step-by-step guide showing you literally where to place each and every piece. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Patiently follow the instructions (and trust that they are right!), you'll eventually build the Lego!&lt;/p&gt;

&lt;p&gt;Let's break everything down again, because I promise I will tie this back to Object-oriented programming.&lt;/p&gt;

&lt;p&gt;In every box of Legos, there are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An idea/picture of what this particular lego model is&lt;/li&gt;
&lt;li&gt;Lego pieces.&lt;/li&gt;
&lt;li&gt;A step-by-step instruction manual on how to build the Lego.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes it easy for any kid (or adult) to pick up a box of Legos and build it without any additional instructions. &lt;/p&gt;




&lt;h1&gt;
  
  
  The Opposite of Legos
&lt;/h1&gt;

&lt;p&gt;Now, let's think of the reverse of what this process might be. &lt;/p&gt;

&lt;p&gt;How annoying would it be for Lego if they didn't include that guide? &lt;/p&gt;

&lt;p&gt;Every customer would either need to figure it out on their own just using the picture (&lt;em&gt;cough&lt;/em&gt; K-NEX &lt;em&gt;cough&lt;/em&gt;), or, perhaps even more annoyingly, ask Lego for instructions every single time. &lt;/p&gt;




&lt;h1&gt;
  
  
  OOP: Built To Last
&lt;/h1&gt;

&lt;p&gt;So, let's regroup. &lt;/p&gt;

&lt;p&gt;Object-oriented programming is a philosophy/paradigm of programming oriented toward the coding of objects, and we can use those objects to, well, &lt;em&gt;build&lt;/em&gt; things!&lt;/p&gt;

&lt;p&gt;Furthermore, we can create that code to create &lt;em&gt;more&lt;/em&gt; code.&lt;/p&gt;

&lt;p&gt;This is better than the reverse of that, which is quite literally, building things from scratch, every single time. &lt;/p&gt;

&lt;p&gt;In (most) Object-oriented programming languages, programmers begin by writing &lt;code&gt;classes&lt;/code&gt;, which act like blueprints for the creation of objects. Every time that blueprint runs, a new &lt;code&gt;instance&lt;/code&gt; of that object gets created!&lt;/p&gt;

&lt;p&gt;To tie back to my Lego example, think of a particular type of Lego model as a &lt;code&gt;class&lt;/code&gt;, and every Lego box that gets created is an &lt;code&gt;instance&lt;/code&gt; of that object.&lt;/p&gt;

&lt;p&gt;For instance (no pun intended), I always loved the Lego trains. There was one particular model that I got for a birthday. It was a black and yellow one fit with a dining car, sleeper car, and, of course, a working engine car that propelled the train!&lt;/p&gt;

&lt;p&gt;I was so excited.  I had the bestest, most amazingest Lego train ever!&lt;/p&gt;

&lt;p&gt;But... I got a rude awakening the next day at school.  It turns out another kid in my school got the same Lego train model for &lt;em&gt;their&lt;/em&gt; birthday!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UbYjjXAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/ioq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UbYjjXAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/ioq.gif" alt="gasp" width="470" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now... as much as I want to believe I was a unicorn-child that got the onlyest Lego toy in the whole wide world, I'm not idiot (probably).&lt;/p&gt;

&lt;p&gt;My Mom probably went to the toy store, went to the Lego section, and picked a Lego train models off the shelf. My classmates parents probably did the exact same thing with the exact same Lego train model.&lt;/p&gt;

&lt;p&gt;That lego Train model is a &lt;code&gt;class&lt;/code&gt; - quite literally a model of this particular line of Lego trains. Each box of that model is an &lt;code&gt;instance&lt;/code&gt;. Assuming every kid builds the train properly, the train will look identical to other kids who have the exact same one because of the instructions inherent to that toy. &lt;/p&gt;




&lt;h1&gt;
  
  
  Lego Island
&lt;/h1&gt;

&lt;p&gt;Well, let's talk about one of my other favorite toys: video games.&lt;/p&gt;

&lt;p&gt;And one of my favorite video games was Lego Island.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uivs5haN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8h7a9onc4w45b1mdles.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uivs5haN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8h7a9onc4w45b1mdles.png" alt="Lego Island" width="682" height="810"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's an old PC game that, you guessed it, is about being on an Island of Legos!&lt;/p&gt;

&lt;p&gt;So, applying our new understanding of Object-oriented programming, Lego Island was probably built using Object-oriented principles. &lt;/p&gt;

&lt;p&gt;Quite literally, the Legos in that game are their own classes.  Each of those instances are the renderings of those classes.  &lt;/p&gt;

&lt;p&gt;The water. The Lego people. The buildings. &lt;/p&gt;

&lt;p&gt;And each of these objects can interact with one another to provide for the interactive gaming experience that makes video games, well, fun!&lt;/p&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;So, why does this matter?&lt;/p&gt;

&lt;p&gt;Object-oriented programming, while a bit harder to grasp initially, actually makes programming much more elegant and sustainable. &lt;/p&gt;

&lt;p&gt;Moreover, it is the foundation for many of the most useful programming languages, such as Ruby, C++, Python and more. &lt;/p&gt;

&lt;p&gt;While each language will have it's own syntax, Object-orientated programming sets the foundation for many programming languages, which ultimately makes it easier to learn and use them. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JYDATVPs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwpspat3eacnm9hhbzuc.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JYDATVPs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwpspat3eacnm9hhbzuc.jpeg" alt="you down with oop?" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming"&gt;https://en.wikipedia.org/wiki/Object-oriented_programming&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>rails</category>
    </item>
    <item>
      <title>The Gitfather, Part 2: The Prequel</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Wed, 22 Jun 2022 14:08:23 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/lessons-from-the-gitfather-pt-2-3hk0</link>
      <guid>https://dev.to/jmacapagal90/lessons-from-the-gitfather-pt-2-3hk0</guid>
      <description>&lt;h2&gt;
  
  
  A long time ago, in a galaxy far, far away...
&lt;/h2&gt;

&lt;p&gt;...Wait, wrong movie reference. &lt;/p&gt;

&lt;p&gt;This is another post from the Gitfather, your all knowing and loving code zaddy. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K5Yy_N7N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a211y47kyvwwih6u372r.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K5Yy_N7N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a211y47kyvwwih6u372r.jpeg" alt="The gitfather" width="620" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wasn't always the Gitfather though...&lt;/p&gt;

&lt;p&gt;Before my current iteration as a Gitdad, I was a Business Analyst. &lt;/p&gt;

&lt;p&gt;A strange role at the unholy intersection of code and clients.&lt;/p&gt;

&lt;p&gt;Sometimes also called a "Product Owner" (and hopefully rarely also a Project Manager), the Business Analyst lives at the complicated marriage of business and technology, marrying the technical with the non-technical. &lt;/p&gt;

&lt;p&gt;(They also get confused with Business Intelligence Analyst who &lt;em&gt;actually&lt;/em&gt; analyze data sets, but that's a topic for another time...)&lt;/p&gt;

&lt;p&gt;To be more blunt, I basically took an idea from  non-technical ask (&lt;em&gt;"we want this button to turn blue!"&lt;/em&gt;) and broke it down into technical requirements that Developers could use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dwqCbmJQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r6isk8akbd5b9489lnjs.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dwqCbmJQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r6isk8akbd5b9489lnjs.jpeg" alt="jira school house rock meme" width="605" height="499"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Story Mode
&lt;/h2&gt;




&lt;p&gt;While BAs do a variety of different jobs, one of the most important jobs was writing &lt;a href="https://www.altexsoft.com/blog/business/functional-and-non-functional-requirements-specification-and-types/"&gt;&lt;strong&gt;&lt;em&gt;User Stories&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;, which is essentially an update request to Developers.&lt;/p&gt;

&lt;p&gt;If you're not familiar with what User Stories are, they basically are a summary of what a development update should do. &lt;/p&gt;

&lt;p&gt;For instance, a ticket with user stories would probably look like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;As a user, when I click on a button, it should change color from red to blue. &lt;/li&gt;
&lt;li&gt;A search feature allows a user to hunt among various invoices if they want to credit an issued invoice.&lt;/li&gt;
&lt;li&gt;The system sends a confirmation email when a new user account is created.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;In essence, a user story should have a: beginning and an end. When something happens, this should happen. &lt;/p&gt;




&lt;h2&gt;
  
  
  Turn Up the AC
&lt;/h2&gt;




&lt;p&gt;User stories are also usually accompanied by &lt;a href="https://www.altexsoft.com/blog/business/acceptance-criteria-purposes-formats-and-best-practices/#:~:text=Here's%20when%20user%20stories%20and,specific%20user%20story%20must%20satisfy."&gt;&lt;em&gt;acceptance criteria&lt;/em&gt;&lt;/a&gt; which is a fancy term for "what completes a user story?"&lt;/p&gt;

&lt;p&gt;Acceptance criteria are the lowest-level functional requirements.&lt;/p&gt;

&lt;p&gt;So, in the above examples, the acceptance criteria for the user story might be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;GIVEN I am on the Home Page with a Button, WHEN I click on the "Return Home" button, THEN the "Return Home" button background color renders from red to blue. &lt;/li&gt;
&lt;li&gt;GIVEN I am on Google, WHEN I enter an input into the Search bar, THEN I am able to view and browse results based on my search input&lt;/li&gt;
&lt;li&gt;GIVEN I am not a registered/authenticated user, WHEN I register with a new account, THEN I am sent a confirmation email confirming my successful registration. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll notice that the acceptance criteria are structured using a "GIVEN... WHEN... THEN" statement. It sounds more "code-y", more developer focused. &lt;/p&gt;

&lt;p&gt;It also sounds kind of like what the user story said, but in much more &lt;em&gt;specific&lt;/em&gt; terms.  This lays out a &lt;em&gt;clear&lt;/em&gt; roadmap for what the Developer must complete in order for the update to be done. &lt;/p&gt;

&lt;p&gt;Acceptance criteria and user stories all "ladder up" to one big project, usually called an Epic, which is the over-arching, bigger software update that is driving everything. &lt;/p&gt;




&lt;h2&gt;
  
  
  One Ticket To Rule Them All
&lt;/h2&gt;




&lt;p&gt;Epics, User Stories, and Acceptance Criteria are major points of the &lt;a href="https://www.atlassian.com/agile#:~:text=Agile%20is%20an%20iterative%20approach,small%2C%20but%20consumable%2C%20increments."&gt;Agile Methodology&lt;/a&gt; of Software Development. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CD0KBQAb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v51ir8r6dg7atr0qllh0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CD0KBQAb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v51ir8r6dg7atr0qllh0.png" alt="Project breakdown" width="880" height="492"&gt;&lt;/a&gt;&lt;a href="https://www.altexsoft.com/blog/business/acceptance-criteria-purposes-formats-and-best-practices/#:~:text=Here's%20when%20user%20stories%20and,specific%20user%20story%20must%20satisfy."&gt;The project lifecycle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While there have been literal textbooks written about Agile, the TL;DR is a project framework of completing software updates into manageable chunks. &lt;/p&gt;

&lt;p&gt;There are many other methodologies, but, in my humble opinion, Agile is the most commonly used (and ripped off...looking at you Waterfall...).&lt;/p&gt;

&lt;p&gt;Basically, breaking big updates into medium ones and those in to smaller ones, and so on, until you get to what would complete the update.  And then working on those updates in 2-3 week "sprints" until the whole thing is finished. &lt;/p&gt;




&lt;h2&gt;
  
  
  Sometimes, The Requirements Ain't The Requirements
&lt;/h2&gt;




&lt;p&gt;As Developers, we are unfortunately at the business end (pun intended) of all of this.  We only get a neat list of to-dos and then we clock out and go play Apex Legends. &lt;/p&gt;

&lt;p&gt;As a former Business Analyst, however, I feel like I need to let Developers in on a dirty secret: they really need to be at the business beginning of software updates. &lt;/p&gt;

&lt;p&gt;Because, as my former Boss once told me: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes, the requirements aren't the requirements...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L9DfcIbD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2GY.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L9DfcIbD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2GY.gif" alt="wutt" width="195" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, you'll be coding something that makes zero sense. Or might be totally unfulfilling or unworthy of your time. &lt;/p&gt;

&lt;p&gt;And it's true. &lt;/p&gt;

&lt;p&gt;That user story to "turn the button blue" probably came from the client who probably actually just wanted to update the button styling. &lt;/p&gt;

&lt;p&gt;And then it telephone-d into this update where it's now a conditional rendering exercise versus maybe an exercise in updating the CSS. &lt;/p&gt;

&lt;p&gt;Or sometimes, you'll deliver an update exactly as promised, and the client still won't be happy. &lt;/p&gt;

&lt;p&gt;For instance, I had a client who wanted to make all their images have rounded corners.  They were adamant about it. &lt;/p&gt;

&lt;p&gt;Sounds easy enough, right? &lt;/p&gt;

&lt;p&gt;Well, we did it, and, guess what, after we did, someone else at the client asked why we agreed to do it.  &lt;/p&gt;

&lt;p&gt;Because we basically spent valuable Developer hours doing this when there was a juicier project sitting there on the shelf. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Needless to say, you can see why I put my life as Business Analyst behind me. &lt;/p&gt;

&lt;p&gt;But, while I love being a Developer, there are other things out there behind the scenes which can make our jobs good and bad. &lt;/p&gt;

&lt;p&gt;While it should be our job as Developers to build the darn things, it's also our job, unfortunately, to question why we are even doing the darn thing in the first place. &lt;/p&gt;

&lt;p&gt;Food for thought the next time you get a request for rounded corners on images. &lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://www.atlassian.com/agile#:~:text=Agile%20is%20an%20iterative%20approach,small%2C%20but%20consumable%2C%20increments."&gt;What is Agile?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.altexsoft.com/blog/business/acceptance-criteria-purposes-formats-and-best-practices/#:~:text=Here's%20when%20user%20stories%20and,specific%20user%20story%20must%20satisfy."&gt;Acceptance Criteria and User Stories&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>sdlc</category>
      <category>agile</category>
      <category>product</category>
    </item>
    <item>
      <title>useState: The Hook Brings You Back</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Thu, 09 Jun 2022 16:56:53 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/usestate-the-hook-brings-you-back-1gp3</link>
      <guid>https://dev.to/jmacapagal90/usestate-the-hook-brings-you-back-1gp3</guid>
      <description>&lt;p&gt;I have a new found appreciation for The Facebook. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v5eozKZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2nu3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v5eozKZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2nu3.gif" alt="image" width="245" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whoops, I meant, Facebook- I mean Meta. &lt;/p&gt;

&lt;p&gt;While I've been a Facebook user so long I can remember the "The", nowadays, I'm fascinated by React, the amazing JavaScript based framework developed and maintained by Meta. &lt;/p&gt;

&lt;p&gt;Specifically, I am truly amazed by the wonderful tool developed in React called &lt;code&gt;useState&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; is a &lt;strong&gt;Hook&lt;/strong&gt;, a special type of function with the specific purpose of helping developers maintain state changes in applications. &lt;/p&gt;

&lt;p&gt;The purpose of this blog is to identify:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why State as a concept is important&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;useState&lt;/code&gt; works&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;useState&lt;/code&gt; is useful&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  useState of the Union
&lt;/h1&gt;




&lt;p&gt;Before we jump right in, let's get philosophical and define what we mean by &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What do we mean by, just the word, &lt;strong&gt;state&lt;/strong&gt;, in real life?&lt;/p&gt;

&lt;p&gt;If you said, Illinois, I would say: damn, I thought I turned off location services on my Facebook privacy...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9tXVH0xr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/7Wxw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9tXVH0xr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/7Wxw.gif" alt="they found me" width="360" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Beyond a politically organized groups of peoples, when we say &lt;strong&gt;state&lt;/strong&gt;, &lt;a href="https://www.merriam-webster.com/dictionary/state?utm_campaign=sd&amp;amp;utm_medium=serp&amp;amp;utm_source=jsonld"&gt;Webster's&lt;/a&gt; dictionary says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mode or condition of being&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is what something is right now. It is also what something will be in the future. It's also what something was in the past.  &lt;/p&gt;

&lt;p&gt;For instance, right now in my iced coffee, I have ice. In the future, the ice will melt and become water. &lt;/p&gt;

&lt;p&gt;In other words, the water is changing state. It's changing from one state (of matter) into another state.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zFiDjQWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2Kg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zFiDjQWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gifer.com/2Kg.gif" alt="whoa" width="340" height="205"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Though basic, this is an important concept to understand, both in life and web development (which is obviously more important of the two).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;When it comes to the technology, we want things to change. &lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;We want &lt;em&gt;things&lt;/em&gt; to change &lt;em&gt;state&lt;/em&gt;. &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;We&lt;/em&gt; want to change the states of things.  &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Aj5bqXyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj557pqacf0oth0u0uve.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Aj5bqXyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj557pqacf0oth0u0uve.jpeg" alt="vision change state" width="701" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without changing state, technology (and life) would really be boring. &lt;/p&gt;

&lt;p&gt;No likes.&lt;br&gt;
No Candy Crush.&lt;br&gt;
Nothing. &lt;/p&gt;

&lt;p&gt;A cold, dark, and boring Internet with static applications. &lt;/p&gt;

&lt;p&gt;Thankfully, we have handy hooks like &lt;code&gt;useState&lt;/code&gt; to make things easier for us.  &lt;/p&gt;


&lt;h1&gt;
  
  
  Well, what even is &lt;code&gt;useState&lt;/code&gt; and why should I care?
&lt;/h1&gt;



&lt;p&gt;Well, first off, rude. &lt;/p&gt;

&lt;p&gt;Secondly, fundamentally, &lt;code&gt;useState&lt;/code&gt; is just another &lt;strong&gt;function&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;A special type of function called a &lt;a href="https://reactjs.org/docs/hooks-overview.html"&gt;&lt;strong&gt;Hook&lt;/strong&gt;&lt;/a&gt;, created by React.  &lt;/p&gt;

&lt;p&gt;According to React, Hooks are:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;functions that let you “hook into” React state and lifecycle features from function components&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; basically lets developers use special logic and features, already written for us! &lt;/p&gt;

&lt;p&gt;Let's think about how we might change the value of a variable in vanilla JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 0;
console.log(x)
&amp;gt;&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setX(){
 x = x + 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setX()
console.log(x)
&amp;gt;&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty straight forward.&lt;br&gt;&lt;br&gt;
We declared an initial value for variable (x = 0). &lt;br&gt;
We performed an operation on that variable (x + 1).&lt;br&gt;&lt;br&gt;
We checked the value of that variable afterwards (x = 1).&lt;/p&gt;

&lt;p&gt;But, what if I told you you can do those 3 lines of code in 1 line of code? &lt;/p&gt;


&lt;h1&gt;
  
  
  Enter useState
&lt;/h1&gt;



&lt;p&gt;While there is some &lt;a href="https://www.the-guild.dev/blog/react-hooks-system"&gt;special magic&lt;/a&gt; that goes on under the hood, the basis of &lt;code&gt;useState&lt;/code&gt; is still rooted within the same idea of maintaining a variable. &lt;/p&gt;

&lt;p&gt;Like with many things in React, we need to import this tool before using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { useState } from 'react;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the magic of useState is in its simplicity. &lt;/p&gt;

&lt;p&gt;Again, &lt;code&gt;useState&lt;/code&gt; is just a function, but it is a special function that returns an &lt;strong&gt;array&lt;/strong&gt; of just two elements: a &lt;strong&gt;State Variable&lt;/strong&gt; and a &lt;strong&gt;Setter Function&lt;/strong&gt; which we can define via array destructuring.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [ count, setCount ] = useState(0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The State Variable's purpose is in its name: its the variable that we want to maintain our state within. So, &lt;code&gt;count&lt;/code&gt; in the previous line of code would be analogous to &lt;code&gt;x&lt;/code&gt; in our previous OG JS code.&lt;/p&gt;

&lt;p&gt;The Setter Function is also exactly what it sounds like: it sets the State Variable. Again, analogous to &lt;code&gt;setX&lt;/code&gt; in our previous example.&lt;/p&gt;

&lt;p&gt;Finally, the &lt;code&gt;useState()&lt;/code&gt; keyword invokes the &lt;strong&gt;Hook&lt;/strong&gt; from React's vast library and then sets an initial value for our State Variable passed as a parameter to the function (in this case 0). &lt;/p&gt;

&lt;p&gt;The difference in &lt;code&gt;useState&lt;/code&gt; versus that of our OG JavaScript function is syntax.  &lt;/p&gt;

&lt;p&gt;We can use array destructuring to easily set these two items, State Variable and Setter Function, without needing to declare and redeclare the variables.&lt;/p&gt;

&lt;p&gt;After declaring our two variables, we can then use them how we'd like in the rest of our code. &lt;/p&gt;

&lt;p&gt;First off, we still need to define the Setter Function's purpose. In my above example, I created another function that I can call that will call my setter function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   function increment (){
      setCount(()=&amp;gt; count + 1)
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now, every time I invoke &lt;code&gt;increment&lt;/code&gt;, it will call &lt;code&gt;setCount&lt;/code&gt; which will update &lt;code&gt;count&lt;/code&gt; which will now be set to the new value!&lt;/p&gt;

&lt;p&gt;No re-calling the variable or redeclaring needed. &lt;/p&gt;

&lt;p&gt;And now we can use both the State Variable and the Setter Function (via that helper function!)&lt;/p&gt;

&lt;h4&gt;
  
  
  *&lt;em&gt;But wait there's more! *&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e4Nuuxik--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42cb4mz18pven5hj90mq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e4Nuuxik--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42cb4mz18pven5hj90mq.jpeg" alt="butwaittheresmore" width="501" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; will not only set our variables (and "func" on them too), it will also &lt;strong&gt;&lt;em&gt;re-render&lt;/em&gt;&lt;/strong&gt; any components (and any JSX/DOM elements) within those components. &lt;/p&gt;

&lt;p&gt;Think about that.  Just one component- &lt;strong&gt;not&lt;/strong&gt; the entire page. &lt;/p&gt;

&lt;p&gt;While this is in part thanks to &lt;a href="https://reactjs.org/docs/faq-internals.html"&gt;React's virtual DOM&lt;/a&gt;, it makes for a more modular, cleaner, and prettier website. &lt;/p&gt;

&lt;p&gt;Think about what you might need to do in OG JS to re-render a component with &lt;code&gt;count&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write some verbose function to keep setting your variables&lt;/li&gt;
&lt;li&gt;Set and append ad nauseam all the HTML element with your new variables&lt;/li&gt;
&lt;li&gt;Oh yeah, &lt;strong&gt;refresh the whole page&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That already sounds like hundreds of lines of code for one element, not to mention if this needs to happen within other elements on a page or other pages. &lt;/p&gt;




&lt;h1&gt;
  
  
  The Hook Brings You Back
&lt;/h1&gt;




&lt;p&gt;In conclusion, &lt;code&gt;useState&lt;/code&gt; is revolutionary in its simplicity, efficiency, and application. &lt;/p&gt;

&lt;p&gt;What probably would have been done with hundreds of lines of JavaScript (with a healthy dose of unnecessary HTML) can now be done with &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useState&lt;/code&gt; hook, via some internal magic, a State Variable, and Setter Function, brings a component back to re-render whenever we need it to- all within an efficient, clean line of code. &lt;/p&gt;

&lt;p&gt;In the words of the immortal song "Hook" by Blues Traveler, &lt;em&gt;the Hook brings you back&lt;/em&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Sources:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://reactjs.org/docs/hooks-overview.html"&gt;Hooks Overview&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.the-guild.dev/blog/react-hooks-system"&gt;Hooks System&lt;/a&gt;&lt;br&gt;
&lt;a href="https://reactjs.org/docs/faq-internals.html"&gt;React's virtual DOM&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bonus: If you really want to dive into the rabbit hole, this &lt;a href="https://pomb.us/build-your-own-react/"&gt;blog&lt;/a&gt; builds it's own React library and dives into how to write your own Hooks.&lt;/p&gt;

</description>
      <category>react</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Advice From A Gitfather: Lessons on Version Control</title>
      <dc:creator>James Macapagal</dc:creator>
      <pubDate>Fri, 03 Jun 2022 16:56:33 +0000</pubDate>
      <link>https://dev.to/jmacapagal90/advice-from-a-gitfather-lessons-on-version-control-48cn</link>
      <guid>https://dev.to/jmacapagal90/advice-from-a-gitfather-lessons-on-version-control-48cn</guid>
      <description>&lt;p&gt;&lt;code&gt;Hello, World!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is my first blogpost as a future programmer! Woo!&lt;/p&gt;

&lt;p&gt;I'm a baby-dev. A hatchling. A student. &lt;/p&gt;

&lt;p&gt;An init() function of a programmer (sorry, I'm new and I'm still loving the ability to make try-too-hard Programming Jokes).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--njGCi4J2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agj5bmzh02k0exxpbzrh.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--njGCi4J2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agj5bmzh02k0exxpbzrh.jpeg" alt="It's my first day..." width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm a student enrolled in the Flatiron's Full-Time Software Engineering Program (Cohort 051622 represent!).&lt;/p&gt;

&lt;p&gt;I'll be using DEV to document my learnings, share my bad dad jokes, and hopefully reflect on the lessons and friends I learned along the way. &lt;/p&gt;

&lt;p&gt;And for my ubiquitous first post, I won't be waxing about an event listener I coded in JavaScript or how I centered a Div in CSS or anything related to actual code.  There are a million angry StackOverflow replies out there for people to read, mess up, and copy-pasta. &lt;/p&gt;

&lt;p&gt;No, for this post, I want to discuss this amazing new power I learned:  version control!&lt;/p&gt;

&lt;p&gt;You see, I was in a group project, and I volunteered as tribute to handle version control and Github. &lt;/p&gt;

&lt;p&gt;Little did I know, it would push me down a path toward becoming...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jCY01ySg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmjgo6jlle65s5984jkv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jCY01ySg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmjgo6jlle65s5984jkv.jpeg" alt="The Gitfather" width="620" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won't lie- I was scared.&lt;/p&gt;

&lt;p&gt;I had never used Github before, and I had only heard about it in tellings as the bane of Programmers, Scrum Masters, and Product Owners alike.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What if I screwed up? &lt;br&gt;
What if I ruined someone else code? &lt;br&gt;
What if I broke the Internet?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And then I read &lt;a href="https://matteweva.medium.com/github-workflow-a-basic-guide-fdfd68d034b6"&gt;Matt Eva's wonderful guide to Github.&lt;/a&gt; and it all became much easier. &lt;/p&gt;

&lt;p&gt;While I won't copy Matt's wonderful work, who goes into incredible detail for the exact commands needed, I will share my learnings in my first foray as Gitfather of our project. &lt;/p&gt;

&lt;p&gt;While Github is an amazing tool for version control, ultimately, I was responsible for using Github to, well, control the versions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function versionCtrl(){
   controlVersion()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I like to think of version control in terms of a restaurant (I'm a huge foodie, so I always try to relate everything to food). &lt;/p&gt;

&lt;p&gt;The way food gets created is incredibly analogous to how code gets deployed. &lt;/p&gt;

&lt;p&gt;Let's think about how a restaurant cooks food: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The kitchen receives an order (also called a ticket).&lt;/li&gt;
&lt;li&gt;The kitchen divides work amongst different stations.&lt;/li&gt;
&lt;li&gt;The dish is worked and passed on at each station. &lt;/li&gt;
&lt;li&gt;All stations finish and food is taken out to the customer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In between each of these steps is a vital team member to a kitchen: The Expo. &lt;/p&gt;

&lt;p&gt;In any (good) restaurant, the Expo is arguably the most crucial staff member to success.  The Expo monitors each of the above steps and makes sure that each step of the dish gets completed so that no other stations get held (aka "in the weeds"). &lt;/p&gt;

&lt;p&gt;Much like food, code undergoes the same process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An update request (sometimes also called a ticket) with deliverables gets created. &lt;/li&gt;
&lt;li&gt;Programmers break down the deliverables and code.&lt;/li&gt;
&lt;li&gt;Code gets merged so the next code session has updated code.&lt;/li&gt;
&lt;li&gt;Once finished, the code is all packaged up and deployed as one complete package.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And, like an Expo, between each of these steps was me- &lt;strong&gt;the Gitfather&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;I was responsible for making sure that each successful code update got merged to &lt;code&gt;main&lt;/code&gt; and that our team was "handing off their dish" correctly. &lt;/p&gt;

&lt;p&gt;Like an Expo, I was responsible for reminding team members to cook our food (code) using good version control practices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull from &lt;code&gt;main&lt;/code&gt; (&lt;code&gt;git pull&lt;/code&gt; or &lt;code&gt;git pull origin main&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Create New Branches (&lt;code&gt;git branch &amp;lt;new branch name&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Track and Commit Their Work (&lt;code&gt;git add &amp;lt;file&amp;gt; or git add .&lt;/code&gt; and&lt;code&gt;git commit -m "comments"&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Push Work (&lt;code&gt;git push&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And like any good kitchen (or any good team), I had to make sure our team was communicating.&lt;/p&gt;

&lt;p&gt;If you've ever watched a (good) kitchen at work, the Expo knows everything going on in the kitchen and is barking orders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let's get those steaks working (start cooking the steak)!&lt;/li&gt;
&lt;li&gt;I got a steak dying over here (my steak is sitting too long)!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where's my salad?!1?&lt;/strong&gt; (Where's the damn salad?!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Spoiler: I've never actually work in a pro kitchen/restaurant, so take everything I say with a huge grain of Maldon Sea Salt- I just watch a lot of cooking shows!)&lt;/p&gt;

&lt;p&gt;As the Gitfather, I had to do the same (although less barking more gentle reminders):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remember to create a new branch!&lt;/li&gt;
&lt;li&gt;Constantly track, commit, and push!&lt;/li&gt;
&lt;li&gt;Make sure you pull from main before you work!&lt;/li&gt;
&lt;li&gt;Main is merged!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where's my salad??!1?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BVYSYTi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0nhr18vi176bwrr7wr6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BVYSYTi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0nhr18vi176bwrr7wr6.jpeg" alt="Gordan Coder" width="500" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, any good Gitfather needs to be on top of what everyone is working on. &lt;/p&gt;

&lt;p&gt;For instance, I knew one team member was working on JS updates and another was working on HTML updates.  I had to make sure the HTML updates wouldn't conflict with the JS updates.  Or, I needed to make sure all JS and HTML was done before we could start hunkering down on CSS. And, in all of this, making sure comments were clear and organized so we all know what we did and where in the code. &lt;/p&gt;

&lt;p&gt;Ultimately, while Github is amazing for version control, the best version control is &lt;strong&gt;you&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Like a good expo, you need to know what is going on at all times in your kitchen.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who's working on what? &lt;/li&gt;
&lt;li&gt;What is being worked on? &lt;/li&gt;
&lt;li&gt;Who is crying in the walk-in? &lt;/li&gt;
&lt;li&gt;Who asked for ranch with their steak frites?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And while intimidating as that seems, it ultimately empowers you to be at the center of it all. And you get to see and learn so much.&lt;/p&gt;

&lt;p&gt;You get to see the your team create literally something out of nothing. You get to see how people approach problems. You get to see the brilliance of your team members and their programming skills. &lt;/p&gt;

&lt;p&gt;And most importantly, you get to take credit for all their work because you merged all their updates to &lt;code&gt;main&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Good luck future Gitfathers, Gitmothers, and Gitzaddy! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kBHjTDYC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2kzr0umrmfx12epofrh.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kBHjTDYC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2kzr0umrmfx12epofrh.jpeg" alt="I am the version control now" width="665" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>github</category>
      <category>git</category>
    </item>
  </channel>
</rss>
