<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bevin Duncan</title>
    <description>The latest articles on Forem by Bevin Duncan (@bevinduncan).</description>
    <link>https://forem.com/bevinduncan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F819585%2F3e17247b-9cde-4c89-972c-724f4ad17ef6.jpeg</url>
      <title>Forem: Bevin Duncan</title>
      <link>https://forem.com/bevinduncan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bevinduncan"/>
    <language>en</language>
    <item>
      <title>'Splain Like I'm Five: We Are Living in a Simulation</title>
      <dc:creator>Bevin Duncan</dc:creator>
      <pubDate>Wed, 20 Apr 2022 20:43:10 +0000</pubDate>
      <link>https://forem.com/bevinduncan/splain-like-im-five-we-are-living-in-a-simulation-gip</link>
      <guid>https://forem.com/bevinduncan/splain-like-im-five-we-are-living-in-a-simulation-gip</guid>
      <description>&lt;p&gt;Ever wonder if you are just an NPC in a videogame? You're not alone. The idea that the entire universe and everything in it could be a simulation has been the "shower thought" of humanity since philosophers of the ancient Greek, Aztec, and Mayan cultures, who mused about the possibility that our reality may be nothing more than a book, a painting, or simply a fever dream of the gods. &lt;/p&gt;

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

&lt;p&gt;The dawn of the digital age inspired contemporary philosopher &lt;a href="https://en.wikipedia.org/wiki/Nick_Bostrom" rel="noopener noreferrer"&gt;Nick Bostrom&lt;/a&gt; to postulate on our existence in a simulation as a very real possibility. Predicting that future humans will be capable of vast amounts of computational power (around the year 2050ish), Bostrom presented a trilemma called "&lt;a href="https://en.wikipedia.org/wiki/Simulation_hypothesis" rel="noopener noreferrer"&gt;the Simulation Argument&lt;/a&gt;". Bostrom's trilemma, presented in 2003, suggests that one of three possible arguments &lt;em&gt;must&lt;/em&gt; be true:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The fraction of human-level civilizations that reach a posthuman stage (that is, one capable of running high-fidelity ancestor simulations) is very close to zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The fraction of posthuman civilizations that are interested in running simulations of their evolutionary history, or variations thereof, is very close to zero&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The fraction of all people with our kind of experiences that are living in a simulation is very close to one.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bostrom's logic continues: "If (1) is true, then we will almost certainly go extinct before reaching posthumanity. If (2) is true, then there must be a strong convergence among the courses of advanced civilizations so that virtually none contains any individuals who desire to run ancestor-simulations and are free to do so. If (3) is true, then we almost certainly live in a simulation."&lt;/p&gt;

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

&lt;p&gt;So, what's the consensus? Depends on who you ask. Other proponents of the Simulation Hypothesis include Neil DeGrasse Tyson, Elon Musk, and Phillip K. Dick, all of whom have publicly expressed a belief in the possibility that we might be living in a simulation. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arguments For:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;True: A constant of any computational processing system is the "artifact", or the upper limit of its processing capability measured in terms of its processing speed. Also true: the differentiation of processing capability (or any additional hardware components) between programs is functionally irrelevant for any operations within the simulated reality of the program &lt;em&gt;except when it is discovered as the maximum container size for that program&lt;/em&gt;. In other words, the observer within the program (the program itself) has no frame for quantifying its own processing capability except when it presents itself as an upper limit (aka the "artifact"). &lt;/p&gt;

&lt;p&gt;It serves to follow that if we live in a simulation of some kind there would be an artifact of our simulation's processing capability. So what is the upper limit in our universal simulation? Can you guess it?&lt;/p&gt;

&lt;p&gt;That's right! &lt;strong&gt;It's the speed of light&lt;/strong&gt;.  If a maximum limit on the container size for a computer program is its processing speeds, the maximum limit of space on which one operation can be performed would appear in our universe as a maximum speed. We don’t know what hardware is running the simulation of our universe or what properties it has... but one thing we can say is that the memory container size for the variable "space" would be about 300,000 kilometers if the processor performed one operation per second. This observation serves as the primary evidence for our existence in a simulation, barring our ability to otherwise measure the hardware and properties of our simulation should we live in it. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Consciousness for who?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another argument for the possibility of simulated reality is a thought experiment about consciousness... the tldr version of this discussion from &lt;a href="https://www.scientificamerican.com/article/confirmed-we-live-in-a-simulation/" rel="noopener noreferrer"&gt;Fouad Khan's article&lt;/a&gt; in Scientific American is a counter-argument to those stating that the existence of human consciousness is proof that we DON'T live in a simulation. Khan posits that because A. we don't have a working theory for an evolutionary PURPOSE of human consciousness, the only purpose is to simply "experience" and B. that the "product" of experience that we are creating in the form of consciousness is not here as an evolutionary mechanism for our own use, then C. the product of experiential consciousness must be for the consumption of someone else. &lt;/p&gt;

