<?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: Tatyana Celovsky</title>
    <description>The latest articles on DEV Community by Tatyana Celovsky (@tcelovsky).</description>
    <link>https://dev.to/tcelovsky</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%2F110882%2F79fe0a00-fea4-4e23-88ed-ee8a71f894a9.jpg</url>
      <title>DEV Community: Tatyana Celovsky</title>
      <link>https://dev.to/tcelovsky</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tcelovsky"/>
    <language>en</language>
    <item>
      <title>Tell Your Story with GitHub Issues</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Wed, 24 Aug 2022 16:25:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/tell-your-story-with-github-issues-e2b</link>
      <guid>https://dev.to/tcelovsky/tell-your-story-with-github-issues-e2b</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oUVJ5w5K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpd0zb2x228z50q9urw8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oUVJ5w5K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpd0zb2x228z50q9urw8.jpeg" alt="Lower right hand angle of an Apple keyboard, a golden pen, a pencil, reading glasses, and two notebooks are spread out on a white background." width="880" height="660"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@jessbaileydesigns"&gt;Jess Bailey&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have heard of GitHub Issues, a built-in tracking tool that is available with every GitHub repository, but have you considered how helpful GitHub Issues may be when working on personal projects? Before starting a new project, you likely have at least a vague idea of what you want it to look like and what features you want to implement. It’s also likely that you do not have a particularly detailed step-by-step plan. This can sometimes result in frustration - you may have to start over a few times when implementing a new feature, or rearrange your project structure several times, just because a clear plan was not in place from the beginning. Sounds familiar? GitHub Issues can help solve these problems.&lt;/p&gt;

&lt;p&gt;GitHub Issues is a tracking tool that is built-in with all GitHub repositories. Do not assume that the word “issue” here has a negative connotation, issues can be a good thing and GitHub Issues can be used to track and document every feature you want to implement in your project. Information included in each Issue can be as detailed or as high-level as you prefer. For example, one of your Issues can be “A user should be able to toggle between a list and a detailed view.” That may sounds simple enough, but GitHub Issues allows you to add as much or as little information as you’d like, so you may choose to specify exactly how you’d like the toggle button to look, what color the selected text should be, and any other details you’d like to include.&lt;/p&gt;

&lt;p&gt;GitHub Issues is a great way to keep track of what features have been implements and what is still outstanding. For example, you can create a new branch for every Issue on your list, work on that feature, merge it into the main branch, and then close out the Issue. If you put down your project for a bit and then get back to it later, you’ll be able to quickly get up to speed on what features have been implemented and what else is still outstanding.&lt;/p&gt;

&lt;p&gt;Lastly, GitHub Issues is a great way to tell the story of your project. You can plan out your Issues such that each one corresponds to a feature you want to implement and each new one builds on the previous Issues. The very first Issue you open in your project can be something very basic, such as “The name of the website should appear at the top of the page.” While the last Issue can signify the end of the project, for example, “The website should look professional and welcoming.” All the Issues in between these two will tell the story of how your project grew and progressed to the “professional and welcoming” final look.&lt;/p&gt;

&lt;p&gt;GitHub Issues is an excellent way to keep track of your plans and can help “tell the story” of your project. GitHub Issues offers a lot of great features, such as the ability to create a new branch for every Issue, automatically close out Issues when the branch is merged, assign and re-assign Issues, search and filter Issues, etc. GitHub has an excellent &lt;a href="https://docs.github.com/en/issues"&gt;guide&lt;/a&gt; that will help you get familiar with all the features and I hope you consider using GitHub Issues for your next project.&lt;/p&gt;

</description>
      <category>github</category>
    </item>
    <item>
      <title>Let's Talk About Big-O - Space Complexity</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Thu, 06 Jan 2022 10:00:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/lets-talk-about-big-o-space-complexity-39jl</link>
      <guid>https://dev.to/tcelovsky/lets-talk-about-big-o-space-complexity-39jl</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OGt3Gr9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58yekdkemerktb49boeh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OGt3Gr9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58yekdkemerktb49boeh.jpg" alt="A pile of manilla folders and mail envelopes on a neutral background." width="880" height="1320"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@sharonmccutcheon?utm_source=medium&amp;amp;utm_medium=referral"&gt;Sharon McCutcheon&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Big-O notation isn’t something that we worry too much about while learning to code. After all, our primary goal is to learn how to code. It’s no secret that in programming there can be multiple ways to correctly do something, for example, in Javascript there are multiple ways to write functions (think arrow functions vs regular functions), and once we’ve mastered the basics, it’s time to focus on optimization. This is where Big-O notation will enter your vocabulary and you’ll want to understand what it actually is. This article is a brief introduction to the Big-O notation.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Big-O?
&lt;/h3&gt;

&lt;p&gt;Big-O (pronounced “big-oh”) is a theoretical measure of the execution of an algorithm; it tells us how much time or memory is needed to execute a function when given the input of size &lt;em&gt;n&lt;/em&gt;. In this case, &lt;em&gt;n&lt;/em&gt; represents the number of items that will be analyzed by the given function and algorithm is the function itself.&lt;/p&gt;

&lt;p&gt;Big-O notation is the language used to talk about how much time the algorithm takes to run (time complexity) or how much memory is used to run it (space complexity). In this article we are going to focus primarily on the space complexity. See &lt;a href="%5Bhttp://tatyanacelovsky.com/let's_talk_about_big_o%5D(http://tatyanacelovsky.com/let's_talk_about_big_o)"&gt;here&lt;/a&gt; for the discussion on time complexity.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Space Complexity?
&lt;/h4&gt;

&lt;p&gt;Space complexity of an algorithm refers to the amount of memory space required to solve the algorithm with respect to the size of the input. It is the memory required by an algorithm until it executes completely.&lt;/p&gt;

&lt;p&gt;Similar to &lt;a href="%5Bhttp://tatyanacelovsky.com/let's_talk_about_big_o%5D(http://tatyanacelovsky.com/let's_talk_about_big_o)"&gt;time complexity&lt;/a&gt;, space complexity is expressed in Big-O notation.&lt;/p&gt;

&lt;p&gt;Big-O notation can express the best, worst or average-case scenario of an algorithm’s growth. However, as software engineers, we are primarily concerned with the worst-case scenario. We want to know the largest possible amount of memory space that will be required to run an algorithm with an input of size n.&lt;/p&gt;

&lt;p&gt;The amount of memory space required to execute an algorithm is affected by all the variables, constants, inputs, data structures, etc., that are utilized in an algorithm. Please note that space complexity can be further affected by variables such as compiler, programming language and even the machine running the algorithm, but Big-O does not take these into account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(1) or Constant Complexity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Any variables declared within a function or passed into a function will always take up the same amount of memory space, even if they are later re-assigned. That’s because memory space for any given variable is allocated at the time it is initialized, so any change in the value of that variable does not change the amount of memory space allocated to it. This means that space complexity of constants and variables is O(1) or constant space complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(n) or Linear Complexity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Any arrays that are either passed to the function or built up within a function will require memory space to be allocated to each element in that array. This means that space complexity of an array is O(n) or linear space complexity, where n is the number of elements of the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Calculating Big-O
&lt;/h3&gt;

&lt;p&gt;Remember that Big-O notation gives the worst-case scenario of an algorithm’s growth rate relative to the size of the input and does not take into account variables such as processors or language used to write the function. Similarly, Big-O is not concerned with any constants that may be a part of an algorithm as these make very little difference in the overall space complexity approximation.&lt;/p&gt;

&lt;h4&gt;
  
  
  O(1) or Constant Complexity
&lt;/h4&gt;

&lt;p&gt;Take a look at the below code example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we have three variables passed to the function, one variable initialized and then re-assigned within the function. Memory space is allocated at the time of initialization of our variable and the amount of memory space needed to later re-assign a value to it does not change. Therefore, space complexity of this example is O(1) or constant complexity.&lt;/p&gt;

&lt;h4&gt;
  
  
  O(n) or Linear Complexity
&lt;/h4&gt;

