<?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 David Fellows on Medium]]></title>
        <description><![CDATA[Stories by David Fellows on Medium]]></description>
        <link>https://medium.com/@dfellows12?source=rss-b4767dcc74bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iwEe10zDAIdEMVzc.jpg</url>
            <title>Stories by David Fellows on Medium</title>
            <link>https://medium.com/@dfellows12?source=rss-b4767dcc74bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:01:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dfellows12/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[Introduction to TDD with JavaScript]]></title>
            <link>https://medium.com/@dfellows12/introduction-to-tdd-with-javascript-7b182786c521?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b182786c521</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 20:40:02 GMT</pubDate>
            <atom:updated>2020-02-16T20:40:02.089Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my first post in a series that dives into TDD (Test Driven Development). I’m going to cover some of the basics of what it is, the benefits, some of the types of tests it uses, and the framework Jest which you can use to implement it. Testing is a valuable skill for any programmer allows you to create more reliable applications. In future posts I’m going to focus on how to write each type of test that makes up TDD.</p><h3>So what is TDD?</h3><blockquote><em>TDD is an iterative approach. Just like say, a living organism evolves and adapts itself to its environment, so too does code — evolving and adapting itself to its tests. (Arek Torczuk)</em></blockquote><p>TDD is a methodology that involves writing tests that fail before development and then writing new code in order to make those tests pass. Each test specifies and describes what that code will do. If TDD was explicitly followed you would do this for every small function in your program until there was 100% coverage (a lofty goal)! However, the primary aim is to make sure everything is operating as expected, covering all inputs and scenarios. Programmers try and use the least amount of code possible to achieve the expected result and then go back to refactor for elegance and team design specification. This is as opposed to a traditional approach where you write code, see if it works, and then refactor. This diagram illustrates the basic process of TDD:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/0*eB9rB9CgOUkfHzMn.png" /><figcaption>TDD process, image from testlodge.com</figcaption></figure><h3>Why do we need TDD and what are the benefits?</h3><p>Let’s be honest, code is messy. I recently heard that the base code for a single Tesla car is over 600 million lines. As programs grow larger and and code interacts in increasingly complex ways bugs become a likely possibility. Functions become interdependent and errors can occur in areas far from where you are actually working! TDD’s goal is ultimately to make code simpler and bug free.</p><p>Proponents of TDD have reported the following benefits:</p><ul><li>While time consuming at first, TDD in the long run cuts development costs. Healthy code base should be maintained continuously and with tests you can be confident that your functions won’t break. Everything still passing? You’re good to go! If they aren’t you’ll have resources and information to track down the bug.</li><li>TDD promotes conscious decision making because it forces you to think about what you are trying to accomplish before implementation. No more hacking your way to a solution!</li><li>TDD creates <a href="https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">SOLID</a> code. Simpler code is easier to test, forcing programmers to create more elegant solutions that follows the Single Responsibility Principle.</li><li>Unit tests are created with descriptions that even non-technical people are able to comprehend. They can act as documentation for the code itself.</li><li>TDD supports long term scalability and major changes in architecture. Without tests engineers have to add changes without true integration, resulting in problems down the line.</li><li>TDD prevents scope creep by having clear goals and defined requirements. No more adding “gold plating” or features that don’t contribute to the programs original purpose.</li></ul><p>I wanted to conclude by stating that while it is a commonly held belief that TDD overall reduces development costs and time, there is a growing subset of programmers that are arguing against its benefits. In my opinion it’s still a better approach to preventing bugs so your customer doesn’t find them.</p><h3>Types of tests</h3><h4>Unit tests</h4><p>Unit tests are the bread and butter of the testing world! They aim to test a fully isolated piece of code like a function by providing input and checking for an expected output. They are the easiest to write and should make up most of your test suite.</p><h4>Integration tests</h4><p>Integration tests deal with dependencies such as when a function calls another function. All of your unit tests could be working but your program crashes because they do not work together properly. The more dependencies or server calls involved the harder it is to write. Being skilled in these will make you very valuable as a QA!</p><h4>End to end tests</h4><p>E2E tests (also known as functional, application, full flow or user interface tests) are the most difficult and least common of the tests. They are designed to simulate user interaction with a virtual browser that expects outcomes without looking at internal code.</p><h3>The Jest Framework</h3><p>There’s no shortage of test frameworks for every language and type of test. Vitali Zaidman made an extremely comprehensive post of JavaScript options in 2019 <a href="https://medium.com/welldone-software/an-overview-of-javascript-testing-in-2019-264e19514d0a">here</a>. I recommend checking it out if you have time! To set your application up for testing you will need a runner which executes tests. Second, you will need an assertion library to define your tests and logic. There are packages that take care of these individually (Mocha and Chai) but Jest is becoming ubiquitous and does both of these steps in one program. It’s an excellent choice for getting started and is fast to run on large frameworks. One of the creator’ s goals was for it to be zero-configuration so it’s ready to use straight out of the box!</p><p>Jest is distributed through node package manager so let’s install it on a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*CsiLUFobxvjBuesNgB5Fzw.png" /></figure><p>Next create a file named <em>util.test.js — </em>Jest watches any file with the word test in the name. Next, going into the package.json file and configure the scripts file to the following:</p><pre>&quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;jest&quot;<br>  },</pre><p>Jest is now ready to go! After writing tests all we need to do is type: “jest — watch” and it will automatically run. Viola! In the next post I’ll cover unit tests, the building block of TDD!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b182786c521" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing Bubble, Selection, and Insertion sort]]></title>
            <link>https://medium.com/@dfellows12/comparing-bubble-selection-and-insertion-sort-89cf3b3dd8eb?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/89cf3b3dd8eb</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Thu, 06 Feb 2020 23:37:39 GMT</pubDate>
            <atom:updated>2020-02-06T23:37:39.943Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bubble sort</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*nh6F_qERbgD3xmV-.gif" /></figure><p>Let’s start with the simplest of all sorts, bubble sort. With this method each element is compared to the one It is quick and easy to implement so often serves as an introduction to sorting for beginners. It is extremely inefficient this becomes more pronounced as the dataset you are sorting grows larger. There is almost always a better method to use. Bubble sort works by comparing each element to the element next to it, swapping them if they are out of place. Larger numbers “bubble” to the top, hence the name. To accomplish this were using nested loops so worst case scenario we’re looking at a <strong>O(n²)</strong> runtime. Not ideal!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*DO9YpyMtvpdPSoSO60TZ5w.png" /></figure><h3>Selection Sort</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*R0MHc4Hd26q6FPut" /></figure><p>Looking at the animation you may notice that selection sort is similar to bubble sort but backwards! Instead of moving larger numbers slowly to the top we are are iterating over the array and keeping track of the lowest number. At the end of each loop that number will be moved to the current “bottom” of the unsorted portion of the array. Selection is more efficient than bubble but not by far. The Big-O notation is <strong>O( (n² + n) / 2)</strong>, which is reduced to <strong>O(n²) even in the best case scenario.</strong> It is typically only favored by engineers over insertion sort because it uses less copies of variables. If each variable takes a significant chunk of memory it can add up on slow processors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*SemVhZR-tCziXvI6UD7pRA.png" /></figure><h3>Insertion Sort</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*Qjg6y-MKmreXIH4D.gif" /></figure><p>Insertion sort is similar to selection sort but instead of setting a point and working through the unsorted portion of the array, it loops inward, comparing values against the already sorted portion. When comparing worst case scenarios insertion sort is equal in runtime to selection sort. However, a true worst case scenario is rare so insertion sort will almost always outperform selection sort. It will shine anytime the dataset is smaller or partially sorted. This is where Big O can be deceiving. At a best case scenario it is O(n) or linear runtime. Another advantage is that insertion sort is “stable” and “live”, meaning that it will still sort properly if new information is inserting into the dataset while processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*lLbKtIVMmAdKAzbtDJSmOg.png" /></figure><p>Conclusion: Bubble, Selection, and Insertion sort are useful for beginner programmers have quadratic runtime in almost all cases, something to be avoided. After getting the hang of these there are far more efficient algorithms to use, such as merge and heap. Master these and move on!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89cf3b3dd8eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hook Basics]]></title>
            <link>https://medium.com/@dfellows12/react-hook-basics-28133388b730?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/28133388b730</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Wed, 05 Feb 2020 16:38:01 GMT</pubDate>
            <atom:updated>2020-02-14T14:38:54.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*D3QNw337f3nEZe6m.jpg" /></figure><p>If you follow React news it’s impossible that you haven’t heard about hooks. Released in February 2019 with patch 16.8.0, they spell out a very different direction for the future of the front end framework. You might be late to the game like me so I wanted to cover the basics in this article. Why were they created, how do I use them, and what do they mean for my current React projects? Let me start by clarifying — hooks are backwards compatible so you will not to be replacing any existing code!</p><p>At their essence, hooks are 10 special functions that allow us to take advantage of React’s features without writing classes. This comes with some big advantages. Overall, classes can be bulky, come with a steeper learning curve, and aren’t always needed. While learning React I often found myself unsure of when to use a functional component vs class component until it had been mostly built out, requiring a rewrite. This was disappointing because the framework seems to lean towards functional components.</p><p>From a practical standpoint, hooks produce leaner and faster code. Take a look at this example from a project I was working on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*k3gLSO4pHaNMWQUPv6Qa_g.png" /><figcaption>Simple class component</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*mb1_p-yphTJ-OtL7TU7HNg.png" /><figcaption>Same component using hooks. Don’t you love a good refactor?</figcaption></figure><p>This gets even worse when attempting to share logic between pre-hook components. With no inherent way to reuse stateful logic, developers had to find workarounds using render props and higher order components. This often ended up in what is called “wrapper hell”. Check out this example from Dan Abrimov’s twitter feed that a company had deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUAO5oHjnj5CHVhJMgyvfA.png" /><figcaption><strong>Fun stuff..</strong></figcaption></figure><p>We all know the the simpler and more clear code is, the better, and that is what the underlying purpose of hooks gets at. Complex components become increasingly harder to understand because of the uncertain effects of state and lifecycle methods. They come with unnecessary logic which produces unexpected outcomes. At the same time this makes it more difficult to separate and simplify the components! Developers often use 3rd party libraries such as redux to take care of this problem. However, hooks have done such a job, there’s talk that it might replace them all together (I doubt this anytime soon). Let’s talk about how it all works.</p><h3>useState hook</h3><p>Before using any hook you must import it from React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*4JGZzIGPiD_lG3grQHcKVA.png" /></figure><p>useState is the hook that you will be using to access state from within functional components. It declares a state variable, takes in one parameter (an initial state), and returns an array. The first value will be the state and the second value will be a function that allows you to change this state. useState is often assigned to a const that destructures the array, allowing you to name the variables whatever you would like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*VhjreXTFj6tt1UHhTEx84g.png" /></figure><p>Instead of calling {this.state.title} like before, using hooks you can just call {title}. If you would like to set up more than one state variable, simply call useState again! Easy stuff!</p><h3>useEffect hook</h3><p>useEffect combines three lifestyle methods (componentDidMount, componentDidUpdate, componentWillUnmount) into one method that runs when the page re-renders. useEffect takes in two parameters — a callback function that will execute on render, and a variable that will cause a render when it changes. This means that if the second parameter is an empty array, it will only render once!</p><p>There are some things to keep in mind for with useEffect. For methods that produce memory leakage (external subscriptions) an extra method should be passed in to clean it up. Also, just like useState, you can separate concerns and use useEffect multiple times! This way instead of grouping a large amounts of unrelated logic into one componentDidMount, you can create simpler functions.</p><h3>Other hooks (and custom)</h3><p>You may remember me saying that there are ten hooks. This is true but the rest are to handle edge cases and are not necessary for creating a React application. useContext and useReducer, for example, can be used abstract control of state similar to redux. They are worth exploring on your own and I encourage you to do so. A complete list can be found <a href="https://reactjs.org/docs/hooks-reference.html">here</a>.</p><p>Custom hooks are what allow us to extract reusable logic and store it in a separate file. You will be identify them because by convention they start with the word “use” and internally call one or more hooks. The name is important because it allows React to know that the “hook rules” apply to it.</p><h3>Conclusion</h3><p>Hooks are simple to implement and can make your code cleaner and more explicit. React will be trending towards using them instead of class components. To stay ahead of the crowd try building out a small project with hooks today!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28133388b730" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding Challenge Practice: 100 Doors]]></title>
            <link>https://medium.com/@dfellows12/coding-challenge-practice-100-doors-65f4b0a486f1?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/65f4b0a486f1</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Fri, 20 Dec 2019 15:43:35 GMT</pubDate>
            <atom:updated>2019-12-20T15:43:35.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*-_A4uVg4b9i45KHm.jpg" /><figcaption>Trying to find your first job</figcaption></figure><p>After beginning my coding journey nearly a year ago, I will soon graduate from Flatiron coding bootcamp and begin the real test — finding my first job. (Does anyone have some spare work experience?) Coming from a liberal arts background I’ve been dreading, one aspect in particular is the technical interview. From what I’ve heard it is enough to make even the most seasoned professionals anxious. Some people may be naturals but I believe with enough practice anyone can learn a new skill. You just need to flex that muscle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/0*Scgnkz2VMiOKOcVg.jpg" /></figure><p>Luckily, in our industry there is a never-ending supply of free resources at our fingertips. Over the next few months I plan on beginning everyday with a series of coding challenges and posting solutions to my weekly favorite here. Feel free to join!</p><p>My first question is from FreeCodeCamp which has a whole track to help you prepare for coding interviews. It includes sections on algorithms, data structures, take home projects, and contains large collections from Rosetta Code and Project Euler. Enough to keep anybody busy for a long time! A in-browser IDE and explicit test suites make it quick and easy to get started. Without further adieu:</p><h3>Rosetta Code: 100 doors</h3><p>There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and ‘toggle’ the door (if the door is closed, open it; if it is open, close it). The second time, only visit every 2nd door (i.e., door #2, #4, #6, …) and toggle it. The third time, visit every 3rd door (i.e., door #3, #6, #9, …), etc., until you only visit the 100th door.</p><p>Implement a function to determine the state of the doors after the last pass. Return the final result in an array, with only the door number included in the array if it is open.</p><h4>Step 1: Understand the problem</h4><p>Read through the problem multiple times! I’m sure everyone can relate to looking at a problem, creating a new problem in your head, and then trying to solve that for way too long. Read each line and clarify any concepts that seem unfamiliar. Repeat the question in a different way.</p><p>Looking at “100 doors” we can make the following observations:</p><ul><li>There are doors numbered 1 through 100 that start closed. We need to find all the numbers of the open doors at the end of the function, returned in an array.</li><li>We will iterate over the range 100 times, toggling the doors open/closed (represented by true/false)</li><li>Each iteration over the range the gap between toggles increases by a multiple, incremented by one.</li><li>On the last iteration only the 100th door will be toggled</li></ul><h4>Step 2: Pseudocode my solution</h4><p>It can be extremely challenging to pseudocode an entire solution before you code. I often find that there is at least one step that is deceivingly complex. After working on it you may find that you have to reexamine the problem and come up with a new plan. It can help to revisit your pseudocode and look at the bigger picture.</p><ul><li>Create an array of 100 boolean values</li><li>Create a counter starting at 1 that increments once with each iteration</li><li>While the counter is less than or equal to the number of doors carry out the following:</li><li>Keep track of the array index you are accessing, starting at the counter number.</li><li>Create another loop that iterates over the number of doors</li><li>For each index that it lands on, change the boolean value to the opposite of what it was</li><li>Increment the index by the counter number</li><li>Create an empty array and a variable to keep track of our current arrays index</li><li>Map over array of boolean arrays, incrementing index counter after each loop</li><li>When index value == true, push the index into the index array</li><li>Return the array of index numbers</li></ul><h4>Step 3: Implement</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*mWfndZL6qnIK0vNzC5Aicg.png" /></figure><p>I’m sure there is a more straightforward answer but this did the trick.. You can always go back and refactor!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*e0I0oLj54rwhYb2L-Bdh9A.png" /></figure><p>This part of the problem took the longest to solve. Nested enumerables can be challenging to figure out! We know we need to pass by the doors 100 times and for each door carry out an action. At each door we will toggle the boolean value to the opposite of what it currently is — an extremely useful programming tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*PbDACMXhlIbv4ejaVDGBVw.png" /></figure><p>We finally have our array of doors that are true or false. After working on a problem for a while it can be hard to remember what you were originally trying to solve! As a refresher: we need to return an array of <strong>door numbers </strong>(array indexes) where the value is true. To get the indexes I mapped over the array of booleans and kept track of the index with a counter, if the boolean equaled true, I pushed the counter into an array and incremented by 1.</p><h4>3. Refactoring</h4><p>During practice it’s best to go back and improve what you can and then search out better solutions on the web. Through other people’s approaches you can find new ways of thinking and operating in your language of choice. For example, I knew there had to be a better way to populate an array with values!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*IqlzE3c3HuRxUx7DVXOz5g.png" /><figcaption>Isn’t that pretty?</figcaption></figure><p>The most apparent refactor is the while loops. While it might get the job done, it is not succinct or efficient. In problems where a counter is involved, for loops can be a better solution</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*VhDK75Ta6E3mtrr3ht-ang.png" /></figure><p>Much better! Given an argument of 100, we should receive the following array:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*DUcV9WcXgGSFVmhmI-ouiQ.png" /></figure><p>We were able to reduce the lines of code from 33 to 22 while also increasing readability! Would you make any changes? Feel free to comment below :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65f4b0a486f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Javascripts essential functions]]></title>
            <link>https://medium.com/@dfellows12/understanding-javascripts-essential-functions-91820b5994f1?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/91820b5994f1</guid>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[callback]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 14:39:38 GMT</pubDate>
            <atom:updated>2019-12-04T18:54:59.319Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding JavaScript’s essential functions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*00tP9dxK-mskzYnX.jpg" /><figcaption>from Fireship youtube tutorial</figcaption></figure><p>Switching from programming in Ruby to learning JavaScript was a jarring change for me. I was used to clear, concise, syntax and keywords that gave way to a never ending stream of parenthesis and brackets. Ultimately what I found the most challenging was the flexible and diverse use of functions. Unlike other languages JS functions are <strong>higher order functions</strong> meaning they can be used as an argument for another function or can return yet another function. How many times do you think I’m going to say function in this post?</p><p>Anyways, while it can be frustrating at first, JavaScripts functions allow for a high degree of abstraction and enable us to break programs into nice compartmentalized chunks. Mastering their various forms is necessary for any serious JS developer. The topics listed below barely skim the surface but provide beginning developers with a launching point for more research. Enjoy and happy learning!</p><h4>1. Function declarations</h4><p>You probably recognize function declarations (also called function statements) from your earliest lessons in Javascript. They can be identified easily because they start with the keyword <strong>function, </strong>and a name for the function. These are followed by a list of parameters and a block/statement that defines what the function does. In Javascript, these functions are stored as objects that can be invoked (or called) at a later time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*Uzl5v2CXesNqu-Nqkbp5CQ.png" /><figcaption>Example of function declaration</figcaption></figure><h4>2. Function expressions</h4><p>Function expressions are quite similar to declarations and can be mistaken if you don’t look carefully. The key difference in syntax is that expressions do not need a function name — which when omitted becomes an <strong>anonymous function</strong>. By themselves anonymous functions are not syntactically correct so must be used in other contexts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*tb3_yQ4RJZHhcGjOB2Dveg.png" /><figcaption>Not allowed! Whenever JavaScript sees a function keyword it expects a definition to take place. Adding a “!” or “void” at the beginning would create a valid statement by treating whatever comes after as an expression.</figcaption></figure><p>After the expression is assigned to a variable it can be called by using the variable name like a normal function. There are, however, several differences and advantages. Unlike declarations, expressions will not be <strong>hoisted</strong>, meaning they cannot be used before the JS interpreter reaches the line of code where they are defined. This allows them to keep information about the local variables from the scope where they are defined.</p><h4>3. Closures</h4><p>Closures are one of the most powerful features of Javascript and far outside the scope of this post (ha.. ha). However complex they may be, they can be defined simply as one function nested within another function. They are extremely useful because they allow you to privatize data that is related to that function. This is called <strong>lexical scope</strong> and sets the scope of a variable or function so that it can only be called from within the environment (block) it was defined. The outer function cannot read variables from the inner function which creates the closure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*DGLwcxdqS-uKP4Caqkbhbw.png" /></figure><p>Some common uses are:</p><ul><li><strong>Callback functions</strong></li><li>Cleaning up code</li><li>Avoiding polluting the global scope</li><li>Emulating private methob . ds</li></ul><h4>4. Callback functions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*DGLwcxdqS-uKP4Caqkbhbw.png" /></figure><p>Callback functions are functions that are passed as an argument to another function and then called at a later time, hence the name. Callbacks really shine when creating <strong>asynchronous </strong>javascript code. In situations when you are communicating with external data (APIs) they most likely will not respond instantaneously which is a very long time for your code to wait! When using callback functions the code that is executed within them is put in a secondary stack to be executed(a lower level topic that is great to research), allowing the rest of your other code to continue. A bonus is rather than having one large nested closure you can split your code into bite size, logical chunks. Just be careful to avoid too many nested callbacks or it can be extremely difficult to debug (commonly referred to as <strong>callback hell).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/0*_sDjWUhs3N4KAyP8.jpeg" /><figcaption>Callback hell</figcaption></figure><h4>5. Immediately invoked function expressions (IIFE)</h4><p>IIFE’s, pronounced as “iffy”, are as you might expect, functions are invoked when they are created and only once. One of the most recognizable examples can be seen in many frameworks/libraries such as jQuery. To protect their variables the entire codebase is wrapped in an IIFE. See an extremely simplified example below. Note the extra set of parentheses on line 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*dntRryTLr-aWWJ5VM6QQTQ.png" /></figure><p>There are several difference syntactic versions of IIFE’s that could be a topic for future posts. IIFE’s were originally used to control scope but have since fallen out of popularity since the introduction of block-scoped variables in ECMAScript 2015. Understanding them at a higher level is useful, however, because there are still developers utilizing them for advanced cases and performance boosts.</p><p>Examples can be found here: <a href="https://mariusschulz.com/blog/use-cases-for-javascripts-iifes">https://mariusschulz.com/blog/use-cases-for-javascripts-iifes</a></p><h4>6. Arrow functions</h4><p>Arrow functions were one of the most anticipated changes of ES6 and serve two primary functions: drastically reducing the size of a function and managing the binding of <strong>this</strong>. They are best approached from these two angles. For the first subject, I’ll let the code speak for itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*8u4O6k2FyabQs6GCdeht3w.png" /></figure><p>When only one parameter is given, drop those parenthesis! Single line block? Who needs curly braces?! All arrow functions are anonymous. Who needs a name?! Such beauty..</p><p>Where was I? Ahem.. As JavaScript began to expand into an object oriented language, especially in modern frameworks such as React, developers ran into a problem. Until arrow functions, every function had its own <strong>this </strong>value, which captured this value within its local environment. Arrow functions allowed it to escape that context and become more abstract, referred to the greater class that function resides in. Cool stuff.</p><p>P.S. function was said 46 times.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91820b5994f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Essential CSS layout properties]]></title>
            <link>https://medium.com/@dfellows12/essential-css-layout-properties-f5160432e091?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5160432e091</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Fri, 15 Nov 2019 20:20:31 GMT</pubDate>
            <atom:updated>2019-11-15T20:20:31.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*pXV0nnIGfnHtMlou.jpg" /></figure><p>So over the course of the the last few months I have toiled to learn the fundamental skills needed to become a full stack software engineer. Ruby has begun to flow more freely from my fingers instead of sporadic spurts. This week I finally began a team project to create our first legit web application — a website that connects users with pet adoption opportunities in their area. I proudly set up an external API, used it to seed our database and create relational objects. With Javascript I was able to query this information and display it for the whole world to see.</p><p>After all this, the thing that almost drove me crazy was trying to center a box on a page. There are many design shortcuts to create good looking websites but they often come with a lot of baggage. For example, the bootstrap framework comes with built in components (forms, buttons, modals, etc.) but they have hidden attributes that make custom changes difficult. I became determined to understand these fundamentals and found the following are most important:</p><h3>1. Display</h3><p>I’ve decided to start with display because it is a crucial property to understand. Every single HTML element in CSS is a box that has a default display value depending on the type of element it is. Determining that display value is going to explain why your text, image, etc keeps flying all over the page *hopefully*! Don’t worry — it’s not as difficult as it seems. The majority of elements either have a display of <strong>block or inline</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*Xjn6OoalYag4RXwMszyfZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*4hE_TscN_B_R-X6uY1g7AQ.png" /></figure><p><strong>&lt;div&gt; is block-level.</strong> Each element will start a newline and stretch left to right as far as possible.</p><p><strong>&lt;span&gt; is inline</strong>. Each element will join into the natural flow of its parent element. Properties effecting positioning such as margin, float, height, etc can be applied but will not make an effect. Inline elements can only expand horizontally.</p><p>Since all divs are blocks and all blocks create a newline you might be curious — how might someone line up divs in a horizontal row? That is where <strong><em>inline block</em> </strong>comes in. It has the properties of inline but allows you to make vertical adjustments.</p><p>One last handy display value for your programmer toolbox is <strong><em>none</em>. </strong>It is often used to hide and show elements without really deleting them. To create a toggle this could be applied to any container and manipulated using javascript.</p><h3>2. Margin, padding and the CSS box model</h3><p>Margin and padding are both positioning values that affect the space around content. It can be explained visually by the box model available with your browsers developer tools. Begin by inspecting an element within your browser. Within the tool’s style tab you can see that element’s box model and highlight different spaces around the content to examine its dimensions. As a developer you will do this often to better understand a pages layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*tbmbu9AkDC6z7ns-jJibew.png" /><figcaption>Image from w3schools.com</figcaption></figure><p>The key takeaway here is that padding refers to the positioning of an element within a container while margin creates space outside of an element. Each side of an element can be selected (i.e. margin-left) but if only one value is inputted all sides will be affected. While troubleshooting your containers an excellent way to get your bearing is to set thick, colored borders to see where everything is.</p><p>Simple enough — but I have one warning for you. When several elements have margin things on your page will start to act in funny ways. This is due to an old HTML rule called margin collapse. If neighboring elements (siblings, parents, or children) each have margin applied to them, when these elements interact the element with the larger margin will override the smaller. This can be tricky and unexpected when manipulating the DOM. One way to avoid it is to communicate with your team and only specify margin throughout your website on chosen sides (left or right).</p><h3>3. Absolute and relative positioning</h3><p>Like display, all CSS elements have an inherent position value of static which means it will follow the normal flow of the page. This isn’t useful for us, though! Sometimes we want to put things exactly where we want them. In comes absolute positioning. Absolute allows us to completely take the element out the flow of the webpage. When applied it is possible to use the left, right, top and bottom attributes to create more specific directions. It will not affect other elements and vice versa. We have to be careful and selective with this attribute because too many absolute elements can make editing very difficult. Imagine making a small layout change and then manually having to change all those extra elements!</p><p>So where do relative come in? If you applied it to an element you might not notice any difference. However, you can now apply directional values just like absolute, except they will be <strong>relative to itself</strong>. This means it will stay within its current context and make changes from that position. Very useful stuff.</p><p>One caveat for all of this — when an element is relative it creates a connection with any absolute positioned elements within it. Absent of this relationship an absolute element will append itself to the entire body container. However, when a parent container is relative you will not be able to move the absolute element outside of that parent container.</p><p><em>Warning: Elements with custom positioning will stack on top of other elements. How things stack can be changed with z-index values!</em></p><h3>4. Float</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS79DEOEONV_GlKNa3n6YQ.png" /><figcaption>Example of two elements — one is a div with float left</figcaption></figure><p>Float is a position attribute which create formats similar to those found on a newspaper. It was originally created to allow developers to position or “float” elements within text boxes. Creative designers saw that float worked on all elements and used the opportunity to mash together versions of modern column/row layouts. However, since the creation of tools such as Flexbox and Grid, it is mainly used for its original purpose and styling within smaller elements.</p><p>Developers working with float will inevitably deal with the frustrating topic of collapsing. When a container only holds elements with float properties they will “collapse” onto a single line. This happens frequently when viewing a website on different display sizes. It can be fixed by applying the clear property after the floating elements but inside of the container!</p><p><em>Quick tip: A common problem with floats is pushdown caused by elements within a float that are larger than the float itself. For example — an oversized image can stick out causing unexpected changes to other elements. Fix it by applying overflow: hidden to the image.</em></p><p>Do you have any CSS tips? Leave a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5160432e091" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git branch and merge made easy]]></title>
            <link>https://medium.com/david-fellows/git-branch-and-merge-made-easy-ec6918469837?source=rss-b4767dcc74bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec6918469837</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Fellows]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 03:06:51 GMT</pubDate>
            <atom:updated>2019-10-03T03:18:35.790Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Git branch and merge</strong></h3><h3><em>Step by step instructions.</em></h3><ol><li><strong>Git branch yourbranchname </strong>#create your branch</li><li><strong>Git checkout yourbranchname #</strong>move to your branch</li><li>Make your changes!</li><li><strong>Git status </strong>#check your changes</li><li><strong>Git add * </strong>#stage your changes</li><li><strong>Git commit -m “your message here” </strong>#commit your changes</li><li><strong>Git checkout master </strong>#switch to master branch</li><li><strong>Git merge yourbranchname</strong></li><li><strong>Git push </strong>#push changes back to remote</li></ol><p><em>#Commands are bolded, comments designated by #. Find more detailed instructions with pictures below!</em></p><p>Git can be a frustrating topics for novice developers. After putting in the hard work to learn a language’s basics, you are finally ready to begin your first project (hopefully with other developers). Little did you know, you would spend most of you first day not dealing with code, but source control! I’ve been there and hopefully I can make this process a little easier for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/0*nZh9Cr4XwNB8efdI" /><figcaption>After a long day of merge errors</figcaption></figure><p>This post assumes you know why source control is crucial and that you have the knowledge to begin a repo or clone one down to your machine. If this sounds like a foreign language head to <a href="https://guides.github.com/">https://guides.github.com/</a> and check out their basic material. “Hello, World” is always good starting place.</p><p>My goal here is to layout a concise, step by step guide, to making your first Git branch and merging it back to the master branch. Basic instructions can be found above — below I will provide a more detailed breakdown with additional useful info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*nS1D54jD5D2hVwm9.png" /><figcaption>Image from docs.microsoft.com</figcaption></figure><p>Why branch? Branching is a fundamental part of source control that allows us to create “sandboxes” to write and test our code. This is critical for working on a team project. Each member can create their own branch to work on features before merging together on a single master branch. The master branch is the single source of truth and contains only thoroughly tested, functional code.</p><p><strong>Step 1 — Git branch yourbranchname </strong>#create your branch</p><p>If you’re conceited like me, your branch was most likely named after yourself. However, convention says it should be indicative of the branches purpose, such as: feature, css, project a, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*DUazPfJDiLxCMuVZKKXX8g.png" /><figcaption>Calling git branch without naming a branch will provide a list of all branches. The head or * will be adjacent to what branch you are currently in.</figcaption></figure><p><strong>Step 2 — Git checkout yourbranchname #</strong>move to your branch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*ZgPhtNQvctbaZTrmak_dqQ.png" /><figcaption>The head is now next the examplebranch, showing the move was successful.</figcaption></figure><p>Pro tip: commands in git can be streamlined using tags (shortened versions of other commands). See documentation for which tags can be used with each specific command. Step 1 and Step 2 can be combined by using the following: <strong>git checkout -b examplebranch</strong></p><p><strong>Step 3 — </strong>Make your changes!</p><p><strong>Step 4 — Git status </strong>#check your changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Sqk3nAxB0tDh5KKsLdjtwg.png" /><figcaption>“git commit -a -m “your message here” will combine steps 5 and 6!!</figcaption></figure><p>Git status is an extremely helpful command which will show you the current state of your working directory and staging area. Files that have been modified but not added to the staging area will be listed in red.</p><p><strong>Step 5 — Git add * </strong>#stage your changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*Q1X7PNRrlVs6acBwT28U0Q.png" /></figure><p>Git add will add your file(s) to the staging here. This doesn’t save anything but lets git know what you would like to commit. * will add all changed files but is considered a bad practice. If you have changed multiple files you should add the exact files you want to save. Simply replace the * with a filename.</p><p><strong>Step 6 — Git commit -m “your message here” </strong>#commit your changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*TRnR8bv4bV0pRYQnJJJUgA.png" /></figure><p>Git commit will create save a snapshot of your current staging area. Committing often is an important aspect of source control. If something goes wrong you will be able to rollback your commits to code that previously worked. Keep commits short (between 2–20 lines). Each commit should have a message which sums up the changes made.</p><p><strong>WARNING: </strong>If a commit is made without a message you will most likely enter the VIM text editor. Commands here vary but hopefully you will be able to exit by hitting the escape keeping, typing q!, and then enter.</p><p><strong>Step 7— Git checkout master </strong>#switch to master branch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*lzTkh0t-gpqys_oBuKi4UA.png" /><figcaption>Although git status shows there is nothing to commit, the master branch is not update to date with your examplebranch</figcaption></figure><p><strong>Step 8— Git merge yourbranchname</strong></p><p>Merging your branch into the master will overwrite your master branch with the changes you made in your new branch. At this time you may want to delete your other branch with the command “<strong>git branch -d</strong>”. Branches are typically removed after the updates are made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*qFreomCqXn0Pc6Irj7wRBw.png" /></figure><p><strong>Step 9— Git push</strong></p><p>If you are making your first git push you will have to set your upstream. Follow the prompt in the command line.</p><p><strong>WARNING:</strong> Git push will “push” your changes up to the remote (online) branch. Be sure sure your code is working properly. At this point, your coworkers will be able to “git pull” these changes down to their local files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*BA35y09Y2snx68_r.gif" /></figure><p>Congratulations!! You have made your first (hopefully successful) branch and merge!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec6918469837" width="1" height="1" alt=""><hr><p><a href="https://medium.com/david-fellows/git-branch-and-merge-made-easy-ec6918469837">Git branch and merge made easy</a> was originally published in <a href="https://medium.com/david-fellows">David Fellows</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>