&lt;p&gt;Kahn goes on to discuss how the consciousness of a Grand Theft Auto NPC becomes essentially an extension of our own consciousness in gameplay, because we are effectively experiencing and emoting through the NPC. While that might feel like an evidence argument for an NPC gaining consciousness, Kahn suggests that it's actually the inverse... a metaphor for how our consciousness is simply a projection of a greater simulant's consciousness in the same way the GTA NPC becomes sentient of ours by proxy. Try not to go too far down that logical rabbit hole. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arguments Against:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As with any currently unprovable scientific theory, there are going to be some naysayers. Physicist &lt;a href="https://en.wikipedia.org/wiki/Marcelo_Gleiser" rel="noopener noreferrer"&gt;Marcelo Gleiser's&lt;/a&gt; commentary on simulation theory posits that posthumans would be entirely too high-brow for such a pointless endeavor as ancestral simulation. "[Posthumans]...being so advanced they would have collected enough knowledge about their past to have little interest in this kind of simulation. ...They may have virtual-reality museums, where they could go and experience the lives and tribulations of their ancestors. But a full-fledged, resource-consuming simulation of an entire universe? Sounds like a colossal waste of time." &lt;/p&gt;

&lt;p&gt;Marcelo, honey... Have you ever met humans before? They'll literally spend hours trying to run a digital frog across a digital road. I'm sure prehistoric humans would have thought we'd find better use of our time with the kind of technological firepower we have at our finger tips these days, but they would be wrong. Assuming the priorities of people who don't exist yet might not be tenable scientific theory. ;) &lt;/p&gt;

&lt;p&gt;Or there's &lt;a href="https://en.wikipedia.org/wiki/Sabine_Hossenfelder" rel="noopener noreferrer"&gt;Sabine Hossenfelder&lt;/a&gt; who essentially states "We can't possibly test this theory, so why even bother thinking about it?", which, to me, is the scientist equivalent of taking your toys and going home because you don't have advanced enough tools to measure your hypothesis. Not very sciency, Sabine! &lt;/p&gt;

&lt;p&gt;And many more scholars who dismiss the hypothesis entirely by throwing around phrases like "merely philosophical", "unfalsifiable", or "inherently unscientific" (Unfalsifiable fact: Those scholars seem pretty unfun at parties). &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Alternate Theories&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're not ready to believe that the entire universe and everything in it is a vast computer simulation, there are other theories born of Bostrom's ideas that may be more palatable. For example, theoretical physicist &lt;a href="https://www.linkedin.com/in/lorenzo-pieri-a638b9a6/?originalSubdomain=uk" rel="noopener noreferrer"&gt;Lorenzo Pieri&lt;/a&gt;, deferring to occams razor, thinks the reality is more "likely to be one of such Brain-in-a-Vat or 'solo players', as it is much easier to simulate the inputs to the brain than the full-blown reality".&lt;/p&gt;

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

&lt;p&gt;Fair, but in the end does that distinction really matter? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is a compelling case to be made for at least entertaining the idea that we may be living in a simulation created by our post-human descendants. The alternative possibilities can only be that 1. Humanity goes extinct before reaching the technological capability to do so, or 2. that post humanity reaches the capability to, but not one singular posthuman would want to recreate our reality as an ancestral experiment. Proof that we may be living in a simulation can be found in studying the inherent qualities of computer systems, and if those qualities can be extrapolated to our reality. Which possibility would you prefer? True existence but inevitable extinction? Sim? Brain in a vat? The world is your oyster.  &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.scientificamerican.com/article/confirmed-we-live-in-a-simulation/" rel="noopener noreferrer"&gt;Confirmed! We Live in a Simulation&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/Simulation_hypothesis#:~:text=end%20the%20simulation.-,Universal%20Constants,through%20observation%20of%20universal%20constants." rel="noopener noreferrer"&gt;Simulation hypothesis&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/Nick_Bostrom" rel="noopener noreferrer"&gt;Nick Bostrom&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/Sabine_Hossenfelder" rel="noopener noreferrer"&gt;Sabine Hossenfelder&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.linkedin.com/in/lorenzo-pieri-a638b9a6/?originalSubdomain=uk" rel="noopener noreferrer"&gt;Lorenzo Peiri &lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>design</category>
      <category>watercooler</category>
      <category>philosophy</category>
    </item>
    <item>
      <title>'Splain Like I'm Five: Model-View-Controller (MVC)</title>
      <dc:creator>Bevin Duncan</dc:creator>
      <pubDate>Wed, 06 Apr 2022 21:05:28 +0000</pubDate>
      <link>https://forem.com/bevinduncan/splain-like-im-five-model-view-controller-mvc-bff</link>
      <guid>https://forem.com/bevinduncan/splain-like-im-five-model-view-controller-mvc-bff</guid>
      <description>&lt;p&gt;The Model-View-Controller(MVC) is a popular software programming architectural style meant to efficiently implement &lt;a href="https://www.computerhope.com/jargon/g/gui.htm"&gt;graphical user interfaces&lt;/a&gt; on mobile and web applications. MVC describes a relationship between the distinct purposes of your code resulting easier readability and a "separation of concerns" when designing the flow of your code. The idea is that each section of your code has a specific objective and the MVC model makes it easy to keep each of those objectives focused on their respective jobs. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;br&gt;