&lt;p&gt;Take a look at the below code example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we have an array passed to the function, one variable is initialized, then we loop through the passed array and re-assign the value of our variable. Memory space is allocated for each item of the array, space complexity of this is O(n), where n is the number of elements in the array. Memory space needed for initialization and later re-assignment of a variable is O(1), or constant space, as discussed above.&lt;/p&gt;

&lt;p&gt;Total space complexity of the above example is O(n+1), but remember that Big-O is not concerned with any constants, so we drop the 1 and are left with space complexity of O(n) or linear complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Space/Time Complexity Tradeoffs
&lt;/h3&gt;

&lt;p&gt;How do we know when our algorithm is efficient? It seems the answer is simple: our algorithm is efficient when it is fast and takes up the least amount of memory possible. Unfortunately, in reality things are not so simple. Often times increasing speed will lead to increased memory consumption or vice-versa. Therefore, we should not aim for the best time and space efficiency, but rather find middle ground that will satisfy our requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Having a good understanding of Big-O notation provides a more well-rounded context when designing algorithms. This article is only an introduction and if you’d like to read more on this topic, I would recommend &lt;a href="%5Bhttps://www.bigocheatsheet.com/%5D(https://www.bigocheatsheet.com/)"&gt;Big-O Cheat Sheet&lt;/a&gt; and &lt;a href="%5Bhttps://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/%5D(https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/)"&gt;What is Big O Notation Explained: Space and Time Complexity&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/34038e0b815b3978d03a157e8a779907"&gt;O(1) Example gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/af276675d6c562f4e7e8febe4d7a43e6"&gt;O(n) Example gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9"&gt;Let’s Talk About Big-O - Time Complexity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.bigocheatsheet.com/"&gt;Big-O Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/"&gt;What is Big O Notation Explained: Space and Time Complexity&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bigo</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Algorithm Series - Insertion Sort</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Wed, 17 Nov 2021 16:00:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/algorithm-series-insertion-sort-29ai</link>
      <guid>https://dev.to/tcelovsky/algorithm-series-insertion-sort-29ai</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R9rQB450--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8r6vgnxqfrc209qrgte2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R9rQB450--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8r6vgnxqfrc209qrgte2.jpg" alt="Bright, multicolored paint cards are arranged in the shape of a hand fan on a white background." width="880" height="880"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@copperandwild"&gt;Dee @ Copper and Wild&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a quick tutorial on the Insertion Sort algorithm and its implementation in Javascript.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Insertion Sort Algorithm
&lt;/h3&gt;

&lt;p&gt;Insertion Sort is a &lt;a href="%5Bhttps://en.wikipedia.org/wiki/Sorting_algorithm%5D(https://en.wikipedia.org/wiki/Sorting_algorithm)"&gt;sorting algorithm&lt;/a&gt; that places the element in its appropriate place based on the sorting order. A good example of Insertion Sort is sorting cards held in your hands during a card game.&lt;/p&gt;

&lt;p&gt;Let’s take a look at Insertion Sort when trying to sort the elements of an array in an ascending order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Assume that the first element of the array is property sorted;&lt;/li&gt;
&lt;li&gt;Store the second element of the array in a &lt;code&gt;key&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compare &lt;code&gt;key&lt;/code&gt; to the first element - if &lt;code&gt;key&lt;/code&gt; is smaller that the first element, then &lt;code&gt;key&lt;/code&gt; is placed in front of the first element;&lt;/li&gt;
&lt;li&gt;Store the next unsorted element of the array in a &lt;code&gt;key&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compare &lt;code&gt;key&lt;/code&gt; to the sorted element and place it in the appropriate place with respect to the sorted elements based on whether &lt;code&gt;key&lt;/code&gt; is smaller or greater than each of the sorted elements;&lt;/li&gt;
&lt;li&gt;Continue with steps 4 and 5 until all elements of the array are sorted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The array is sorted when all the unsorted elements are placed in their correct positions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Insertion Sort Code in Javascript
&lt;/h3&gt;

&lt;p&gt;Let’s take a look at the code for the Insertion Sort algorithm described above (ascending order):&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Let’s take a look at the code for the Insertion Sort algorithm described above (ascending order):&lt;/p&gt;

&lt;h3&gt;
  
  
  Insertion Sort and Big-O
&lt;/h3&gt;

&lt;p&gt;Insertion Sort compares the adjacent elements, hence, the number of comparisons is:&lt;/p&gt;

&lt;p&gt;(n-1) + (n-2) + (n-3) +…..+ 1 = n(n-1)/2&lt;/p&gt;

&lt;p&gt;This nearly equals to n2, therefore Big-O is O(n²) or quadratic time. We can also deduce this from observing the code: insertion sort requires two loops, therefore Big-O is expected to be O(n²).&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Insertion Sort inserts each element of the array in its appropriate place based on whether the array is being sorted in ascending or descending order. It is a simple way to sort a list when complexity does not matter and the list that needs sorting is short.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/4c7b1b5a852adacf13ba7a3604000f79"&gt;Insertion Sort Algorithm gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9"&gt;Let’s Talk About Big-O&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>Algorithm Series - Selection Sort</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Wed, 27 Oct 2021 08:50:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/algorithm-series-selection-sort-21b7</link>
      <guid>https://dev.to/tcelovsky/algorithm-series-selection-sort-21b7</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lvhtJXz4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4l2b8aihm26qk67d20s.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lvhtJXz4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4l2b8aihm26qk67d20s.jpeg" alt="Multicolored pencils are laying flat on a light background. The pencils are not aligned, with some of them appearing to be longer than others." width="880" height="525"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@jessbaileydesigns"&gt;Jess Bailey&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a quick tutorial on the selection sort algorithm and its implementation in Javascript.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Selection Sort Algorithm
&lt;/h3&gt;

&lt;p&gt;Selection sort is a &lt;a href="%5Bhttps://en.wikipedia.org/wiki/Sorting_algorithm%5D(https://en.wikipedia.org/wiki/Sorting_algorithm)"&gt;sorting algorithm&lt;/a&gt; that divides the input list into two parts: a sorted sublist that is built up from left to right and a sublist of the remaining unsorted values. The sorted sublist is placed at the front (to the left of) the unsorted sublist. Initially, the sorted sublist is empty and the unsorted sublist consists of the entire input list. The algorithm selects the smallest (or largest, depending on the ask) element in the unsorted sublist, places that element at the beginning of the unsorted sublist and moves the sublist boundary one element to the right (because there is now one element present in the sorted sublist, while the unsorted sublist became smaller by one element).&lt;/p&gt;

&lt;p&gt;Let’s take a look at selection sort when trying to sort the elements of an array in an ascending order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the first element of the array as &lt;code&gt;minimum&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compare &lt;code&gt;minimum&lt;/code&gt; with the second element, if the second element is smaller than &lt;code&gt;minimum&lt;/code&gt;, assign the second element as &lt;code&gt;minimum&lt;/code&gt; , otherwise, do nothing;&lt;/li&gt;
&lt;li&gt;Compare &lt;code&gt;minimum&lt;/code&gt; with the following element, if that element is smaller than &lt;code&gt;minimum&lt;/code&gt;, then assign &lt;code&gt;minimum&lt;/code&gt; to that element, otherwise do nothing;&lt;/li&gt;
&lt;li&gt;Continue step 3 above until the last element has been reached;&lt;/li&gt;
&lt;li&gt;Move &lt;code&gt;minimum&lt;/code&gt; to the front of the array and move the sublist boundary one element to the right (because there is now one element present in the sorted sublist, while the unsorted sublist became smaller by one element);&lt;/li&gt;
&lt;li&gt;Continue with steps 3 - 5, until all elements are in their sorted positions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The array is sorted when all the unsorted elements are placed in their correct positions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selection Sort Code in Javascript
&lt;/h3&gt;

&lt;p&gt;Let’s take a look at the code for the selection sort algorithm described above (ascending order):&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The above code sorts the array in ascending order. To sort an array in descending order, replace the “greater than” sign in the &lt;code&gt;if&lt;/code&gt; statement with a “less than” sign.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selection Sort and Big-O
&lt;/h3&gt;

