<?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: coding4grandmas</title>
    <description>The latest articles on DEV Community by coding4grandmas (@coding4grandmas).</description>
    <link>https://dev.to/coding4grandmas</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%2F646782%2Fa51b12c7-1c72-4883-b246-08f32402c313.jpg</url>
      <title>DEV Community: coding4grandmas</title>
      <link>https://dev.to/coding4grandmas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coding4grandmas"/>
    <language>en</language>
    <item>
      <title>Flow for Grandmas </title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Wed, 30 Jun 2021 20:26:58 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/flow-for-grandmas-2m0c</link>
      <guid>https://dev.to/coding4grandmas/flow-for-grandmas-2m0c</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P3jEWsXq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pamx4009yjkdnz6wy6sa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P3jEWsXq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pamx4009yjkdnz6wy6sa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Normally Ruby and most other programming languages process instructions in a linear way, top to bottom. But what if we needed something more? What if our logic requires us to evaluate certain conditions and then operate upon that choice?&lt;/p&gt;

&lt;p&gt;Today we will be covering conditionals, comparison and logical operators, and we will even throw in some ternary operators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conditionals&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Quoting Russ Olsen from Eloquent Ruby:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;If indention, comments, and the form of your variables are the things that give you program its look, it's the control structures - the ifs and elses and whiles - that bring it to life&lt;/em&gt;".&lt;/p&gt;

&lt;p&gt;Conditionals play a very important role in our code as it tells the program how to proceed based on defined parameters. The statements that we use are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If / else&lt;/li&gt;
&lt;li&gt;if / elsif&lt;/li&gt;
&lt;li&gt;unless&lt;/li&gt;
&lt;li&gt;case&lt;/li&gt;
&lt;li&gt;while / until&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;IF/ELSE&lt;/code&gt;: this is the most important flow control. If a condition is met (true), then it will do something; otherwise, it will do something else - a classic one.&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"You can vote"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"You can't vote"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "You can't vote&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In plain English, we are telling Ruby - "If the age is equal to or above 18, then print 'You can vote', otherwise print 'You can't vote'".&lt;/p&gt;

&lt;p&gt;In programming, we assign 14 to our age variable. When Ruby runs the expression, it checks whether the age variable is greater than or equal to 18. Since the age (14) is less than 18, it does not implement the logic (i.e. "You can vote"). Because the first part of the if expression was not met, Ruby executes the else expression, which means the expression(s) above were false.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ELSEIF&lt;/code&gt;:  is used when you have more than one condition to evaluate. For example:&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;digit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;digit&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Zero"&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;digit&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"One"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I don't know this digit,sorry!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "One"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In plain English, we are telling Ruby - "If the digit is equal to 0 print "Zero", else if digit equals to 1 print "One", otherwise if none of these are true print "I don't know this digit, sorry!"&lt;/p&gt;

&lt;p&gt;Ruby ran the statement, and it evaluated the first expression as false since the value of our digit is 1. Then it checked the second expression, and it was true since 1 equals 1. In this statement, we never reached the else expression. This is perfectly fine.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Unless&lt;/code&gt;: is the exact opposite of 'if'. 'If' will execute when the statement is true. 'unless' on the other hand will execute when the statement is false:&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;

&lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"You can't vote"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"You can vote"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "You can vote&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In plain English, we are telling Ruby - "If the age is not equal to or above 18, then print 'You can vote', otherwise print 'You can't vote'". In this instance, we will execute the unless statement since 14 is less than 18, meaning we have a false value. It takes some time wrapping your head around this particular expression.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CASE/WHEN&lt;/code&gt;: is very similar to if / else expression. The premise is very similar:&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;digit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;case&lt;/span&gt; 
&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;digit&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Zero"&lt;/span&gt;
&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;digit&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"One"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I don't know this digit,sorry!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; 1 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we said, it is very similar to if-else. In this instance, we are telling ruby to execute the statement when the digit variables match 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison Operators&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;They are used to check values between strings and numbers.&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="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;Equal&lt;/span&gt;

&lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;Not&lt;/span&gt; &lt;span class="n"&gt;equal&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Greater&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Less&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;Greater&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="n"&gt;equal&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; 

&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;Less&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="n"&gt;equal&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't worry; we are not going back to solving math problems. Comparison operators allow the programmer to build a much more complex conditional statement. &lt;/p&gt;

