<?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>DEV Community: Nyior Clement Jr.</title>
    <description>The latest articles on DEV Community by Nyior Clement Jr. (@nyior).</description>
    <link>https://dev.to/nyior</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%2F107825%2F7e71e65f-bf90-4043-bc2a-342ecd55eca3.jpeg</url>
      <title>DEV Community: Nyior Clement Jr.</title>
      <link>https://dev.to/nyior</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nyior"/>
    <language>en</language>
    <item>
      <title>Dynamic and Asynchronous Vue Components: The What &amp; How</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Sun, 10 Sep 2023 18:49:39 +0000</pubDate>
      <link>https://dev.to/nyior/dynamic-and-asynchronous-vue-components-the-what-how-44em</link>
      <guid>https://dev.to/nyior/dynamic-and-asynchronous-vue-components-the-what-how-44em</guid>
      <description>&lt;p&gt;It’s asking the right questions that count, they say. So let’s exploit that ancient wisdom and kick things off here with the questions that matter :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UbqC5MRW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g89b4h4l7pmp9n21jmf5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UbqC5MRW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g89b4h4l7pmp9n21jmf5.png" alt="Vue tabs" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows a user interface with two tabs: &lt;code&gt;JobDescription&lt;/code&gt; and &lt;code&gt;ApplicationForm&lt;/code&gt;. We want to explore how to create tabbed interfaces like this one using Vue. &lt;/p&gt;

&lt;p&gt;It's easy to think it's simple – just create &lt;code&gt;&amp;lt;JobDescription /&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;ApplicationForm /&amp;gt;&lt;/code&gt; components and render them to the DOM, as shown in the snippet below. But is it really that straightforward?"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;JobDescription&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ApplicationForm&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that's not quite right. If we render our components that way, both of them would appear at the same time. What we need is to have a single component appear dynamically based on the selected tab.&lt;/p&gt;

&lt;p&gt;There's some dynamic behaviour we need: while we anticipate the user's selection of one of two components, the precise choice remains uncertain. What we want is a placeholder, a receptacle if you will, where Vue could insert components based on the selected tab in real-time. &lt;/p&gt;

&lt;p&gt;Using vue-router here is not ideal. We do not want our URL changing when users switch between tabs. They are tabs, not pages.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;So we pose the question, how can this type of dynamic behaviour be achieved in Vue?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I will show you how, but first, let's take a quick detour...&lt;/p&gt;

&lt;p&gt;Suppose we've managed to learn how to dynamically render components in Vue. With this in mind, let’s take our analysis a step further. You may have already observed that the 'ApplicationForm' tab includes a basic job application form with a field for entering the full names of applicants. &lt;/p&gt;

&lt;p&gt;Typically, if you enter your name in the 'ApplicationForm' tab's input field, then switch to the 'JobDescription' tab, and come back to your form, you'll notice that what you typed in the input field is gone. The image below illustrates this behavior:"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V1tbiHxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v16gotahwbn0mcowbtpf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V1tbiHxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v16gotahwbn0mcowbtpf.gif" alt="Dynamic components without keep-alive" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you think about how Vue renders components, you’d see that this type of behaviour is expected. Every time we switch from a component, Vue un-mounts that component. &lt;/p&gt;

&lt;p&gt;In our scenario, when transitioning from 'ApplicationForm' to 'JobDescription,' Vue un-mounts the former from the DOM and then mounts the latter. Any input in the field is lost because Vue needs to completely re-render the 'ApplicationForm' component when we switch back to it.&lt;/p&gt;

&lt;p&gt;Could we potentially retain the state of a tab we've just left, you may ask? After all, we wouldn't want our users to have to re-enter their information from the beginning whenever they switch to a different tab, would we?&lt;/p&gt;

&lt;p&gt;This brings us to our second question: &lt;em&gt;How can we persist the state of components in our tabs scenario?&lt;/em&gt;  What we want is an effect like the one shown in the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OfyYB7C6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uu9dotb61qmxna4yyj74.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OfyYB7C6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uu9dotb61qmxna4yyj74.gif" alt="Dynamic components with keep-alive" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, let’s assume we’ve somehow figured out how to persist the state of our components, and in our quest for perfection, we want to do one more thing: some performance optimization. &lt;/p&gt;

&lt;p&gt;You see, even though Vue dynamically renders our components one at a time, depending on what tab is selected, whenever that page is visited, Vue would load the code for all the tabs on that page. Imagine if we had thousands of tabs we could switch between - not ideal, but a little bit of exaggeration could help here. &lt;/p&gt;

&lt;p&gt;The first time that page is visited the code for all the thousands of tabs would be loaded from the server. I put this to you: Especially since Vue would only be rendering one tab at a time to the DOM, is grabbing the code for all the tab components upfront really necessary? What potential performance drawbacks might arise from this approach? Take a moment and reflect - or maybe you don't need to.&lt;/p&gt;

&lt;p&gt;If your spidey-sense is already telling you there’s got to be a better way, then you’re absolutely right. What we could do is have Vue load the code for a tab only when it’s selected. So each time the page is visited only the code for the default tab is loaded. For other tabs, they’d only be loaded when visited. If you want to associate this technique with a name, just call it &lt;em&gt;lazy loading.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This brings us to our third and final question: &lt;em&gt;How can we implement lazy component loading in Vue?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the subsequent sections, this piece would demonstrate how you could address the first two questions we raised with &lt;strong&gt;Vue Dynamic Components&lt;/strong&gt; and how you could implement lazy loading with &lt;strong&gt;Asynchronous Components.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Components
&lt;/h2&gt;

&lt;p&gt;As mentioned just now, we could implement tabbed interfaces where users could switch between tabs and have each tab persist its state with dynamic components. &lt;/p&gt;

&lt;p&gt;Normally, to add a component to a template, we’d add it by name to the template like in the snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ApplicationForm&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That way, we are statically adding our component to that template and by extension statically rendering it to the DOM. What makes a component in Vue dynamic is the fact that instead of statically adding the component to the template we’d have a placeholder of some sort where Vue could insert one of many components after some action happens. A placeholder?&lt;/p&gt;

&lt;p&gt;Well yes. Vue has an inbuilt &lt;code&gt;&amp;lt;component&amp;gt;&lt;/code&gt; element with the special &lt;code&gt;is&lt;/code&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;component&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;is&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"currentTab"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;component&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;component&amp;gt;&lt;/code&gt; element in the above is the placeholder, and the component rendered in that frame would change once the component &lt;code&gt;CurrentTab&lt;/code&gt; is tied to changes. To make this work with our tabs scenario, you’d need to have a list of components defined in the script section of your component. At each point, one of the components in your list has to be mapped to &lt;code&gt;currentTab&lt;/code&gt;. The &lt;code&gt;&amp;lt;component&amp;gt;&lt;/code&gt; frame would then render whatever component is tied to &lt;code&gt;currentTab&lt;/code&gt;. Way too abstract? Okay, let’s look at how we could do this with our &lt;code&gt;ApplicationForm&lt;/code&gt; and &lt;code&gt;JobDescription&lt;/code&gt; tabs.&lt;/p&gt;

&lt;p&gt;The snippet below shows what the script section of our component would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import JobDescription from "@/components/JD.vue"
import ApplicationForm from "@/components/ApplicationForm.vue"

export default &lt;span class="si"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;JobDescription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;ApplicationForm&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;currentTab&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JobDescription&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;tabs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JobDescription&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ApplicationForm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the snippet above, we initialized &lt;code&gt;tabs&lt;/code&gt; array with the components we imported. We then set &lt;code&gt;JobDescription&lt;/code&gt; to be our default &lt;code&gt;currentTab&lt;/code&gt;.  What this means is that each time that page is visited, the &lt;code&gt;JobDescription&lt;/code&gt; tab is what will be shown. But how do we update our &lt;code&gt;currentTab&lt;/code&gt; to &lt;code&gt;ApplicationForm&lt;/code&gt; when users switch to that tab in the UI? The update is done in the &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; section of our component as shown in the snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
          &lt;span class="na"&gt;v-for&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tab in tabs"&lt;/span&gt;
          &lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tab"&lt;/span&gt;
          &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"currentTab = tab"&lt;/span&gt;
        &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;tab&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;KeepAlive&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;component&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;is&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"currentTab"&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tab"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;component&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;KeepAlive&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;template&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the snippet above we are using &lt;code&gt;@click&lt;/code&gt; to update &lt;code&gt;currentTab&lt;/code&gt; to the tab being clicked. One other thing you might have noticed is how the &lt;code&gt;&amp;lt;component&amp;gt;&lt;/code&gt; element is wrapped by a &lt;code&gt;KeepAlive&lt;/code&gt; component. The &lt;code&gt;keepAlive&lt;/code&gt; is an inbuilt component that preserves the state of our component. In our case with the &lt;code&gt;keepAlive&lt;/code&gt; around, when switching from the &lt;code&gt;ApplicationForm&lt;/code&gt; component, whatever we typed in the input field would still be there when we return.&lt;/p&gt;

&lt;p&gt;Two of our concerns had been addressed. What’s left for us now is exploring how we could load components on-demand. We previously tagged this &lt;em&gt;lazy loading.&lt;/em&gt; Let’s quickly look at how we could do this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asynchronous Components
&lt;/h2&gt;