&lt;p&gt;Selection Sort compares the adjacent elements, hence, the number of comparisons is:&lt;/p&gt;

&lt;p&gt;(n-1) + (n-2) + (n-3) +…..+ 1 = n(n-1)/2&lt;/p&gt;

&lt;p&gt;This nearly equals to n2, therefore Big-O is O(n²) or quadratic time. We can also deduce this from observing the code: selection sort requires two loops, therefore Big-O is expected to be O(n²).&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Selection sort finds the lowest value of the array and moves that value to the beginning of the array, it then proceeds to look for the next lowest value and moves that in front of the unsorted elements. This continues until all values of the array have been sorted; it is a simple way to sort a list when complexity does not matter and the list that needs sorting is short.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/4c7b1b5a852adacf13ba7a3604000f79"&gt;Selection Sort Algorithm gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9"&gt;Let’s Talk About Big-O&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>Algorithm Series - Bubble Sort</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Tue, 26 Oct 2021 16:50:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/algorithm-series-bubble-sort-17li</link>
      <guid>https://dev.to/tcelovsky/algorithm-series-bubble-sort-17li</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FAqVim6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9plupey4807tqdg76ue0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FAqVim6---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9plupey4807tqdg76ue0.jpeg" alt="Soap bubbles floating in the air in the street, the background includes a blurred out image of an old building." width="880" height="515"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@pieterpanflute"&gt;Pieter&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a quick tutorial on the bubble sort algorithm and its implementation in Javascript.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Bubble Sort Algorithm
&lt;/h3&gt;

&lt;p&gt;Bubble sort is a &lt;a href="%5Bhttps://en.wikipedia.org/wiki/Sorting_algorithm%5D(https://en.wikipedia.org/wiki/Sorting_algorithm)"&gt;sorting algorithm&lt;/a&gt; that compares two adjacent elements and swaps them if they are not in the intended order (ascending vs descending).&lt;/p&gt;

&lt;p&gt;Let’s take a look at bubble sort when trying to sort the elements of an array in an ascending order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First iteration (compare and swap): 

&lt;ul&gt;
&lt;li&gt;Starting from the first index, compare the first and second elements;&lt;/li&gt;
&lt;li&gt;If the first element is greater than the second element, they are swapped;&lt;/li&gt;
&lt;li&gt;Compare the second and third elements;&lt;/li&gt;
&lt;li&gt;If the second element is greater than the third element, they are swapped;&lt;/li&gt;
&lt;li&gt;Continue the above process until the last element of the array is reached.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Remaining iterations:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Continue the same process for the remaining iterations, such that after each iteration, the largest element among the unsorted elements is placed at the end. In each iteration, the comparison takes place up to the last unsorted element.&lt;/p&gt;

&lt;p&gt;The array is sorted when all the unsorted elements are placed in their correct positions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bubble Sort Code in Javascript
&lt;/h3&gt;

&lt;p&gt;Let’s take a look at the code for the bubble sort algorithm described above (ascending order):&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The above code sorts the array in ascending order. To sort an array in descending order, replace the “greater than” sign in the &lt;code&gt;if&lt;/code&gt; statement with a “less than” sign.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optimizing Bubble Sort Algorithm
&lt;/h3&gt;

&lt;p&gt;In the code example above, all the comparisons between the array elements are made even if the array is already sorted - this increases the execution time. To solve this, we can introduce an extra variable called &lt;code&gt;swapped&lt;/code&gt;. This variable can keep track of whether a swap occurs. If no swaps have occurred, then we know that the elements are already sorted and there is no need to perform further iterations. This will reduce the execution time and help optimize the bubble sort algorithm.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The above code will keep track of whether a swap was made in an iteration. If no swap was made, then we know that the array is sorted and we can stop the bubble sort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bubble Sort and Big-O
&lt;/h3&gt;

&lt;p&gt;Bubble Sort compares the adjacent elements, hence, the number of comparisons is:&lt;/p&gt;

&lt;p&gt;(n-1) + (n-2) + (n-3) +…..+ 1 = n(n-1)/2&lt;/p&gt;

&lt;p&gt;This nearly equals to n2, therefore Big-O is O(n²) or quadratic time. We can also deduce this from observing the code: bubble sort requires two loops, therefore Big-O is expected to be O(n²).&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Bubble sort compares adjacent items in a list and swaps them if they are not in the right order. It is a simple way to sort a list when complexity does not matter and short and simple code is preferred.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/a06e2222cc1e5e5d2f0156f54293c9b7"&gt;Bubble Sort Algorithm gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/8c2e8179ccd8d847e7c5af219960aff5"&gt;Optimized Bubble Sort Algorithm gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9"&gt;Let’s Talk About Big-O&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>Let's Talk About Big-O - Time Complexity</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Wed, 14 Jul 2021 10:00:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9</link>
      <guid>https://dev.to/tcelovsky/let-s-talk-about-big-o-2ah9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--flNqrVG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a62vhbdkmij3s2r4j0o4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--flNqrVG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a62vhbdkmij3s2r4j0o4.jpeg" alt="A table clock displayed on a white background, it's dials are showing 14 minutes after 10 o'clock." width="880" height="704"&gt;&lt;/a&gt; Photo by &lt;a href="https://unsplash.com/@insungyoon"&gt;Insung Yoon&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Big-O?
&lt;/h2&gt;

&lt;p&gt;Big-O (pronounced “big-oh”) is a theoretical measure of the execution of an algorithm; it tells us how much time or memory is needed to execute a function when given the input of size n. In this case, n represents the number of items that will be analyzed by the given function and algorithm is the function itself.&lt;/p&gt;

&lt;p&gt;Big-O notation is the language used to talk about how much time the algorithm takes to run (time complexity) or how much memory is used to run it (space complexity). In this article we are going to focus primarily on the time complexity.&lt;/p&gt;

&lt;p&gt;Big-O notation can express the best, worst or average-case running time of an algorithm. However, as software engineers, we are primarily concerned with the worst-case scenario. We want to know the largest possible number of steps or operations that could happen for an input of size n. The time required to complete all steps or operations of a given function is proportional to the number of “basic operations” in that function. Here are some examples of basic operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one arithmetic operation (e.g., +, -, *).&lt;/li&gt;
&lt;li&gt;one assignment (e.g. x := 0)&lt;/li&gt;
&lt;li&gt;one test (e.g., x = 0)&lt;/li&gt;
&lt;li&gt;one read (of a primitive type: integer, float, character, boolean)&lt;/li&gt;
&lt;li&gt;one write (of a primitive type: integer, float, character, boolean)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that for the purposes of Big-O notation, the time it takes to run an algorithm does not equate to seconds or milliseconds. Instead, we think of time as the number of steps or operations that are needed to complete a problem of size n. This is because Big-O does not take into account variables such as processors or language used to write the function. Rather, Big-O notation helps us track how quickly the runtime of the function grows relative to the size of the input.&lt;/p&gt;

&lt;h3&gt;
  
  
  O(1) or Constant Time
&lt;/h3&gt;

&lt;p&gt;Some algorithms perform the same number of operations every time they are called. For example, the basic operations described above require the same or constant amount of time to complete. Consider how easy it is to find your spot in a book if you’ve left a bookmark. Regardless of the size of the book it will always take you exactly one step.&lt;/p&gt;

&lt;p&gt;O(1) simply means that it takes a constant time to run an algorithm, regardless of the size of the input.&lt;/p&gt;

&lt;p&gt;In programming, a lot of operations are constant; here are some examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;basic operations&lt;/li&gt;
&lt;li&gt;accessing an array via the index&lt;/li&gt;
&lt;li&gt;accessing a hash via the key&lt;/li&gt;
&lt;li&gt;returning a value from a function&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  O(n) or Linear Time
&lt;/h3&gt;