&lt;p&gt;For example, the equal (==) comparison will return true if the value on the left is equal to the value on the right&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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; true&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Logical Operators&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Think of logical operators as Boolean operators.&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;and&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;

&lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;

&lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&amp;amp;&amp;amp; returns true when both conditions are satisfied for example&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"True"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "True"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the &amp;amp;&amp;amp; (and) operator to evaluate true, both conditions need to be true. For example:&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"True"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"False"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "False"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;a == 1 was evaluated as true; however, b was evaluated as false. Hence the output we got was false.&lt;/p&gt;

&lt;p&gt;The || (or) works a little bit different. Only when one of the conditions is true, it will return true.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"True"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"False"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; "True"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly the ! (not) is an interesting one as it returns true when the condition is not satisfied.&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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; true&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this instance, Ruby evaluates the numbers in the parenthesis which is true. However, when the ! (not) operator is used, the value returned is false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ternary Operator&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The ternary operators is used when you want to make a quick if / else statement.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt; 

&lt;span class="c1"&gt;# =&amp;gt; true Let's break this down. First, Ruby evaluates whether the statement a == 1 is true or false. If it is true, the code to the left of : gets executed. If the statement is false, the code to the right of : gets executed. You can see it is very similar to an if / else statement, and it is much easier to implement and read.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets break this down. First, Ruby evaluates whether the statement a == 1 is true or false. If it is true the code to the left of : gets executed. If the statement is false the code to the right of : gets executed. You can see it is very similar to an if / else statement, also it is much easier to implement/read and quite common in other languages such as Java script. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are finally at the end. Today we've covered a few important concepts, conditionals, comparison, logical and ternary operators. All of them play an important role in the program. It does take some time to wrap your head around the conditionals. But once you have a good understanding of it, your code can become much more sophisticated and complex.&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Methods for Grandmas</title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Thu, 24 Jun 2021 13:43:07 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/methods-for-grandma-1n92</link>
      <guid>https://dev.to/coding4grandmas/methods-for-grandma-1n92</guid>
      <description>&lt;p&gt;Today we will be covering a very interesting topic - methods.  &lt;/p&gt;

&lt;p&gt;Methods primarily achieve two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allows the code to be reusable&lt;/li&gt;
&lt;li&gt;Keeps your code organised&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Implementing methods achieves a very important objective - it keeps your code DRY (No grandma, we are not suggesting that you drink less water). DRY stands for &lt;strong&gt;Don't Repeat Yourself.&lt;/strong&gt; In programming, you should always seek to keep your code simple, elegant and easy to understand, hence the need to apply the DRY principle. When possible the programmer should always aim to avoid re-writing code. &lt;/p&gt;

&lt;p&gt;Methods allows you to be much more efficient with your programming. Instead of writing the same lines of code a number of times, you can implement a method that will execute a pre-defined code.&lt;/p&gt;

&lt;p&gt;For example:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_name_is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&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;"Hello my &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By implementing this simple method, we can call it when we need it anywhere in our code. Thus we are following the DRY principle and minimising unnecessary lines of code in our program.&lt;/p&gt;

&lt;p&gt;Now, let's break it down how a method actually works.&lt;br&gt;
A method is written like this.&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;method_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
 &lt;span class="n"&gt;executable&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; 
&lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three points to consider: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method Names&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly, to variables method can be named. We do advise naming the methods in easily understood names that clarify what that method is supposed to do. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Argument&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Next is the argument(s). When you want to use a method, most of the time, you pass an argument. In the previous example, we passed a name. What is being passed can be various data types (strings, integers, arrays). You can even pass more than one argument - the possibilities are endless (until your program crashes).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Executable Code&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Lastly, this is where the magic happens. As a programmer, you can implement anything you like. Do you want the method to calculate the square area of the house or convert a string to an integer or maybe calculate the age of you grandma. It can be done.&lt;/p&gt;

&lt;p&gt;Let's implement an example to understand how a method works fully. For the example below, we are looking to calculate the age of our grandma.&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;grandma_birth_year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1930&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_age&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;current_age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Grandma is &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;current_age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;calculate_age&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grandma_birth_year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 91&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It might seem like there is a lot, but it is not - let's break it down by line. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We assign a birth year which is 1930.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;grandma_birth_year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1930&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We create a method which accepts a year. Year in the parenthesis is a parameter which receives an argument, when the method is called.
&lt;/li&gt;
&lt;/ol&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;calculate_age&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We implement our logic. We take the current year minus the year we passed as an argument (1930).
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;current_age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We write some logic which will print out the age of our grandma
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Grandma is &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;current_age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old."&lt;/span&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The last part we have not covered, which is calling the method.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;calculate_age&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grandma_birth_year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the method is called, it tells the computer not to run any other lines and go to the called method and execute the code inside that method. Once the code has been executed, Ruby resumes from where the method was called.&lt;/p&gt;