&lt;p&gt;Let’s load our &lt;code&gt;ApplicationForm&lt;/code&gt; component on-demand. Note that you could apply this to just any component. To load our component in question asynchronously, all we have to do is update how we are registering the component. See the snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import JobDescription from "@/components/JD.vue"
// import ApplicationForm from "@/components/ApplicationForm.vue"
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineAsyncComponent&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from 'vue'

export default &lt;span class="si"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;JobDescription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;ApplicationForm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;defineAsyncComponent&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/components/ApplicationForm.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;currentTab&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JobDescription&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;tabs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JobDescription&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ApplicationForm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Essentially, the only change we made is in using vue3’s &lt;code&gt;defineAsyncComponent&lt;/code&gt; feature to register our &lt;code&gt;ApplicationForm&lt;/code&gt; as an asynchronous component. With that, the &lt;code&gt;ApplicationForm&lt;/code&gt; component will be loaded on demand.&lt;/p&gt;

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

&lt;p&gt;In this piece, we’ve seen how we could render components to the DOM dynamically in Vue. We’ve also seen how the inbuilt &lt;code&gt;&amp;lt;KeepAlive&amp;gt;&lt;/code&gt; component in Vue could help us persist the states of our component. And lastly, we explored how we could load components on demand to optimize for speed.&lt;/p&gt;

&lt;p&gt;That’s all I have for you :) &lt;/p&gt;

&lt;p&gt;If you want to share your thoughts on this tutorial with me or simply just connect, you can find/follow me on &lt;a href="https://github.com/Nyior"&gt;Github&lt;/a&gt;, &lt;a href="https://www.linkedin.com/in/nyior/"&gt;Linkedin&lt;/a&gt;, or &lt;a href="https://twitter.com/nyior_clement"&gt;Twitter.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>DR-CLI: A Flexible Cookie cutter and CRUD Endpoints Generator for Django</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Fri, 13 May 2022 15:50:21 +0000</pubDate>
      <link>https://dev.to/nyior/dr-cli-a-flexible-cookie-cutter-and-crud-endpoints-generator-for-django-2nlb</link>
      <guid>https://dev.to/nyior/dr-cli-a-flexible-cookie-cutter-and-crud-endpoints-generator-for-django-2nlb</guid>
      <description>&lt;p&gt;I've been writing REST APIs with the Django framework for some time now. Over the years, I couldn't help but notice, with discontent, how I've been repeating certain things in every project. &lt;/p&gt;

&lt;p&gt;And there were things I just wished could be better. Permit me to kick this off with a catalogue of some of the issues I felt needed fixing :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem-1:&lt;/strong&gt; First of all, I noticed I was repeating at least one of the following integrations/features in every project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A custom user model defined in a &lt;code&gt;users&lt;/code&gt; app&lt;/li&gt;
&lt;li&gt;Authentication endpoints.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pypi.org/project/python-decouple/"&gt;python-decouple&lt;/a&gt;: for managing environment variables &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://drf-spectacular.readthedocs.io/en/latest/readme.html"&gt;drf-spectacular&lt;/a&gt;: for auto-generating API docs &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jazzband/dj-database-url"&gt;dj-database-url&lt;/a&gt;: for connecting to various databases &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/"&gt;pre-commit, black, isort, flake8&lt;/a&gt;: for code linting with pre-commit hooks &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pytest-django.readthedocs.io/en/latest/"&gt;pytest-django&lt;/a&gt;: for writing unit tests with pytest &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learndjango.com/tutorials/django-docker-and-postgresql-tutorial"&gt;Docker&lt;/a&gt;: for containerization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At a point, I wished there was a tool that could start my project with the integrations I need already configured. I found &lt;a href="https://github.com/agconti/cookiecutter-django-rest"&gt;cookie-cutter-django-rest&lt;/a&gt; to be useful, but sometimes it's just an overkill for my use-case. &lt;/p&gt;

&lt;p&gt;I needed something more flexible. Something that could start my project with a few or all the integrations above as the case may be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem-2:&lt;/strong&gt; Furthermore, I also realized I was always creating CRUD endpoints for most of the database models I define. CRUD endpoints like authentication are mainstay of most projects. &lt;/p&gt;

&lt;p&gt;But most importantly, CRUD endpoints are so nondescript that I wish there was a tool to automate the task of writing them myself. &lt;/p&gt;