&lt;p&gt;Consider an example where we have to insert an element into an array. We would have to move the current element and all subsequent elements one place to the right in order to make space for the new element. The worst case scenario would be if we had to insert an element at the beginning of an array, because in that case all of the elements of the array must be moved. Therefore, in the worst case, the time for insertion is directly proportional to the number of elements in the array. We say that the worst-case time for the insertion operation is linear in the number of elements in the array. For a linear-time algorithm, if the problem size doubles, the number of operations also doubles. Therefore, O(n) means that the run time increases at the same pace as the input.&lt;/p&gt;

&lt;p&gt;In Javascript, methods like &lt;code&gt;forEach&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, and &lt;code&gt;reduce&lt;/code&gt; run through the entire collection of data, from start to finish. They are good examples of linear-time operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  O(n²) or Quadratic Time
&lt;/h3&gt;

&lt;p&gt;Quadratic time means that the calculation runs in the time equivalent to the squared size of the input data. Here are some examples of the more basic sorting algorithms that have a worst-case run time of O(n²):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.programiz.com/dsa/bubble-sort"&gt;Bubble Sort&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.programiz.com/dsa/insertion-sort"&gt;Insertion Sort&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.programiz.com/dsa/selection-sort"&gt;Selection Sort&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that in general, seeing two nested loops is a good indicator that the function has a run time of O(n²). Three nested loops would indicate a run time of O(n³).&lt;/p&gt;

&lt;h3&gt;
  
  
  O(log n) or Logarithmic Time
&lt;/h3&gt;

&lt;p&gt;An example of a phone book is often used to describe logarithmic time. Let’s say you are looking for your friend’s phone number in a phone book. You know that your friend’s name starts with a letter “M”. You will likely open the phone book around the middle and see whether the names there begin with any letter that precedes “M” or any letters that follows “M”. Based on that, you will open the phone book closer towards the front or further towards the back and will, again, see if you’ve gotten close to the letter “M. You will continue performing these steps, and continue to decrease the size of the population by two, until you’ve located your friend’s name. Note that you will perform the same steps regardless of how large the phone book is (first open in the middle, then move towards the front or the back, thus decreasing the population, depending on how close you are to the desired value).&lt;/p&gt;

&lt;p&gt;O(log n) means that the running time grows in proportion to the logarithm of the input size, meaning that the run time barely increases as you exponentially increase the input. Logarithm is the inverse function to exponentiation, it’s the power to which a number must be raised in order to get some other number. For example, the base ten logarithm of 100 is 2, because ten raised to the power of two is 100: log 100 = 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calculating Big-O
&lt;/h2&gt;

&lt;p&gt;Remember that Big-O notation helps us track how quickly the runtime of the function grows relative to the size of the input and does not take into account variables such as processors or language used to write the function. Similarly, Big-O is not concerned with any constants or operations that run in constant time that may be a part of an algorithm. Such operations make very little difference in the overall run time approximation.&lt;/p&gt;

&lt;h3&gt;
  
  
  O(n) or Linear Time
&lt;/h3&gt;

&lt;p&gt;Take a look at the below code example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we have two separate loops that are iterating through the length of an array (linear time). Each loop logs an item in the collection (constant time). As mentioned above, we are not concerned with operation that run in constant time. Therefore, we only have to take the two loops into account and add them to calculate the Big-O. This gives us O(2n), but number 2 is a constant, so we drop it and are left with the Big-O of O(n).&lt;/p&gt;

&lt;h3&gt;
  
  
  O(n²) or Quadratic Time
&lt;/h3&gt;

&lt;p&gt;Now take a look at the code example below, it’s very similar to what we just saw, but here we nested our loops:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this example of nested loops we are logging &lt;code&gt;numbers[i]&lt;/code&gt; five times. To calculate Big-O here we have to multiply O(n) * O(n), because the execution of our log is dependent on iterating through the entirety of the second loop before we can increment &lt;code&gt;i&lt;/code&gt; and move to the next index in our first loop. Thus, the Big-O in this case is O(n²).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The top portion of this function is the same as our previous example, we know its Big-O is O(n²). Then we may want to add O(n) related to the &lt;code&gt;reduce&lt;/code&gt; function, which is linear. We get O(n² + n). However, Big-O is not concerned with non-dominant terms and because quadratic time is worse than linear time, we drop the second n. The final Big-O of the above function is O(n²).&lt;/p&gt;

&lt;h3&gt;
  
  
  O(log n) or Logarithmic Time
&lt;/h3&gt;

&lt;p&gt;Take a look at this code example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here we are trying to locate number 128 in a given (already sorted) array. In the first iteration of our &lt;code&gt;while&lt;/code&gt; loop, we split our data (the array) in half and call that point a pivot. We then check to see if the value in the array at pivot equals 128. If it does, we return a statement to say where the number was located. If it’s less than 128, then we change the value of our &lt;code&gt;startIndex&lt;/code&gt; to the value of pivot plus one. That’s because if the value of pivot is less than 128, then we know that all of the numbers preceding pivot will also be lower than 128 (remember, the array has been sorted). If the value of pivot is greater than 128, then we change the value of our &lt;code&gt;startIndex&lt;/code&gt; to the value of pivot minus one. This way we are able to halve our data.&lt;/p&gt;

&lt;p&gt;We continue executing the above steps until we’ve found the number we are looking for or returned &lt;code&gt;false&lt;/code&gt; to indicate that the number does not exist in the given array. With each pass we divide our data by two. Whenever you see this pattern of dividing the population or data by two, know that you are looking at Big-O of O(log n).&lt;/p&gt;

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

&lt;p&gt;Having a good understanding of Big-O notation provides a more well-rounded context when designing algorithms. This article is only an introduction and if you’d like to read more on this topic, I would recommend &lt;a href="https://www.bigocheatsheet.com/"&gt;Big-O Cheat Sheet&lt;/a&gt; and &lt;a href="https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/"&gt;What is Big O Notation Explained: Space and Time Complexity&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/a62b16ed73af772b7180d03e98ce5f4c"&gt;O(n) Example gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/f33683c40d6fdb30fb9f738879115f5b"&gt;O(n²) Example gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/aba19ebcfa797a4dc7eed889ceb932eb"&gt;O(n²) Example 2 gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/tcelovsky/dd455f417bd0eb09abd3db54e55b9f4a"&gt;O(log n) Example gist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.bigocheatsheet.com/"&gt;Big-O Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/"&gt;What is Big O Notation Explained: Space and Time Complexity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/dsa/bubble-sort"&gt;Bubble Sort Algorithm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/dsa/insertion-sort"&gt;Insertion Sort Algorithm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/dsa/selection-sort"&gt;Selection Sort Algorithm&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bigo</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Why Am I Here?</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Tue, 22 Jun 2021 17:00:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/why-am-i-here-50fe</link>
      <guid>https://dev.to/tcelovsky/why-am-i-here-50fe</guid>
      <description>&lt;p&gt;&lt;em&gt;“Why do you want to be a software engineer?” is not an easy question to answer. There are many reasons and they are different for each person. I wanted to share my reasons, consider this my Personal Statement!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I loved playing Battleship as a kid, but not the paper and pencil kind that dates back to World War I. I loved playing Battleship on a programmable calculator that my dad got me when I was seven. This little gadget could take in programs and produce results based on the information I provided to it. It came with an instructions booklet that contained a dozen programs and each had to be fed into the calculator, line by line, before any game could be played.&lt;/p&gt;

&lt;p&gt;My favorite part of the process was spending 45 minutes to an hour programming a game before I could play it. If I made a mistake, I had to start over. Surprisingly, that made the process more interesting. I knew that I had to pay attention as the calculator could only perform the commands that I supplied. Therefore, the commands had to be logical, concise and, most importantly, accurate. I had no idea at the time that this was my first introduction to software development.&lt;/p&gt;

&lt;p&gt;Fast forward about 20 years. I first heard of MOOCs (Massive Open Online Courses) when MIT and Harvard announced the creation of edX in 2012, a new open online course platform. The power of MOOCs is hard to deny, they bring education to the masses at low or no charge. By this time I was well underway in my career as a tax professional, working with interesting clients and solving issues related to optimal investment structuring and tax mitigation strategies. The news of edX creation planted a thought in my mind: there was a possibility to learn coding without going back to school and getting another degree. That was tempting.&lt;/p&gt;

