<?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 Sands on Medium]]></title>
        <description><![CDATA[Stories by David Sands on Medium]]></description>
        <link>https://medium.com/@davidmaxsands?source=rss-64a7fe57b0d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Nry2GXOB5APEjMSA-EwF6w.jpeg</url>
            <title>Stories by David Sands on Medium</title>
            <link>https://medium.com/@davidmaxsands?source=rss-64a7fe57b0d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:36:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidmaxsands/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[Recharts]]></title>
            <link>https://medium.com/@davidmaxsands/recharts-a4c6a8fc08b4?source=rss-64a7fe57b0d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4c6a8fc08b4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[recharts]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Sands]]></dc:creator>
            <pubDate>Fri, 22 Apr 2022 18:04:47 GMT</pubDate>
            <atom:updated>2022-04-22T18:04:47.361Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data visualization in React</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZhBOWxiaWL_UyKI4" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For one of my recent projects, I built out a web analytics solution akin to Google Analytics. While building out this application I became familiar with an excellent charting library called “Recharts”. Recharts is an intuitive charting library built on React components and provides a quick and easy way to integrate beautiful charts into your application. In this blog post, I want to walk through a simple implementation of a Recharts area chart.</p><p>I have created this simple area chart to demonstrate how to implement Recharts in your code. Feel free to play around in the sandbox while you continue to read, as it will give you a better idea of how this library works.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fpedantic-pond-dwit29%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fpedantic-pond-dwit29%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fdwit29%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca31a1f9bbfe0af524fa4832be135a4/href">https://medium.com/media/aca31a1f9bbfe0af524fa4832be135a4/href</a></iframe><h3>Step by step</h3><p>The first thing you will need to do is install Rehcarts:</p><pre>$ npm install recharts</pre><p>Next, we need to import the necessary components from Recharts. In our case, we need to import AreaChart, Legend, Area, CartesianGrid, Tooltip, XAxis, and YAxis.</p><pre>import {</pre><pre>AreaChart, Legend, Area, CartesianGrid, Tooltip, XAxis, YAxis</pre><pre>} from &quot;recharts&quot;;</pre><p>We will also need some data to use in our chart. Recharts is setup to take in an array of objects. This makes it easy to fetch some JSON data from an API and use it with Recharts. For the sake of simplicity, I have declared this data variable which we can use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5be791bc30c2b141a854995ab4a0cb6c/href">https://medium.com/media/5be791bc30c2b141a854995ab4a0cb6c/href</a></iframe><p>The main component we will be using is the AreaChart component. Within this component, we will specify the width, height, and the data set we will be using.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86fc557f7eae477fd2d0ffe5e26e5f98/href">https://medium.com/media/86fc557f7eae477fd2d0ffe5e26e5f98/href</a></iframe><p>Next, we will add in some of the other components needed to finish off this chart:</p><ol><li>The Tooltip component is used to add the tooltip on hover to show the data points that you are currently hovering over.</li><li>The Area component is used for the actual data visualization. As you can see below, we are using two Area components, one for “views” and one for “visitors”. You may use as many Area components as are necessary for your particular data set. For each Area component, we will pass a “dataKey” which will be on of the keys in our data set. We can also specify a color for the the stroke and fill.</li><li>The CartesianGrid component will allow us to include and customize a grid for our chart.</li><li>The XAxis and YAxis should be included to display the x-axis and y-axis for the chart. We can pass a dataKey to the XAxis component to display the name of the data along the x-axis. In this case, I passed “name” which represents the date of the data.</li><li>Lastly, we can use the Legend component to display a legend at the bottom of the chart for quick and easy reading.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10d7ec2450da69c029d2329e75a94317/href">https://medium.com/media/10d7ec2450da69c029d2329e75a94317/href</a></iframe><h3>TL;DR</h3><ol><li>Install Recharts using npm.</li><li>Import the necessary components for the type of chart you need.</li><li>Define the data needed in the chart.</li><li>Pass all the necessary props to each of the chart components for customization.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4c6a8fc08b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced SQL — CTEs]]></title>
            <link>https://levelup.gitconnected.com/advanced-sql-ctes-f36d00cbf051?source=rss-64a7fe57b0d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f36d00cbf051</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Sands]]></dc:creator>
            <pubDate>Tue, 05 Apr 2022 01:07:22 GMT</pubDate>
            <atom:updated>2022-04-05T01:07:22.552Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced SQL — CTEs</h3><h4>Common Table Expressions using the WITH clause.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3-wzrhNj0QplkOcLFGmeQ.jpeg" /></figure><p>When writing out SQL queries, it is easy for things to get out of hand or too complex to the point where readability is drastically reduced. Thankfully, in 2005, CTEs (common table expressions) were introduced into SQL Server, granting us the ability to assign a name to a set of results that can be utilized within some other CRUD statement. In this blog post, I want to briefly introduce CTE syntax and how to use it. I hope to write another blog post going into more detail on complex use cases in the future.</p><h3>What is a CTE?</h3><p>As stated above, a CTE (sometimes referred to as a “WITH statement”) is a temporary named result set that is not saved anywhere, it only exists in memory while the query is being run (unlike a temp table which exists in a temp DB file). The results of a CTE only exist within the execution scope of a specific statement; in other words, the results are only available to the CRUD statement immediately following the WITH clause in which the CTE is defined. CTEs are a great way to simplify and manage complex queries, making your code easier to read by breaking it into sections.</p><h3>CTE syntax</h3><p>I have written a simple SQL query as an example to showcase how a CTE can be used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2f7a2fd12b21dac018fb5af6e5e0cae/href">https://medium.com/media/f2f7a2fd12b21dac018fb5af6e5e0cae/href</a></iframe><p>The query above will return the following results based on the sample data that I got from <a href="https://www.sqlservertutorial.net/load-sample-database/">sqlservertutorial.net</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrrP-kuzLewqoimjV8teYA.png" /></figure><p>The first thing to note about CTE syntax is that it is defined within a WITH clause directly preceding the CRUD statement in which its results are intended to be used. The basic syntax is as follows:</p><pre>WITH CTE-name AS (CTE-definition) </pre><p>You can also define multiple CTEs by separating the definitions using commas:</p><pre>WITH name AS (definition),<br>second-name AS (second-definition)</pre><p>In order to define a CTE, you simply write a SELECT statement as your parenthetical text. This statement should capture any data that you desire to use within another query. Once you have defined your CTE, it can now be referenced in your final query:</p><pre>WITH <strong><em>name</em></strong> AS (definition)</pre><pre>SELECT * FROM <strong><em>name</em></strong></pre><p>Lets take another look at the example query above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*z2tWLcdNKyWaO1O8CojNJQ.png" /></figure><p>The section highlighted in green is the WITH clause where the CTE is defined and the section highlighted in blue is the SELECT statement that is querying off of the CTE. This is a great setup because the CTE can handle most of the hard work for us and we can edit our final query based on precisely what we need from this data set.</p><h3>Common use cases</h3><p>A CTE is an incredibly useful and flexible tool to add to your SQL repertoire. Here are a couple of the most common use cases:</p><ol><li>CTEs are often used to increase the readability and manageability of queries. By defining multiple CTEs, you can break up a long, complex query into chunks of logic that can be referenced in your final query. They are also a great way to follow the DRY principle if you are referencing the same data in multiple subqueries.</li><li>CTEs can be used to create recursive queries, which is helpful as a normal SELECT statement cannot reference itself. See Microsoft’s <a href="https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms186243(v=sql.105)?redirectedfrom=MSDN">documentation</a> on recursive queries using CTEs for more information on this.</li></ol><h3>TL;DR</h3><ol><li>A CTE exists only in the execution scope of the subsequent statement.</li><li>Unlike a temp table, CTEs are not saved anywhere.</li><li>A CTE is defined by writing a SELECT statement in parentheses following a WITH clause.</li><li>A CTE can be referenced like any other table following the FROM clause in a query.</li><li>CTE’s are a great way to DRY up code, increase readability and manageability, and write recursive queries.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f36d00cbf051" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/advanced-sql-ctes-f36d00cbf051">Advanced SQL — CTEs</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Variables]]></title>
            <link>https://levelup.gitconnected.com/css-variables-71a217bfc4f4?source=rss-64a7fe57b0d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/71a217bfc4f4</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[variables]]></category>
            <dc:creator><![CDATA[David Sands]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 01:25:02 GMT</pubDate>
            <atom:updated>2022-03-22T22:17:34.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rS-UdAxSiRWvkm_g7kWQA.jpeg" /></figure><p>When it comes to CSS, it is easy to get lost when an application has the same color or the same border radius in multiple places, and you (or your client) decide a change is needed. Suppose you have the same color in hundreds of different places and decide that it needs to be darker; what do you do? Find and replace? Track them down by hand?</p><p>Thankfully, CSS has a great solution for this:<strong> CSS variables</strong> (sometimes referred to as custom properties). CSS variables are excellent for making quick updates to specific properties, DRYing up your CSS file, and making your code more intuitive to other developers (prima facie, --primary-color is more descriptive than #3f1314).</p><p>I have created this simple welcome page to demonstrate how to implement CSS variables in your code. Feel free to play around in the style.css file while you continue to read, as it will give you a better idea of how custom properties work in an application.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fawesome-matan-nk5o1o%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fawesome-matan-nk5o1o%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fnk5o1o%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/abdacf545854d06479dd921d07721552/href">https://medium.com/media/abdacf545854d06479dd921d07721552/href</a></iframe><h3>What are CSS variables?</h3><p>CSS variables are custom properties defined within a style sheet that can be cascaded down to child elements. Whenever a custom property is declared, you are actually making a <em>new </em>property that can be used within your application. Since this isn’t a standard property like “padding”, we need to let the browser know what the new property is. We can do this by declaring our new property within a selector:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d800634e7630e464abc911ed7f11aeb9/href">https://medium.com/media/d800634e7630e464abc911ed7f11aeb9/href</a></iframe><h3>Breaking it down.</h3><p>The first thing you might notice in the above example is the “:root” selector. Root is a pseudo-class selector that refers to the document’s root element (the &lt;html&gt; element in most cases). However, even though it is used to select the &lt;html&gt; element, root has a higher level of specificity. It is usually best practice to declare your custom properties within the :root pseudo-class as this will allow the variables to be accessed anywhere in the document.</p><p>Now that we know what the root selector is, let’s talk about the syntax being used. In order to declare your new custom variables, you will need to use what is called “custom property notation”. This notation consists of two dashes, the name of the variable, and the value of the variable (e.g., --name: value;).</p><p>Once we declare our variables in our root element, we can access them from anywhere in our document. Let’s take a look at the button selector to see how we can access these properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e1b2679aa4016f4bdf448153b11fda9/href">https://medium.com/media/5e1b2679aa4016f4bdf448153b11fda9/href</a></iframe><p>As shown above, we are accessing our --primary-clr and our --secondary-clr properties via the var() function within the linear-gradient() function. Since our custom properties were declared in our root element, we can access them in any of our selectors.</p><p>By declaring and calling our custom properties in this way, we can make global updates to these variables all from our root element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*z72LC93UAVM3KydXVxPRoA.gif" /></figure><p>By changing the --secondary-clr to blue, not only did we change the button color, but we also changed the border color as it was also utilizing the --secondary-clr property.</p><h3>BONUS: using the calc() function with CSS variables.</h3><p>If we don’t want our main border and our button to have the same border-radius, but we still want them to be proportional, we can use the calc() function. Lets take a look at the button selector again, specifically the border-radius property:</p><pre>border-radius: <strong>calc(</strong>var(--br)<strong> / 2 )</strong>;</pre><p>We can wrap the var() in a calc() function to perform a calculation on the custom property. In this case, we are dividing it by two. By adding this calculation, the main border will maintain a border-radius of 1rem while the button radius will be calculated to 0.5rem .</p><p><strong>TL;DR</strong></p><ol><li>CSS variables help to DRY up your CSS file and make it easier to update styles across the entire application.</li><li>CSS variables are usually declared within the :root pseudo-class selector for global access.</li><li>In order to let the browser know about our custom properties, we need to define them using custom property notation.</li><li>We can access these properties by using the var() function.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71a217bfc4f4" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/css-variables-71a217bfc4f4">CSS Variables</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reuse, reduce. . . useReducer?]]></title>
            <link>https://levelup.gitconnected.com/reuse-reduce-usereducer-5f11f2dd1e98?source=rss-64a7fe57b0d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f11f2dd1e98</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Sands]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 08:26:32 GMT</pubDate>
            <atom:updated>2022-03-19T21:13:20.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reuse, reduce. . . useReducer?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fxa6oJFh2lRD7EnAcZIcQg.png" /></figure><p>React is a wonderful tool that makes writing JavaScript applications much more accessible and cleaner. Anyone who has built both a vanilla JavaScript app and a React app will probably agree that the React app has definite advantages. Thankfully for us, hooks were introduced in React 16.8, which only further augments the library’s ease of use and elegance.</p><p>Some of the most commonly used hooks are useEffect and useState, both of which have a relatively shallow learning curve as they are pretty straightforward and employ simple syntax. However, in this blog post I want to discuss one of the more complex React hooks… useReducer. We will look at each of the steps required to implement this hook and discuss when it is most useful.</p><h3>What is useReducer?</h3><p>Before we jump into the code, let‘s talk about <em>what </em>useReducer actually is. The useReducer hook is very similar to the useState hook in that it is a tool used for managing state within an application. Essentially, it allows us to store state and setup rules for how we can manipulate that state within our application.</p><p>One of the most notable benefits of useReducer is that it allows for a much neater state management solution compared to useState, especially with more complex state. Additionally, as stated in the <a href="https://reactjs.org/docs/hooks-reference.html#usereducer">React documentation</a>, useReducer is preferred over useState in instances where the next state is calculated based on the previous state. This is because useReducer produces a more consistent and predictable state transition.</p><h3>The useReducer hook in action.</h3><p>As a basic example, I have created this app that utilizes useReducer to manage/manipulate the count state. Feel free to open the sandbox and mess around with the code as you continue to read.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fsuspicious-sunset-zwlny9%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fsuspicious-sunset-zwlny9%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fzwlny9%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cfe3abb227b93d1fa6a0054612a76e0/href">https://medium.com/media/5cfe3abb227b93d1fa6a0054612a76e0/href</a></iframe><p>This app has an initial value of 1 (stored as a piece of state) and several buttons that can manipulate that state. Let’s take a look at what we would need to do to implement this app using useReducer.</p><ol><li>When utilizing the useReducer hook, the first thing we need to do is import it from React. This will allow us to “hook into” the useReducer feature:</li></ol><pre>import React, { <strong>useReducer</strong>, useState } from “react”;</pre><p>2. Next, we will get our initial setup for useReducer using destructing assignment syntax, similar to useState. In our example, this reducer function will take in two parameters, i.e. a function and an initial value, and will return an array (the state and a dispatch function):</p><pre>const [state, dispatch] = useReducer(reducer, { count: 1 });</pre><p>3. Now we need to write our reducer function that we passed to useReducer. This function is going to take in state (current state) and an action. The action will be passed into the dispatch function mentioned above and will be set to whatever we call dispatch with (see 5):</p><pre>function reducer(state, action) {</pre><pre>}</pre><p>4. Once we have our reducer function, we can start building out our actions using a switch statement. Here we can create a case for each of the state manipulations we want to perform:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d366d814e79abdbfdbf0cb429a5d0cf7/href">https://medium.com/media/d366d814e79abdbfdbf0cb429a5d0cf7/href</a></iframe><p>5. Now that we have all of our different cases delineated in our reducer function, we can use our dispatch function to send an action to our reducer which will trigger the change in state associated with that action type. This is similar to the setter function in the useState hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50b2d3076c67ae35076ae6f486f1f2c8/href">https://medium.com/media/50b2d3076c67ae35076ae6f486f1f2c8/href</a></iframe><p>These functions can then be passed to the event listeners on our buttons in our JSX:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f2f5b73ed78a92a337eebaa83089636/href">https://medium.com/media/5f2f5b73ed78a92a337eebaa83089636/href</a></iframe><h3>Wait… a payload? Like in Crimson Skies?</h3><p>As you may have noticed in the above examples, one of the dispatch functions has a payload object passed into it. This is where you really start to see the magic of useReducer. Lets take another look at our switch statement, specifically the set-number case:</p><pre>case “set-number”:</pre><pre>return { count: (state.count = <strong>action.payload.value</strong>) };</pre><p>The purpose of this action is to set the counter to whatever value we enter in our form. However, in order for this action to know what that value is, we need to somehow let it know. We can do this by passing a payload into our dispatch function. The payload is an object that should contain all of the values needed to perform the specified action that we are calling.</p><pre>const handleSet = (e, num) =&gt; {</pre><pre>e.preventDefault();</pre><pre>dispatch({ type: “set-number”, <strong>payload: { value: num }</strong> });</pre><pre>setNum();</pre><pre>};</pre><p>As you can see above, we are passing a value of num (which is a piece of state that holds the value of the form on submit) to our “set-number” action so that it can set the counter to that number. In the switch statement we are able to get that value by drilling down into the object via dot notation.</p><h3>TL;DR</h3><ol><li>useReducer is a React hook that helps us manage and manipulate state.</li><li>useReducer is most beneficial with complex state or state that is calculated based on the previous state.</li><li>useReducer is set up using destructing assignment syntax. It is passed a reducer function and initial state and returns the state and a dispatch function.</li><li>The reducer function takes in two parameters, the current state and an action.</li><li>The reducer function contains all the actions for manipulating state.</li><li>The dispatch function sends an action to our reducer function which will trigger the change in state based on our predefined rules.</li><li>A payload is an object that is passed into a dispatch function and contains all of the values necessary to perform the action.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f11f2dd1e98" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/reuse-reduce-usereducer-5f11f2dd1e98">Reuse, reduce. . . useReducer?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming: a world of facts, not data.]]></title>
            <link>https://medium.com/@davidmaxsands/programming-a-world-of-facts-not-data-91da94817e17?source=rss-64a7fe57b0d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/91da94817e17</guid>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Sands]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 02:59:16 GMT</pubDate>
            <atom:updated>2022-02-22T02:59:16.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*oOfyHhgayxYuEQOnn17qwA.jpeg" /></figure><p>Most of the software engineers that I know are very mathematically minded individuals. I did not think I would be good at programming for a long time because I do not like mathematics, nor have I ever been good at it. However, I have always been incredibly interested in philosophy, logic, and language, which I have found very useful during my journey of becoming a software engineer.</p><p>Throughout my time at Flatiron, I have been amazed at the diverse backgrounds of my fellow students. Further, I have really enjoyed seeing the different thought processes everyone has when attempting to solve a problem. Given the general success of my peers and the diversity of thought in my cohort, I have become convinced that anyone can be a software engineer so long as they are willing to embrace how they learn and how they think.</p><h3>My noetic framework:</h3><p>The first programming language I ever fiddled around with was VBA as I tried to figure out how to build a macro that would reduce my workload. I quickly fell in love with programming and started writing macros for everything. I realized that computer programming logic is very similar to formal logic, which I was already very familiar with.</p><p>Due to my thinking being heavily influenced by philosophy, I want to try to articulate how I view programming from a high-level, non-technical perspective. The way that I would sum it up is as follows:</p><blockquote>A program is the actualized form of what was once pure creative potential — a world of facts created by the developer. When writing a program, one must construct specific facts and determine how those facts relate to one another and combine to actualize one’s intentions in digital space.</blockquote><h3>An explication of my view:</h3><p>One of the essential writings in 20th-century philosophy is the Tractatus Logico-Philisophicus, written by Ludwig Wittgenstein. The Tractatus is a book that explores the relationship between language and the world and the limits of language. I want to examine parts of the Tractatus and see how they might elucidate my way of thinking about programming. Let us take a look at the first premise and some of its sub-premises:</p><blockquote>1) The world is everything that is the case.</blockquote><blockquote>1.1) The world is the totality of facts, not of things.</blockquote><blockquote>1.11) The world is determined by the facts, and by these being <em>all</em> the facts.</blockquote><blockquote>1.12) For the totality of facts determines both what is the case, and also all that is not the case.</blockquote><blockquote>1.13) The facts in logical space are the world.</blockquote><p>Wittgenstein’s point in this first premise is that the world is comprised of facts rather than merely things.</p><p>As the world cannot be adequately described by merely listing all of the things contained in it, so a program cannot be adequately described by merely listing all of the data used in it.</p><h3>What is a ‘fact’ in programming?</h3><p><em>In my mind, a ‘fact’ in programming is how pieces of data stand in relation to one another — how data is logically acted upon within the program. In example 2 below, one of the facts about the program is that for every index of myArray, the program will console log some sentence x that includes the value of index i.</em></p><p>It would be incorrect, in my view, to say that a program is the totality of data as one could not ascertain a complete description of the program should he only have access to an exhaustive list of all the data used in it. Instead, a program is the totality of all the facts that hold in the program.</p><p>This is clearly the case as you could have several different programs that utilize the same data yet are wholly discrete.</p><p>Take, for example, the two programs listed below:</p><p><strong>Example 1</strong></p><pre>let myArray = [1, 2, 3, 4 ,5]<br></pre><pre>if(myArray.length &gt; 3) {</pre><pre>console.log(“Plenty of inventory”)</pre><pre>} else {</pre><pre>console.log(“Restock soon!”)</pre><pre>}</pre><pre>// expected output: “Plenty of inventory”</pre><p><strong>Example 2</strong></p><pre>let myArray = [1, 2, 3, 4 ,5]<br></pre><pre>for(let i = 0; i &lt; myArray.length; i ++) {</pre><pre>let money = myArray[i] &gt; 1 ? “dollars” : “dollar”</pre><pre>console.log(`I have ${myArray[i]} ${money}`)</pre><pre>}</pre><pre>// expected output:</pre><pre>“I have 1 dollar”</pre><pre>“I have 2 dollars”</pre><pre>“I have 3 dollars”</pre><pre>“I have 4 dollars”</pre><pre>“I have 5 dollars”</pre><p>Though both of these programs rely on the same data (namely, an array of 5 numbers in sequential order starting at 1) to generate their output, they function entirely differently because they contain different facts about the data.</p><h3>How do we decide what facts should hold in our program?</h3><p>The first step in writing a good program is imagination! What is imagination? Let us say our imagination is the sum total of all of our intents. For example, one might imagine an application for tracking inventory. This might be broken up into different intents, ex. display how much of x is in stock, place an order for more y if I have less than 3 in stock, etc. These intents can then be broken up in to facts about how these intents will be actualized using the available data.</p><p>For example: if I have some variable that holds the amount of z I have in stock (data), and I want to console log the current amount if it drops below 4 (intention), then I need to introduce some fact into my program that will actualize my intention based on my data:</p><pre>let zStock = 3<br></pre><pre>if (zStock &lt; 4) {</pre><pre>console.log(zStock)</pre><pre>}</pre><pre>// expected output: 3</pre><h3>In conclusion:</h3><p>From a high-level, non-technical perspective, I approach writing a program by imagining the program, breaking it up into different intents, analyzing the data I need, and determining which facts need to be in place to actualize my intents.</p><p>I hope that anyone reading this blog post will be encouraged to pursue software engineering regardless of their background. Anyone can leverage their experience to help frame the way they think about programming: if this is done well, the programs produced will be as unique as the people producing them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91da94817e17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>