<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mez Charney</title>
    <description>The latest articles on Forem by Mez Charney (@mezzolite).</description>
    <link>https://forem.com/mezzolite</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%2F259254%2F7dd36e28-d10c-43a9-896b-bae0c6effd24.png</url>
      <title>Forem: Mez Charney</title>
      <link>https://forem.com/mezzolite</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mezzolite"/>
    <language>en</language>
    <item>
      <title>Prevent Re-rendering, Save Usability</title>
      <dc:creator>Mez Charney</dc:creator>
      <pubDate>Wed, 29 Jan 2020 21:01:06 +0000</pubDate>
      <link>https://forem.com/mezzolite/prevent-re-rendering-save-usability-cak</link>
      <guid>https://forem.com/mezzolite/prevent-re-rendering-save-usability-cak</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3f1w8p0qa067e27b5wht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3f1w8p0qa067e27b5wht.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last hurdle before graduation at Flatiron School is the Capstone. This is a 3 week project that is supposed to encapsulate most of what we learned in the 15 week program, and create something that shows off those skills. Mine is Imp-Politic, a game that creates incentives for people to participate in democracy through legislative advocacy. My original idea was to create a project that facilitates legislative access to underrepresented communities through education. The idea to gamefy advocacy came from thinking about how to make something like calling your senator less of a chore, and more something people want to do. &lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges
&lt;/h2&gt;

&lt;p&gt;During the build process, I came across multiple challenges, and re-rendering was one of them. When a player completes an action, they click on a button which opens a modal with a congratulatory message and a reward. One of the processes that isn't visible to the player is also adding that reward to the total points the player has already accumulated. The total rewards are held in state in the app. When state is updated, components re-render themselves. Left unchanged, the modal with congratulations and reward would never be shown, and the player would lose all the components they had opened and the app would go back to its original state. This is where preventing re-rendering in certain circumstances comes in. &lt;/p&gt;

&lt;h2&gt;
  
  
  Finding a solution
&lt;/h2&gt;

&lt;p&gt;Below is a diagram of my app. While most state and lifecycle methods with fetches are held in the Main component, most of the functionality of the app once a user is logged in happens in the children of the LoggedIn Home Page. &lt;/p&gt;

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

&lt;p&gt;I started out having everything in Main, and passing props down to children components that would change Main state. This meant that every time state changed, the entire app would re-render. My first solution was to use a lifecycle method like &lt;strong&gt;shouldComponentUpdate&lt;/strong&gt; to prevent re-rendering. &lt;/p&gt;

&lt;p&gt;The React docs for this method are &lt;a href="https://reactjs.org/docs/react-component.html#shouldcomponentupdate" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use shouldComponentUpdate() to let React know if a component’s output is not affected by the current change in state or props. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My method's syntax looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nf"&gt;shouldComponentUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loggedInUserPoints&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;nextState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loggedInUserPoints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, because everything was being kept in the same component, this method didn't work for me. I started debugging by moving around where certain methods and state were held, to see if having these things in lower order components would help. &lt;/p&gt;

&lt;p&gt;As seen in the diagram above, most components share LoggedIn Home Page as the top-most parent, not Main. While the player's total points are calculated and kept in state in the Home Page, the method that updates them is called in Action Card. By moving these methods down into Home Page and lower, I was able to eliminate the need for Main to re-render every time an action is completed. &lt;/p&gt;

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

&lt;p&gt;While there are a few different ways to prevent re-rendering, such as &lt;strong&gt;shouldComponentUpdate&lt;/strong&gt; or &lt;strong&gt;Pure Components&lt;/strong&gt;, it seems that first figuring out the component structure and refining the placement of state and methods is the best way to ensure an app works the way it's supposed to. &lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/mezzolite/capstone-frontend" rel="noopener noreferrer"&gt;Project Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://imp-politic-game.firebaseapp.com/" rel="noopener noreferrer"&gt;Imp-Politic&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Beginner Node.js:  Many-to-Many Relationships</title>
      <dc:creator>Mez Charney</dc:creator>
      <pubDate>Mon, 16 Dec 2019 04:58:51 +0000</pubDate>
      <link>https://forem.com/mezzolite/beginner-node-js-many-to-many-relationships-3nln</link>
      <guid>https://forem.com/mezzolite/beginner-node-js-many-to-many-relationships-3nln</guid>
      <description>&lt;p&gt;For my third (and first solo) project at Flatiron School, I wanted to explore the language of flowers. Being a self-described old lady and lover of Victorian romances, I knew that flowers have meanings, and it would be fun to figure out a way to put together messages with those flowers. &lt;/p&gt;