&lt;p&gt;I chose taxation as my career because it offers an opportunity to problem-solve within the given parameters of tax law. The law could definitely be dry, but the results are very real and tangible, primarily focused around increased returns on investment and reduced cash outflow (think paying less taxes). Attention to detail is important, as one word can often make a big difference.&lt;/p&gt;

&lt;p&gt;I enjoyed working in my profession for the last 13 years. I spent the first seven years working at a large firm serving a diverse group of clients. I went from being an intern to leading my own teams that varied in size from two to twelve people. I ultimately decided to leave this firm and joined a smaller investment company that was growing its internal tax team. There I was able to focus on the needs of one company and really dive in and provide comprehensive tax advice that spanned multiple areas. I’ve been at this company for six years now.&lt;/p&gt;

&lt;p&gt;I’ve learned a lot over the years working in a professional environment. I’ve developed relationships both inside and outside my organization and learned to utilize my network when I need some advice. I’ve learned to both be a productive member of a team and an effective leader. My current position requires frequent contact with company leadership, which can be daunting, but also exciting. I am close to the decision making process and am able to provide more tailored advice considering the interests of both the company and the shareholders.&lt;/p&gt;

&lt;p&gt;All the while coding was in the back of my mind and every so often I looked at the classes available on platforms like edX and Coursera. This periodic search led me to the discovery of coding bootcamps that seemed to be popping up everywhere a few years ago. A restless mind is hard to tame and, upon some self reflection, I realized that I will not rest easy until I learn at least one programming language. That is how I ended up joining a self-paced software engineering program at the Flatiron School.&lt;/p&gt;

&lt;p&gt;I wanted to ease into coding and a self-paced program provided enough structure and flexibility to do just that. The program wasn’t easy, but every time my code did exactly what it was supposed to do was terribly exciting! I was taken back to those days when, as a kid, I would spend hours playing with my programmable calculator. When the time for my final project came, I wanted to build something for myself.&lt;/p&gt;

&lt;p&gt;One of my other passions is astrophysics and space exploration and with the number of private rocket companies increasing around the world, I found it difficult to keep up with all the rocket launches. So I decided to create a web app that would list out the upcoming rocket launches around the world. I wanted to have a database (PostgreSQL) that would store all the launches on the backend (built with Rails API) and I wanted my frontend (a React app) to send a fetch request to the backend API. It’s still a little wild to me that there was a time when I didn’t know what any of these words meant.&lt;/p&gt;

&lt;p&gt;I prepared for my final review as well as I could. I went over all my notes and practiced talking about my code. The review was going fine until it was time for live coding. My reviewer asked that I add a search field and build some basic search functionality for my web app. It felt like this was the only topic I did not prepare for.&lt;/p&gt;

&lt;p&gt;I think this is when my experience in tax kicked in. Don’t laugh, let me explain. Tax law is complex and there are a lot of exceptions to every rule. Nobody can be expected to know every detail, but tax professionals are expected to be able to talk about various options based on their knowledge and prior experience. Even if later you have to add to or revise your advice, you are still expected to talk about possibilities off the top of your head. So that’s what I did.&lt;/p&gt;

&lt;p&gt;Although I’ve never built search functionality before, I started by talking about my data and how I would iterate over it. I talked about comparing my data to the input received from the search field. I planned to save the matches to a new array and put it in my state (this was a React app) to make sure that I can display them on the screen when the state is updated. By the time I was done it was clear that I talked through the entire process and the final act of building the functionality no longer felt daunting.&lt;/p&gt;

&lt;p&gt;I passed my final review and graduated. I added that search field to my web app and pushed it to GitHub. I found that I was no longer able to go back to being a tax accountant.&lt;/p&gt;

&lt;p&gt;As I look to the future, I am both nervous and excited. A career change is never easy, but I know that I want to be a software engineer. I also know that my prior experience is not a burden, but rather an advantage. I am able to think on my feet, to separate the important issues from the less relevant ones, and to focus on delivering an accurate work product. I’ve worked on many teams over the years and learned the importance of collaboration. I am excited to learn new things and am ready to work hard. I can’t wait for this new adventure!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>careerchange</category>
    </item>
    <item>
      <title>Launch Calendar</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Wed, 05 May 2021 19:46:00 +0000</pubDate>
      <link>https://dev.to/tcelovsky/launch-calendar-1em6</link>
      <guid>https://dev.to/tcelovsky/launch-calendar-1em6</guid>
      <description>&lt;p&gt;&lt;em&gt;This post is an overview of how I built a webpage that lists upcoming rocket launches around the world with details on the date, time, rocket and mission for each.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For my &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=flatironschool&amp;amp;uqaid=513747011515&amp;amp;CjwKCAjwhMmEBhBwEiwAXwFoEV6tNm3M-Vh9W3Qee6Y6O1ogIZTjsSYSVzsGo9HKE6b7t7VVYgW12xoCQF0QAvD_BwE&amp;amp;gclid=CjwKCAjwhMmEBhBwEiwAXwFoEV6tNm3M-Vh9W3Qee6Y6O1ogIZTjsSYSVzsGo9HKE6b7t7VVYgW12xoCQF0QAvD_BwE"&gt;Flatiron School&lt;/a&gt; final project I wanted to build something that I would find interesting and fun to work on. I also knew that I did not want to tackle a super complex project as I wanted to make sure that I worked within certain time constraints. After all, the purpose of this project was to help me graduate and to show off the skills I have acquired during my studies. After some reflection I decided that what I would find most exciting right now was building a webpage that would show a list of upcoming rocket launches around the world.&lt;/p&gt;

&lt;h2&gt;
  
  
  MVP
&lt;/h2&gt;

&lt;p&gt;There were many features I wanted my webpage to have, but in order to make sure that I actually finish this project, I decided on the following &lt;a href="https://www.freecodecamp.org/news/minimum-viable-product-between-an-idea-and-the-product/"&gt;Minimum Viable Product (“MVP”)&lt;/a&gt; goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home page with a welcome message&lt;/li&gt;
&lt;li&gt;A page with a list of upcoming rocket launches&lt;/li&gt;
&lt;li&gt;For each launch list the following: 

&lt;ul&gt;
&lt;li&gt;Date of launch&lt;/li&gt;
&lt;li&gt;Time of launch&lt;/li&gt;
&lt;li&gt;Rocket type&lt;/li&gt;
&lt;li&gt;Mission description&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Routes: 

&lt;ul&gt;
&lt;li&gt;Home page&lt;/li&gt;
&lt;li&gt;Index view with a list of launches&lt;/li&gt;
&lt;li&gt;Show view for each launch &lt;/li&gt;
&lt;li&gt;Do not intend to have a separate page for each launch&lt;/li&gt;
&lt;li&gt;About page&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At least initially, I also decided on the following stretch goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calendar functionality for each launch: 

&lt;ul&gt;
&lt;li&gt;Decide how to handle time parcing and conversion&lt;/li&gt;
&lt;li&gt;Decide what to do about launches where date or time are not yet known&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Information about different rockets: 

&lt;ul&gt;
&lt;li&gt;A view page for each rocket type with specs and history&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Twitter bot that will tweet out about upcoming launches&lt;/li&gt;
&lt;li&gt;Link to webpages where launches can be viewed live (depending on availability)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;p&gt;I knew that I wanted to build my own Rails API to handle the backend logic. The requirements for the frontend were to use React, Redux, HTML and CSS. Here is what I ended up doing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend: 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://guides.rubyonrails.org/api_app.html"&gt;Rails API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/javan/whenever"&gt;Whenever gem&lt;/a&gt; used to schedule a custom Rake task (website scraping)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Frontend: 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/create-react-app"&gt;React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redux.js.org/"&gt;Redux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getbootstrap.com/docs/3.4/css/"&gt;Bootstrap&lt;/a&gt; with some custom CSS&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/moment/luxon"&gt;Luxon gem&lt;/a&gt; used to convert date and time in the appropriate format needed for the Add To Calendar button&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I made a decision to use Whenever and Luxon gems while I was already working on my project and incorporated them into the existing code base.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Building Phase
&lt;/h2&gt;