&lt;p&gt;This type of automation I believe is necessary as it would save me minutes and perhaps hours(when dealing with hundreds of models) spent on the mundane CRUD stuff :(&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem-3:&lt;/strong&gt; Lastly, I had always wish there was a way to create multiples apps at once in my Django projects. I felt the need for this feature because most times I tend to know all the apps in my project at the design phase.&lt;/p&gt;

&lt;p&gt;Overall, I was just dissatisfied with the time spent configuring third party packages, and writing CRUD endpoints when I could channel that energy into the more exciting parts of my projects.&lt;/p&gt;

&lt;p&gt;To solve my problems, I scoured GitHub and PYPI for that one tool forged with the "super powers" to start my project with the integrations I need already configured as well as the potential to generate CRUD endpoints for the models I define with just a command.&lt;/p&gt;

&lt;p&gt;My hunt ended rather disappointingly, and I figured well, maybe someone needs to create that tool. &lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Django Rest CLI(dr-cli)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Np1aGe0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vchsl487bunon2b65tj3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Np1aGe0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vchsl487bunon2b65tj3.PNG" alt="Start Project with Django Rest CLI" width="880" height="216"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created dr-cli to be a tool that comes bundled with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The capability to start your project with the integrations you need already configured. For example: authentication endpoints with dj-rest-auth, auto-generated docs with drf-spectacular, docker support, and more.&lt;/li&gt;
&lt;li&gt;The potential to generate CRUD endpoints for the models you define. For example, if you define a model, &lt;strong&gt;Product&lt;/strong&gt; in your &lt;code&gt;models.py&lt;/code&gt; file, this tool could generate a &lt;em&gt;GET /products POST /products PUT /products/&lt;/em&gt; etc. endpoints for that model.&lt;/li&gt;
&lt;li&gt;An ability to create multiple apps at once in your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cool, how can I get started with this?&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;pip install dr-cli&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;I highly recommend that you install this in a virtual environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a New Project
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;Run dr-cli startproject project_name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You'd be prompted to start your project from one of three templates: &lt;strong&gt;Basic, Medior, and Advanced&lt;/strong&gt; templates. Learn more about what each template comes bundled with &lt;a href="https://github.com/py-universe/django-rest-cli/blob/docs/templatesInfo.md"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On selecting one of the templates your project will then be created. Git will be initialized in your project, and all project dependencies installed.&lt;/p&gt;

&lt;p&gt;The generated project comes with a nice Readme containing the steps for running the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create New Apps in your Project
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;Run dr-cli startapps todo me-nu user&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 Where todo, me-nu, and user are the app names.&lt;/p&gt;

&lt;p&gt;On running the above command, name validations would be performed first, and then all apps that pass the validation would be created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure to add your created apps to the list of INSTALLED APPS&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate CRUD Endpoints for your Apps
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;Run dr-cli addcrud memo user&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 to create CRUD endpoints for the models defined in the memo &amp;amp; user apps, for example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure to register the URLs for each app in the top level urls.py file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing the docs page
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run

&lt;code&gt;python manage.py runserver&lt;/code&gt;

to fire up your local development server, and point your browser to &lt;code&gt;http://localhost:8000/api/v1/docs&lt;/code&gt; to view the auto-generated docs page similar to the one shown in the image below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zeWQb6yu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xj2kjublph85bb3e59i4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zeWQb6yu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xj2kjublph85bb3e59i4.PNG" alt="Auto Generated Docs with dr-cli" width="880" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can visit the &lt;a href="https://github.com/py-universe/django-rest-cli"&gt;project's repository&lt;/a&gt; to see a nice demo demonstrating these commands.&lt;/p&gt;

&lt;p&gt;We are seeking ways to improve our current implementation. We'd really be happy to hear your thoughts. You can find me on &lt;a href="https://www.linkedin.com/in/nyior/"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://twitter.com/nyior_clement"&gt;Twitter&lt;/a&gt; or &lt;a href="https://github.com/Nyior"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>django</category>
      <category>tooling</category>
      <category>python</category>
    </item>
    <item>
      <title>Unveiling Django-rest-paystack: A minimal plugin for integrating the Paystack payment gateway into a Django API backend.</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Tue, 11 Jan 2022 10:05:51 +0000</pubDate>
      <link>https://dev.to/nyior/unveiling-django-rest-paystack-a-minimal-plugin-for-integrating-the-paystack-payment-gateway-into-a-django-api-backend-54h4</link>
      <guid>https://dev.to/nyior/unveiling-django-rest-paystack-a-minimal-plugin-for-integrating-the-paystack-payment-gateway-into-a-django-api-backend-54h4</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;wtf&lt;/em&gt;(pardon my French) is django-rest-paystack?
&lt;/h2&gt;

&lt;p&gt;First, Django is a tool that helps us build web applications. If/when you feel the need to dazzle your audience, you can call Django a web framework LOOL. Think Laravel, Node, and Spring. Django-rest-framework is built on top of Django. It just makes writing REST APIs with the Django framework so much easier.&lt;/p&gt;

&lt;p&gt;Second, Paystack is a service that makes processing payments in our projects easy-breezy. Think Stripe, Paypal, and Razorpay.&lt;/p&gt;

&lt;p&gt;Lastly, django-rest-paystack is a library we made. The goal with this project is to make the task of integrating the Paystack payment gateway into a django-rest project a snip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is this even useful?
&lt;/h2&gt;

&lt;p&gt;Well, I'd let you be the judge of that. But from my personal experience, creating those payment endpoints for every single e-commerce project we work on could become redundant and perhaps somewhat boring overtime. While there are different approaches to integrating and processing payments with any payment gateway, in each approach, the flow doesn't really change. If it doesn't change then why repeat yourself? &lt;/p&gt;

&lt;h2&gt;
  
  
  Enter django-rest-paystack
&lt;/h2&gt;

&lt;p&gt;when installed and configured in your project, this package generates all the endpoints you'd need to start and complete a transaction. Literally everything from initializing a transaction, handling webhook, and persisting useful transaction data. This package handles all the mundane payment stuff, just so you could focus on the more dynamic and exciting parts of your project. Did I mention that this package is very extensible?&lt;/p&gt;

&lt;h2&gt;
  
  
  How can I get this?
&lt;/h2&gt;

&lt;p&gt;You can install the package in your project with &lt;code&gt;pip&lt;/code&gt; :&lt;br&gt;
&lt;code&gt;pip install django-rest-paystack&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also checkout the project on &lt;a href="https://github.com/Nyior/django-rest-paystack"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  I love this package. How can I thank you?
&lt;/h2&gt;

&lt;p&gt;Just share this with your friends, and leave us a star on the repo. I'd love the attention :)&lt;/p&gt;

</description>
      <category>python</category>
      <category>django</category>
      <category>paystack</category>
      <category>library</category>
    </item>
    <item>
      <title>The Django Framework: An Overview</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Mon, 05 Apr 2021 18:18:19 +0000</pubDate>
      <link>https://dev.to/nyior/the-django-framework-an-overview-21f9</link>
      <guid>https://dev.to/nyior/the-django-framework-an-overview-21f9</guid>
      <description>&lt;p&gt;Hi there,&lt;/p&gt;

&lt;p&gt;Where have I been? Around the world and now I'm back again :D It's been a while since the last time I wrote. I recently got done with school, and I had to move from my city to a different city. I've been quite busy and lazy too. How I'm able to use the words &lt;em&gt;busy&lt;/em&gt; and &lt;em&gt;lazy&lt;/em&gt; in the same sentence is something that I don't want to talk about right now. Why? Because I'm only here to talk about Django. Oh, Django the famous Belgian-born jazz guitarist? LOL NO! I'm talking about Django the &lt;strong&gt;web framework.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a web framework you ask?
&lt;/h2&gt;

&lt;p&gt;Literally, a framework = frame + work. In other words, a framework provides us with a frame for doing some work. So when we talk about web frameworks, we are talking about the frames that allow us to do some web-related work. But what is a frame you ask?&lt;/p&gt;

&lt;p&gt;Seen a picture frame before? it provides a predefined layout for inserting pictures. same with a building frame. Thus, a web framework is more or less like a picture frame. It describes a predefined architecture for building web applications and more. &lt;/p&gt;

&lt;p&gt;And more? Yes, web frameworks also provide reusable components that make developing web applications so much easier. A reusable component provided by a web framework is usually some code that takes care of some repetitive task that's an essential component of all web applications. Essentially, all web applications map client requests to some business logic that modifies or reads some data and then returns a response. Mapping URLs or requests to some business logic, managing an application's data, and dynamically rendering an HTML page based on some data retrieved from the database are three examples of the most common problems all web applications have to deal with. The three problems mentioned are formally called routing, database management, and templating. Web frameworks exist to solve problems like the ones mentioned above and more.&lt;/p&gt;

&lt;p&gt;Now, if you don't get anything I have said in the paragraph above, just remember these two things: web frameworks provide us with a predefined architecture and reusable components for building, and running web applications. But that begs the question, if Django is a web framework, how does it discharge the two functions mentioned above?&lt;/p&gt;

&lt;p&gt;Django provides a predefined architecture that forces the developer to separate the development of an application into three loosely coupled components: the component that manages an application's data and usually interacts directly with the database, the layer that presents data to or accepts data from the user; usually this is what most users interact with, and lastly the part that sits between the data management layer and the data presentation layer. This layer grabs data, usually, some user input, from the presentation layer, manipulates the data, and then passes it to the data management layer. This layer is also capable of fetching data from the data management layer, manipulating, and formatting the grabbed data in a certain way, and then returning the data as a response to the presentation layer. If you ever feel the need to impress anyone, you could tell them the Django web framework uses a Model-Template-View(MTV) architecture. Where MTV represents the data management, the presentation, and the third layer that sits between the data management and presentation layers respectively. As most of you might have figured out already Django is not really doing anything new. It just puts its twist on the popular MVC software development pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Oh okay, I get the architecture that Django provides, but what reusable components does it come with?
&lt;/h2&gt;

&lt;p&gt;In fact, the provision of reusable components is Django's greatest strength. Django is tagged as a 'batteries included' framework. It comes fully loaded with lots of extras that make the development of web applications faster and easier. Django comes bundled with components like the Admin backend with a corresponding web interface, Object Relational Mapping(ORM) tool, Routing, and Templating features that allow developers to focus on the application's business logic that changes from application to application and not these mundane tasks that stay the same, more or less.&lt;/p&gt;

&lt;p&gt;An admin panel is one of the pivotal components of most modern web applications. In fact, it's unimaginably hard to come across a web application without an admin panel. If the application does not have an admin panel just yet, it's only a matter of time until that basic application needs one. Django recognizes this repetitiveness with admin panels; developers have to make an admin panel for every web application they develop. Repetition isn't Pythonic. Thus, to allow developers to focus on the more important things like the application's core business logic that's more likely to change from application to application, Django comes bundled with an admin full-stack logic. This logic automatically adds an admin panel to every web application created with the Django web framework. Essentially, the Django admin view allows users with the required permissions to manage an application's data from a web interface.&lt;/p&gt;

&lt;p&gt;In a similar fashion, Django also recognizes the fact that the data layer is one of the standard components of most modern web applications. As a result, Django also comes with a tool out of the box that makes working with relational databases like Mysql and Postgresql so much easier. Django comes with an Object Relational Mapping(ORM) tool. ORM? Don't worry, ORM is just another computer science jargon that's not too hard to understand at all. &lt;/p&gt;

&lt;p&gt;Normally, how you'd interact with your SQL-based database in let's say Python, is through SQL queries. For example, to get a list of all the users from a database table named Users you'd write an SQL query that looks like this:&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;SELECT * FROM Users;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 While this works, it could be really time-consuming as you'd have to write both Python and SQL code. Furthermore, while this is not advisable, sometimes developers use one relational database for development and a different one in the production environment. In situations like that, the developer would have to make modifications to the code that interacts with the database. Object Relational Mapping solves this problem; essentially, it allows you to call and manipulate data from the database using your language of choice, for example, Python instead of SQL. In addition, the ORM also allows switching between relational databases with minimal code modification. In python and many more languages like it, Object Relational Mapping could be achieved using a tool called the Object Relational Mapper. The Django web framework comes with an inbuilt Object Relational Mapper that allows developers to interact with their databases using vanilla Python code.&lt;/p&gt;

&lt;p&gt;Furthermore, Django also recognizes the fact that the task of mapping an incoming request(usually a URL path) to some application logic that in turn returns a response could be hard and somewhat repetitive. Again, to allow developers to focus on the main application logic, Django comes with an out-of-the-box solution that routes the incoming request to a Django view function(which is usually some defined logic for executing some task). Django is able to achieve this by allowing developers to specify a list of URLs in a URL configuration file. Each URL in the list is a path to match against the URL, and a target, which is either a view function or a different URLconf. Django is able to correctly route requests to the appropriate view function on behalf of the developer by looking at the list of URLs defined in the URLconf file and invoking the view function mapped to the URL pattern where a match is found.&lt;/p&gt;

&lt;p&gt;Lastly, one common problem that arises in almost every web application is the issue of displaying content that changes frequently on an HTML page. In other to make rendering dynamic content within static HTML pages more convenient, Django uses a solution adopted by most web frameworks. Django uses templates to render dynamic content within a static HTML page. A template contains the static parts of the desired HTML output as well as some placeholder for inserting dynamic data. Django and many more frameworks like it is able to achieve this through the use of a template system that it provides out of the box. Django uses a template system called the Django template language (DTL). Django also ships with a built-in backend for the popular Jinja templating engine. The Django template system allows you to specify variables using a "double-handlebars" syntax e.g.&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{{ variable_name }}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 The variable_name will be replaced by values passed in from the view function when a page is rendered. The template system also provides support for expressions&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;(with syntax: {% expression %})&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
  Syntax like the above would allow templates to perform simple operations as iterating list values passed into the template.&lt;/p&gt;

&lt;p&gt;Conclusively, Django is a batteries-included web framework that puts its own twist on the popular MVC architecture. Django comes with lots of out-of-the-box solutions like the admin interface, a routing mechanism, an ORM, and a template system that makes developing web applications with this tool very convenient.&lt;/p&gt;

</description>
      <category>django</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Better Way to Shorten Your URLs</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Wed, 30 Dec 2020 20:02:39 +0000</pubDate>
      <link>https://dev.to/nyior/how-do-you-shorten-your-urls-3o7k</link>
      <guid>https://dev.to/nyior/how-do-you-shorten-your-urls-3o7k</guid>
      <description>&lt;p&gt;To shorten your URLs, I imagine that what you would normally do is copy the URL to be shortened, navigate to one of the many URL shortening websites out there, and have it shortened. Yes, that works, but do you have to go through all that just to shorten a URL?&lt;/p&gt;

&lt;p&gt;No, you don't. Recently, we made a browser add-on for Google Chrome code-named klinurl. With klinurl, you could now shorten your URLs with just a click. You don't have to leave your browser's current tab. Klinurl saves you the time you would usually commit to making a decision about what URL shortening website to use and the effort required to navigate to one of these sites. klinurl is all about making the URL shortening process more convenient for everyone.&lt;/p&gt;

&lt;p&gt;Our add-on is currently available in the chrome web store. For installation, you could find it &lt;a href="https://chrome.google.com/webstore/detail/klinurl-for-chrome/jbeoijelmjlhahfdlccjlemcnfegiolc?hl=en&amp;amp;authuser=0" rel="noopener noreferrer"&gt;here&lt;/a&gt;. We are super interested in hearing what you think of our extension. You could do that by giving us a review in the chrome web store.&lt;/p&gt;

&lt;p&gt;Klinurl is currently a public repository on Github. Thus, PRs are welcome. Or do you just love what we are doing? Find our repo below and give us a star. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/MLH-Fellowship" rel="noopener noreferrer"&gt;
        MLH-Fellowship
      &lt;/a&gt; / &lt;a href="https://github.com/MLH-Fellowship/klin-url" rel="noopener noreferrer"&gt;
        klin-url
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      google chrome add on for shortening urls
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;
    KlinUrl: Google Chrome URL Shortener
&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;
    &lt;i&gt;A google chrome addon for shortening urls in a more convenient way&lt;/i&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/MLH-Fellowship/klin-url/blob/feature/save-url/images/klinnurl-cover.png"&gt;&lt;img width="900" height="400" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FMLH-Fellowship%2Fklin-url%2Fraw%2Ffeature%2Fsave-url%2Fimages%2Fklinnurl-cover.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Descripttion&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;This google chrome add on helps people especially developers shorten urls easily without having to visit sites like bitly. It makes shortening urls more convenient😃&lt;/p&gt;

&lt;p&gt;If you like this repo, click the ⭐&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Frontend Project Setup(klinurl_frontend folder):&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;clone project to your local machine&lt;/li&gt;
&lt;li&gt;navigate to the klinurl_frontend directory&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;To install project dependencies(jest) run:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To test if it works, visit &lt;code&gt;chrome://extensions&lt;/code&gt; in your browser and ensure that the Developer mode checkbox in the top right-hand corner is checked.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click Load unpacked extension and select the directory in which your extension files live(basically, this project's folder). If the extension is valid, it will be active straight away so you can click on the extension's icon in your browser's address bar; this action should trigger a display of a pop up icon.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/MLH-Fellowship/klin-url" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Find below an explainer video that explains how klinurl works.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/GzSVSA-EO74"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>productivity</category>
      <category>chromeextension</category>
    </item>
    <item>
      <title>Artificial Intelligence Vs Machine Learning Vs Deep Learning: A Quick Comparison</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Sun, 20 Dec 2020 22:00:28 +0000</pubDate>
      <link>https://dev.to/nyior/artificial-intelligence-vs-machine-learning-vs-deep-learning-a-quick-comparison-22ii</link>
      <guid>https://dev.to/nyior/artificial-intelligence-vs-machine-learning-vs-deep-learning-a-quick-comparison-22ii</guid>
      <description>&lt;p&gt;The buzzwords AI, ML, and DL had always confused me. In fact, I had wrongly used them interchangeably several times. I say wrongly because, now that I understand what each of them means, it's very clear to me that even though they're related, they don't mean the same thing. It took me a bit of research to really understand these three concepts and how they differ. In this piece, I'd be sharing with you my understanding of these terms. Permit me to begin this writing by interrogating the eldest of the three.&lt;/p&gt;

&lt;h1&gt;
  
  
  Artificial Intelligence
&lt;/h1&gt;

&lt;p&gt;By way of definition, we could say that artificial intelligence is a field of study that most of my friends are completely disinterested in :)&lt;/p&gt;