&lt;p&gt;The outcome, we get is a print statement&lt;br&gt;
"Grandma is 91 years old."&lt;/p&gt;

&lt;p&gt;Before we wrap up this blog, it is important to touch on parameters and arguments.&lt;br&gt;
In the example above, the parameter was (year). The parameter is what the method accepts. A point to note the parameter could be named anything we want (however, we also advise following a good naming convention).&lt;br&gt;
The argument in the above is (grandma_birth_year). The code calls the method, and the argument is sent to the parameter in the method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;What's been covered is very simple in nature (hopefully our grandmas think the same). One thing to consider is that, once the program becomes complex as more logic is implemented, employing methods will achieve two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The code will be reusable&lt;/li&gt;
&lt;li&gt;The code will be organised &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This ties up very well with the DRY principle. The concept is to minimise how many lines are written and not to repeat your self - hence, using method statement achieves both. In the professional environment, methods are used often and we believe every programmer should have a good mastery over them.&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Programming Basics for Grandmas (Ruby)</title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Tue, 22 Jun 2021 14:27:50 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/programming-basics-for-grandmas-10ma</link>
      <guid>https://dev.to/coding4grandmas/programming-basics-for-grandmas-10ma</guid>
      <description>&lt;p&gt;Today is the big day; we finally get to explore the intricate world of programming (kind of). Hopefully, by the end of this blog, our Grandmas will be able to write the first lines of code for their Airbnb app clone.&lt;/p&gt;

&lt;p&gt;A few points of clarification before we dwell on the blog. As you know, the world of programming is very diverse which covers many different fields. With diversity comes various programming languages. As a matter of fact, our trustworthy Wikipedia source indicates there are approximately 700 programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l41YtZOb9EUABnuqA/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l41YtZOb9EUABnuqA/giphy.gif" alt="https://media.giphy.com/media/l41YtZOb9EUABnuqA/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, we couldn't believe it as well. But you might ask, what is a programming language? A programming language aims to provide detailed instructions to the computer in a binary format (computers can only understand 0 and 1). In short, any instruction written in a programming language gets translated to binary format, allowing the computer to execute a specific set of instructions (computer language).&lt;/p&gt;

&lt;p&gt;With the difficult part out of the way; let's cover what language we will be using. We feel most comfortable in Ruby, and we also believe Ruby is relatively easy to read and understand (very similar to English). One thing to mention more or less, every language is the same in terms of basics. The main difference is how it is written. For the programming savvy, the term is 'syntax'. The reason why we have so many languages is they are used for different purposes - each programming language is designed to make certain things easy. Another point is that once one language is learned, other languages can be picked up relatively quickly.&lt;/p&gt;

&lt;p&gt;Now, let's get back to the real stuff - coding!&lt;/p&gt;

&lt;p&gt;Today we are going to cover two concepts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Data types &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the first things we learned when we started coding was variables. Variables are an essential part of programming as it allows you to stores values. The best way to explain how a variable works is through the box example. Value(s) can be stored in the box which are then labelled. In this instance the variable name is Grandma, and the stored value is Barbara.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dBGNqp6w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfb3r2ljhcrdbdzq6s8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dBGNqp6w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfb3r2ljhcrdbdzq6s8u.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might ask, what is so great about variables? The answer is very simple, they allow the programmer to store values that can be accessed at a later use.&lt;/p&gt;

&lt;p&gt;The creation of a variable works by associating a Ruby object with a variable name this is called a variable assignment.&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="no"&gt;Grandma&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Barbara"&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="no"&gt;Grandma&lt;/span&gt; 

&lt;span class="c1"&gt;# =&amp;gt; "Barbara"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best way to understand variable assignments is to read from right to left (we assigned "Barbara" to Grandma variable). Then we can use the Grandma variable when we require.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data types&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The different Ruby data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Numbers (integer &amp;amp; float)&lt;/li&gt;
&lt;li&gt;Boolean (True, False &amp;amp; nil)&lt;/li&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Hashes&lt;/li&gt;
&lt;li&gt;Symbols&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Strings&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;A string is a text.&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;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello world!"&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt;