&lt;p&gt;I find that actually starting the project is the most difficult part. As I was agonizing over the details before ever writing a single line of code, I decided that writing down a step by step plan may help me get started. Below is the basic plan I wrote to get my project done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create GitHub Repository
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a new repository in GitHub with .gitignore, README.md and LICENSE files.&lt;/li&gt;
&lt;li&gt;Clone the newly created repository to your computer using &lt;code&gt;git clone&lt;/code&gt; command followed by the SSH link to the GitHub repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add .drawio Diagram
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a new .drawio file using &lt;code&gt;touch .drawio&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;In the .drawio file create a diagram representing relationships between the backend models using Entity Relation shapes: 

&lt;ul&gt;
&lt;li&gt;Include title of each model.&lt;/li&gt;
&lt;li&gt;Include characteristings of each model.&lt;/li&gt;
&lt;li&gt;Include relationships between models.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Backend Setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create Rails API structure by using &lt;code&gt;rails new&lt;/code&gt; command followed by name of the Rails API: 

&lt;ul&gt;
&lt;li&gt;Add &lt;code&gt;--api&lt;/code&gt; flag after the name to ensure that Rails only includes the necessary folders and capabilities for the API.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;--database=postgresql&lt;/code&gt; flag to create the Rails API with Postgres database, instead of the default SQLite3.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;For this project, I entered the following in my terminal: &lt;code&gt;rails new backend --api --database=postgresql&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note.&lt;/strong&gt; &lt;code&gt;rails new&lt;/code&gt; command will generate a new Rails repository that will include .git folder. In order to ensure that both the frontend and backend can be stored in the same repository on GitHub (in two separate folders), you’ll have to delete this .git file as it will prevent you from pushing your new backend repository to GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cd into the new Rails repository just created.&lt;/li&gt;
&lt;li&gt;In your terminal enter &lt;code&gt;rm -r .git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;cd back to the top folder of your project&lt;/li&gt;
&lt;li&gt;Ensure that the items listed in the .gitignore file at the root of your project are prefaced with the name of your backend repository. For me this meant adding ‘backend’ at the front of each item listed in the .gitignore file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Backend Setup (Continued)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;cd into the new backend directory just created.&lt;/li&gt;
&lt;li&gt;Navigate to the gemfile and add gem ‘nokogiri’. &lt;a href="https://github.com/sparklemotion/nokogiri"&gt;Nokigiri&lt;/a&gt; gem will help us with scraping and parsing.&lt;/li&gt;
&lt;li&gt;Uncomment gem ‘rack-cors’ - his will allow &lt;a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing"&gt;Cross Origin Resource Sharing (CORS)&lt;/a&gt; in the API. CORS is a security feature that prevents API calls from unknown origins.&lt;/li&gt;
&lt;li&gt;Add gem ‘active_model_serializers’ to the gemfile. Serialization is the process of converting data into a format that can be transmitted across a computer network and reconstructed later. Backend and frontend of this project will make requests to each other across the interwebs.&lt;/li&gt;
&lt;li&gt;Run bundle install.&lt;/li&gt;
&lt;li&gt;Inside config/initializers/cors.rb file uncomment the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'

    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :patch, :delete, :options, :head]
  end
end

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

&lt;/div&gt;



&lt;p&gt;Inside the allow block, origins ‘*’ means that requests from all origins are allowed. This can be changed to only allow requests from the address of the frontend repo - localhost:3000 for example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note.&lt;/strong&gt; You may wish to create a custom Rake task to expedite the process of dropping, creating, migrating and seeding the database by using a single command. To do so, navigate to the lib directory and create a new file with .rake extension (I named my file dcms.rake). Inside thew newsly created file add the following code:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;namespace :db do&lt;br&gt;
    task :dcms do&lt;br&gt;
     desc 'Drop, Create, Migrate and Seed the Database'&lt;br&gt;
      Rake::Task["db:drop"].invoke&lt;br&gt;
      Rake::Task["db:create"].invoke&lt;br&gt;
      Rake::Task["db:migrate"].invoke&lt;br&gt;
      Rake::Task["db:seed"].invoke&lt;br&gt;
      puts 'Database dropped, created, migrated and seeded.'&lt;br&gt;
    end&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;The above code will invoke each of the Rake tasks in sequence (drop, create, migrate, seed) when running command &lt;code&gt;rake db:dcms&lt;/code&gt; and will put out “Database dropped, created, migrated and seeded.” message when the task has been completed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Frontend Setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;From the main directory of your app, run &lt;code&gt;npm init react-app&lt;/code&gt; command followed by the desired name for the frontend diretory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;For this project, I entered the following in my terminal: &lt;code&gt;npm init react-app frontend&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cd into the new frontend directory just created.&lt;/li&gt;
&lt;li&gt;Create src folder, this is where most of the frontend logic will live.&lt;/li&gt;
&lt;li&gt;cd into the src folder and create folders for your components, containers, reducers, actions, styles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I find that once I have the basic set up of the backend and the front, the coding comes easier. Don’t forget to consistently test your code as you go. I would recommend navigating to the backend directory and running &lt;code&gt;rails s&lt;/code&gt; command in your terminal to start the Rails server. Then I would open up a new terminal window and navigate to the frontend directory, run &lt;code&gt;npm start&lt;/code&gt; in the terminal to start the server. Having both servers runnig helps me test my code as I go. It’s also really exciting to see your project grow and develop during this process!&lt;/p&gt;

&lt;p&gt;I hope you find the above overview helpful and feel free to check out my &lt;a href="https://github.com/tcelovsky/launch-calendar"&gt;code&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>react</category>
    </item>
    <item>
      <title>Overview of Active Record Associations</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Thu, 27 Aug 2020 13:20:18 +0000</pubDate>
      <link>https://dev.to/tcelovsky/overview-of-active-record-associations-okd</link>
      <guid>https://dev.to/tcelovsky/overview-of-active-record-associations-okd</guid>
      <description>&lt;p&gt;This is an overview of Active Record Associations, after reading this post, you will be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand the types of Active Record associations.&lt;/li&gt;
&lt;li&gt;Declare associations between Active Record models.&lt;/li&gt;
&lt;li&gt;Use the methods added to your models by creating associations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An association is a connection between two Active Record models that is used add features to your code. Rails supports six types of associations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;belongs_to&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;has_one&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;has_many&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;has_many :through&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;has_one :through&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;has_and_belongs_to_many&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By declaring one of these associations, you instruct Rails to maintain information between the instances of your models. The following is an overview of each Rails association.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;belongs_to&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;belongs_to&lt;/code&gt; association sets up a one-to-one connection with another model, meaning that each instance of the declaring model “belongs to” one instance of the other model. For example, if your application includes authors and blog posts, and each post can be assigned to exactly one author, you’d declare the blog post model this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Post &amp;lt; ApplicationRecord
  belongs_to :author