The model portion of your code can be described as the raw ingredients of your app. This is where your database is kept, and where essential components of your app are defined. Models are where you structure what your app is about, and how it's expressed on a foundational level. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;br&gt;
The view portion of your code can be described as the client-focused side of your app. The view displays the information organized through your models, and creates an environment where the user can see and interact with that information. View code is generally design-oriented and structured around a front-end framework of displaying data. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller&lt;/strong&gt;&lt;br&gt;
The controller portion of your code is the go-between the Model core and the View shell of your app. It receives user input, decides what to do with that input based off of available model data, and decides what to return the user display. Controller code is generally made up of action functions that make decisions about what model data is displayed to the user while interacting with the view code to display a user request. &lt;/p&gt;

&lt;p&gt;All of these elements work together in a cycle: A request made by the user comes to the controller, the controller calls/ edits data relevant to the request from the model, then pushes the data to a template in the view. Once complete, the request is handed back to the application server as rendered HTML. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d9VwvjWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm6280rrx2hmcp0crmjx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d9VwvjWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm6280rrx2hmcp0crmjx.jpeg" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;History&lt;/strong&gt;&lt;br&gt;
The MVC model dates back to the late 1970's, when programmer Trygve Reenskaug imagined MVC while working on the Smalltalk-79 project at the Xerox Palo Alto Research Center (PARC). His goal was to create a pattern most efficient for when users interact with a large, complex data set. His design initially had four parts: Model, View, Thing, and Editor. Model and View functioned as described above. Thing was a variant of controller, and Edit was a specialized kind of Controller that is created by a particular view and used to modify that View. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1DC7KJFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3htpvf09a1j4g5u8t469.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1DC7KJFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3htpvf09a1j4g5u8t469.png" alt="Image description" width="850" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reenskaug's MVTE model gave rise to the simplified MVC model, which three decades years later was the inspiration for developing the Ruby on Rails framework. The Django framework (developed for Python) put forward a similar design, the "Model Template View (MVT)" wherein the view component becomes a controller of sorts, and the template becomes the GU interface. Both Rails and Django debuted with a strong emphasis on rapid deployment, which increased MVC's popularity in the mainstream of software engineering thus making MVC an industry-standard to this day. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Similar Models&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are some variants on the theme of MVC that have evolved since Reenskaug's original configuration:&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Hierarchal Model View Controller&lt;/u&gt;&lt;br&gt;
 The HMVC variant of the MVC configuration is essentially a scalable version of the same MVC functioning. HMVC creates hierarchy of parent/child MVC layers. Each MVC subgroup (also known as a triad) functions independently from one another, but can communicate via their controllers. This is particularly useful for applications with a large variety of servers, platforms and protocols, and that have a scaling dataset.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x1si0qS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0squ9axhekrbyzb2o5ax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x1si0qS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0squ9axhekrbyzb2o5ax.png" alt="Image description" width="540" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Model View Adapter &lt;/u&gt;&lt;br&gt;
The MVA structure is ideal for complex computer applications that present large amounts of data to users. In this scenario, you may wish to separate data and UI concerns so that changes to the user interface will not affect data handling or data can be reorganized without changing the user interface. MVA is different from MVC by arranging model, adapter (a mediating controller) and view linearly without any connections whatsoever directly between model and view. One benefit of this structure is that multiple adapters may be created to change the way one view presents data for a given model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9XblaC5w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sl91hf1p38tvoxx5esox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9XblaC5w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sl91hf1p38tvoxx5esox.png" alt="Image description" width="681" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many more niche software design configurations out there, too extensive for the scope of this blog! &lt;/p&gt;