&lt;span class="c1"&gt;# =&amp;gt; String &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The simplest and most common way to create a string is to enclose the object in quotes.&lt;/p&gt;

&lt;p&gt;You can do some nifty stuff with strings. For example, you can use concatenation. Which means you can combine various strings into a single string.&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="s2"&gt;"Grand"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"ma"&lt;/span&gt;
&lt;span class="c1"&gt;# ⇒ "Grandma" &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other way of doing (better) is using interpolation&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="nb"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Grandma"&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Hello, &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!"&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; "Hello Grandma!"                     &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other interesting stuff that can be done is using Ruby's build in methods.&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="s2"&gt;"Grandma"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 7&lt;/span&gt;

&lt;span class="s2"&gt;"Grandma"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upcase&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; "GRANDMA"&lt;/span&gt;

&lt;span class="s2"&gt;"Grandma"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; "amdnarG"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Ruby there are two different types of numbers integers and floats. Integers are represented without a decimal places and floats have a decimal places. &lt;/p&gt;

&lt;p&gt;Integer&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Float&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="mf"&gt;2.0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 10.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we introduce division, the difference become apparent - integers and floats will produce different results.&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; 
&lt;span class="c1"&gt;# =&amp;gt; 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mf"&gt;10.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; 1.25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might ask, why is this happening? The answer is simple integer data type cuts off after the decimal places. In contrast, the float provides the numbers after the decimal places.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Booleans&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Boolean data type is very straightforward; it has three properties true, false and nil. The main purpose of using true or false is to evaluate a logical statement, to check whether it is true or false.&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="s2"&gt;"Grandma"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Grandma"&lt;/span&gt;
&lt;span class="c1"&gt;#= &amp;gt; true &lt;/span&gt;

&lt;span class="s2"&gt;"Grandma"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Barbara"&lt;/span&gt;
&lt;span class="c1"&gt;#= false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, the nil data type is somewhat unique - it represents nothing (yes, you've heard us right). Sometimes you might need to assign a nil value to an object (this will be discussed in the future).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arrays give the programmer a very useful tool at his or her disposal. It allows to store multiple values in a single variable. The stored values can be any data type from strings to numbers.&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;grandma_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"grandma"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Square brackets represent arrays. As mentioned previously, they can store more than one value.&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;number_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&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="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To access the array is done by referring to the index. &lt;/p&gt;

&lt;p&gt;For example:&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;grandma_items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"glasses"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"walking stick"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"medication"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the array above, the first element would be glasses. Counter-intuitively the index starts at 0.&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="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;grandma_items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; "glasses"&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;grandma_items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; "medication"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how indices work within an array. The counting always starts at 0.&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;grandma_items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"glasses"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"walking stick"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"medication"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; 
                       &lt;span class="mi"&gt;0&lt;/span&gt;             &lt;span class="mi"&gt;1&lt;/span&gt;              &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hashes and Symbols&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have decided to dedicate a separate blog to hashes and symbols as they are more complicated data types than what's been covered above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We've only covered the basics here; in subsequent blogs, we will break down each concept in much greater detail. The reasoning behind this is to keep the posts short and sweet. It can be overwhelming with all the new information, especially with someone like our Grandmas who have no prior experience in coding. The idea is to make each post relatively easy to digest.&lt;/p&gt;