&lt;h3&gt;
  
  
  Come onnnnn are you kidding me?
&lt;/h3&gt;

&lt;p&gt;Well, not really. While the definition above might come off as a complete joke, there are actually two facts in it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Yes, most of my friends fiercely hate artificial intelligence.&lt;/li&gt;
&lt;li&gt;Artificial intelligence is a field of study or branch of knowledge.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For now, we would ignore the first fact and pursue the second one. The common denominator to all fields of study is that they answer at least one fundamental question about humanity. For example, Physics tries to unravel how the universe works, History explores the evolution of human cultures and Biology demystifies life. But this begs the question: If AI is a field of study then what fundamental question about humanity does it try to answer? Artificial intelligence tries to answer this one question: &lt;em&gt;How can we build machines with human intelligence?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With this understanding of artificial intelligence, we could redefine AI as a branch of knowledge that primarily concerns itself with building machines that could perform tasks that would usually require human intelligence. While endowing machines with human intelligence is a really broad statement, see it as giving machines the ability to learn, build some pool of knowledge/experience from what they've learned, and then use these experiences to solve problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Oh okay, Nyior I get what artificial intelligence is, but the idea of building machines that are as smart as humans sounds really impractical to me. I mean how can this be achieved?
&lt;/h3&gt;

&lt;p&gt;It's simple. I present to you...&lt;/p&gt;

&lt;h1&gt;
  
  
  Machine Learning
&lt;/h1&gt;

&lt;p&gt;It is one of the ways artificial intelligence could be achieved. It's centered around the idea that we could endow machines with human intelligence if we give them access to data and allow them to learn from that data.&lt;/p&gt;

&lt;h3&gt;
  
  
  what does learning entail you ask?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;“Learning” entails using sophisticated mathematical algorithms to optimize some function called the &lt;strong&gt;predictor function&lt;/strong&gt; so that, given input data x about a certain domain (say, square footage of a house), it will accurately predict some interesting value h(x) (say, the market price for the said house).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Yo Nyior, you're just saying buzzwords oh 😭
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;abeg no vex&lt;/em&gt;, let's try to make sense of that fancy definition😅. The key to making sense of the definition above lies in understanding what a predictor function is. Usually, when programmers write code, they are basically just hard coding rules that could be used by the machine to solve a given problem. Most rules in programming are expressed with some mathematical function. However, hardcoding rules for machines is not the machine learning way of building algorithms. In machine learning, we give our algorithm some data and allow them to autonomously discover those rules themselves. Thus, predictor functions are the rule(s) that a machine learning algorithm has to discover.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do ML algorithms automatically generate the predictor function you ask?
&lt;/h3&gt;

&lt;p&gt;An ML algorithm is first passed a function that performs really poorly at the task at hand. This could be something like y = theta1 + theta2x. The algorithm then learns by optimizing the initial function it was passed to do better at the given task.  A function formally called the loss function, indicates the degree of the wrongness of a predictor function. Thus, generally, training a model in ML implies calling the loss function to measure the degree of the wrongness of the predictor function after every training data had been passed to the algorithm. In addition, learning in this context simply means exposing an ML algorithm to some data and having it optimize its predictor function. &lt;/p&gt;

&lt;h1&gt;
  
  
  Deep Learning
&lt;/h1&gt;

&lt;p&gt;It is a subset of machine learning. Technically, deep learning is machine learning. It is just the collective name for the revolutionary breed of machine learning algorithms that had recently appeared on the AI scene. ML algorithms under the deep learning umbrella, unlike the traditional ML algorithms; have a logical structure that models the structure and behavior of the human brain. Algorithms that follow this structure are called Artificial Neural Networks(ANNs). &lt;/p&gt;

&lt;h3&gt;
  
  
  But what is this structure you ask?
&lt;/h3&gt;

&lt;p&gt;Deep learning algorithms possess a layered structure that simulates the architecture of the human brain(a network of neurons). In a nutshell, the human brain functions by passing an electrical charge emitted by some neuron to the next neuron. Similarly, deep learning algorithms make computational decisions by accepting some data through the first layer called the input layer, manipulating the data, and then passing its output to the next layer, until it reaches the last layer called the output layer.  ANNs could have one or more layers between the input and output layers. ANNs with more than one layer between the input and output layers are called deep neural networks.&lt;/p&gt;

&lt;p&gt;Conclusively, think of AI as this broad concept of building machines that are as smart as humans, machine learning as one practical way of achieving artificial intelligence, and deep learning as the collective name for machine learning algorithms that model the structure and behavior of the human brain.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>ai</category>
    </item>
    <item>
      <title>How to Waste the Remaining Six Weeks of the MLH Fellowship.</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Mon, 16 Nov 2020 13:55:21 +0000</pubDate>
      <link>https://dev.to/nyior/the-mlh-fellowship-my-journey-so-far-35b3</link>
      <guid>https://dev.to/nyior/the-mlh-fellowship-my-journey-so-far-35b3</guid>
      <description>&lt;p&gt;To all my fellow explorers, congratulations on making it this far!&lt;br&gt;
Yes! we've all been working very hard, and it's surely worthy of praise. &lt;br&gt;
But don't sit back, it's not over yet; we are still in the race. &lt;br&gt;
Okay, Enough of the smooth and easy stuff.&lt;br&gt;
Let me hit you with something tuff.&lt;/p&gt;