&lt;p&gt;MVC and its variants are the industry standard for a user-interface-focused architectural design in software engineering. Separation of concerns, explicit purpose of code, and defining specific roles for sections of code create an efficient and powerful model for an effective, client-minded website. MVC's logic can be traced back to the early days of computer programming, which speaks to its timeless usability for software engineers. Variants on the theme can be used depending on the depth of data set and/or the scalability needs of your website. No need to reinvent the wheel with MVC! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://towardsdatascience.com/everything-you-need-to-know-about-mvc-architecture-3c827930b4c1"&gt;Everything you need to know about MVC architecture&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Hierarchical_model%E2%80%93view%E2%80%93controller"&gt;Hierarchical Model View Controller&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.researchgate.net/figure/Schematics-of-Reenskaugs-MVC-paradigm-according-to-his-descriptions-in-Reenskaug-1979b_fig31_339845169"&gt;Schematics of Reenskaug's MVC paradigm according to his descriptions in Reenskaug (1979b)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.codecademy.com/article/mvc"&gt;MVC: Model, View, Controller&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93adapter"&gt;Model–view–adapter&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>'Splain Like I'm Five: Ruby REPLs and Pry</title>
      <dc:creator>Bevin Duncan</dc:creator>
      <pubDate>Tue, 22 Mar 2022 04:00:22 +0000</pubDate>
      <link>https://forem.com/bevinduncan/splain-like-im-five-ruby-repls-and-pry-1347</link>
      <guid>https://forem.com/bevinduncan/splain-like-im-five-ruby-repls-and-pry-1347</guid>
      <description>&lt;p&gt;Welcome to the Back-End! If you're reading this Ruby blog, you've likely made your way here through front-end web development.  &lt;/p&gt;

&lt;p&gt;"Ok, front end was cool--I had a nifty browser console in which to test my code. Code goes in, changes on the browser come out! Easy-peasy!" -You, probably.&lt;/p&gt;

&lt;p&gt;Well, now you're in back-end. Sunlight in the form of a browser console doesn't reach back here. You're now working in terms of creating and passing data to and between databases, and none of those tasks require a browser to write or operate. So how do we test our code?? &lt;/p&gt;

&lt;p&gt;The simple answer: REPLs -- or Read, Evaluate, Print, Loop programming environments. REPLs are an interactive terminal shell which takes a user's input, evaluates it, and returns the result to the user. &lt;em&gt;REPLs are a back-end programmer's most-used and most powerful tool for debugging and modifying code in real-time.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ruby's REPLs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ruby installs with its own built-in REPL called IRB ("Interactive Ruby"). You can enter the IRB environment by simply typing "irb" in your terminal. You're now in a "sandbox" programming environment where you can test your code functionality. The unfortunate thing about IRB is that it's not connected with your actual program in any way-- it simply tests the code, then you have to exit IRB and retype the correct code in to your text editor or through terminal in order to add it to your program. In other words, it's a bare-bones testing REPL that has no interactivity to your program. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wyLA9K0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th1slbe5c3l4l5mjmakd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wyLA9K0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th1slbe5c3l4l5mjmakd.png" alt="Image description" width="820" height="336"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;PRY&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PRY is one of many third-party REPLs in the form of a installable Ruby gem. It, too, creates an interactive terminal programming environment with which to test Ruby code, only with tons of extra perks. The two main perks of Pry that IRB doesn't have are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It can loop through code and pause at intervals of user-specified subsections of code. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interact with and test-edit your code without ever leaving the Pry programming environment. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;"Runtime Invocation" with Binding.pry&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Pry is, at its core, a powerful debugging tool. It utilizes a Ruby class, Binding, which captures the objects-- specified by its placement-- for use outside of the program (aka in the REPL environment). You can then "pry" in to that specific bit of code and inspect it. It works by adding the line "binding.pry" in to any (or multiple) parts of your code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hj6n0lGW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0zeq7g82jb078pmh76a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hj6n0lGW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0zeq7g82jb078pmh76a.png" alt="Image description" width="880" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the line is &lt;em&gt;invoked&lt;/em&gt; during runtime, it will freeze your program and open a REPL environment so you may inspect that specific line of code within the scope it was called. If you, for example, place a binding.pry in the middle of a method, when the program runs your code it freezes upon the binding call and enters a REPL so you can explore the data within that method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--07woeLFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzg43n7x7hn9sg9gko7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--07woeLFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzg43n7x7hn9sg9gko7g.png" alt="Image description" width="880" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Command Shell Integration&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Pry commands can be forwarded to the command line with the "." preface. This means you can navigate your file system, launch editors, run git commands, and utilize &lt;a href="https://www.rubyguides.com/2019/02/ruby-rake/"&gt;Rake &lt;/a&gt; directly from Pry!  &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Other features of Pry:&lt;/u&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Syntax highlighting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Autocompletion (IRB has some, but very basic)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Introspection commands (list methods, variables, constants, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Documentation Browsing using pry-doc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And much more! Pry is fully customizable, so check out a full list of pry plugins &lt;a href="https://github.com/pry/pry/wiki/Customization-and-configuration"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You Didn't Hear It From Me&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Additionally, you can check out &lt;a href="https://www.youtube.com/watch?v=4OinPTpt3I8"&gt;this video&lt;/a&gt; about some Pry hacks that are, on paper, not considered good practice... For example, editing your Ruby classes in-line using Pry. Yes, it's that powerful! But doing so does verge on the frowned-upon practice of "Monkey Patching" which you can read more about &lt;a href="https://www.geeksforgeeks.org/monkey-patching-in-ruby/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I will say, taking 10 minutes to dive in to multi-line editing with Pry helped me understand how Pry works in the grand scheme of the command line and the program as a whole, so I found it helpful for context. You didn't hear it from me, though... &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Many Other Ruby REPLs and More:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Outside of the two most used Ruby REPLs--IRB and Pry-- there are countless other Ruby REPLs on the market, all with their own functional focus. This is probably because you can actually &lt;em&gt;&lt;a href="https://cdragon.medium.com/make-your-own-ruby-repl-from-scratch-2b0677b4b291"&gt;make your own Ruby REPL&lt;/a&gt;&lt;/em&gt;! Many folks have, and left them available on codebases like GitHub for public use.&lt;/p&gt;

