<?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>Forem: adenaddis</title>
    <description>The latest articles on Forem by adenaddis (@adenaddis).</description>
    <link>https://forem.com/adenaddis</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%2F891124%2F6ff3e98f-a8da-4998-97e4-75599ee32480.png</url>
      <title>Forem: adenaddis</title>
      <link>https://forem.com/adenaddis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adenaddis"/>
    <language>en</language>
    <item>
      <title>Javascript vs Ruby: Syntax Edition</title>
      <dc:creator>adenaddis</dc:creator>
      <pubDate>Fri, 16 Sep 2022 17:14:16 +0000</pubDate>
      <link>https://forem.com/adenaddis/javascript-vs-ruby-syntax-edition-3mhp</link>
      <guid>https://forem.com/adenaddis/javascript-vs-ruby-syntax-edition-3mhp</guid>
      <description>&lt;p&gt;Transitioning from consistently working with javascript to moving straight into ruby might be difficult due to adjusting our eyes to look at a new way of writing code and with that changing our habits.&lt;/p&gt;

&lt;p&gt;Lets start simple...&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript Syntax
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;jsFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Look how Im written&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&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;Lets jot down a couple things we see with js syntax &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use starter keyword &lt;strong&gt;function&lt;/strong&gt; to show the code is a function&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jsFunction&lt;/strong&gt; is the variable name (we use this term to refer to the code wherever we please)&lt;/li&gt;
&lt;li&gt;NEED parentheses &lt;strong&gt;( )&lt;/strong&gt; right after the variable name to place any parameters we might have in them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;param&lt;/strong&gt; is the variable name for the functions parameter that will be used when the function is later passing an argument and being invoked. &lt;/li&gt;
&lt;li&gt;Next, curly brackets &lt;strong&gt;{ }&lt;/strong&gt; is a MUST to indicate the body of the function&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;console.log()&lt;/strong&gt; is what will be displayed in the terminal&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;return&lt;/strong&gt; is different in which it is not specifically for the terminal. We use this so that our function can have a return value when it is called on. For this example we have param plus 5.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How to check function !&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;const&lt;/span&gt; &lt;span class="nx"&gt;jsFunctionReturnValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jsFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; ""Look how Im written"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myFunctionReturnValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above we just called the jsFunction and passed an argument of 3 and assigned that to a variable called jsFunctionReturnValue. This in turn displays my earlier console.log in the terminal. When I console.log the new variable I made, I get the number 8 due to the 3 + 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby Syntax
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rb_method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;param&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Look how Im_written"&lt;/span&gt;
  &lt;span class="n"&gt;param&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets see what makes ruby different:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use starter keyword &lt;strong&gt;def&lt;/strong&gt; to show the code is a method&lt;/li&gt;
&lt;li&gt;We use &lt;strong&gt;snake case&lt;/strong&gt; for the variable name of the method. This just means the words are separated by an underscore (_). While JS uses camel case.&lt;/li&gt;
&lt;li&gt;Parameters still come after the method name, &lt;strong&gt;parentheses are optional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Since we don't need curly braces here like in js, we use the keyword &lt;strong&gt;end&lt;/strong&gt; after the code to identify where the code finishes.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;return&lt;/strong&gt; keyword is not needed in Ruby but you can use it. It is just known to ruby that the last line will the the return value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now to check Ruby code, you need to run IRB and put your previous code, press enter then check with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;rb_method_return_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rb_method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Look how Im_written&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 15&lt;/span&gt;
&lt;span class="n"&gt;rb_method_return_value&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see the argument of 10 being passed into our method and being assigned to a new variable which then we can call on and we get 15 because of 10 + 5.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Fun fact&lt;/strong&gt;&lt;br&gt;
&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JUfuZpRI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0apqjun5639idch06h1m.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JUfuZpRI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0apqjun5639idch06h1m.jpeg" alt="jsrb" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Props for Beginners (react)</title>
      <dc:creator>adenaddis</dc:creator>
      <pubDate>Thu, 04 Aug 2022 16:05:00 +0000</pubDate>
      <link>https://forem.com/adenaddis/props-for-beginners-react-o3c</link>
      <guid>https://forem.com/adenaddis/props-for-beginners-react-o3c</guid>
      <description>&lt;p&gt;What makes the framework react so interesting and much better than vanilla javascript, is the fact that it is built on sections of your app called components. These components are functions that return what you would like that section of the app to do and results in much cleaner code. But what we will be focusing on is how we pass information from one component to the next. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a prop
&lt;/h2&gt;

&lt;p&gt;Props is short for properties and like I said above, it is used to pass information/data from one component to another.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Lets look at an example:&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// PARENT COMPONENT

function ArticlePost() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;ArticleContent articleText="Today Sherry Tomford, the girl who's been missing for the last 12 years, has finally been found" /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

// CHILD COMPONENT