&lt;p&gt;Flatiron School mostly focuses on Ruby on Rails for backend development, and I readily admit this project would have been easier had I stuck with that. However, to get the info on flowers I wanted without having to hardcode everything, I wanted to try web-scraping, and the first tutorial I found used Node.js, Axios, and Cheerio. So I set off on the adventure of learning Node.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Set-up
&lt;/h2&gt;

&lt;p&gt;First things first, in order to set up a database, you need to figure out the relationships you'll need to build. Since I was working in thin vertical slices, I knew that I would need a table for "flowers", to host the information on flowers and their meanings I was scraping. I built all the Knex queries and the full CRUD routes for the flowers table.&lt;/p&gt;

&lt;p&gt;Once that was complete, and the front end connected, the next step was to create a "bouquets" table. This is where collections of flowers, and the "messages" that those flower collections convey, would be stored. Once those were done, the only thing left was to figure out how flowers and bouquets were connected. What it became is a many-to-many relationship, with a "bouquets-flowers" join connecting flowers to their bouquets.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6B9hooFC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8cut7fbykt9s5lqryvbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6B9hooFC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8cut7fbykt9s5lqryvbk.png" alt="DB Visualization"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the join table was created, the next coding problem was figuring out how to get the flowers that belonged to a certain bouquet to show up in the bouquets get. &lt;/p&gt;

&lt;h2&gt;
  
  
  Many-to-many Query
&lt;/h2&gt;

&lt;p&gt;Here's the code for the query I wrote that connects to the bouquets table, maps through the bouquets, and attaches the flowers that are in that bouquet using the join table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./knexfile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;knex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;getFlowersInBouquets&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bouquets&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bouquets&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promises&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bouquets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bouquet&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bouquets-flowers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flowers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flowers.id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bouquets-flowers.flower_id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bouquet_id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bouquet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flowers&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                            &lt;span class="nx"&gt;bouquet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flowers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;flowers&lt;/span&gt;
                            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;bouquet&lt;/span&gt;
                        &lt;span class="p"&gt;})&lt;/span&gt;
                &lt;span class="p"&gt;})&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;promises&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In each iteration of the map, a variable called "promises" is created, in which the flower_id that's stored in the join with the bouquet_id of the bouquet being mapped over is attached to the bouquet itself. When this query is run using a GET method, what's returned is all the bouquets, each with the information in its columns, such as id, and name, but also with the flower_ids that belong to the bouquet. This makes it much easier to fetch all relevant data at once in order to have the bouquet show up on the front end. &lt;/p&gt;

&lt;h2&gt;
  
  
  Sources and Project Links
&lt;/h2&gt;

&lt;p&gt;Web-scraping tutorial using Node.js, Axios, and Cheerio: &lt;a href="https://blog.bitsrc.io/https-blog-bitsrc-io-how-to-perform-web-scraping-using-node-js-5a96203cb7cb"&gt;How to Perform Web Scraping&lt;/a&gt;&lt;br&gt;
Another web-scraping tutorial I used together with the first one: &lt;a href="https://levelup.gitconnected.com/web-scraping-with-node-js-c93dcf76fe2b"&gt;Web Scraping with Node.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github repo for my floral messaging project: &lt;a href="https://github.com/mezzolite/talk-floral-to-me-project"&gt;Talk Floral To Me&lt;/a&gt; &lt;/p&gt;

</description>
      <category>node</category>
      <category>database</category>
      <category>knex</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Partnership in Development</title>
      <dc:creator>Mez Charney</dc:creator>
      <pubDate>Tue, 03 Dec 2019 01:41:33 +0000</pubDate>
      <link>https://forem.com/mezzolite/partnership-in-development-1j50</link>
      <guid>https://forem.com/mezzolite/partnership-in-development-1j50</guid>
      <description>&lt;p&gt;More than in most other professions, partnership and group work are integral to successful software engineering. While the myth of the lone genius hacker prevails, the reality of working in the tech industry is very different. A vast majority of companies of all sizes use a team-based approach to development. &lt;/p&gt;