&lt;p&gt;In summary, variables allow the programmer to store values (box example). The variables then can be accessed at a later use. Understanding various data types is important as well - if something is unclear, we would advise having another read. If it is still unclear, do not hesitate to get in touch with us. We are happy to help (can't be worse than explaining to our Grandmas).&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Git and GitHub for Grandmas</title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Fri, 18 Jun 2021 21:43:00 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/git-and-github-5g05</link>
      <guid>https://dev.to/coding4grandmas/git-and-github-5g05</guid>
      <description>&lt;p&gt;Suggested &lt;a href="https://open.spotify.com/playlist/0MJBni0UzdnML1amikx0Rc?si=1bec9f5885804c4b"&gt;playlist&lt;/a&gt; while reading this post.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CPMqV14A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrtu2o7ev0hrtf0139sa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CPMqV14A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrtu2o7ev0hrtf0139sa.png" alt="Playlist on Spotify"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In today's post, we will cover two very important concepts: Git and Github. While they do sound similar, they serve two very different purposes. Git is an open-source version control system (in layman's terms, it allows you to monitor and track your code). On the other hand, Github is a website (and a cloud-based service) that help programmers manage, store, track, and control changes to their code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Git?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We all know how difficult it can be working within a team - especially in programming with so many moving pieces. However, Git is a tool that overcomes the issues mentioned above. It allows multiple programmers to monitor and track different versions of the codebase (you will still have to deal with your passive-aggressive colleagues, though...).&lt;/p&gt;

&lt;p&gt;Without Git (manual version control), this is how version control would look like:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Jjt-W4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4hi24k8do0ab71phlvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Jjt-W4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4hi24k8do0ab71phlvu.png" alt="manual version control"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git does something special, it tracks all the data that has been amended. A better way to explain it: imagine Git saveing/storing information through a series of snapshots. No, Grandma, Git doesn't take literal photos of the code, but it does act in a similar concept. Every time we save the project, Git (being a smart apple) takes a picture of all your files at that moment in time and saves a reference point to that snapshot.&lt;/p&gt;

&lt;p&gt;To break it down further, it keeps track of all the data that have been amended. Additionally, it tracks who did it, what they changed and when they changed it. And this is what you call version control. Let's not forget that with Git, you can also share your code with collaborators using GitHub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While Git is a command-line tool operating locally, Github is a Git repository hosting service for developers to host code and their versions (under Git management). It makes code sharing and collaborating easier. Also, you can find a lot of open source projects on it where you could contribute.&lt;/p&gt;

&lt;p&gt;Imagine a massive website like Facebook. Suppose a software developer wants to implement a specific change to the codebase of Facebook. In that case, we can assume it would be very dangerous to alter the code directly within the codebase.&lt;/p&gt;

&lt;p&gt;Instead of editing the source code directly, GitHub provides some nifty tools for us.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;branching (forking)&lt;/li&gt;
&lt;li&gt;merging&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Branching allows the programmer to copy the code from the original codebase and implement changes to the copied code without affecting the original code.&lt;/p&gt;

&lt;p&gt;Once the developer carries out the desired revisions to the copied code, they can merge the altered code to the official source code. Below is an example of how branching (forking) would work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D58eCRGw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3dpdx8hofoe9d6ausfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D58eCRGw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3dpdx8hofoe9d6ausfo.png" alt="Gri branching"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both Git and GitHub provide useful utility for the developer. Git provides a snapshot of the code as it goes through iterations. On the other hand, GitHub allows a programmer to implement changes to a duplicate version of the source code through branching, which can then be merged into the official codebase.&lt;/p&gt;

&lt;p&gt;That's all for now, folks; the next blog will cover Ruby programming basics.&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Terminal for Grandmas</title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Tue, 15 Jun 2021 12:56:50 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/terminal-for-grandmas-1l41</link>
      <guid>https://dev.to/coding4grandmas/terminal-for-grandmas-1l41</guid>
      <description>&lt;p&gt;Grandma are you ready (we are not)? &lt;/p&gt;

&lt;p&gt;Today's blog will cover the Terminal / Command Prompt / Command Line (all are effectively the same thing)&lt;/p&gt;

&lt;p&gt;Once we go through the various terminal concepts, we feel our Grandmas might be able to challenge us in a Hackathon!&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminal
&lt;/h2&gt;

&lt;p&gt;Linux Shell or Terminal &lt;/p&gt;

&lt;p&gt;For clarity we will be using Linux commands.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--paYnIYX_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5y61e58x5ruhcpx7ims.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--paYnIYX_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5y61e58x5ruhcpx7ims.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the uninitiated, the blank screen might look intimidating; for others, a hacking device. Rest assured, the command line is an essential part of any programmer's toolset.&lt;/p&gt;

&lt;p&gt;In Layman's term (or grandmas?), the terminal acts as an interface between the computer and the human.&lt;/p&gt;

&lt;p&gt;To break it down further, the command line allows us to input information and read the output from the computer.&lt;/p&gt;
&lt;h3&gt;
  
  
  You might ask what kind of input?
&lt;/h3&gt;

&lt;p&gt;The answer can range from creating files to running apps. &lt;/p&gt;

&lt;p&gt;For example, our grandma wanted to create a folder titled airbnb_clone.&lt;/p&gt;

&lt;p&gt;She would input the following command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir airbnb_clone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If she wanted to create a file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch airbnb.rb 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is this black magic? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mkdir&lt;/strong&gt; stands for make directory. This creates a folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;touch&lt;/strong&gt; creates a file. As we are learning ruby programming language, we have indicated it to be a ruby file by naming it rb.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Are there any other commands?
&lt;/h3&gt;

&lt;p&gt;Glad you asked grandma.&lt;/p&gt;

&lt;p&gt;Commands which get used quite often are:&lt;/p&gt;

&lt;p&gt;pwd =&amp;gt; print working directory &lt;/p&gt;

&lt;p&gt;ls =&amp;gt; list&lt;/p&gt;

&lt;p&gt;cd =&amp;gt; change directory (cd )&lt;/p&gt;

&lt;p&gt;cd .. =&amp;gt; goes back to parent directory&lt;/p&gt;

&lt;p&gt;rm  =&amp;gt; remove a file&lt;/p&gt;

&lt;p&gt;rm -r  =&amp;gt; remove a directory&lt;/p&gt;

&lt;p&gt;rm -rf  =&amp;gt; force remove a directory&lt;/p&gt;

&lt;p&gt;mv   =&amp;gt; move file_1 to file_2_location&lt;/p&gt;

&lt;p&gt;mv    =&amp;gt; rename a file&lt;/p&gt;

&lt;p&gt;stt / code . =&amp;gt; open sublime text/vs code in the current folder&lt;/p&gt;

&lt;p&gt;cat  =&amp;gt; show the content inside the file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HboumuNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqv0rd5x9e4jd5mxz0t8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HboumuNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqv0rd5x9e4jd5mxz0t8.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's how we felt the first time when we saw the various commands. Rest assured, they are not as bad as they seem. &lt;/p&gt;

&lt;p&gt;We have learned mkdir and touch. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mkdir&lt;/strong&gt; creates a folder&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;touch&lt;/strong&gt; creates a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The beauty of the command line is that the mouse cursor doesn't work. Everything is done via commands (typing).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pwd =&amp;gt; print working directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to know in which directory you are in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls =&amp;gt; list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to check all the file names in the current directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd =&amp;gt; change directory (cd &amp;lt;folder_name&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you wan to navigate to a different directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd .. =&amp;gt; goes back to parent directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to go back to the previous directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm &amp;lt;filename&amp;gt; =&amp;gt; remove a file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to delete a file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -r &amp;lt;foldername&amp;gt; =&amp;gt; remove a directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to remove a folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv &amp;lt;file_1_location&amp;gt; &amp;lt;file_2_location&amp;gt; =&amp;gt; move file_1 to file_2_location
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to move a file from one directory to a different directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv &amp;lt;file_with_old_name&amp;gt; &amp;lt;file_with_new_name&amp;gt;  =&amp;gt; rename a file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to rename the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stt / code . =&amp;gt; open sublime text/vs code in the current folder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to open your text editor like a bad-ass&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat &amp;lt;filename&amp;gt; =&amp;gt; show the content inside the file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to look at the contents of the file you are currently in&lt;/p&gt;

&lt;p&gt;Hopefully, this wasn't too much (Grandma, are you still awake?). In summary, the terminal is an essential part of the programmer's toolset. It allows implementing various actions from creating files to running programs.&lt;/p&gt;

&lt;p&gt;The next blog will cover git and GitHub.&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hello grandma!</title>
      <dc:creator>coding4grandmas</dc:creator>
      <pubDate>Wed, 09 Jun 2021 20:31:38 +0000</pubDate>
      <link>https://dev.to/coding4grandmas/hello-grandma-3pmd</link>
      <guid>https://dev.to/coding4grandmas/hello-grandma-3pmd</guid>
      <description>&lt;p&gt;&lt;strong&gt;Who are we as devs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are R. and E., and both of us are working in non-programming fields. Our goal is to ditch our current jobs and become software developers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are we doing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are doing a full stack web development boot camp based in London. As full-stack devs, we are learning back-end (Ruby on Rails, SQL) and front-end (HTML, CSS and Javascript) web development concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goals?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To allow our grandmas to deploy the next Airbnb killer app;&lt;/li&gt;
&lt;li&gt;To keep it simple and accessible (especially for our dear grandmas);&lt;/li&gt;
&lt;li&gt;We, as aspiring developers, want to learn through teaching.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Timetable?&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The plan is to share what we have learned in the Bootcamp (grandma, thanks for the big loan). We will do it by publishing various programming topics in a digestible format. Next week we will start from scratch discussing Terminal and Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;puts "Stay tuned!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>career</category>
      <category>devjournal</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
