<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tom Tobar on Medium]]></title>
        <description><![CDATA[Stories by Tom Tobar on Medium]]></description>
        <link>https://medium.com/@codetombomb?source=rss-c738665b01b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b_zdRsZTpzMS_hcq8SMt2Q.png</url>
            <title>Stories by Tom Tobar on Medium</title>
            <link>https://medium.com/@codetombomb?source=rss-c738665b01b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:15:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codetombomb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Render Deployment: Solving the “Unexpected token ‘??=’” Error in Node.js on Render]]></title>
            <link>https://medium.com/@codetombomb/render-deployment-solving-the-unexpected-token-error-in-node-js-on-render-4d55bbd8bdea?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d55bbd8bdea</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[render]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[error-message]]></category>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Wed, 01 May 2024 16:29:48 GMT</pubDate>
            <atom:updated>2024-05-01T16:29:48.383Z</atom:updated>
            <content:encoded><![CDATA[<p>When deploying applications, encountering environment-specific errors is common, especially when different platforms support different software versions. Recently, I came across a perplexing issue on Render, a popular deployment service. My Vite + React application, which ran perfectly locally, was failing with a cryptic syntax error on deployment. Here’s how I diagnosed and solved the problem.</p><h3>The error</h3><p>The application deployment logs showed the following error:</p><pre>(node:268) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token ‘??=’<br>(node:268) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag ` - unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)<br>(node:268) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.<br>==&gt; Publish directory dist does not exist!<br>==&gt; Build failed 😞<br>==&gt; Common ways to troubleshoot your deploy: https://docs.render.com/troubleshooting-deploys</pre><p>This error was a little misleading because there was no explicit use of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment">nullish coalescing assignment operator (??=)</a> in my code. This operator is a <a href="https://en.wikipedia.org/wiki/Null_coalescing_operator#JavaScript">part of ES2020</a> and allows developers to assign a default value to a variable only when it is null or undefined.</p><h3>Root Cause</h3><p>The root cause of the issue was that Render’s default Node.js version did not support ES2020 features, including the nullish coalescing operator. Even though my local Node.js version supported these features, the discrepancy between the local and production environments led to this syntax error.</p><h3>The Solution</h3><p>To resolve this issue, I needed to align the Node.js versions between my local environment and Render. Here’s how I did it:</p><ol><li>Check Local Node.js Version: First, I confirmed my local Node.js version by running node -v in the terminal.</li></ol><p>2. Configure Node.js Version on Render: Render allows you to specify the Node.js version through environment variables. I set the NODE_VERSION environment variable to match my local version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*J7y5z9K5jx7lQOP1KOyeow.png" /><figcaption>Check Local Node.JS version</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPASAKRa-csIrDEG4ZZWCQ.png" /><figcaption>Add an environment variable on Render under your static site’s Environment tab specifying the same Node version. Save changes.</figcaption></figure><h3>Render Docs References</h3><p>The last line of the error message got me started in the debugging process: <a href="https://docs.render.com/troubleshooting-deploys">https://docs.render.com/troubleshooting-deploys</a></p><pre>Common ways to troubleshoot your deploy: https://docs.render.com/troubleshooting-deploys</pre><p>I ended up finding the solution in the docs here: <a href="https://docs.render.com/language-support#set-your-language-version">https://docs.render.com/language-support#set-your-language-version</a></p><h3>Conclusion</h3><p>This experience underscores the importance of ensuring consistent environments between development and production. By specifying the Node.js version in Render’s environment variables, I was able to resolve the syntax error and ensure that my deployment environment accurately reflected my development environment.</p><p>For anyone deploying modern JavaScript applications, always check if your hosting service’s default settings align with your development environment’s capabilities, especially regarding language features and version compatibility.</p><p>Happy coding, and may your deploys be smooth and your coffee be strong! 🚀💪☕️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d55bbd8bdea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With Python and VS Code]]></title>
            <link>https://medium.com/swlh/getting-started-with-python-and-vs-code-d795fcf72fc9?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d795fcf72fc9</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[vscode]]></category>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Thu, 24 Sep 2020 18:39:29 GMT</pubDate>
            <atom:updated>2020-12-21T18:59:24.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zDy8dzyJdNNmvcyyz-yYsA.jpeg" /></figure><p>In my experience, learning a new programming language is easier if you already know one. When I started learning Python, I noticed similarities to Ruby and JavaScript; which I’m comfortable with. The shapes of the syntax in Ruby are reminiscent of the Python Programming Language and because of its Object-Oriented design, it feels familiar. Invoking functions in JavaScript and Python is basically the same. There were a couple of Python specific syntax rules that were weird at first but with practice, it becomes second nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/0*uniFuOT-YA7tsmeg" /><figcaption><a href="https://qz.com/1624252/pythons-creator-thinks-it-has-a-diversity-problem/"><strong>Guido Van Rossum</strong></a></figcaption></figure><p><em>“ Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another’s code; too little and expressiveness is endangered.“ </em>— <a href="https://en.wikipedia.org/wiki/Guido_van_Rossum"><strong>Guido Van Rossum</strong></a>, <em>Creator of the Python Programming Language (</em><a href="https://en.wikipedia.org/wiki/Benevolent_dictator_for_life">BDFL</a>)</p><h3>First Things First</h3><p>If you’re on a Mac, you might already have Python installed on your computer but you want to make sure that you have the latest version. At the time of this writing, Python 3.8.5 is latest and greatest from the <a href="https://www.python.org/downloads/">Python.org</a> website.</p><ul><li>Download the installer and save it to your desktop.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jzyr9_K5K1kAETldTxt32A.png" /><figcaption><a href="https://www.python.org/downloads/release/python-385/">https://www.python.org/downloads/release/python-385/</a></figcaption></figure><ul><li>Double click the package and follow the prompts on the installer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/147/1*l_2lz41uf4rd7gYAMDCVGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*ajy89xd8_crN79BRbaBWQg.png" /></figure><ul><li>Now you can confirm that you have Python installed by running the following command command in your terminal:</li></ul><pre>python3 --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*RO1Mjuu6anPBsLZ56n0VnA.png" /></figure><p>You should get the above output in the terminal if you’ve installed it correctly.</p><h3>Hello World 🌎</h3><p>Now, we can fire up a Python3 session right in our terminal. Just type:</p><pre>python3</pre><p>and hit the return key. You will get the following in the terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TB1UYHxad3EEV8XkEfNRQg.png" /></figure><p>It’s like the big bang just happened and we have a blank Python universe to play with and create in.</p><h4>The print( ) Function 🖨</h4><p>As the name implies, <a href="https://www.w3schools.com/python/ref_func_print.asp#:~:text=The%20print()%20function%20prints,before%20written%20to%20the%20screen.">the print function</a> will print a message to the screen. It can take in zero or more Python objects (like strings, variables, and even other functions etc) that will be converted to a string before being written to the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*UwhGK6_ZeBbiIdjeWZj2WQ.png" /></figure><p>Try adding multiple strings separated by space or commas or a combination of the two to see how it affects the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*GATnWREnAJeWgjIpSx4aKQ.png" /></figure><p>Add integers (whole numbers) to the mix and see what happens. Error messages are pretty helpful in letting you know what the problem is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d67wVHc0ve0_FEsvOVvPsw.png" /><figcaption>In this case, Python needs to have the strings and integers separated by a comma.</figcaption></figure><p>Running the above code with a comma separating the strings from the integers makes the interpreter happy again and we get the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d8iZ8BRdL9z-UAStXKL_tA.png" /></figure><p>To exit a terminal Python session, call the exit() function:</p><pre>&gt;&gt;&gt; exit()</pre><p>and press the return key. This will escape the Python terminal session.</p><h3>Data Types in Python</h3><p>Python has different ways of storing data. The different types of data can do different things and can be leveraged in different ways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*LwUi41J292XIs3Vu1ykdeg.png" /></figure><p>Visit <a href="https://www.w3schools.com/python/python_datatypes.asp">https://www.w3schools.com/python/python_datatypes.asp</a> for a more in depth look at data types in Python.</p><h3>Python + VS Code = ❤️</h3><p><a href="https://code.visualstudio.com/">Visual Studio Code</a> is my preferred text editor and it is what I have been using to learn Python. I really love the Debug Console for Python because the output is really easy to read and it is user friendly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4CHqk2GqG92vqcCozE5bUA.png" /></figure><p>Go to <a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a> and get the version that is right for your OS. After downloading and unzipping, drag the app icon from the Downloads to your Applications.</p><p>Now launch the program and once it is open, type:</p><p>command(⌘) + shift(⇧) + p</p><p>This will open up your Command Palette at the top of the screen and it will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2B1LgHlMXgLqkVPPWG8FQ.png" /></figure><p>In the Command Palette search bar, type:</p><pre>&gt;shell command</pre><p>You should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0IbT4fxVTBlOZoH6go-6w.png" /></figure><p>Click on <strong>Shell Command:</strong> Install ‘code’ command in PATH. What this is going to allow you to do is to start VSCode from the terminal using the ‘code’ command. You can also open a directory and its contents from terminal in VSCode using the ‘code .’ (don’t forget the space after ‘code’) command which we will use in just a sec.</p><p>One more thing. Get the Microsoft Python Extension. Click the “Extensions” icon on the left side of the screen. Looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/136/1*N92w5Y_Sk9oXLBwumBTrRA.png" /><figcaption>‘Extensions’</figcaption></figure><p>You will then see this window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*tizY4LHDUAJXHg-nK_gE1A.png" /></figure><p>In the search bar at the top, search for ‘python’ and look for:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*hgAi9oZjyGY5Gkg1RLBuig.png" /><figcaption>Python by Microsoft</figcaption></figure><p>Click on Python by Microsoft and this window will pop up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r8lhj0eSXa6cT_bXqKUbGA.png" /></figure><p>Click the install button and you’re all set.</p><h3><strong>Create a New Directory</strong></h3><p>Open your terminal and navigate to the Desktop. Then create a new directory named “python”.</p><pre>Desktop % mkdir python</pre><p>Change directory into that folder.</p><pre>Desktop % cd python</pre><p>Once you’re there, we can open that folder in VSCode by typing ‘code .’</p><pre>python % code .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BHBUkcSzkMR84YCYNRC7Q.png" /></figure><p>VSCode will open up and you will see a ‘Welcome’ screen. In the top left corner where it says ‘EXPLORER’, you will see:</p><ul><li>OPEN EDITORS</li><li>PYTHON (The empty directory we just made)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*SgA73_lD-FNi2BG7hwLAmw.png" /></figure><p>Click on the ‘python’ directory and you will see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*rlTy8A2Q1izfaRPH9shT_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/106/1*fY9Co9BB8M5Vo6RqQXF9iQ.png" /></figure><p>Click on the ‘new file’ button and create the ‘hello_world.py’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*k1JO62O0fPw6IuDJbaFm3Q.png" /></figure><p>Now we can write some code in the new file.</p><h3>Functions</h3><p>Functions in Python are defined starting with the ‘def’ keyword. That is followed by the name of the function, a set of parenthesis with or without parameters, and a colon : (The toughest part about my transition to Python is remembering to put a colon at the start of the function body) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6aa89d6c626aa92ebf210962411bc69/href">https://medium.com/media/d6aa89d6c626aa92ebf210962411bc69/href</a></iframe><p>Above are two defined functions. The top function, though functional, just illustrates how a Python function comes together. We can call function_two and get some output in the Debug Console.</p><p>Calling functions or, invoking functions, is a lot like calling functions in JavaScript.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6aa89d6c626aa92ebf210962411bc69/href">https://medium.com/media/d6aa89d6c626aa92ebf210962411bc69/href</a></iframe><p>On line 14, function_two is being invoked and the code inside of it will be executed. Let’s run this saved file in the VSCode’s Debug Console.</p><h3>The Debug Console</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*eNAReOdg3Ji6lHv3ojQlDw.png" /><figcaption>The ‘Run’ button</figcaption></figure><p>On the left side of the screen you will find this icon. Click it and then you will see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*hrWl999HxvjB8QOxBWYL-A.png" /><figcaption>Click on the <strong>create a launch.json file</strong></figcaption></figure><p>Click on the <strong>create a launch.json file. </strong>This will open up the Debug Configuration. Select the <strong>Python File Debug the currently active Python file </strong>pictured below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmbmpSr059cGgnPKAC47RA.png" /><figcaption>Select the ‘<strong>Python File Debug the currently active Python file”</strong></figcaption></figure><p>This will create a ‘.vscode’ file in your directory and it contains the ‘launch.json’ file which controls the behavior of VSCode during a debugging console session.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77172bbb4342bba71ac34ab4dfc33fe0/href">https://medium.com/media/77172bbb4342bba71ac34ab4dfc33fe0/href</a></iframe><p>Inside of the ‘configurations’ array lives an object and its last value is named “console”. We should be able to hit the run button and get some output in the integrated terminal window that pops up at the bottom of the VSCode screen at this point but it is just not as awesome as the Debug Console. Take a look at this monstrosity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N1Mcfemql1IU55pacw_L1g.png" /></figure><p>To set the <a href="https://code.visualstudio.com/docs/python/debugging#_console">Debugging Console</a> as the default, we will need to change the “console” value in the ‘launch.json’ file from ‘integratedTerminal’ to ‘internalConsole’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77172bbb4342bba71ac34ab4dfc33fe0/href">https://medium.com/media/77172bbb4342bba71ac34ab4dfc33fe0/href</a></iframe><p>Save the ‘launch.json’ file and then click on DEBUG CONSOLE in the terminal window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*sGp0HRpP_bVxJyIOIlxELg.png" /></figure><p>Now click the run button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*eNAReOdg3Ji6lHv3ojQlDw.png" /><figcaption>The ‘Run’ button</figcaption></figure><p>Then click the green triangle button at the top of the screen next to the ‘Python: Curre’ dropdown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*F55lTnQD9L6_LqM475bwpg.png" /></figure><p>And we get some nice output in the Debug Console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*FYHRy3QSTDdw3eOuKBUA-Q.png" /></figure><h3><strong>Parameters and Arguments in Functions</strong></h3><p>You can add parameters to your functions that will be used in the body of the function to change return value based on user input. We can calculate the square of a number by multiplying it times itself. Comment out the code (highlight all code and press command(⌘) + /) in the file or delete it and add this code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/538de0ae709cf27904f6ecffb52b93cb/href">https://medium.com/media/538de0ae709cf27904f6ecffb52b93cb/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*xSm_onXMbnyc55FIMEQBmQ.png" /></figure><p>The ‘num’ in the parenthesis on line three is called a parameter. A parameter is a function variable that can be used inside of the function’s body in a specific way. ‘Num’ is being multiplied times itself and save to the ‘answer’ variable. Then, ‘answer’ is printed to the console using the print function.</p><p>When calling or invoking the function on lines 8–10, the number that is passed into the parenthesis is called the argument. The argument will replace the parameter in the function and be passed into the body where it is referenced. We can also write the functions to take in multiple arguments.</p><h3>Multiple Parameters and Arguments</h3><p>Multiple parameters can be set in a function separated by a comma. Once again, clear or comment out the previous code and insert:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c540c2f31567252d0e4fde30185a742/href">https://medium.com/media/4c540c2f31567252d0e4fde30185a742/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJRszGN2jcsEE7PCcLKltQ.png" /></figure><p>There are a few new things happening in the code above. Starting at line two, the ‘introduction_with_language’ function is being defined. This function will take two arguments when invoked, a name and language.</p><p>On line three, the print function is rendering a string to the console. The string starts with an ‘f’. This is called an ‘<a href="https://www.datacamp.com/community/tutorials/f-string-formatting-in-python?utm_source=adwords_ppc&amp;utm_campaignid=1565261270&amp;utm_adgroupid=67750485268&amp;utm_device=c&amp;utm_keyword=&amp;utm_matchtype=b&amp;utm_network=g&amp;utm_adpostion=&amp;utm_creative=332661264374&amp;utm_targetid=aud-299261629574:dsa-429603003980&amp;utm_loc_interest_ms=&amp;utm_loc_physical_ms=9028263&amp;gclid=CjwKCAjw5Kv7BRBSEiwAXGDElXoKEa-2ixpfJVj0sd1wip8lpBjVlEwtIJ0whOMCltH0msoj4KawShoC3SAQAvD_BwE">f-string</a>’ and it is a way to <a href="https://www.google.com/search?rlz=1C5CHFA_enUS879US879&amp;sxsrf=ALeKk02gnDcVdFQaCYM2KqMEc6bgFAn5PQ%3A1600898011914&amp;ei=28NrX_idN4qwsAW9zo3ADA&amp;q=interpolate&amp;oq=interpolate&amp;gs_lcp=CgZwc3ktYWIQAzIECCMQJzIECCMQJzIFCAAQsQMyBwgAEBQQhwIyBQgAELEDMgIIADICCAAyBAgAEAoyBAgAEAoyAggAOgQIABBHUKssWKssYKQ2aABwAXgAgAF3iAF3kgEDMC4xmAEAoAEBqgEHZ3dzLXdpesgBCMABAQ&amp;sclient=psy-ab&amp;ved=0ahUKEwi498jqoYDsAhUKGKwKHT1nA8gQ4dUDCA0&amp;uact=5">interpolate</a> information into another string. When the Python interpreter gets to {name} in the print function, ‘name’ is being evaluated to the string “Tom” and being inserted instead of the variable ‘name’. The process repeats for ‘language’.</p><p><a href="https://www.freecodecamp.org/news/if-name-main-python-example/">Line 6 is an interesting one</a>. It’s is a Python ‘if’ statement and it is checking to see if the ‘__name__’ property, given to the module (Python files are called modules and they are identified by the ‘py.’ extension) by the Python interpreter, has the assigned value of ‘__main__’. If that is the case, then the expression will evaluate to True and the ‘introduction_with_language’ function will be called.</p><h3>Parameter Default Values</h3><p>Function parameters can be configured to have a default value:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f61ca393982dcb2b396d366974c9b95/href">https://medium.com/media/3f61ca393982dcb2b396d366974c9b95/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJRszGN2jcsEE7PCcLKltQ.png" /></figure><p>On line two in the parenthesis, you see the parameters:</p><pre>name, language = &quot;Python&quot;</pre><p>Line 7 in the code invokes the function and only one argument is given, “Tom”. If a second parameter is not given for this function, it will default to the string “Python”. If you were to provide an argument, the parameter will be set to the argument you provide:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a4e0d87459b3ce504620936f0569bfd/href">https://medium.com/media/6a4e0d87459b3ce504620936f0569bfd/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XiuAiW2FtXHKwyOTT5hkA.png" /></figure><h3>Variable Number of Arguments</h3><p>You can also configure functions to accept a varying number of arguments. Lets create a function that will add all numbers that are passed to it and return the total:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53dcd56146304eccb3d6a64735d0203a/href">https://medium.com/media/53dcd56146304eccb3d6a64735d0203a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*gstcZFfvyr4o-tpMrHcl5g.png" /></figure><h3>Conditionals</h3><p>Making decisions is an essential part of your programs. The Python if statement will be something that will be used regularly in your code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b7a772ab62532d0325ac2f74372a1b4/href">https://medium.com/media/8b7a772ab62532d0325ac2f74372a1b4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*UJxgmFQjaO974wwN_3WO9Q.png" /></figure><p>On lines 10–12, the main function is invoked and passed in different values for the parameters “a” and “b”. Inside the main function on line 2, the “if” statement begins and a comparison between “a” and “b” is evaluated.</p><p>Each line in the ‘if’ statement is like a gateway. If the expression that follows ‘if, elif, else’ evaluates to “True”, that specific block of code will be executed.</p><p>In the case of line 10, ‘a’ is 5 and ‘b’ is 10. When those values are plugged into the expression in line 2, 5 is greater than 10 and that block will execute.</p><p>Line 11 passes in 10 for both ‘a’ and ‘b’ so line 4 will evaluate to “True” and that block will fire.</p><p>Line 12, 15 is greater than 10 so line 7 will be executed.</p><p>Below is another example that will choose a line to print out based on the chance of rain and the temperature.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fea91b493c0df38324f585f40a65e03b/href">https://medium.com/media/fea91b493c0df38324f585f40a65e03b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmgUsyuj35ag2vniZ4C5Tg.png" /></figure><h3>Loops</h3><h4>While</h4><p>The ‘while’ loop will execute the code block as long as its expression evaluates to “True”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a49ecb7abb523d6422cb2a8424b3075d/href">https://medium.com/media/a49ecb7abb523d6422cb2a8424b3075d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*YKNkDyLcEzCE9jV_2nW61Q.png" /></figure><p>Inside of the while_loop function on line 3, the variable x is set to 0. Then on line 4, the while loop is defined and the expression x &lt; 5 is evaluated to True because 0 is less than 5. The block of code inside of the while loop is executed and 0 is printed to the console. Then, x is incremented by one and the while loop repeats itself until x = 5. If the expression on line 4 said:</p><pre>while x &lt;= 5:</pre><p>then the output would include the number 5:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*B05_t7X9rrIfPoygB-jlNw.png" /></figure><h4>For loop</h4><p>We can use the for loop to iterate over different data structures that store data like lists, tuples, dictionaries, strings, or sets. To iterate over something is to stop on and inspect, or do something with, the value of each place in the data structure.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5baaae24a99a2bb846c164ca61e655e/href">https://medium.com/media/a5baaae24a99a2bb846c164ca61e655e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*GB7_o0FdASb9JWIZi8SkAQ.png" /></figure><p>In the for_loop function above, each value of the_list is being printed to the console. On line 4, I start by defining the ‘for’ loop with the ‘for’ keyword. That is followed by the placeholder variable, ‘each_individual_value’, that will be assigned the value of each item inside of the list on each iteration. This variable could have been named ‘x’ or any other name (other than a Python keyword) but I wanted to illustrate a bit better what was happening in the loop.</p><p>On the first iteration of the the ‘for’ loop, ‘each_individual_value’ will be assigned the value of 1 since ‘the_list’ first value on the left is a 1. Inside of the ‘for’ loop block, the variable ‘each_individual_value’ is printed to the console and the loop repeats until it has reached the end of ‘the_list’.</p><h3>Index in a List</h3><p>Given a list:</p><pre>days_of_week = [&quot;Mon&quot;, &quot;Tues&quot;, &quot;Wed&quot;, &quot;Thurs&quot;, &quot;Fri&quot;, &quot;Sat&quot;, &quot;Sun&quot;]</pre><p>you can reference each value based on its index or position in the list. Each position, left to right, has a number associated with it starting at 0. We can pull the value of the first position and print it to the console:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92690c12a1c64461328e763f70344f00/href">https://medium.com/media/92690c12a1c64461328e763f70344f00/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*slwzjEYqwsj0uHQAvOxZYQ.png" /></figure><p>Above, the variable ‘first_index’ is assigned the value of the first position in the days_of_week list which is ‘Mon’. The variable ‘first_index’ is then printed to the console.</p><p>We can inspect the second position by adding this line to the code:</p><pre>days_of_week[1]</pre><p>Im going to assign it to a variable ‘second_index’ and print it to the console:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92690c12a1c64461328e763f70344f00/href">https://medium.com/media/92690c12a1c64461328e763f70344f00/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*i63yR3je6AU2i--YBWiiaA.png" /></figure><h4>Enumerate Function</h4><p>We can use the built in Python ‘enumerate’ function to print out the index of each place in days_of_week:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e9c320d1fcdaa61c1429f91ddc4a026/href">https://medium.com/media/0e9c320d1fcdaa61c1429f91ddc4a026/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*pIYFTO1DNzqFRPbCDRivjg.png" /></figure><h3>Happy Coding</h3><p>We have only just scratched the surface of the Python Programming Language but hopefully this is enough to get you started and curious. <a href="https://www.w3schools.com/python/default.asp">W3C Schools</a> is always a great resource for anything coding related so check it out to continue down this Python wormhole!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d795fcf72fc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/getting-started-with-python-and-vs-code-d795fcf72fc9">Getting Started With Python and VS Code</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Envisioned Mechanical Marvel]]></title>
            <link>https://medium.com/@codetombomb/the-envisioned-mechanical-marvel-32fb4f840ccc?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/32fb4f840ccc</guid>
            <category><![CDATA[computer-programming]]></category>
            <category><![CDATA[ada-lovelace]]></category>
            <category><![CDATA[charles-babbage]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[the-analytical-engine]]></category>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 08:56:11 GMT</pubDate>
            <atom:updated>2020-09-09T20:55:51.243Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I felt compelled to investigate the origins of programming and learned about a fascinating device called The Analytical Engine. It was a machine thoughtfully imagined by a man named Charles Babbage, a British polymath who had many ideas for mechanized calculators but only managed to build parts of his inventions. Had his plans for the Analytical Engine been built, it would have been an extremely complex work of mechanical art and would have been <a href="https://en.wikipedia.org/wiki/Turing_completeness">Turing-complete</a>. Mighty glowing cogs of golden brass that stood proud at about 15 feet tall and 25 feet long. It would have been able to store data in memory, retrieve data from memory, receive input, give output, compute conditional logic and perform loops all while being powered by steam. It could fulfill even the most elaborate of steampunk fantasies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Bm8b-gUJn1zsTvGK.jpg" /><figcaption>Plans for the Analytical Engine from the 1840s Photo Credit <a href="https://computerhistory.org/blog/the-analytical-engine-28-plans-and-counting/">computerhistory.org</a></figcaption></figure><h3>Charles Babbage Dec 1791 — Oct 1871 (79 years)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*dPoS5OuZhwiHmpRo.jpg" /><figcaption>Charles Babbage Photo Credit <a href="http://www.nationaltrustcollections.org.uk/object/814168">nationaltrustcollections.org.uk</a></figcaption></figure><p>Born late December of 1791 and son of a wealthy Banker in London, England, Charles Babbage introduced a revolutionary idea to the world, the first programmable computer.</p><h4>Early Life and School</h4><p>The 1790s were a time of social and political upheaval in France and produced the famous military leader, <a href="https://www.google.com/search?gs_ssp=eJzj4tDP1TfIMk2yMGD04shLLMjPSc3PAwA6TgYm&amp;q=napoleon&amp;rlz=1C5CHFA_enUS879US879&amp;oq=napo&amp;aqs=chrome.1.69i57j46l3j0l3j69i60.4544j0j4&amp;sourceid=chrome&amp;ie=UTF-8">Napolean Bonapart</a> in the French Revolutionary Wars. In the United States, <a href="https://www.google.com/search?q=george+washington&amp;rlz=1C5CHFA_enUS879US879&amp;oq=George+Washington&amp;aqs=chrome.0.0j46j0l5j69i60.1072j0j4&amp;sourceid=chrome&amp;ie=UTF-8">George Washington</a> had just been elected into office and carried out the majority of his reign over the first 15 states. Notable inventions of that period are the cotton gin, the first successful vaccine for small-pox, the hydraulic press, plywood, and the sewing machine. The times of Babbage’s early days saw some great things come forth from great minds.</p><p>Babbage was sickly as a child and even had to overcome a life threatening fever but was able to study away from home while in recovery. Enamored with mathematics as a teen, Babbage was guided by well educated tutors that propelled his understanding to a high level. He was accepted to the <a href="https://www.google.com/search?gs_ssp=eJzj4tDP1TcwL0k3MWD0Ei_NyyxLLSrOLKlUyE9TSE7MTSrKTElPBQDHPgv7&amp;q=university+of+cambridge&amp;rlz=1C5CHFA_enUS879US879&amp;oq=University+of+Cambridge&amp;aqs=chrome.1.0j46j0l5j69i60.2956j0j9&amp;sourceid=chrome&amp;ie=UTF-8">University of Cambridge</a> in England where he was unimpressed by the quality of Math being offered. He graduated, somewhat unceremoniously, from the university in 1814 at the age of 23 and headed for home in London (<a href="https://www.google.com/search?rlz=1C5CHFA_enUS879US879&amp;sxsrf=ALeKk03iv8SFoqqiNY9hYbiItpeCbPJbZw%3A1599680591391&amp;ei=TzBZX5i6F8OUsgXOm6LQBw&amp;q=distance+from+cambridge+university+to+london&amp;oq=distance+from+cambridge+uni+to+london&amp;gs_lcp=CgZwc3ktYWIQAxgAMgYIABAHEB46BAgAEEc6BAgjECc6BggAEAgQHlCmMljwP2DGS2gBcAF4AIABZIgBrgOSAQM0LjGYAQCgAQGqAQdnd3Mtd2l6wAEB&amp;sclient=psy-ab">about 60 or so miles south of the university</a>).</p><h4>Royal Astronomical Society</h4><p>Though seemingly well established in the intellectual community of London, he was not successful in commencing a career. Nearing the age of 30, he took part in the forming of the <a href="https://www.google.com/search?q=royal+astronomical+society&amp;rlz=1C5CHFA_enUS879US879&amp;oq=Royal+Astronomical+Society&amp;aqs=chrome.0.0l6j69i60j69i61.1371j0j9&amp;sourceid=chrome&amp;ie=UTF-8">Royal Astronomical Society</a> that is still around today. It was during this period of contribution to the R.A.S. that he came up with the idea for his first mechanical calculator, The Difference Engine.</p><h3>The Difference Engine</h3><p>The aim for this machine was to calculate <a href="https://www.youtube.com/watch?time_continue=2&amp;v=pBiaec43Ph8&amp;feature=emb_logo">polynomial functions </a>in an effort to improve the Astronomical Society’s Nautical Almanac. He received funding from his government to carry out the build. It would have been a machine that came to life by turning a hand crank. Clicking cogs and oddly satisfying clanking of metal mating surfaces coming together and moving apart to provide a beautiful solution to Mathematical questions. But after almost a decade of work, by 1822, only a prototype of the machine had been built and development halted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*In18wGGZMbF-Jal9.jpg" /><figcaption>A section of the Difference Engine no. 1 shown by Babbage at parties and used as a way to promote his work Photo Credit <a href="https://collection.sciencemuseumgroup.org.uk/objects/co62243/difference-engine-no-1-difference-engine-portion-only">collection.sciencemuseumgroup.org.uk</a></figcaption></figure><p>I can only speculate that Babbage had some epiphanies while trying to breathe life into his first attempt at the Difference Engine because in the late 1840s, he reworked his design to reflect improvements. This design would never receive funding from the British government and would not be built in Babbage’s lifetime.</p><p>Almost a century later in 1989 and over a three year span, a fully functional Difference Engine was constructed, by a group of Scientists at the <a href="https://collection.sciencemuseumgroup.org.uk/objects/co526657/difference-engine-no-2-designed-by-charles-babbage-built-by-science-museum-difference-engine">Science Museum in London</a>, using the latter of Babbage’s designs. Parts were manufactured with period accurate precision. Babbage had also envisioned a printer for the machine which they also brought to life.</p><p>A duplicate of this mammoth master piece was constructed for the former Chief Technology Officer at Microsoft and Co-Founder of Intellectual Ventures, Nathan Paul Myhrvold. His copy of the machine was on display for the public at Computer History Museum for about 8 years until it was returned to him and it now resides inside the building of <a href="https://www.geekwire.com/2016/inside-intellectual-ventures-lab/">Intellectual Ventures</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*UE3z1mkp222H1PKt.jpg" /><figcaption>The Difference Engine no. 2 Photo Credit <a href="https://collection.sciencemuseumgroup.org.uk/objects/co526657/difference-engine-no-2-designed-by-charles-babbage-built-by-science-museum-difference-engine">collection.sciencemuseumgroup.org.uk</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c0D2LRE-OppKZ1xW.jpg" /><figcaption>The Difference Engine no. 2 complete with a printer Photo Credit <a href="http://www.xrez.com/case-studies/exhibition/babbage-gigapixel-difference-engine/">xrez.com</a> (the link to <a href="http://www.xrez.com/case-studies/exhibition/babbage-gigapixel-difference-engine/">xrez.com</a> has some really amazing photos of the engine)</figcaption></figure><h4>Ada Lovelace “Lady Fairy”</h4><p>Augusta Ada King, Countess of Lovelace, was born on the 10th day of the same month as Babbage (December) in 1815. To add a bit of context, it was a year after Babbage graduated from university. Ada’s father was a famous poet at the time of her birth which in those times, could be comparable to a modern day rock star. As with some celebrities, he had some inner demons and he abandoned both his wife and baby daughter.</p><p>Ada’s mother set out to destroy any possibility of her daughter developing her fathers characteristics by immersing her in education. Ada, like Babbage, was also sickly as a child overcoming a devastating sickness. Her mother was distant in her younger years but she was in good company with the likes of tutors and estate workers that took care of her and taught her well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*vGdavXEjLzT6dcgw.jpg" /><figcaption>Portrait of a young Ada painted by French artist <a href="https://en.wikipedia.org/wiki/Alfred_Edward_Chalon">Alfred d’Orsay</a> Photo Credit <a href="https://en.wikipedia.org/wiki/Alfred_d%27Orsay">Wiki</a></figcaption></figure><p>Upon returning from a year long tour of Europe with her mother, a 12 year old Ada was stricken with something of an obsession to fly. She thoughtfully examined the possibilities of how to make her dream a reality. She looked at birds for inspiration and studied potential building materials. She thoroughly documented her findings in her book aptly named ‘Flyology’. This knack that the ‘Lady Fairy’ had for documenting her ideas led her to cement her place in history as the first computer programmer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*u3iUzCxzUryCbc-M.jpg" /><figcaption>This painting of Ada was possibly made by the Swiss portrait painter <a href="https://en.wikipedia.org/wiki/Alfred_Edward_Chalon">Alfred Edward Chalon</a></figcaption></figure><blockquote>What is imagination?…It is a God-like, a noble faculty. It renders earth tolerable; it teaches us to live, in the tone of the eternal.<em> </em><strong><em>— Ada Lovelace</em></strong></blockquote><p>Per the customs of that period in England at the age of 17, Ada went to London to present herself to the King, who at that time was <a href="https://en.wikipedia.org/wiki/William_IV_of_the_United_Kingdom#:~:text=William%20IV%20(William%20Henry%3B%2021,until%20his%20death%20in%201837.">William IV</a>. Ada’s personality and brilliant mind hooked into everyone she came into contact with and she quickly became the talk of the town. As the universe intended, she would end up catching the attention of another brilliant mind, Charles Babbage.</p><p>Babbage quickly learned how sharp Ada was intellectually and began to establish a solid friendship with her. They became close and Charles opened up to her about his personal issues and they had profound mathematical conversations.</p><h3>The Analytical Engine</h3><p>The Analytical Engine is the idea supernova from the mid 19th century whose shockwave is still felt to this day. The collaborative brain child of two great minds with the imagination to see ahead of their time.</p><p><a href="http://sydneypadua.com/">Sydney Padua</a>, a graphic artist, utilized her talents to compose a novel called “<a href="https://www.amazon.com/Thrilling-Adventures-Lovelace-Babbage-Computer/dp/0307908275">The Thrilling Adventures of Lovelace and Babbage</a>” in which she illustrates her interpretation of Babbage, Lovelace, and The Analytical Engine. Her commitment to researching the topic gives a distant admirer, like myself, some insight to her understanding with fantastic illustrations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Q9d8JDaKBy6FZymY.jpg" /><figcaption>Photo Credit Sydney Padua sourced from <a href="http://sydneypadua.com/2dgoggles/the-marvellous-analytical-engine-how-it-works/">sydneypadua.com</a></figcaption></figure><p>The illustration depicts The Analytical Engine in great detail and gives a general idea for what the Engine would have looked like.</p><h4>1. The Store</h4><p>The store, known as memory in modern computers, is pictured here as the wall of columns with thousands of little slots next to Babbage. Each of these columns were designed to hold a single digit up to 50 decimal places.</p><h4>2. The Mill</h4><p>The Mill is the equivalent to the modern day CPU. It is the component of the engine where all of the calculations take place. The Mill had registers much like the columns in the memory, that could hold numbers to be operated on. He called it ‘The Mill’ because he imagined information being milled around and processed into a solution that was spat out.</p><h4>3. Steam Engine</h4><p>In the early to mid 1800s, steam power was the top technology that produced significant rotational force equivalent to the internal combustion engine that powers automobiles today. Steam powered the mighty locomotives of the First Industrial Revolution. Such a force would have been required for the Analytical Engine to power the intricate multitude of inner workings.</p><h4>4. The Printer</h4><p>Babbage was adamant on incorporating the functionality of a printer in the second version of the Difference Engine and wanted the same for the Analytical engine.</p><p><a href="https://youtu.be/BlbQsKpq3Ak?t=597">Here is a great video of the Difference Engine no. 2 that shows how the printer might have looked on the Analytical Engine!</a></p><h4>5. Operational Cards</h4><p>These cards were used to input instructions for the engine to use.</p><h4>6. Variable Cards</h4><p>These cards were used to input data into the engine.</p><h4>7. Number Cards</h4><p>The last of the three types of cards used to input information into the engine for The Mill to perform calculations on. Together, all three cards formed the engine’s software. The idea for the cards was inspired by the <a href="https://en.wikipedia.org/wiki/Jacquard_machine">Jacquard machine</a>’s cards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zsdm0asZVgmRwADf" /><figcaption>The linked cards of a Jacquard Machine Photo Credit <a href="http://www.nms.ac.uk/">nms.ac.uk</a></figcaption></figure><p>A series of cards could be linked together to be passed in front of a face of what looks like a spring loaded bed of spikes. If a spike was blocked by the card when pressed against it, it would engage an arm that selected specific functionality when the engine was running. Since each column in the store was able to hold a digit up to 50 decimal places, number cards needed to reflect this capability with 50 columns of 10 places each. To input a 5, the fifth position on the card for that specific column would not have a hole punched so that it would push on that spike when pressed against the the bed of spikes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lXxqCr3O-atDdIdE.jpg" /><figcaption>This is Babbage’s drawing of the number card. You can see that there are six hoops, three on top and three on the bottom, to link a sequence of cards together. Each column shows holes for positions 1–9. You can see a rough idea of the “bed of spikes” above the card. If a spike passed through a number hole, it would not be input into the engine. Photo Credit <a href="http://ds-wordpress.haverford.edu/bitbybit/bit-by-bit-contents/chapter-two/the-analytical-engines-machinery/">ds-wordpress.haverford.edu</a></figcaption></figure><p>Another critical piece of information that a number card contained was the address of the column in the store that the number was to be written to. When the card arms engaged for that specific column, a gear would shift to complete the a mechanical path to that column so it could be edited.</p><h4>8. The Barrel Controllers</h4><p>Microprograms or built in functionality that the Mill used to process a users request.</p><h3>The Worlds First Programmer</h3><p>Ada Lovelace married Lord William King in the summer of 1835 when she was 19 years old. She and her husband had three children together, Byron, Anne, and Ralph. In 1838, Lord King was made an Earl, or member of the nobility and therefore, Ada became the Countess of Lovelace.</p><p>Although Ada’s hands were full raising a family and she was constantly learning different things, her passion for Mathematics drew her back to her old friend, Charles Babbage. She asked Babbage to help her find a tutor to help her further her math knowledge. Augustus De Morgan, a former math professor, helped her become proficient in Calculus.</p><p>About a decade before Ada passed away from uterine cancer, she translated an article of an Italian military engineer. The article was supplemented with her extensive notes and it was within these notes that she had documented an algorithm to be executed by a machine. Because of this, she commonly known as the first programmer though there are some that reject this idea.<br>Nevertheless, her work in the early days of computer history contributed massively to where we are today.</p><h3>In Closing</h3><p>A quick Google search for the Analytical Engine will send you spiraling out of control, crash landing in a different time. It was an exciting time of worldwide growth politically, socially, and technologically. I hope I’ve inspired you to type those three words into the Google search bar made possible by our Computer Science forefathers and mothers. Better yet, just click the link below:</p><p><a href="https://www.google.com/search?sxsrf=ALeKk03ce3RefwbWYR81vJO7y3hYdmh7Hg%3A1599641535053&amp;source=hp&amp;ei=v5dYX6hkkpayBenOr7AF&amp;q=The+Analytical+Engine&amp;btnK=Google+Search">The Analytical Engine</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32fb4f840ccc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing With RSpec]]></title>
            <link>https://medium.com/swlh/testing-with-rspec-3a6ec6116cef?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a6ec6116cef</guid>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[behavior-driven-dev]]></category>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Sun, 30 Aug 2020 02:29:43 GMT</pubDate>
            <atom:updated>2020-08-31T23:09:13.270Z</atom:updated>
            <content:encoded><![CDATA[<p>First, a little on the subject of Test-Driven Development or TDD. It is a recursive process by which we write code, test code, and repeat. In the words of Kent Beck, author of “Test-Driven Development: By Example”, it “encourages simple designs and inspires confidence.”</p><p>RSpec is communicative when it gives you feedback after you process the code you wrote against the tests. If configured for colour (which should be default in my opinion), it shows if the tested code fails in(red) or passes in (green) along with a descriptive output. It can tell you all the problems that need work or can hone in on one problem at a time to keep you focused. Seeing a green output in the terminal is like having a dopamine button at your fingertips and can be very addicting but in a good way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rb15QZhCiAZ8wx4fiB3dIw.png" /><figcaption>This is the green that you will learn to love! 😍</figcaption></figure><h3>What is RSepc?</h3><p>RSpec is a Testing Framework written in the Ruby programming language. The “R” in RSpec stands for “Ruby” and “Spec” means “Specification”. It uses a unique <a href="https://en.wikipedia.org/wiki/Domain-specific_language#:~:text=A%20domain%2Dspecific%20language%20(DSL,is%20broadly%20applicable%20across%20domains.">Domain Specific Language</a> (DSL) that is meant to read like a normal conversation. If you are not familiar with RSpec and you read a test, it will probably make sense to you.</p><h3>Getting Started With RSpec 🐎</h3><p>Since RSpec is written in the Ruby Programming Language, we first need to start with checking the version that is installed on your computer. In the terminal, run this command:</p><pre>ruby -v</pre><p>You should take the time to upgrade your Ruby version if it’s not 2.4 or higher. RSpec will work with older versions of Ruby but there have been improvements to Ruby that make it faster and that means faster testing with RSpec.</p><p>You can check to see if you already have RSpec installed on your system using the command:</p><pre>rspec --version</pre><p>If you do make sure that you have the latest and greatest from RSpec by <a href="https://rspec.info/upgrading-from-rspec-2/">visiting the website</a>. &lt;== Click me!</p><h3>Installing RSpec</h3><p><a href="https://github.com/rspec/rspec#description">RSpec is a collection of Ruby gems</a> that work together to give us this wonderful capability. RSpec itself is a gem and installs just like all other <a href="https://rubygems.org/gems/rspec">Ruby Gems</a>:</p><pre>gem install rspec</pre><h3>RSpec help</h3><p>This command will give you some handy info on RSpec.</p><pre>rspec --help</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ivWcl74Kv_GNy6Q4CdF_OQ.png" /></figure><p>I have this copied and pasted in my <a href="http://evernote.com/">Evernote</a> notes. The <em>output</em> section here is particularly helpful for formatting your output so it’s easier to read in the terminal. You can configure RSpec on your machine to make output changes permanent by creating a ~/.rspec file in your root directory and adding the flag(s) that you want RSpec to fire on each call.</p><p>RSpec lets you run one test at a time using the ‘fail fast’ flag. This information can be found at the top under:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNNAVgoOQrjy60enfRJlng.png" /></figure><pre>rspec spec/file_name.rb --fail-fast</pre><pre>#the --fail-fast flag can also be reduced to:</pre><pre>--f-f</pre><h3>Initializing RSpec Within a Directory</h3><p>In a new project directory, use the command:</p><pre>rspec --init</pre><p>This will generate an .rspec file, a spec directory, and a file inside that directory called spec_helper.rb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*61j3Y1E--RrzSIzBlGyR-Q.png" /></figure><h3>Creating a Test File</h3><p>When naming your test files, it is convention to take the corresponding name of the file that contains the tested code and add _spec.rb to the end of it. Here is a file tree example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*ajPdrVRKDu2gMcviplK_Ug.png" /><figcaption>cat_spec.rb named after the cat.rb file in lib dir</figcaption></figure><p>In the top most level of the project directory lives the lib directory, spec directory and the .rspec file. Just ignore that spec_helper.rb file for now. The cat.rb file in the lib directory is where we will be writing the code that we want to test. Cat_spec.rb is where we will writing all of the tests for cat.rb so we need to make a connection to that file by requiring it in our cat_spec.rb file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5618cb2f9725853b724ac1de44dd5256/href">https://medium.com/media/5618cb2f9725853b724ac1de44dd5256/href</a></iframe><h3>🤔Thinking about what we are testing</h3><p>Considering what behavior you would like to see from the code you are testing is a critical step. At this point we can ask questions like “What attributes should my cat class have?” or “What should an instance of my cat class respond to?” Questions like this can easily be converted into RSpec DSL and be structured in a very similar way. There are many testing cases that we can account for but overall functionality of what we want to see a particular function produce is the most important.</p><blockquote>Does the thing successfully do what you want it to do?</blockquote><p>Other cases to consider:</p><blockquote>What could go wrong? How do we handle a bad input?</blockquote><p>We should consider these questions so that our program can gracefully handle these scenarios and users can still have a great experience. We want to test for all possible scenarios but there are some that just will not be that common. Writing tests for these edge cases is important but not on the same level as testing for core functionality.</p><h3>Things that we don’t want to test</h3><p>Let just all agree that the Ruby Programming Language, in its 25 years of existence (as of 2020), has been well maintained and is functioning as it was intended. Given that, we do not need to make sure that it is doing what it’s supposed to. In the same vein, Rails functionality and third party API’s should not need to be tested for functionality.</p><p>Additionally, we don’t want to double test something in our code. If you test functionality in one place and another part of your project utilizes that same code, you don’t need to make sure that it is doing the same thing in a different location.</p><h3>🗣Speaking RSpec</h3><p>We start off with describe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cd286d85a359ac05d337ca45379e2ef/href">https://medium.com/media/3cd286d85a359ac05d337ca45379e2ef/href</a></iframe><p><em>Describe</em> is an RSpec method that takes an argument of a string or class name and is used to define an example group. In the above example, I passed in a class name to the describe method but it could have been a string as well. Heres another way to look at it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc0f28f67a0f67f4270e48d24374d736/href">https://medium.com/media/dc0f28f67a0f67f4270e48d24374d736/href</a></iframe><p>The second example is functionally the same as the first but the beauty of RSpec’s DSL is that when structured like the first example, it is easier to read and that is key here. The tests can be used to communicate with non technical persons to clarify what is happening so having well structured tests will serve more than one purpose.</p><h3>‘It’, not the clown…🤡</h3><p>Let’s say that I want my Cat instance to be initialized with a name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/914f31ec3443b298183ff399f0e0ff0f/href">https://medium.com/media/914f31ec3443b298183ff399f0e0ff0f/href</a></iframe><p>Inside of the example block, the ‘it’ is used to define an example. This clever use of ‘it’ allows us to read the test intuitively. The main parts that might catch your eye here are “Describe Cat — it is initialized with a name — I expect cat name to equal “Wednesday”. The semantics of RSpec are powerful and make learning it easy.</p><h3>Anatomy of a Test</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/914f31ec3443b298183ff399f0e0ff0f/href">https://medium.com/media/914f31ec3443b298183ff399f0e0ff0f/href</a></iframe><h3>Describe</h3><ul><li>Used to define an example group inside of a Ruby block</li><li>RSpec method that takes in one argument of a string or class name. This argument will be really helpful when reading the output when a test is run.</li><li>“context” is an alias for describe and can be used interchangeably. Semantically, it is used within the context of a given test.</li></ul><h3>It 🤡</h3><ul><li>Used to define an example inside of a Ruby block</li><li>RSpec method that takes an argument of a string that will be used mostly for output.</li></ul><h3>Expect</h3><ul><li>used to define expected outcomes</li></ul><h3>Expectations 👩‍🏫</h3><p><a href="https://github.com/rspec/rspec-expectations">Expectations in RSpec</a> have a a basic structure and they are as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de37f31e9a74bf50f6eedb5b72963842/href">https://medium.com/media/de37f31e9a74bf50f6eedb5b72963842/href</a></iframe><p>There are really four main parts to expectations:</p><ul><li>expect</li><li>the expect(argument)</li><li>.to or .not_to method</li><li>and then an argument to the .to/.not_to method. These are the “matchers”</li></ul><h3>Matchers</h3><p>Matchers are abundant in RSpec. <a href="https://www.rubypigeon.com/posts/rspec-expectations-cheat-sheet/">Click here</a> to get a more in depth look at just how many there are! Here are some of the more common types:</p><h3>Equality Matchers</h3><p>Lets take a moment to consider Ruby’s comparison operators.</p><ul><li>The ‘==’ operator in Ruby will compare two values on the basis that both are roughly equal. So values like 1 and 1.0 are going to return true when compared using ‘==’ even though the data types are different.</li></ul><pre>2.6.1 :001 &gt; 1 == 1.0</pre><pre>=&gt; true</pre><ul><li>Ruby has different levels of strictness when using comparison operators. Ruby will make a type comparisons using the .eql? method and since integer != float, we have:</li></ul><pre>2.6.1 :001 &gt; 1.eql?(1.0)</pre><pre>=&gt; false</pre><p>Lastly, Ruby has an Object comparison method that is the strictest. If an object stored in memory is not the exact same, it will return false:</p><pre>2.6.1 :001 &gt; tom = &quot;Human&quot;<br>=&gt; &quot;Human&quot;</pre><pre>2.6.1 :002 &gt; josh = &quot;Human&quot;<br>=&gt; &quot;Human&quot;</pre><pre>2.6.1 :003 &gt; tom.equal?(josh)<br>=&gt; false</pre><pre>2.6.1 :004 &gt; tom.object_id<br>=&gt; 70274033337080</pre><pre>2.6.1 :005 &gt; josh.object_id<br>=&gt; 70274033321180</pre><pre>2.6.1 :006 &gt; tom.equal?(tom)<br>=&gt; true</pre><p>There are similar levels of strictness in RSpec when testing equality. Here is the Ruby version and it’s RSpec counterpart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wsGRJlJB_6ySiVBNX-QPhg.png" /></figure><h3>Collection Matchers</h3><h4>Strings 😺</h4><p>string = “ReSPECt”</p><ul><li><strong>include</strong>(string) — expect(string).to include(“SP”) — you can also use Regex — expect(string).to <strong>include</strong>(/([A-Z])\w+/) — just make sure that your Regex skills are awesome if you use this because it could work against you.</li><li><strong>start_with</strong>(string) — expect(string).to start_with(“Re”) — or expect(string).not_ to <strong>start_with</strong>(“SP”)</li><li><strong>end_with</strong>(string) — expect(string).to <strong>end_with</strong>(“Ct”) — or expect(string).not_to <strong>end_with</strong>(“Re”)</li></ul><h4>Arrays 🗳</h4><p>array = [1, 2, 3, 4]</p><ul><li><strong>include</strong>(int) this matcher works like the string include matcher. Keep in mind that order does not matter here. You can check to see if an array contains the elements and if they are in the array, it returns true. expect(array).to <strong>include</strong>(2, 4)</li><li><strong>start_with</strong>(int) —expect(array).not_to <strong>start_with</strong>(2)</li><li><strong>end_with</strong>(int) — expect(array).to <strong>end_with</strong>(4)</li><li><strong>match_array</strong>(arr) — expect(array).to <strong>match_array</strong>([2, 1, 4, 3])</li><li><strong>contain_exactly</strong>(arr) — expect(array).not_to <strong>contain_exactly</strong>([2, 3])</li></ul><h4>Hashes 🍰 🍎</h4><p>hash = {:apple =&gt; 1.00, :cake =&gt;10.00}</p><ul><li><strong>include</strong>(:key) — expect(hash).to <strong>include</strong>(:cake) — use this matcher when you’re expecting a certain key to show up in your hash. You can provide more than one key as well. You can even check for key/value pairs — expect(hash).to <strong>include</strong>(:cake =&gt; 10.00)</li></ul><p><strong>Boolean Matchers</strong></p><h4>Be 🐝</h4><p>Let’s first talk about the syntactic sugariness in RSpec. We are able to write tests like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36f35e46cf9a0e7354ca3911d0124927/href">https://medium.com/media/36f35e46cf9a0e7354ca3911d0124927/href</a></iframe><ul><li><strong>be</strong>(true) — expect(2&gt;1).to <strong>be</strong> true</li><li><strong>be</strong>(false) — expect(1&gt;2).to <strong>be</strong> false</li><li><strong>be</strong>(nil) — expect(nil).to <strong>be</strong> nil — <strong>be_nil</strong> is the same thing in this case</li><li><strong>be_truthy</strong> — expect(“string”).to <strong>be_truthy</strong></li><li><strong>be_falsey</strong> — expect(nil).to <strong>be_falsey</strong></li></ul><p>There are many more matchers that you have at your disposal and you can find more info <a href="https://relishapp.com/rspec">here</a>!</p><h3>Conclusion 🔚</h3><p>RSpec encourages you to think about your code in a different way and because of that, you can create better, concise code. This can also make writing Ruby more enjoyable as if it weren’t already intensely fun already! I hope this at least gets you started looking for more answers to one of my favorite frameworks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a6ec6116cef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/testing-with-rspec-3a6ec6116cef">Testing With RSpec</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All We Are Sayin, is Give Vim a Chance]]></title>
            <link>https://medium.com/@codetombomb/all-we-are-sayin-is-vim-a-chance-4d4c27a4fe6b?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d4c27a4fe6b</guid>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Fri, 21 Aug 2020 07:11:39 GMT</pubDate>
            <atom:updated>2020-09-08T15:48:15.686Z</atom:updated>
            <content:encoded><![CDATA[<p>As an aspiring programmer, I inevitably came across articles and tutorials with super hacker programmers that were using vim and it honestly looked pretty intimidating. Keeping your hands at 10 and 2 and never touching the trackpad to navigate a text editor seemed like something that was more trouble for me than what it was worth. With so many professional sounding programmers singing vim’s praises, I decided to see what the fuss was about. Once I got familiar with the basic commands and navigation, I began to understand how capable vim was. I actually had a great time learning the basics of vim and I hope this encourages you to at least give it a shot.</p><p>Conveniently, vim was already installed on my mac but it’s always a good idea to check the version before you get started. Paste this in the terminal to check your current version:</p><pre>vim --version</pre><h3>Starting vim</h3><p>To learn the basics, lets just navigate to the desktop directory and type this in the terminal:</p><pre>vim hello_vim.txt</pre><p>and press the return key. You should see this in your terminal now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mdwwpX-JTZgwaCiUe6Dtg.png" /></figure><p>You will see tilde (~) on the left of the terminal and the cursor flashing at the top of the screen. The tilde are there to indicate that there is no content on that particular line. At the bottom of the screen you will see:</p><p>“hello_vim.txt” [New File]</p><p>This line at the bottom is called the status line and it is where all of the interactions with vim happen. We are in “normal mode” at this point and in normal mode, we can tell vim to do things. Let start by telling vim to save or “write” the current file. Type:</p><pre>:w</pre><p>and hit return. We just told vim to save the current file if it does not exist in the current working directory. The : lets vim know that your about to give it some instructions. The lower case w in vim means “write”. You will get a confirmation in the status line that looks like this:</p><p>“hello_vim.txt” [New] 0L, 0C written</p><h3>Insert Mode</h3><p>We can directly modify the file by entering “insert mode”. Press “i” to enter the insert mode. You will know that vim got your request to enter insert mode by seeing:</p><p>— INSERT —</p><p>in the status line. While vim is in insert mode we can type text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*Qx4qfuxEOvdze9WTyO4vuA.png" /></figure><p>To make these changes permanent, we need to write the file again. First we need to escape the insert mode. You can do this by hitting the escape key or by typing:</p><p>control + c</p><p>Once your back in normal mode, you can type:</p><pre>:w</pre><p>to save the changes. The file is now written to the disc and we are back in normal mode.</p><p>To exit the vim session, type:</p><pre>:q</pre><p>and hit return. This will take you back to the terminal and back into the directory where you were when you started your vim session.</p><h3>Navigation</h3><p>One of the benefits of using vim is that it will save you time by keeping your hands on your home keys instead of using a mouse or arrow keys. While you can use your arrow keys in vim, you would be doing yourself an injustice to not use the vim navigation keys that are on the right hand home keys. In normal mode:</p><p>h = moves the cursor left</p><p>j = moves the cursor down</p><p>k = moves the cursor up</p><p>l = moves the cursor right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0J1hj0RQ6LZATlVSpP_LNg.jpeg" /></figure><p>Just think of it like this: The “h”key is on the left and moves the cursor left. The “l” key is on the right and moves the cursor right. The “j” key looks like it is pointing down and moves the cursor down. At first this is a little tough to get use to but once I became comfortable with it, vim allows you to prefix your desired direction with a number. Vim will then execute the command the specified number of times. For example typing “10j” will move the cursor down in the document 10 times. “5l” will move the cursor to the right 5 times etc. To help become more comfortable with these commands go to <a href="https://vim-adventures.com/">vim-adventures.com</a> for some fun learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YylEvmCVNfrLbtmJWYKWyg.png" /><figcaption>Cement your vim nav skills at <a href="https://vim-adventures.com/">vim-adventures.com</a></figcaption></figure><p>You will navigate through a maze and learn vim directional navigation at the same time. Pretty fun way to cement your vim nav skills!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d4c27a4fe6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The BEST Ruby CLI App Gem]]></title>
            <link>https://medium.com/@codetombomb/the-best-ruby-cli-app-gem-bc9917985fa7?source=rss-c738665b01b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc9917985fa7</guid>
            <dc:creator><![CDATA[Tom Tobar]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 05:08:47 GMT</pubDate>
            <atom:updated>2020-06-05T05:08:47.664Z</atom:updated>
            <content:encoded><![CDATA[<p>The first project that I did while attending the Flatiron Bootcamp was a command line interface application using Ruby, SQLite3, and Rails’ Active Record. The idea for the app is to learn a random fact based on numbers that you can use to start a conversation with someone. The API that I found on <a href="https://rapidapi.com/divad12/api/numbers-1">Rapid API</a> was the biggest source of inspiration for this so if you’re in Mod one banging your head against the wall looking for inspiration on the web, start <a href="https://rapidapi.com/">here</a>! Here is a short demo of what my CLI app does:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FH8kO7bLe3Cc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DH8kO7bLe3Cc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FH8kO7bLe3Cc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a90d5c7a05c7c66453b2d2ccc588dbb/href">https://medium.com/media/4a90d5c7a05c7c66453b2d2ccc588dbb/href</a></iframe><p>There are many useful and fun gems that are floating around the <a href="https://rubygems.org/">rubygems.org </a>website but there is one in particular that made the process of making the app really enjoyable and that is the <a href="https://rubygems.org/gems/tty-prompt">tty-prompt gem</a>. Tty-prompt allowed for easy implementation of the scrolling selection menu and the validations for user password. Think of it as a sophisticated and cleaner way to obtain user info rather than using Ruby’s <strong><em>gets.chomp</em></strong>. The <a href="https://github.com/piotrmurach/tty-prompt#263-multi_select">docs</a> are super helpful as well and really outline how to use this gem in your app.</p><p>Here is a shot of the gem file in use for this application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvRmY-_FAGN7mUiNGQKKJQ.png" /></figure><p>Installation is just like any other Ruby gem. You can:</p><p>Add this to your Gemfile like in the above image</p><pre>gem ‘tty-prompt’</pre><p>And then, in the terminal, run:</p><pre>bundle install </pre><p>Or, you can simply run this command in the terminal</p><pre>gem install tty-prompt</pre><p>in <em>config/environment.rb file</em></p><p>Once installed, open up your environment file and create an instance of the Prompt module and save it to a variable. I saved mine to a constant and named it PROMPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ah6Coue_VdZAPW-M5uSXPw.png" /></figure><p>Once that is in place, you can then reference that constant where you would have used a <em>gets.chomp </em>and save the collected user data to a variable to do checks on it. Here, I am simply collecting a boolean from my user and then rendering the next series of questions based on that answer.</p><p>**Side note** I used puts“/n” * 35 to clear the terminal page while the app was running to simulate a ‘next page’ and it made for a tidy user experience. I sprinkled these little beauties around the app in addition to the PROMPT constant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UohPEb_i5nH8gdwHvIXm3Q.png" /></figure><p><strong>Login/Validation</strong></p><p>TTY-Prompt also made validations and the login ridiculously easy and straight forward. At the start of the self.login method, I used the .<a href="https://github.com/piotrmurach/tty-prompt#263-multi_select">select method</a> to give the user a choice between logging in and exiting and then used a case statement to walk the user down a path of their choosing. If my user selects the login option, they are then asked what their username is. I save that into the find_user variable and ping my DB for the collected username and check for a found user. Once found, the user is then prompted for an email and the process repeats until I have a current user set to a class variable that is available to pass around my app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i47dSbYsdlMwtu44PuCk7w.png" /></figure><p>Once again, the docs on this gem are so easy to follow that I am confident that I cannot explain them any better. They have a <a href="https://ttytoolkit.org/">complete toolkit</a> but I just used the tty-prompt. Give this a try and I hope that you enjoy working with this gem as much as I did.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc9917985fa7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>