&lt;p&gt;Pry, though, remains the industry standard for debugging Ruby code in real-time. Pry is the best because you can freeze your code and debug at intervals of your choosing, interact with your code inside the REPL, and it has all kinds of other handy features and plug-ins to customize for your use! For a quick tutorial on how to install and use Pry for yourself, check out &lt;a href="https://www.sitepoint.com/pry-a-simple-start/#:~:text=To%20start%20pry%2C%20simply%20type,the%20Rails%20console%20with%20Pry."&gt;this article&lt;/a&gt;! &lt;/p&gt;

&lt;p&gt;Give it a pry! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.rubyguides.com/2018/12/what-is-a-repl-in-ruby/"&gt;What is a REPL in Ruby? (IRB, Pry, and More...)&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://learn.co/lessons/debugging-with-pry"&gt;Debugging with Pry &lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.rubydoc.info/gems/pry#edit-methods"&gt;Ruby Docs: Pry&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.youtube.com/watch?v=4OinPTpt3I8"&gt;Pry Irresponsibly - Things You Shouldn't Do But We Will Anyway&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.geeksforgeeks.org/monkey-patching-in-ruby/"&gt;Monkey Patching in Ruby&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.rubyguides.com/2019/02/ruby-rake/"&gt;What is Rake in Ruby &amp;amp; How to Use it&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://cdragon.medium.com/make-your-own-ruby-repl-from-scratch-2b0677b4b291"&gt;Make your own ruby REPL from scratch&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.sitepoint.com/pry-a-simple-start/#:~:text=To%20start%20pry%2C%20simply%20type,the%20Rails%20console%20with%20Pry."&gt;Pry: A Simple Start&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>ruby</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>'Splain Like I'm Five: React Props and Components</title>
      <dc:creator>Bevin Duncan</dc:creator>
      <pubDate>Wed, 09 Mar 2022 22:06:13 +0000</pubDate>
      <link>https://forem.com/bevinduncan/splain-like-im-five-react-props-and-components-53gk</link>
      <guid>https://forem.com/bevinduncan/splain-like-im-five-react-props-and-components-53gk</guid>
      <description>&lt;p&gt;Among the many differences between React.js and Vanilla JavaScript, one of the most important is the interplay between &lt;a href="https://www.w3schools.com/react/react_props.asp" rel="noopener noreferrer"&gt;Props&lt;/a&gt; and &lt;a href="https://dev.tourl"&gt;Components&lt;/a&gt; in React. The beauty of React is that your code is kept organized by compiling each individual subsection of your web page &lt;em&gt;modularly&lt;/em&gt; -- in its own receptacle of code -- that is then referenced in parent receptacles. The component/props dynamic makes it easy to pass data and page functionality between subsections of your page. The benefits of modular coding via components and props include keeping code clean and organized, easier debugging, easier navigation, and a more manageable variable scope. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Functional Components&lt;/em&gt; can be equated to a vanilla JavaScript function that returns &lt;a href="https://reactjs.org/docs/introducing-jsx.html" rel="noopener noreferrer"&gt;JSX&lt;/a&gt;. A component is essentially a modularized function that returns a subsection of your webpage-- including the data you wish to display-- written in HTML. Components can drafted in to individual .js files, which are imported into sibling or parent Component.js files for rendering. All lower-level components are &lt;em&gt;then&lt;/em&gt; referenced by your granddaddy index.js file to tie the components of your page together. &lt;/p&gt;