&lt;p&gt;As a student at Flatiron School, I've been able to experience both partner and team based projects. In my experience, the two main ways a project is coded is either through pair programming, or by having each collaborator be responsible for a feature.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pair Programming
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fDiVocUr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/q3wnknw3ucuiuet28ik9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fDiVocUr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/q3wnknw3ucuiuet28ik9.jpeg" alt="pair programming"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.agilealliance.org/"&gt;Agile Alliance&lt;/a&gt;'s definition:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Pair programming consists of two programmers sharing a single workstation (one screen, keyboard and mouse among the pair). The programmer at the keyboard is usually called the “driver”, the other, also actively involved in the programming task but focusing more on overall direction is the “navigator”; it is expected that the programmers swap roles every few minutes or so.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My first partnered project at Flatiron was built completely using pair programming. My partner and I planned out each feature together, and coded each one together as well. As beginner programmers, the ability to talk through the code while building meant that our minds were constantly engaged and the code was being proofread as we went. Because we had two brains working on the same problem, we were able to compliment each other, sharing knowledge and skill as we went. For me, the instant feedback of having another person right there was the most valuable part. Sometimes, the methodology involved in pair programming was akin to white-boarding as we went.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Dividing Work by Feature
&lt;/h3&gt;

&lt;p&gt;In my second paired project, we started out using pair programming but once the basics had been set up, we divided the features between us and worked on them separately. We came together every few hours, comparing notes, going over code, and working on styling.&lt;/p&gt;

&lt;p&gt;This method involved practicing different skills from pair programming. The independence meant that while my partner was there for backup, I was responsible for that feature, and therefore its integration into the project itself. The responsibility added pressure, a feeling of a lack of safety net, but at the same time, it spurred me to want to research and find the best ways to complete the task. Of course, my partner was available for brainstorming and help whenever I needed her, but when the feature came together and worked, there was a definite feeling of victory. It also made me feel like a contributor, creating a part that was integral to the whole. &lt;/p&gt;

&lt;h3&gt;
  
  
  Useful Tools
&lt;/h3&gt;

&lt;p&gt;No matter what method is being used for the build, planning is integral to the execution. We were using the agile method as much as possible, planning and building in thin vertical slices, coming together for review, testing, deployment and further planning whenever a feature was complete.&lt;/p&gt;

&lt;p&gt;&lt;a href="//trello.com"&gt;Trello&lt;/a&gt; is an indispensable tool in a developer's arsenal. It provides the ability to plan features down to the most minute detail, create task boards that assist with visualization, and track progress.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9UciQ4Z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/36ffn1e3bvbvgdyxa8il.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9UciQ4Z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/36ffn1e3bvbvgdyxa8il.png" alt="Project Trello Board"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Both pair programming and individual feature work have their pros and cons. Pair programming bends the power of two brains onto one problem, allowing for instant communication and inline proofreading. However, having two developers work on a feature together means that the project may take longer than if the partners were working individually. Individual feature work offers independence and speed, but also a greater allowance for mistakes and requires time to be taken for separate review. &lt;/p&gt;

&lt;p&gt;Regardless of the method used, my main takeaway from both projects was the necessity of "buy-in". Each of the partners has to believe in what they're doing, and the method being used. Agile especially requires that everyone on a team is on the same page, and is working fluidly together. &lt;/p&gt;

</description>
      <category>development</category>
      <category>pairprogramming</category>
      <category>partnership</category>
      <category>groupprojects</category>
    </item>
    <item>
      <title>Anticipating User Input When Building a CLI App</title>
      <dc:creator>Mez Charney</dc:creator>
      <pubDate>Wed, 30 Oct 2019 03:12:41 +0000</pubDate>
      <link>https://forem.com/mezzolite/anticipating-user-input-when-building-a-cli-app-4h2f</link>
      <guid>https://forem.com/mezzolite/anticipating-user-input-when-building-a-cli-app-4h2f</guid>
      <description>&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;My project partner and I recently completed our first ever coding project, a CLI App built using Ruby. As a novice in coding, it was really exciting and rewarding to build something other people could interact with. Besides overall concerns about the app working, our biggest challenge was anticipating a user's input, and accounting for variations. &lt;/p&gt;

&lt;h3&gt;
  
  
  Will users follow directions?
&lt;/h3&gt;