function ArticleContent(props) {
  return &amp;lt;div&amp;gt;{props.articleText}&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example we can see 2 components. One being the parent and one the child. The parent component (ArticlePost) is returning a div containing article text. When we go on to the child component (ArticleContent) we can use props as the parameter followed by a return that states (props.articleText). This lets the code know that we want to grab article text from the parent component. &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%2F9to8akwzsx0z16h185zy.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%2F9to8akwzsx0z16h185zy.jpeg" alt="scold"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NOTE: Data only flows from parent component to the child component. In the same way that the parent tells the child what to do, not the other way around.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Double check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(props);
// =&amp;gt; { articleText: "Today Sherry Tomford, the girl who's been missing for the last 12 years, has finally been found" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can console.log props so we can see that it is indeed referring to the parent components data of article text.&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%2F51on4ewxt8pdf6u19hlm.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%2F51on4ewxt8pdf6u19hlm.jpeg" alt="toy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is this helpful ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Usually components will be in different files so the use of props allows you to write a piece of code once and use it in multiple other areas without having to rewrite it everywhere you want to use it.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why would you even want to pass that data down, can't you just use the original component ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, different component have different functions. The second component might want to access just a piece of data from the first component so it can make that data do something else.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;For example we can take a look here: &lt;/u&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%2F6bprs41a6y18lru24io0.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%2F6bprs41a6y18lru24io0.png" alt="Canvas e.g"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a parent component which is holding (isPublished) but we brought it here to the child component(BlogContent) so that we can manipulate the data via conditional rendering. If isPublished is false (is not published) then return null so the user can see no DOM elements displayed. But if it is published, display the following published content (shown in the return. The return wants to show the user the article text and the minutes to read. This is a more developed example of how and why we use props to grab data from the parent function/component to use it in the child and manipulate the data to show us something we want.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Variables:Code's Harmonizer</title>
      <dc:creator>adenaddis</dc:creator>
      <pubDate>Wed, 13 Jul 2022 06:28:21 +0000</pubDate>
      <link>https://forem.com/adenaddis/variablescodes-harmonizer-5eo</link>
      <guid>https://forem.com/adenaddis/variablescodes-harmonizer-5eo</guid>
      <description>&lt;p&gt;You'd be surprised how much the simple things mean until they're not there anymore. In Javascript or just code all together, one of the most common things done by a developer is variable assignment. It goes over many peoples head how vital this is to the coding process.&lt;/p&gt;

&lt;p&gt;Variables let code harmonize and work together beautifully. Makes for much cleaner code. If you're a beginner, prepare to use variable assignment like it's your best friend. It'll make your life a hundred times easier. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Variable Assignment ?
&lt;/h2&gt;

&lt;p&gt;It's quite simple. You just set your code expression equal to a word that best describes it. This way you can store the information the expression provides all into one word. It's just like a storage box that stores data so that Javascript can keep it in its memory so that we can access it later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we need to access it you may ask ? Well lets look at an example&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;We need to access the data with a simple variable so that we can do things to it like in this example remove it. Here we are selecting the main through its id and assigning it to the word 'main'. Now in the second line we can use the word 'main' to remove it from html instead of writing out the whole &lt;code&gt;document.getElementById("main")&lt;/code&gt;. This will be extra extra handy for when you have to do multiple things to that variable (see below for advanced example).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Now how do we write out variable assignment ?
&lt;/h2&gt;

&lt;p&gt;The two recommended methods to assign a variable are 'let' or 'const'. Followed by the name of the variable you choose and the assignment operator which is an equal sign (=). Followed then, by your expression.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Let&lt;/strong&gt; is used to assign a variable that &lt;u&gt;can be reassigned&lt;/u&gt;. If you're doing a long code where you would need to change the value of a variable, let allows that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Const&lt;/strong&gt; is used when you are certain of the value for that variable because it &lt;u&gt;cannot be reassigned&lt;/u&gt;. If you're doing a long code and don't want to mess yourself up by accidentally reusing the same variable name for a different value, const is the way to go.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B1ovLc3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj5tx32ee2yal6x8nair.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B1ovLc3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj5tx32ee2yal6x8nair.png" alt="Let vs Const" width="750" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, we used let on the variable y and const on the variable x. When we tried to reassign y to a different string, it worked and the new value popped right below it. However when we tried to reassign the x, we got an error. This is because const is permanent, let is not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More advanced example of why variables are amazing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FnKr9t9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92djjkakdn88nqvxyxr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FnKr9t9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92djjkakdn88nqvxyxr4.png" alt="advanced eg" width="728" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without the variable assignment of form, newComment and li, we would get the longest lines of code that are much more prone to errors and bugs. Because we stored those expressions into variables we get a much cleaner code that is also easier for other coders to read. Now we can give form a submit event listener, create a list and through that list give newComment text content to make a successful comment section for people to submit things into.&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://replit.com/new/nodejs"&gt;Replit&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