&lt;p&gt;For example, you may have a "Cats.js" component on which you render your cat webpage Home Page functionality. You would then import your Cats.js component to its parent component (usually an App.js file) so it can exist with the rest of the components of your webpage. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Props&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Props can be equated to function arguments in Vanilla Javascript passed as &lt;a href="https://dev.tourl"&gt;HTML attributes&lt;/a&gt;. Props are essentially a representative bit of variable data that can be imported and passed into child components as parameters. Props can be any kind of variable data type, though any prop that is not a string (numbers, booleans, objects, etc...) should be referenced in components with {curly brackets}. Prop object key value pairs are referenced with dot notation. One can also assign a "default prop" in the event that you need a default value to display in the absence of any assigned values. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Prop Destructuring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes we will want to pass an object as a prop. React has a lovely way of "destructuring" the prop object in our component so we may more easily use the key values of the object! Destructuring works by passing the props object imported in to the parent component and assigning them to variables with the same names of the object keys in the argument of the child component. See here: &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Prop Drilling&lt;/strong&gt;&lt;br&gt;
Sometimes we need to send props through multiple layers of nested components to reach a base child component that needs to use the prop. This is referred to as "prop drilling". Prop drilling has some benefits, but is by and large is frowned upon as a practice. The benefits mean that there is a way to statically review the flow of the code without having to render any extra functioning or potentially break your code with complicated modifications. The main reasons prop drilling is so frowned upon include: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It often results in refactoring the shape of some data (ie, an Object: {catList: {name: 'Kitten Face'}}  turns in to {Catlist: {firstName: 'Kitten', lastName: 'Face'}}) down the line. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can result in over-forwarding props, or passing more props than necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conversely, it can result in under-forwarding props by way of abusing defaultProps-- Often times this results in not being made aware of missing props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Renaming props halfway through (ie  renders ). This evolution can make keeping track of the same prop differently named in another component tricky.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Component Lifecycle&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Initialization&lt;/u&gt;: Props and/or State are assigned (State is an entire can of worms too big for the scope of this blog post, but you can read more about from how it works my colleague, Hannah Glazier, &lt;em&gt;&lt;a href="https://dev.to/hannahglazier/the-usestate-hook-in-react-id4"&gt;here&lt;/a&gt;&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Mounting&lt;/u&gt;:Then the component is "mounted" (created and then inserted in) to the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;DOM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Updating&lt;/u&gt;: The component then undergoes the updating phase as soon as and every time props or state change. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Unmounting&lt;/u&gt;: The component unmounts from the DOM at the end of the cycle. &lt;/p&gt;

&lt;p&gt;Here is a diagram of some of the possible rendering calls that can be made during the component lifecycle depending on the objective of your components:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Components and props are integral elements to the functionality of a React web page, and to cover their different use cases would make this an endless blog post. The basic points are: Components make your code modular, so they are easier to read, easier to debug, and easier to pass through your web application. Props are a way to pass all types of data through the component hierarchy with agility and ease, especially through methods like destructuring. Some prop methods, like prop drilling, can be helpful in some situations and hurtful in others. Components and their props are integral to the outcome of the component lifecycle, and therefore the functionality of your web page! As a software developer, I find using the component/prop system quite elegant in practice hand fun to boot! Happy modularizing!  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.w3schools.com/react/react_props.asp" rel="noopener noreferrer"&gt;React Props&lt;/a&gt;&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.w3schools.com/react/react_components.asp" rel="noopener noreferrer"&gt;React Components&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://dev.to/hannahglazier/the-usestate-hook-in-react-id4"&gt;React's Use State Hook by Hannah Glazier&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.freecodecamp.org/news/how-to-understand-a-components-lifecycle-methods-in-reactjs-e1a609840630/" rel="noopener noreferrer"&gt;Component Lifecycle&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.freecodecamp.org/news/how-to-understand-a-components-lifecycle-methods-in-reactjs-e1a609840630/" rel="noopener noreferrer"&gt;How to understand a component’s lifecycle methods in ReactJS&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://reactjs.org/docs/introducing-jsx.html" rel="noopener noreferrer"&gt;Intro to JSX&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://www.w3schools.com/html/html_attributes.asp" rel="noopener noreferrer"&gt;HTML Attributes&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;Introduction to the DOM&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>'Splain Like I'm Five: JavaScript Events</title>
      <dc:creator>Bevin Duncan</dc:creator>
      <pubDate>Wed, 23 Feb 2022 22:03:42 +0000</pubDate>
      <link>https://forem.com/bevinduncan/splain-like-im-five-javascript-events-3l8b</link>
      <guid>https://forem.com/bevinduncan/splain-like-im-five-javascript-events-3l8b</guid>
      <description>&lt;p&gt;It is safe to say that the heart and soul of any effective web page is the ability for a user to functionally interact with the contents of that web page. Being able to click on, scroll through, or input information through a web browser is fundamental to the usability of most modern-day web applications--from social media, to banking, to learning software engineering through an online bootcamp. But what exactly is going on under the hood when you click that like button, anyway? The answer to that question is: &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events" rel="noopener noreferrer"&gt;A JAVASCRIPT EVENT&lt;/a&gt;! &lt;/p&gt;

&lt;p&gt;Javascript events describe a multi-process coding cycle that involves three major components: HTML Elements, Event Listeners, and Event Handling Functions. Let's dig in to how these three components work together to create an enriching, interactive experience for your user!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML Elements and the DOM&lt;/strong&gt;&lt;br&gt;
As you may know, the elements you see on a web browser are structured by HTML. Each &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;HTML element&lt;/a&gt; has a specific purpose in the HTML document, and therefore the structure of the web browser. For example, if you'd like to add a "like" button to your page you would first craft its structure in the HTML document as an element. However, these HTML elements are static unless we use javaScript to animate them, which are then rendered in the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model" rel="noopener noreferrer"&gt;DOM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Javascript Event Listeners&lt;/strong&gt;&lt;br&gt;
Unless you use javaScript to tell the browser what to do with that "like' button once its clicked, that like button will be nothing more than a fancy icon decorating your browser with no real functionality. So how do we create a line of communication to the HTML document to animate our like button? Luckily, javaScript has a built-in system for "listening" for events! Simply put, an "event listener" is a built-in javaScript command that links an HTML element to the event you would like to have happen. This is done in three steps: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"Grabbing" the HTML element from the document with a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="noopener noreferrer"&gt;query selector&lt;/a&gt; and attaching it to a constant variable.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const likeButton = document.querySelector("button"); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Linking that constant variable to the event you would like to enact using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener" rel="noopener noreferrer"&gt;.addEventListener()&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;likeButton.addEventListener("click", );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Referencing the "Event Handler" function in the event listener that will ultimately enact the event we want once it's called.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;likeButton.addEventListener("click", handleLikeButton);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Event Handlers&lt;/strong&gt;&lt;br&gt;
Hold up, we referenced an event handling function with the event listener we just learned about! What's going on there?? The "event handler" is an important piece of this puzzle, because we need to tell our program what to do with the 'click' we just assigned in our listener using a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions" rel="noopener noreferrer"&gt;function&lt;/a&gt;. An event handler is a callback function that indicates to the listener what the outcome of the event will be. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleLikeButton(){
  likeNumber.textContent = ++likes
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above case, we've created a function that incrementally (&lt;em&gt;++likes&lt;/em&gt;) increases the displayed (&lt;em&gt;text content&lt;/em&gt;) number of likes (&lt;em&gt;likesNumber&lt;/em&gt;) on our page! The event handler dictates the outcome of the event. The handler is called by the event listener--which links it to the 'click'--and increases the likes once the click is initiated.   &lt;/p&gt;

&lt;p&gt;Here's visual of how the components of the javaScript event cycle work together: &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Types of Events&lt;/strong&gt;&lt;br&gt;
As you can imagine, click events are one of many, MANY javaScript events that can be applied to a webpage. Other common events include: &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Mouse events&lt;/u&gt;: Any interaction having to do with mousing over, in/ out of, or clicking on an element.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Keyboard Events&lt;/u&gt;: Any interaction having to do with key presses of any kind.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Submit Events&lt;/u&gt;: Events pertaining to inputting and submitting values to forms. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Screen Sizing Events&lt;/u&gt;: Events that occur when resizing or scrolling through the browser window. &lt;/p&gt;

&lt;p&gt;And many &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events#standard_events" rel="noopener noreferrer"&gt;more.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event Objects&lt;/strong&gt;&lt;br&gt;
Event objects are a way for you to call on the event in a handler as a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Parameter" rel="noopener noreferrer"&gt;parameter&lt;/a&gt;. Common usage for this would be to change specific properties of the event target (In our case, the LikeButton variable we grabbed from the HTML sheet):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleLikeButton(e){
   console.log('e: ', e.target);
    } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The target property of the event object is a reference to the element the event occurred upon. So, in the above example, we are logging the content of our like button to the console. Other uses for this method would be to modify the qualities of the event target (like the color or text content), or to link the event target to a database object (and many more).  Event objects can be labeled in any way, but conventionally they're labeled "e", "evt", or "event" because they're short and easy to remember, plus it's always good to be consistent in shared code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bubbling and Capturing&lt;/strong&gt;&lt;br&gt;