&lt;p&gt;The MLH team needs to clad us all in gold for our Genghis-Khan-like bravery in battle...lol. Battle? Yes! The past six weeks, for me, every single day was like a puzzle that needed to be solved. But in the end, we are all still here. And now, we have just little time left to  wrap up this fellowship. We've spent the first half of this fellowship connecting with new people, working on projects, and for me all these experiences had added up to an overwhelmingly inestimable lessons. &lt;/p&gt;

&lt;p&gt;Please permit me to, in this piece, share some of these lessons I had learnt; more specifically, &lt;em&gt;tips on how to waste the six weeks that we have left in this fellowship... haha.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Focus on the Technical Aspect of the Fellowship and that Alone!
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Build bridges?&lt;/em&gt; nah! burn them! You don't need to walk on any bridge to become a successful developer. You could just swim anyway.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;not always about what you know, sometimes it's about who you know?&lt;/em&gt; Gibberish! That's what incompetent and highly political people say to justify their efforts to replace meritocracy with nepotism in the workplace. And fortunately for us all they haven't succeeded. These days you don't need any network to become a successful entrepreneur or get your dream job.&lt;/p&gt;

&lt;p&gt;Be intentional and relentless in your efforts to avoid all avenues provided by the MLH team to help you improve your soft skills. Also avoid opportunities provided by the MLH team to help you build relationships through 1-on-1s, and to improve your communication/presentation skills through show and tells, and round tables. Focus on improving your hard skills alone and you go dey alright (you'll be fine).&lt;/p&gt;

&lt;h1&gt;
  
  
  Work With New Sets of Technologies Every Sprint
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;The best generalists were at some point specialists?&lt;/em&gt; Come on! that doesn't even make sense! You are better off working with new sets of technologies every sprint. You are better off having just a shallow understanding of all the programming languages and frameworks of our time. I mean, who even cares about how well or deep you understand a technology?&lt;/p&gt;

&lt;p&gt;I know even as you read this, some of you would argue that it's easier to transition to a new technology if one already has some prior deep understanding of a related technology. What a lame argument! After all, the explorer track is all about experimenting with new technologies and of course that ultimately means working with new sets of technologies every sprint and not pursuing an interest.&lt;/p&gt;

&lt;h1&gt;
  
  
  Completely Ignore the Engineering Focus of Each Sprint; Who Cares About These Things Anyway
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Git? Clean code? Security? Testing?&lt;/em&gt; For crying out loud who comes up with these things? The MLH team expects fellows in the explorer track to focus on each of these per sprint? What a waste of time! Software engineers only write code. All these other things are just distractions. Focus on writing code and that alone.&lt;/p&gt;

&lt;p&gt;Why waste your valuable time learning a version control system when you could spend that time perfecting your Python or Javascript skills. Why push your code to some remote server when you'd just be fine having it locally on your own machine?&lt;/p&gt;

&lt;p&gt;I'm so tired of all the bullshit(please pardon my french) about version control systems making collaboration between devs easier, helping developers and organizations track changes made to a code base overtime and serving as a backup of some sort in cases of file loss. I strongly don't think these are good reasons to learn and use a version control system and I hope you see things the way I do. These guys only want us to learn this thing because everyone uses it! You don't have to fit the mold tho! Don't bow to societal pressure! Just do your &lt;em&gt;thang&lt;/em&gt; and ignore all the noise around you.&lt;/p&gt;

&lt;p&gt;Like learning how to use git effectively isn't enough burden already, the MLH team wants its fellows to focus on learning how to write clean code and a bunch of other things? clean code? You don't need that. You're not writing code for other people; you are writing code for yourself. So your code is excellent provided you can always understand what you've written.Even if you don't understand the code, it doesn't really matter! It still works.&lt;/p&gt;

&lt;h1&gt;
  
  
  Only Work on Your Team's Project When Motivated
&lt;/h1&gt;

&lt;p&gt;Yes! you read that right. I really don't have much to say here. All I can say is, the best way to get a lot done is by only working when you are motivated.&lt;/p&gt;

&lt;p&gt;Ladies and gents! commit to applying all the above tips and you will successfully waste the remaining six weeks we have left in this fellowship...haha&lt;/p&gt;

&lt;p&gt;Lastly, on a somewhat unrelated note, if the sarcasm in this writing isn't very obvious then I did a horrible job. Please forgive me. It's not intended to be rude.&lt;/p&gt;

&lt;p&gt;Okay I'm done.&lt;/p&gt;

</description>
      <category>mlh</category>
      <category>explorer</category>
    </item>
    <item>
      <title>Beginners Guide to Recursion</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Thu, 15 Oct 2020 05:00:35 +0000</pubDate>
      <link>https://dev.to/nyior/beginners-guide-to-recursion-1ipe</link>
      <guid>https://dev.to/nyior/beginners-guide-to-recursion-1ipe</guid>
      <description>&lt;p&gt;In most programming languages, we use loop constructs like ‘while’ and ‘for’ to repeatedly execute a block of code until a certain condition is met. A recursive function does pretty much the same thing; except that it does this by calling itself within itself! And just as in loops it stops calling itself when a certain condition is met. Thus, in computer programming, recursion is when a function calls itself.&lt;/p&gt;

&lt;p&gt;In code this is what recursion looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decrement_number_until_zero(number):
    print(number)
    decrement_number_until_zero(number - 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Oh that Works ?&lt;/strong&gt;&lt;br&gt;
Well, it wouldn’t! Why? When executed this function will throw a stack overflow error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stack Overflow Error ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A stack at the most basic level is a data structure that only exposes its topmost element. Think of a stack as a cylinder with one end open and the other end closed. In such a cylinder you obviously can only add and remove items from the open end. A stack is often referred to as a first in last out data structure. This is true because since stacks only allow you to add and remove items from the top of the stack only, then the last element to go into the stack will be the first to go out and the first to go into the stack will be the last to go out. Adding an element to a stack is called pushing and removing an element from a stack is called popping.&lt;/p&gt;

&lt;p&gt;Okay, How is this Connected to Stack Overflow You Ask?&lt;/p&gt;

&lt;p&gt;Well, anytime you make a function call, in Python and most programming languages, the function is pushed into a stack data structure called the call stack. And when the function returns, the function is popped from the call stack. Each function pushed into a stack is called a stack frame. A stack frame basically stores information like the variables used in a function and where the function is suppose to return to among others. In recursive functions every single time a function references itself that same function is pushed into the call stack. In Python there is an upper bound to the number of functions a call stack could accommodate at once.&lt;/p&gt;

&lt;p&gt;Our function above will throw the stack overflow error because our function will attempt to add it self to the call stack for an infinite number of times. Remember, the call stack in python has a threshold. The stack overflow error is thrown when the threshold is reached.This is happening because the function definition does not specify the condition for when the function is suppose to stop calling itself. This condition is called the base case. So a better way of writing the function above will be this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decrement_number_until_zero(number):
    if number &amp;gt; 0:
        print(number)
        decrement_number_until_zero(number - 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This revised function wouldn’t attempt to execute to infinity because now a condition for when it should stop executing had been provided.&lt;/p&gt;

&lt;p&gt;A second example of seeing recursion in action is seen below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def reverse_string_recursively(string):
     if len(string) == 0:
         return string
     else:
         return reverse_string_recursively(string[1:] )+ string[0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function above reverses a string recursively. Again this is a great example of recursion because it specifies a condition for when the program should end execution.&lt;/p&gt;

&lt;p&gt;As you might have figured out already, a good recursive function has two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Base case:&lt;/strong&gt; a boolean expression that when it evaluates to ‘true’ the program execution terminates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursive case:&lt;/strong&gt; is the part that executes when the base case evaluates to false. Usually this is where the function references itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now I’ve said a lot about call stacks, base cases and recursive cases. Let me quickly demonstrate how recursive functions are executed under the hood.&lt;/p&gt;

&lt;p&gt;The way recursive functions execute under the hood could be likened to a storyteller who is telling a story about Person A then switches mid way to a story about person B then again switches mid way to a story about Person C. At the end of Person C’s story, the storyteller then goes back to the story about Person B where s/he left off. At the end of person B’s story, the storyteller then moves on and completes Person A’s story where s/he left off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Didn’t Get that ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s first of all start by looking at an example of how this works in regular functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def c():
    print(“at the beginning of c”)
    c()
    print(“at the end of c”)

def b():
    print(“at the beginning of b”)
    c()
    print(“at the end of b”)

def a():
    print(“at the beginning of a”)
    b()
    print(“at the end of a”)
a()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all, the function a is loaded into the call stack and just as in the story teller analogy, mid way into it’s execution, the main execution thread switches to function b and there too it switches to function c. when function c is done executing the main execution thread switches to function b. It ends its execution with function a.&lt;/p&gt;

&lt;p&gt;So the output of calling function a above would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;at the beginning of a
at the beginning of b
at the beginning of c

at the end of c
at the end of b
at the end of a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned earlier on when the last line of a function is executed, the function returns. As a result that function is popped from the call stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beginning to Understand How this Works?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alright let’s look at how this works in recursive functions. Let’s try to understand this by looking at a popular problem in recursion: finding the factorial of a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def factorial(number):
    """factorial recursive implementation"""
    if number &amp;lt;0:
        return -1
    elif number &amp;lt; 2:
        return 1
    else:
       return number * factorial(number-1)

factorial(5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all factorial(5) * 5 is called. But because 5 is greater than 2, factorial(5) will again trigger a call to factorial(5-1) * 5-1. This will continue until one of the conditions specified evaluates to true. This happens when factorial(1) is called. Because 1 is less than 2 factorial(1) returns some value that is then passed to the functions below it in the stack. Of course after factorial(1) * 1 returns, it is popped from the stack. visualize it this way :&lt;/p&gt;

&lt;p&gt;factorial(1) * 1&lt;br&gt;
factorial(2) * 2&lt;br&gt;
factorial(3) * 3&lt;br&gt;
factorial(4) &lt;em&gt;4&lt;br&gt;
factorial(5)  &lt;/em&gt; 5&lt;/p&gt;

&lt;p&gt;Note that the item at the bottom is the first item loaded into the call stack&lt;/p&gt;

&lt;p&gt;Because 1 is less than 2, based on our function definition, factorial(1) will return 1 and this output is then multiplied by 1. The result from the layer above is then passed to the function below: 1 is passed to factorial(2). factorial(2) then returns what it’s been passed and the output, 1,  is multiplied by 2. Thus the second layer returns 2 and again this is passed to the function below, which is factorial(3). It continues this way until the function at the bottom of the stack returns.&lt;/p&gt;

&lt;p&gt;This is how recursive functions are executed !&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Still Don’t get it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well just give up on recursion and keep using your loops… lol&lt;/p&gt;

&lt;p&gt;But see, frankly speaking, any recursive function could be implemented with loops. For example, the reverse string and factorial functions above could be implemented using loops like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def reverse_string(string):
“””iterative implementation”””
    length = len(string) - 1
    reversed_string = " "

    while length &amp;gt;= 0:
        reversed_string += string[length]
        length -= 1
    return reversed_string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def factorial(number):
    """iterative implementation of factorial"""

    if number &amp;lt;0:
        return -1
    elif number &amp;lt; 2:
        return 1
    else:
        factorial = 1

        for num in range(1, number+1):
            factorial = factorial * num
        return factorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Furthermore, when compared with their iterative counterparts, recursive solutions do not necessarily have better space and time complexity. In fact, because recursive functions repeatedly add stack frames to the call stack, one could even argue that they have a terribly bad space complexity. Recursive solutions are just more elegant.! They are more concise! This in turn improves code readability and by extension code quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/"&gt;Freecodecamp: How Recursion Works Explained&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=AfBqVVKg4GE"&gt;Youtube: Recursion for Beginner, a Beginners Guide to Recursion&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Demystifying Memory Management and Type System in Python</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Thu, 24 Sep 2020 18:17:50 +0000</pubDate>
      <link>https://dev.to/nyior/demystifying-memory-management-and-type-system-in-python-7ho</link>
      <guid>https://dev.to/nyior/demystifying-memory-management-and-type-system-in-python-7ho</guid>
      <description>&lt;p&gt;&lt;em&gt;I will be using the term Python throughout this article. However, taking into account that there are different implementations of Python(Cpython, Cython, Jython etc.) just using the word ‘Python’ could be quite ambiguous. However, I’d like to state clearly from the outset of this article, that the ‘Python’ used in this post refers to the Cpython implementation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python is a High Level Programming Language.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What programmers do primarily, is write instructions for the computer with programming languages. These written instructions are usually loaded into memory and processed by the computer’s brain formally called its CPU. The exact moment when an/a instruction/program is loaded into memory and executed by the CPU will be called run-time in this article. It is important to note here that the CPU only understands 0’s and 1’s(machine code). While in some programming languages the programmer writes instructions in machine code, most programming languages today, allow the programmer to write instructions in languages that are syntactically similar to our natural languages. Languages in the former category are called low level languages, and those in the later category are called high level languages. High level languages are highly abstracted from machine code. Think of abstraction in this context as the amount of work the computer has to do to process the instructions. Because Python is a high level language that’s why we use words like: while, for, if, else and when writing our programs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Since the CPU Could Only Process Machine Code, How Does it Process Our High Level Python Code ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Through translation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Translation?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes! It’s how a source code written in a high-level language is converted to machine code. This is achieved by using a piece of software that takes as input a high level source code and outputs a machine level code that is then executed by the CPU. Translators either compile, interpret or assemble a high level source code into machine code. In Python, even though there is a compilation step, Python source code, for the most part, is usually interpreted into machine code. Unlike in compilation where a language’s compiler translates the entire source code before run-time, the Python interpreter translates a python source code at run-time. It does this by reading the instruction one line at a time from memory and producing its machine code equivalent that is then executed by the CPU. I mentioned earlier on that for easy access, at run-time instructions are loaded into memory. Let’s explore how this is done in Python in great detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Allocation and Management in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the heart of every programming language is memory allocation and management. In Python everything is considered an object. When we declare variables like: &lt;/p&gt;

&lt;p&gt;x=2,  name=”nyior”.&lt;/p&gt;

&lt;p&gt;At run-time, objects are created in memory. In fact we could even have objects that store other objects. For example lists, dictionaries etc. But hold on, this could actually be slightly confusing. When we declare a variable that points to a value say y=3 in Python which is considered the object? The variable on the left or the value on the right?&lt;br&gt;
Well, in Python we have object references and the objects themselves. In python and most programming languages, variables are just object references. The values they point to are the objects. So going with our previous example, where y=3. y is the object reference and 3 is the object.&lt;/p&gt;

&lt;p&gt;An object reference points to the memory address where the object it points to is stored. Every computer memory has a section called the stack and a second section called the heap. In python, object references are stored on the stack and the real objects they point to are stored on the heap. Going with our previous example when you declare a variable like so y=3, y is stored on the stack and 3 is created and stored on the heap. Furthermore, unlike in languages like Java, Python does not allow the creation of duplicate objects on the heap. For example, if you already have y=3 and then a second variable x=3 is also declared, python does not create a second object with value 3 on the heap. It just creates a new reference in the stack that points to the object with value 3 already stored in memory.&lt;/p&gt;

&lt;p&gt;This process of allocating space to objects on the heap and object references on the stack is what’s is termed memory management. But memory management does not end there. It also encompasses removing an object from memory when it’s no longer needed. While in some languages like Rust the programmer has to manually allocate memory and deallocate memory space afterwards, in Python, memory management is done automatically under the hood through a technique called garbage collection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Garbage Collection ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Generally, languages that use garbage collection to deallocate space used by unused objects do this through a mechanism called reference counting. The number of times an object is referenced is kept track of. Once the number reaches 0, the object is deleted from memory. In Python, the main garbage collection technique is the reference counting too. So during a program execution in python all the objects used in the program are loaded into memory. These objects are then assigned three properties: a type, a reference count and a value.&lt;/p&gt;

&lt;p&gt;When an object is referenced, its reference count is incremented and decremented when an object is dereferenced. If an object’s reference count is 0, the memory space allocated to that object is deallocated. An object is usually referenced when: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is assigned to a variable&lt;/li&gt;
&lt;li&gt;When it is added to a data structure or added as a property of a class&lt;/li&gt;
&lt;li&gt;When it is passed as an argument to a function&lt;/li&gt;
&lt;li&gt;Even though problematic, when an object is assigned to itself, its reference count also increases. This type of problem is called reference cycle in Python. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To solve this problem of cyclical reference that comes with reference counting garbage collection mechanism in Python, the generational garbage collection was created.&lt;/p&gt;

&lt;p&gt;Here, all the Python objects in a given program are grouped into three conceptual layers called generations. There are: generations 0, 1 and 2. each layer has an upper bound of the number of objects it could accommodate. This upper bound is formally called its threshold. Once a generation reaches it’s threshold, the generational garbage collection algorithm executes on all the objects in that generation. The algorithm basically finds and obliterates objects with cyclical reference. All the objects that survive are then moved up to the next generation.&lt;/p&gt;

&lt;p&gt;Basically, Python uses two techniques to free up space in the memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reference counting where an object is immediately removed from memory once its reference count reaches 0.&lt;/li&gt;
&lt;li&gt;Generational garbage collection, where objects with cyclical references are tracked and removed from memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Type System in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As stated earlier on, when an object is created on the heap, it is assigned three properties namely: a value, a reference count and a type(int, string, float, etc). Every programming language has a type system: a language’s set of rules that dictates how the data types of objects are declared, how and when the data type of an object is discerned among others.&lt;br&gt;
A programming language is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Either dynamically typed or statically typed and&lt;/li&gt;
&lt;li&gt;Either strongly or weakly typed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Python is a Dynamically and Strongly Typed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In dynamically typed languages, an object’s type is only checked at run time. Dynamically typed languages do not require the programmer to specify the type of a construct in his/her code. This is because the construct is assigned a type on the fly based on its value. Statically typed languages on the other hand type check before a program’s execution; usually at compile time. Statically typed languages require the programmer to declare a construct’s data type before hand in his/her code.&lt;/p&gt;

&lt;p&gt;Furthermore,  Python could be considered a strongly typed language because it is very unforgiving when it comes to type coercion. In most cases Python does not allow for implicit type conversions. For example, “2” + 4 will raise a Type error in Python. Weakly typed languages like Javascript and Php on the other hand are very forgiving when it comes to type coercion. For example, “2” + 4 will yield 24 in Javascript.&lt;/p&gt;

&lt;p&gt;Conclusively, Python is a high level programming language that uses an interpreter to translate code. Furthermore, Python is dynamically and strongly typed. Reference counting and generational garbage collection mechanisms are used to manage memory in Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://stackify.com/python-garbage-collection/#:~:text=The%20garbage%20collector%20is%20keeping,into%20a%20second%2C%20older%20generation."&gt;Python Garbage Collection&lt;/a&gt;&lt;br&gt;
&lt;a href="%EF%81%AEhttps://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7"&gt;Python Type System&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>memorymanagement</category>
      <category>typesystem</category>
    </item>
    <item>
      <title>How the Internet Works</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Sun, 13 Sep 2020 08:17:21 +0000</pubDate>
      <link>https://dev.to/nyior/the-why-what-and-how-of-the-internet-39d5</link>
      <guid>https://dev.to/nyior/the-why-what-and-how-of-the-internet-39d5</guid>
      <description>&lt;p&gt;The term internet has been grossly misused and in fact slandered. When my kid sister told me the internet is the cloud, I said to myself: enough is enough! In this article I’ve explained the internet in a way that even the non-techies could understand. If you have a strong grasp of the nitty-gritty of the internet, you’d find that this article has been oversimplified. Well, I’m just setting the lower bound for what I believe every person should know about the internet. Enough of the &lt;em&gt;yarns&lt;/em&gt;; shall we get to the main thing?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before the Internet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When people began to use machines for work, humans have been relentless in their pursuit of ways to make most of  human experiences faster, easier, and more reliable. For example, in communication, there has been a shift from the use of town criers, to telegraphs, and subsequently telephones. Furthermore, when computers emerged, computer people began to explore ways to make communication more efficient and reliable with computers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But was communication inefficient and unreliable prior to the internet you ask?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes! Prior to the internet, communication over long distances was  highly inefficient. Most times letters took days to arrive at their destination. Then came the telephone era. While this new machine disrupted the communication sphere and made information dissemination faster, it wasn’t very efficient and reliable. This is true because, with telephones, two people could only talk over a dedicated communication line. What this means is this: if this communication line was a road, then only one car could go through at a time. The width of the road notwithstanding. Even if this car spoils mid way, other cars would have to wait. Relating this to telephones, talking over a dedicated communication line means it can only be used by two people at a time. Even if the users at the two ends aren’t really talking, simply because these two telephones are connected, other users wanting to use that particular communication line or to connect to one of the connected  telephones would have to wait. This technique of moving data  over a dedicated communication line is formally called circuit switching. While this technique undeniably had its strengths, it is, in my opinion, a makeshift solution at best. To fill this gap in communication, the internet was created. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can you tell me what this internet is already?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lol.. calm down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Okay, Meet the Internet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The internet is just a more efficient and reliable way of passing data around with computers. As opposed to circuit switching, the internet uses packet switching to move data around. with packet switching, before being transferred, a piece of data is broken down into smaller chunks called packets. These packets are then transferred through several routes to their destination where they are then reassembled. Because of this architecture, on the internet, computers don’t have to wait. Thus, a computer on the internet could be sending data to several  computers while receiving from other computers.&lt;/p&gt;

&lt;p&gt;In reality, at any given time, there will be thousands or millions of people in different parts of the world who’d want to talk to each other. Thus, at any given time, there are thousands or millions of these computers that are connected and sharing information with each other in a network of some sort. The internet at the most basic level is the name given to this global digital community of computers constantly talking to each other. Oh, computers too talk ?&lt;/p&gt;

&lt;p&gt;Yes! Pretty much the way humans do. It happens all the time. When you send an email to a friend the two devices involved are in a back and forth communication with each other. This communication is possible because these computers model the reality of human communication. This doesn’t make sense you think? I imagine you hold that opinion because you believe humans are able to communicate because they have and use language, but computers don’t have this do they ?  Well, they do. Let me tell you how.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the Internet Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Computers on the internet have and use protocols. Just as language simplifies communication between two people, protocols on the internet make communication between computers on the internet possible. These protocols are predefined rules for formatting and moving data on the internet. Still struggling to understand what protocols do on the internet? It’s alright. Just carry on; you will soon understand.&lt;/p&gt;

&lt;p&gt;When you say “hello” to a friend in an email, these protocols format your “hello” text in a certain way. After formatting this data, these protocols then carry this text from your device to the receiver’s device. Protocols are powerful! &lt;/p&gt;

&lt;p&gt;The internet does not have just one monolithic protocol that does everything though. The internet is composed of several related protocols with each protocol doing one thing really well. These set of inter-related protocols on the internet are collectively called the TCP/IP suite.&lt;/p&gt;

&lt;p&gt;Protocols in the TCP/IP suite are layered. Each layer is usually made up of protocols that leverage the capabilities of the protocols in the layer below it. These layers collectively make up the internet protocol stack, and this stack has four major layers:&lt;/p&gt;

&lt;p&gt;The application layer (HTTP, SMTP)&lt;br&gt;
The transport layer (TCP, UDP)&lt;br&gt;
The network layer (IP)&lt;br&gt;
Link layer (Ethernet)&lt;/p&gt;

&lt;p&gt;The application layer protocols are usually embedded in the several applications in your computer. Embedded? Well, yes. Remember, protocols are just rules so they are programmed as part of these applications. For example browsers use the HTTP protocol and some email clients use the SMTP protocol. Using the protocols in this layer, these applications allow users to construct messages that are then passed down to the transport layer.&lt;/p&gt;

&lt;p&gt;The transport and network layer protocols are usually embedded in the operating system of your device. The transport layer ensures that the message is reliably delivered to the right application in the receiving device. Message segments from the transport layer are then passed to the network layer. The network layer ensures that message segments are routed to the appropriate destination machine&lt;/p&gt;

&lt;p&gt;The link layer protocols are most times embedded in the network interface cards. Segments from the network layer are then passed to the link layer that carries the data to the destination machine.&lt;/p&gt;

&lt;p&gt;These protocols are collectively able to move data to a specific device and to a specific application in that device majorly because of IP addresses and port numbers.&lt;/p&gt;

&lt;p&gt;IP addresses and Port numbers ? I thought you said non-techies could understand this too?&lt;/p&gt;

&lt;p&gt;Yeah! See it’s simple: Every computer connected to the internet has a unique address called an IP address. An IP address is a series of numbers. Port numbers on the other hand, provide us with a way to uniquely identify processes/applications on a given computer. Protocols in the transport layer use these port numbers to forward messages to specific processes. Think of IP addresses as street addresses, and port numbers as house numbers within a street. Just as written letters are first of all transported to a particular street using the street address and then to a particular home using the house number, all messages on the internet are first of all routed to a computer (using its IP address) then to a specific application on that computer(using its port number).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So far, my explanation of how the internet works has been quite abstract right?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t give up yet, I saved the best for last.&lt;/p&gt;

&lt;p&gt;Going with the “hello” example at the beginning of this article, when you say “hello” to a friend in an email, the application layer forwards the message to the transport layer. At the transport layer, the port number of the email client is appended to the message passed from the application layer. Of course after splitting the message into segments. These segments with port numbers are then passed to the network layer. At the network layer, the IP address of the destination and the source computer is again added to each segment. Fully equipped with all the necessary extra data, the message is then moved to the data link layer that then moves all the segments to the destination computer using the IP address appended to each segment.&lt;/p&gt;

&lt;p&gt;At the destination computer, the received segments are then moved from the data link layer to the network layer. At the network layer of the receiving computer, each segment is then stripped of the IP address appended to it (because it’s no longer needed). The segments are then moved to the transport layer. At the transport layer,  the segments are then reassembled into the original message. Depending on whether the two devices are using the TCP or UDP protocols, at the transport layer, the receiving device could even send a message to the sending device confirming that it has successfully received all the segments. Using the port number appended to the received message, the  transport layer is able to tell the process it is suppose to forward the message to in the application layer.&lt;/p&gt;

&lt;p&gt;This is how the internet works. This is how every data you send is routed to the receiving device.&lt;/p&gt;

</description>
      <category>internet</category>
      <category>protocols</category>
    </item>
    <item>
      <title>You Can’t Improve What You Don’t Understand: Know thy Algorithm’s Run Time Complexity</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Sun, 06 Sep 2020 23:21:44 +0000</pubDate>
      <link>https://dev.to/nyior/you-can-t-improve-what-you-don-t-understand-know-thy-algorithm-s-run-time-complexity-4e4m</link>
      <guid>https://dev.to/nyior/you-can-t-improve-what-you-don-t-understand-know-thy-algorithm-s-run-time-complexity-4e4m</guid>
      <description>&lt;p&gt;In my &lt;a href="https://dev.to/nyior/i-am-a-crude-software-engineer-84d"&gt;previous post&lt;/a&gt; in this series, I mentioned that in this article I’d explain how the efficiency of an algorithm could be measured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But why measure the efficiency of algorithms you ask ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just as there could be several paths to a destination and we often go with the shortest path, there are usually several algorithms for solving one computational problem. Measuring the efficiency of algorithms helps us identify the shortest path to solving a given computational problem.&lt;/p&gt;

&lt;p&gt;For a given task, we measure the efficiency of an algorithm in terms of :&lt;/p&gt;

&lt;p&gt;*The space it requires to complete the task. This is formally called its space complexity.&lt;br&gt;
*The time it takes to complete the task. This is formally called its time complexity.&lt;/p&gt;

&lt;p&gt;Thus, measuring the efficiency of an algorithm implies deducing the time-space complexity of the algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Okay so how can I deduce the time-space complexity of my algorithm?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Very easy. Implement the algorithm, run it on a computer and observe how long it takes to execute and how much memory it uses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run it on a computer ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well spotted! So if we were comparing the performance of different algorithms we’d have to implement and run all of them? I mean why write code for several algorithms and run them only to pick one at the end ? That’s a brute force approach and not deft  I’d say!&lt;/p&gt;

&lt;p&gt;What if we could do a priori analysis of the time-space complexity of these algorithms then implement the most efficient ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Priori analysis ? how can we possibly measure how fast an algorithm will perform or how much space it would take without running it on a computer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I will tell you how, but before I do let me quickly correct this: you see, testing the time-space complexity of an algorithm by running it on a computer isn’t even cool. Why?  Computers have disparate hardware. In addition, the execution time and space used by our algorithm could also be affected by the number of processes also running at the time of testing, the result obtained could be decidedly misleading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oh this actually makes sense. So how do you suggest I do this priori analysis?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt; It’s easy! I present to you the Big-O notation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Big-O notation? Warisdat?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This provides us with a unique way to describe the performance of our algorithms without having to run them on a computer. With Big-O, we deduce how the number of steps an algorithm takes to complete a task will grow as a function of the input size in the worst case scenario. Algorithms always act on some data: in this case the input. So with Big-O, we are basically just trying to figure out the relationship between the growth rate of an algorithm with respect to the input of size, n. Even though Big-O could be used to deduce the space complexity of an algorithm too, for brevity's sake, this article will focus on the time complexity aspect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worst case scenario ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Big-O assumes for example when iterating a list, that the element does not exist in the list. In which case our algorithm will have to loop to the end of the list. With Big-O, we are only concerned with how well an algorithm will perform in the most terrible situation. In which case it will have to do the hardest job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can this Big-O be used to measure the run time complexity of an algorithm?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are existing classes of run time complexities. Usually, one of these is used to describe an algorithm’s runtime complexity. We will cover the most common ones here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Constant time complexity O(1)&lt;/strong&gt; : An algorithm is said to have a constant  time complexity if the number of steps it takes to complete a task stays the same even with increasing input size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = [1, 2, 3]

first_element = my_list[0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code snippet above, even when the size of the defined list grows, this algorithm will always take one step to complete its task of retrieving the first item in the list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Linear time O(n) :&lt;/strong&gt; For algorithms in this class, the number of steps required to complete a task grows in direct proportion to the input size. If input size = n, then the algorithm will take n steps to complete its task. 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;my_list = [1, 2, 3]

For element in my_list:

    Print(element)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Quadratic time O(n*n):&lt;/strong&gt;  For algorithms in this class, the number of steps required to complete an operation will equal the square of the input size. This is so because it performs a linear time operation on each unit of the input. If input size=x, the algorithm will require x*x steps to complete its operations&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr = [1,2,3]

For x in arr :

    For y in arr :

        print(x, y)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Logarithmic time O(LogN):&lt;/strong&gt;  Algorithms in this class usually take LogN steps to complete their task where N =size of the input and LogN is the number that 2 must be raised to, to give N. For example, if N=16 then Log16=4. As you might have figured out already algorithms in this class are relatively efficient. How do algorithms in this class achieve this efficiency? At each step, they cut down the input size to half of the original size. A classic example of an algorithm that’s in this class is the binary search algorithm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def binary_search(element, arr):

    """ function that searches a 
        sorted list in a binary fashion.
        where element is the search key
        and arr is the list that's to be 
        searched 
    """

    mid_point = len(arr)//2 #floor division

    while True:

        if element == arr[mid_point]:

            print(f"match found at index: {mid_point}")

            break

        elif element &amp;gt; arr[mid_point] and mid_point&amp;gt;0:

            mid_point = len(arr[mid_point: ])//2 + mid_point

            

        elif elem &amp;lt; arr[mid_elem] and mid_elem&amp;gt;0:

            mid_elem = len(arr[:mid_elem])//2

        else:

            print("element not in list")

            break
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Exponential time O(2&lt;/strong&gt;n): ** Algorithms in this class usually take 2 to the power of n steps to complete a task. For algorithms in this class, the number of steps they require to complete a task, doubles with a unit increase in the input size. For example if n = 3 then an algorithm in this class will require 2 to the power of 3 = 8 steps to complete its task. If n increases to 4 then the algorithm will require 2 to the power of 4 = 16 steps. As you can see the number of steps doubles from 8 to 16.&lt;/p&gt;

&lt;p&gt;While the most common time complexities have been covered in this article, the  list here is not exhaustive; there are others. Furthermore,  real life software systems are usually made up of complex algorithms that could in fact be described with two or more classes of run time complexities. In situations like that, always describe your algorithm’s performance in terms of the most complex run time complexity present. &lt;/p&gt;

&lt;p&gt;Stay tuned for my next article on linked lists :)&lt;/p&gt;

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

&lt;p&gt;&lt;a href="http://www.freecodecamp.org/news/time-is-complex-but-priceless-f0abd015063c/"&gt;www.freecodecamp.org/news/time-is-complex-but-priceless-f0abd015063c/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>runtimecomplexity</category>
      <category>bigo</category>
    </item>
    <item>
      <title>I am a Crude Software Engineer</title>
      <dc:creator>Nyior Clement Jr.</dc:creator>
      <pubDate>Sun, 06 Sep 2020 23:04:08 +0000</pubDate>
      <link>https://dev.to/nyior/i-am-a-crude-software-engineer-84d</link>
      <guid>https://dev.to/nyior/i-am-a-crude-software-engineer-84d</guid>
      <description>&lt;p&gt;I have built things for the web and some of these things had really clever algorithms. I have written unit tests. I understand, and have done most of the things in-between building and deploying to a production server( this too included). Did I fail to mention that I’ve also collaborated with other developers using git ? Oh yeah I have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bruh! you are a pro mehn!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I wish... Even though I know I still have a lot to learn, there is one unchecked box that has become my biggest concern lately: I’m yet to master algorithms and data structures. Not mastering algorithms and data structures only means one thing: I’m a crude software engineer .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oh wow! These constructs must be really important in software engineering then&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No! algorithms and data structures aren’t essential components of software engineering; &lt;em&gt;They are software engineering&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I’d love to really ask what makes these constructs so important in software engineering, but I don’t even know what they are to begin with&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A data structure is a particular way of organizing data in a computer. For example, we could organize data in an indexed, ordered structure(lists/arrays). An algorithm on the other hand is any step by step instruction that manipulates some data. For example, when you write a for loop that prints each element in a list/array, that’s an algorithm.&lt;/p&gt;

&lt;p&gt;These constructs are so important in software engineering because they guarantee building efficient software systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I beg your pardon?!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Building efficient software systems entails crafting applications that require the least amount of memory possible and the minimum execution time that’s achievable, to execute tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is this important you ask ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Usually a computer has several applications installed and most times 2 or more running concurrently. This wouldn’t have been a problem if these computers had infinite memory and indescribably fast processor clock speed, but they don’t. Remember, now there is a need for speed(pun intended) every where you go. As a result, if a program requires so much space and takes too long to execute, it will considerably slow down the computer, but most importantly, this will result in a poor user experience. It is imperative that every software engineer builds programs that are highly efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Okay now I think I get the gist, but tbh, I still don’t understand how understanding these constructs will help me write efficient code though&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mastering data structures presupposes understanding the several existing ways data could be organized in a program and by extension the computer(lists, linked-lists, binary trees etc.). Usually, a given data structure is optimized for certain operations. For example, while lists/arrays are optimized for retrieving items based on index, linked lists are optimized for operations like inserting and removing items( something lists/arrays are poor at). There is always the right data structure for your use case. Using the wrong data structure could result in a revoltingly inefficient code.&lt;/p&gt;

&lt;p&gt;Mastering algorithms on the other hand encompasses understanding the several existing ways for efficiently performing some of the most common operations(e.g. searching and sorting) in computer programming. Because some of these algorithms are relatively more efficient, knowing what algorithms exists and their behaviour will enable one use the optimal or near-optimal algorithm in a given scenario. Most times as software engineers, we create our own algorithms; having a strong grasp of these constructs helps us measure the efficiency of our algorithms too.&lt;/p&gt;

&lt;p&gt;So tell me, how can I possibly be a pro when, out of ignorance I’ve probably wrongly used a data structure?  How can I be a pro when out of ignorance I’ve probably written code that searches my sorted python list(probably called arrays in your favourite programming language) in a linear fashion, when there is a more efficient approach called binary search. No! to be a pro I’ve got to understand the art and the technique of software engineering. I need to start writing code that not only does the right thing, but does it well. To achieve this I need to start using correct data structures and highly efficient algorithms. Every software engineer needs to master algorithms and data structures! E get why!&lt;/p&gt;

&lt;p&gt;Interested in understanding how to measure the efficiency of your algorithms? Read my post on &lt;a href="https://dev.to/nyior/you-can-t-improve-what-you-don-t-understand-know-thy-algorithm-s-run-time-complexity-4e4m"&gt;space-time complexity, and the big-o notation&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/data-structures/#"&gt;https://www.geeksforgeeks.org/data-structures/#&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://softwareengineering.stackexchange.com/questions/212575/why-are-algorithms-and-data-structures-important"&gt;https://softwareengineering.stackexchange.com/questions/212575/why-are-algorithms-and-data-structures-important&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>datastructures</category>
    </item>
  </channel>
</rss>