end

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: &lt;code&gt;belongs_to&lt;/code&gt; associations must use the singular term (i.e. author). Using the pluralized form (i.e. authors) in the above example would cause an error because Rails automatically infers the class name from the association name. If the association name is wrongly pluralized, then the inferred class will be wrongly pluralized too.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreatePosts &amp;lt; ActiveRecord::Migration
  def change
    create_table :authors do |t|
      t.string :name
      t.timestamps
    end

    create_table :posts do |t|
      t.belongs_to :author
      t.datetime :published_at
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After declaring the &lt;code&gt;belongs_to&lt;/code&gt; association, the declaring class automatically gains 6 methods related to the association:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;association&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;association=(associate)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;build_association(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create_association(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create_association!(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reload_association&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above methods, &lt;code&gt;association&lt;/code&gt; is replaced with the symbol passed as the first argument to &lt;code&gt;belongs_to&lt;/code&gt;. In our example where posts belong to authors, each instance of the post model will have these methods available:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;author&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;author=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;build_author&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;create_author&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;create_author!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;reload_author&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These additional methods make your code cleaner and easier. For example, you could add a new author while writing a post:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new_author = @post.build_author(name: "Your Name")
new_author.save

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: If you use the `build&lt;/em&gt;&lt;code&gt; option, you’ll have to persist your new &lt;/code&gt;author&lt;code&gt; with &lt;/code&gt;#save&lt;code&gt; while the &lt;/code&gt;create_` option will persist to the database for you._&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;has_one&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;has_one&lt;/code&gt; association also sets up a one-to-one connection with another model, but unlike &lt;code&gt;belongs_to&lt;/code&gt; association, &lt;code&gt;has_one&lt;/code&gt; association indicates that each instance of a model contains only one instance of another model. For example, each customer would have only one account and you would declare the customer model as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Customer &amp;lt; ApplicationRecord
  has_one :account
end

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

&lt;/div&gt;



&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateCustomers &amp;lt; ActiveRecord::Migration
  def change
    create_table :customers do |t|
      t.string :name
      t.timestamps
    end

    create_table :accounts do |t|
      t.belongs_to :customer
      t.sting :account_number
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After declaring &lt;code&gt;has_one&lt;/code&gt; association, the declaring class automatically gains 6 methods related to the association:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;association&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;association=(associate)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;build_association(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create_association(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create_association!(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reload_association&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As previously mentioned, in the above methods, &lt;code&gt;association&lt;/code&gt; is replaced with the symbol passed as the first argument to &lt;code&gt;has_one&lt;/code&gt;. In our example of customers and accounts, each instance of the customer model will have these methods available:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;account&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;account=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;build_account&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;create_account&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;create_account!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;reload_account&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;has_many&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;has_many&lt;/code&gt; association indicates a one-to-many connection with another model and is found in models corresponding to a &lt;code&gt;belongs_to&lt;/code&gt; association. &lt;code&gt;has_many&lt;/code&gt; association indicates that each instance of the model has multiple instances of another model. Going back to the example of authors and blog posts, the author model would be declared as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Author &amp;lt; ApplicationRecord
  has_many :posts
end

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: The name of the other model (i.e. posts) is pluralized when declaring a &lt;code&gt;has_many&lt;/code&gt; association.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateAuthors &amp;lt; ActiveRecord::Migration
  def change
    create_table :authors do |t|
      t.string :name
      t.timestamps
    end

    create_table :posts do |t|
      t.belongs_to :author
      t.datetime :published_at
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After declaring &lt;code&gt;has_many&lt;/code&gt; association, the declaring class automatically gains 17 methods related to the association:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;collection&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection&amp;lt;&amp;lt;(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.delete(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.destroy(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection=(objects)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection_singular_ids&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection_singular_ids=(ids)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.clear&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.empty?&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.size&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.find(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.where(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.exists?(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.build(attributes = {}, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.create(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.create!(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.reload&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above methods, &lt;code&gt;collection&lt;/code&gt; is replaced with the symbol passed as the first argument to &lt;code&gt;has_many&lt;/code&gt;, and &lt;code&gt;collection_singular&lt;/code&gt; is replaced with the singularized version of that symbol. In our example of authors and posts, each instance of the author model will have these methods:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts&amp;lt;&amp;lt;(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.delete(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.destroy(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts=(objects)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;post_ids&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;post_ids=(ids)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.clear&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.empty?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.size&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.find(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.where(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.exists?(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.build(attributes = {}, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.create(attributes = {})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.create!(attributes = {})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.reload&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;has_many :through&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;has_many :through&lt;/code&gt; association sets up a many-to-many connection with another model, indicating that the declaring model can be matched with multiple instances of another model through a third model. For example, in the case of a workout studio where students sign up for classes with various instructors, association declarations would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Instructor &amp;lt; ApplicationRecord
  has_many :workout_classes
  has_many :students, through: :workout_classes
end

class Workout_class &amp;lt; ApplicationRecord
  belongs_to :instructor
  belongs_to :student
end

class Student &amp;lt; ApplicationRecord
  has_many :workout_classes
  has_many :instructors, through: :workout_classes
end

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

&lt;/div&gt;



&lt;p&gt;Note how workout_class class serves as a connector between instructor class and student class in the above example. This is that third model that helps to set up a many-to-many connection between students and instructors.&lt;/p&gt;

&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateWorkoutClasses &amp;lt; ActiveRecord::Migration
  def change
    create_table :instructors do |t|
      t.string :name
      t.timestamps
    end

    create_table :students do |t|
      t.string :name
      t.timestamps
    end

    create_table :workout_classes do |t|
      t.belongs_to :instructor
      t.belongs_to :student
      t.timestamps
    end
  end
end

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;has_many :through&lt;/code&gt; association is very useful for setting up shortcuts through nested &lt;code&gt;has_many&lt;/code&gt; associations. Continuing with the workout studio example, a workout studio has many instructors and an instructor has many workout classes. It’s possible to get a list of all workout classes offered at the given studio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Workout_studio &amp;lt; ApplicationRecord
  has_many :instructors
  has_many :workout_classes, through: :instructors
end

class Instructor &amp;lt; ApplicationRecord
  belongs_to :workout_studio
  has_many :workout_classes
end

class Workout_class &amp;lt; ApplicationRecord
  belongs_to :instructor
end

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

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;through: :instructors&lt;/code&gt;  in the above example, Rails will now understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@workout_studio.workout_classes

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;has_one :through&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;has_one :through&lt;/code&gt; association is used to set up a one-to-one connection with another model, such that the declaring model can be matched with only one instance of another model by proceeding through a third model. In the case of a customer and account example, each customer has only one account, and each account is associated with only one account history. The customer model would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Customer &amp;lt; ApplicationRecord
  has_one :account
  has_one :account_history, through: :account
end

class Account &amp;lt; ApplicationRecord
  belongs_to :customer
  has_one :account_history
end

class AccountHistory &amp;lt; ApplicationRecord
  belongs_to :account
end

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

&lt;/div&gt;



&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateAccountHistories &amp;lt; ActiveRecord::Migration
  def change
    create_table :customers do |t|
      t.string :name
      t.timestamps
    end

    create_table :accounts do |t|
      t.belongs_to :customer
      t.string :account_number
      t.timestamps
    end

    create_table :account_histories do |t|
      t.belongs_to :account
      t.integer :credit_rating
      t.timestamps
    end
  end
end

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;has_and_belongs_to_many&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; association creates a direct many-to-many connection with another model. In this case, no third or intervening model is needed. If your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies. The association declarations would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Assembly &amp;lt; ApplicationRecord
  has_and_belongs_to_many :parts
end

class Part &amp;lt; ApplicationRecord
  has_and_belongs_to_many :assemblies
end

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

&lt;/div&gt;



&lt;p&gt;The corresponding migration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateAssembliesAndParts &amp;lt; ActiveRecord::Migration
  def change
    create_table :assemblies do |t|
      t.string :name
      t.timestamps
    end

    create_table :parts do |t|
      t.string :part_number
      t.timestamps
    end

    create_table :assemblies_parts, id: false do |t|
      t.belongs_to :assembly
      t.belongs_to :part
    end
  end
end

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

&lt;/div&gt;



&lt;p&gt;Note the assemblies_parts join table in the above example that allows the &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; relationship to work.&lt;/p&gt;

&lt;p&gt;After declaring a &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; association, the declaring class automatically gains 17 methods related to the association:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;collection&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection&amp;lt;&amp;lt;(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.delete(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.destroy(object, ...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection=(objects)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection_singular_ids&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection_singular_ids=(ids)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.clear&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.empty?&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.size&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.find(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.where(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.exists?(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.build(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.create(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.create!(attributes = {})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collection.reload&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above methods, &lt;code&gt;collection&lt;/code&gt; is replaced with the symbol passed as the first argument to &lt;code&gt;has_and_belongs_to_many&lt;/code&gt;, and &lt;code&gt;collection_singular&lt;/code&gt; is replaced with the singularized version of that symbol. In our example of assemblies and parts, each instance of the part model will have these methods:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies&amp;lt;&amp;lt;(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.delete(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.destroy(object, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies=(objects)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assembly_ids&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assembly_ids=(ids)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.clear&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.empty?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.size&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.find(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.where(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.exists?(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.build(attributes = {}, ...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.create(attributes = {})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.create!(attributes = {})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;assemblies.reload&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When deciding whether to use &lt;code&gt;has_many :through&lt;/code&gt; or &lt;code&gt;has_and_belongs_to_many&lt;/code&gt;, consider whether you need to have the independent relationship model. If you don’t need to do anything with the relationship model (for example, have validations, callbacks or other attributes), it may be simpler to set up a &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; relationship and the corresponding join table. Otherwise, use &lt;code&gt;has_many :through&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Active Record associations are versatile and powerful tools. As mentioned above, declaring associations adds many useful methods to your models that will help keep your code succinct. A much more detailed guide to associations can be found in the in the &lt;a href="http://guides.rubyonrails.org/association_basics.html"&gt;Rails Associations Guide&lt;/a&gt; and &lt;a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html"&gt;Rails API docs&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>activerecord</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>All the Ruby Modules</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Tue, 06 Aug 2019 12:27:23 +0000</pubDate>
      <link>https://dev.to/tcelovsky/all-the-ruby-modules-912</link>
      <guid>https://dev.to/tcelovsky/all-the-ruby-modules-912</guid>
      <description>&lt;p&gt;&lt;em&gt;The goal of this post is to provide a brief introduction to Ruby modules and to show the distinction between Ruby modules and Ruby classes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ruby modules are quite similar to Ruby classes, with the main difference being that modules, unlike classes, don’t have instances. We start our definition of a module with a &lt;code&gt;module&lt;/code&gt; keyword:&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;module&lt;/span&gt; &lt;span class="nn"&gt;MyModule&lt;/span&gt;
 &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_hello&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="no"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
 &lt;span class="k"&gt;end&lt;/span&gt; 
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This module can then get included in a class, giving instances of the class the ability to call the instance methods defined in the module:&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;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;say_hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the second line of the above code snipped, this is how &lt;code&gt;MyModule&lt;/code&gt; module gets included in &lt;code&gt;MyClass&lt;/code&gt; class. The result of the above will be &lt;code&gt;“Hello, World!”&lt;/code&gt; output because module &lt;code&gt;MyModule&lt;/code&gt; was included in class &lt;code&gt;MyClass&lt;/code&gt;, which resulted in &lt;code&gt;MyClass&lt;/code&gt; class getting access to the instance methods within &lt;code&gt;MyModule&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;It is important to note the difference between inheriting from a class and including a module. Ruby classes can inherit from only one class at a time, but multiple Ruby modules can be included in any single class. Note the difference below between class inheritance (first line) vs. model inclusion (second and third lines):&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;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MySuperClass&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule1&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule2&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, multiple Ruby classes can include the same module, thus, modules provide the ability to share the same instance methods between multiple Ruby classes. This ability comes in handy when you are writing a program where multiple classes share behaviors. &lt;/p&gt;

&lt;p&gt;It is generally best practice to use a noun for your class name, while using an adjective for your module name. This general guidance is not followed in the above examples, mainly for ease of understanding and presentation. &lt;/p&gt;

&lt;p&gt;Considering that multiple modules can be included in any single class, it is not impossible that we can encounter two different methods with the same definition. What’s an Object to do in a case like that? When a message, for example a method definition, is passed to an Object, the Object will look for that method in the following order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Object’s class&lt;/li&gt;
&lt;li&gt;Modules included in Object’s class, in reverse order of inclusion&lt;/li&gt;
&lt;li&gt;The class’s superclass&lt;/li&gt;
&lt;li&gt;Modules included into the superclass, in reverse order of inclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The very first method that the Object encounters that matches the message passed to the Object will be executed. This means that if method &lt;code&gt;my_method&lt;/code&gt; is defined within the Object’s class, that method will be executed, even if there is another method &lt;code&gt;my_method&lt;/code&gt; defined in a module included in the Object’s class. If the same method is defined twice in the same class, then the second definition (the one defined later) will take precedence. Same rule applies to modules. Keep in mind that modules included in Object’s class are searched in reverse order of inclusion, thus the model that is included later will be searched first. Fun fact, including the same module twice to influence the order in which modules are searched does not actually do anything. This means that including &lt;code&gt;MyModule1&lt;/code&gt; in line 4 below will not force Object to search it first. Object will still search &lt;code&gt;MyModule2&lt;/code&gt; first and then move on to &lt;code&gt;MyModule1&lt;/code&gt;.&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;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MySuperClass&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule1&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule2&lt;/span&gt;
 &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;MyModule1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How should one decide when to include a module vs. inherit a class? There is no one rule for this, but it may be helpful to keep the following in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modules don’t have instances. Thus, it is generally better to set up classes for entities or things and then use modules to encapsulate the behavior of these entities or things. This is also why class names generally tend to be nouns, while module names tend to be adjectives. &lt;/li&gt;
&lt;li&gt;A class can inherit from only one superclass, but multiple modules can be included in a class. If your class will have several characteristics, it may be better to put those in separate modules, since your class would not be able to inherit from multiple superclasses.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Objects have Class</title>
      <dc:creator>Tatyana Celovsky</dc:creator>
      <pubDate>Mon, 19 Feb 2018 22:48:54 +0000</pubDate>
      <link>https://dev.to/tcelovsky/objects-have-class-3a0</link>
      <guid>https://dev.to/tcelovsky/objects-have-class-3a0</guid>
      <description>&lt;p&gt;It was mostly smooth sailing for me in my coding adventure until I hit the subject of Object Oriented Programming (“OOP”) in Ruby (so I really didn’t go very far before this first road block). I read the text of the lessons until all these getters, setters, classes and objects were all jumbled up in my head and life did not make sense anymore.&lt;/p&gt;

&lt;p&gt;I just had to take a little break from the lessons for a few days and, instead, read some other resources online. I have to admit, at first none of them made sense either, but writing some concepts down in my own words really helped and I started to see a glimmer of light at the end of the OOP tunnel.&lt;/p&gt;

&lt;p&gt;So what I figured out is that a Class is really just a blueprint for creating a base version of a Thing. All of the attributes of the Thing can be found within its Class and we can add more attributes by defining new methods within our Class. This means that every new Thing is “born” with a set of predefined, standard attributes. I think this is pretty neat because all you have to do is decide what you want your Things to look like and how they should behave and then every new Thing will act exactly as you expect it to. A standard name for a Thing is an Object; so all of the attributes of an Object are stored within its Class.&lt;/p&gt;

&lt;p&gt;I was very happy once I understood that Classes are just blueprints and that really everything in Ruby is an Object. Then came instance variables. These are nifty little things; I’m a big fan of instance variables. A local variable defined within one method cannot be accessed by another method. You get around this by prefacing the variable name with @ symbol. That’s it! You’ve got yourself an instance variable that can be accessed by all methods within you Class.&lt;/p&gt;

&lt;p&gt;Setter and getter methods were most difficult for me to understand. I just could not comprehend why you would need two methods to get a Thing to do something. &lt;a href="http://instruction.learn.co/student/video_lectures#/231"&gt;This&lt;/a&gt; video lecture helped big time! I had to understand that I am really defining two completely different methods, one would be a name method, for example, and another would be name= (name equals) method. The name method is the getter or reader method, it simply returns information stored in the instance variable. The name= method is the setter or writer method, this is the method that can change information stored in the instance variable. Once I understood the difference between getter and setter methods things became a lot clearer!&lt;/p&gt;

&lt;p&gt;It may have taken a while, but I finally had a decent grasp on Object Oriented Programming. It was time to apply my newfound skills and rewrite my Tic Tac Toe using OOP. Boy did that take a while! I guess applying concepts is harder than learning them, but I am done with with Tic Tac Toe now, at least until AI Tic Tac Toe. I’ll let you know how that one goes!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>oop</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