Sometimes you'll want to link an event listener to a parent node that oversees multiple HTML elements with their own events. This can be super handy, like when we have lots of buttons on one page nested under the same parent node and only want to take the time to write out one event listener, or to link multiple events under the same parent node. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Capturing"&lt;/em&gt; is a phase in the DOM's order of operations where the browser reads our code from the outermost layered node in the DOM tree, to the innermost. In this phase, the browser is "listening" for events starting from the top down.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Bubbling"&lt;/em&gt; is essentially the opposite of the capturing phase, and starts &lt;em&gt;at the time the event is triggered&lt;/em&gt;. The inner-most nested node is triggered first, then its parent node, grand parent node, and so on all the way back to the top of the document. If events are linked to these respective nodes the events will be triggered in order from the innermost nested event out to the top. It's important to note that modern browsers handle events in the bubbling phase by default. &lt;/p&gt;

&lt;p&gt;Here is a diagram of the Capture/Bubble cycle: &lt;/p&gt;

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

&lt;p&gt;You can read more about the Capture/Bubble cycle &lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop Propagation&lt;/strong&gt;&lt;br&gt;
 There are times where bubbling can be detrimental to to the functionality of your page. One scenario is when two events firing in tandem with each other negatively effect the outcome of one or all of the events. Luckily, there's a way to "stop the propagation" of the bubbling phase! It's called, naturally, "&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation" rel="noopener noreferrer"&gt;.stopPropagation()&lt;/a&gt;". &lt;/p&gt;