&lt;p&gt;The app consists of a database of planets in our solar system, which the user is able to get information on by entering the name of their current location, and picking a planet from a presented list. Here is the code for the method that asks the user where they're from, and compares their answer to existing planets in the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user_planet&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"What planet in the Solar System do you currently reside on?"&lt;/span&gt;
        &lt;span class="n"&gt;user_location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;capitalize&lt;/span&gt;
        &lt;span class="n"&gt;solar_planets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Planet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="n"&gt;user_location&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;solar_planets&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            &lt;span class="n"&gt;user_location&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; 
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Please enter a planet in the Solar System."&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;colorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:red&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;user_planet&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;Because our database only has the 8 major planets in the Solar System, we had to make sure the user could only pick one of those for their current location. We based later methods and calculations on this answer, so had to create air-tight logic around the input. The use of an &lt;code&gt;if...else&lt;/code&gt; statement was imperative here, as it allowed us to guide the user to the correct answer. If they picked one of the 8 planets, their answer was recorded. If they tried something funny, like Pluto, or Gallifrey, they got a red message redirecting them to give another answer, and were sent back to the beginning of the method. This way, they had infinite chances to get this right (or at least make the rest of our methods happy).&lt;/p&gt;

&lt;h3&gt;
  
  
  Y/N Complications
&lt;/h3&gt;

&lt;p&gt;At a different point in the app, the user is asked a series of yes or no questions. While the prompt offers Y and N as answer options, we still had to make sure the logic would stand up to testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;distance_from_selection&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Would you like to see the distance to your selection? Y/N"&lt;/span&gt;
        &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;downcase&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"y"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"yes"&lt;/span&gt;
            &lt;span class="n"&gt;distance&lt;/span&gt;
            &lt;span class="n"&gt;print_distance&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            &lt;span class="n"&gt;display_travel_time&lt;/span&gt;
        &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"n"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"no"&lt;/span&gt;
            &lt;span class="n"&gt;display_travel_time&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Please enter Y or N."&lt;/span&gt;
            &lt;span class="n"&gt;distance_from_selection&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;Above, we take in the user's input and convert it to lower case letters using &lt;code&gt;.downcase&lt;/code&gt; in order to account for users with a love for capitals, and ones who never use them. In our &lt;code&gt;if...elsif...else&lt;/code&gt; statement, we make sure to anticipate multiple options for yes and no, the requested answers, as well as something else that could be entered. The &lt;code&gt;else&lt;/code&gt; option prompts the user for a correct answer and returns them to the beginning of the method. Each option has its own internal path of methods that are followed depending on the user's selection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple Interesting Options
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ending_options&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"*---*---o---*---~---o---~---*---o---*---*"&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"--*---*---o---*---~---o---~---*---o---*--"&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"What would you like to do now? Please select 1, 2, or 3."&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;colorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:yellow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"1. Go back to Planet Menu."&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"2. View your Favorite Planets."&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"3. Exit Travel Agency."&lt;/span&gt;
        &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;
            &lt;span class="nb"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"clear"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;main_menu&lt;/span&gt;
        &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"2"&lt;/span&gt;
            &lt;span class="n"&gt;display_favorites&lt;/span&gt;
        &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Thank you for visiting the Milky Way Travel Agency. Good Bye!"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;colorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:magenta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"imgcat ./lib/images/purple_solarsystem.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Please make another selection."&lt;/span&gt;
        &lt;span class="n"&gt;ending_options&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 is the code for the ending of our app. We had to make sure the user had multiple options, and would clearly know what each one did. Each option has a number, and the user was asked to input the number of their selection to proceed. While the &lt;code&gt;if...elsif...elsif&lt;/code&gt; part of the logic covers the presented options, the &lt;code&gt;else&lt;/code&gt; is there in case of typos or general messing around. It returns the user to the option menu to remind them of the app's desired input. It also gives them another chance to see the adorable star ribbon we coded, of which I'm very proud. &lt;/p&gt;

&lt;p&gt;Here's a link to the project's repo: &lt;a href="https://github.com/mezzolite/milky_way_travel_agency"&gt;Milky Way Travel Agency&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources&lt;/strong&gt;: planet image from &lt;a href="https://solarsystem.nasa.gov/resources/545/artists-concept-our-solar-system/"&gt;Jenny Mottar via NASA&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>logic</category>
      <category>cliapp</category>
    </item>
  </channel>
</rss>