&lt;p&gt;Best practice is to call .stopPropagation() on the event object in your event handler, which will stop the bubbling phase at the time the event is called. When invoked on a handler's event object, .stopPropagation() makes it so that first handler is run but the event doesn't bubble any further up the chain. &lt;/p&gt;

&lt;p&gt;An example of .stopPropagation() syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;likesBttn.addEventListener("click", function (event) {
    event.stopPropagation();
    likeNumber.textContent = ++likes

  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Prevent Default&lt;/strong&gt;&lt;br&gt;
A default action of a submit form event is to reload the browser. In some cases, we want to prevent that default action. Luckily, javaScript has a built-in command to deal with this issue: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault" rel="noopener noreferrer"&gt;.preventDefault()&lt;/a&gt;. Having this command included in your event handler function creates a catch-all scenario for those circumstances when you don't want the browser to automatically refresh the form.&lt;/p&gt;

&lt;p&gt;Here's an example of .preventDefault() syntax in the context of a form event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleReviews(e){
  e.preventDefault()
  let reviewLi = document.createElement('li')
  reviewLi.textContent = `${reviewInput.value}

  e.target.reset()
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we've created an event handler that handles a form for users to add new reviews to our page! The event object is referenced, then we use &lt;a href="https://codeburst.io/javascript-quickie-dot-notation-vs-bracket-notation-333641c0f781" rel="noopener noreferrer"&gt;dot notation &lt;/a&gt; to add the preventDefault() command to it. The rest of the code displayed here allows us to add a new HTML element with our users new review to the DOM, and reset our review form input fields for the next user! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Events are hugely important to creating an interactive, functional web page. The options for how to deploy events and their handlers are endless, and there are many "best practices" to look for when planning your event cycles, depending on what events you'll be including on your page. Events exist in many coding languages and javaScript is only one of many iterations of this process in the field! The more you learn about events--and there is much, MUCH more to learn!-- the more empowered you'll be to make effective, functional, interactive web applications to attract users. &lt;/p&gt;

&lt;p&gt;Happy eventing! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events#standard_events" rel="noopener noreferrer"&gt;&lt;em&gt;MDN: Event reference&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events" rel="noopener noreferrer"&gt;MDN: Introduction to Events&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://javascript.plainenglish.io/the-3-phases-of-event-propagation-explained-f76348b5343f" rel="noopener noreferrer"&gt;The 3 Phases of Event Propagation in JavaScript Explained&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://haruncsebd.wordpress.com/2011/10/01/what-is-event-capturing-and-event-bubbling/" rel="noopener noreferrer"&gt;What is event capturing and event bubbling&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation" rel="noopener noreferrer"&gt;MDN: Stop Propagation&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault" rel="noopener noreferrer"&gt;MDN: Event Prevent Default&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="_https://codeburst.io/javascript-quickie-dot-notation-vs-bracket-notation-333641c0f781"&gt;JavaScript Quickie— Dot Notation vs. Bracket Notation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;MDN: HTML Elements &lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="noopener noreferrer"&gt;MDN: Query Selector&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener" rel="noopener noreferrer"&gt;MDN: Add Event Listener&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions" rel="noopener noreferrer"&gt;MDN: Functions&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Parameter" rel="noopener noreferrer"&gt;MDN: Parameters&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
