<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sadick</title>
    <description>The latest articles on Forem by Sadick (@sadick).</description>
    <link>https://forem.com/sadick</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%2F64581%2Fab003e95-d9aa-4abe-9e14-5d05cd7db02a.jpeg</url>
      <title>Forem: Sadick</title>
      <link>https://forem.com/sadick</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sadick"/>
    <language>en</language>
    <item>
      <title>The Only Way to Achieve Continuous Integration.</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Thu, 12 Oct 2023 07:31:00 +0000</pubDate>
      <link>https://forem.com/sadick/the-only-way-to-achieve-continuous-integration-890</link>
      <guid>https://forem.com/sadick/the-only-way-to-achieve-continuous-integration-890</guid>
      <description>&lt;h3&gt;
  
  
  Single Branch.
&lt;/h3&gt;

&lt;p&gt;The only way to achieve continous integration is through &lt;strong&gt;Trunk-Based Development&lt;/strong&gt;. Trunk-based development is based on the idea that there is a single branch i.e &lt;code&gt;main|master|dev|trunk&lt;/code&gt; in which all the developers on your team commit to frequently (at least once everyday).&lt;/p&gt;

&lt;h3&gt;
  
  
  The confusion around continous integration.
&lt;/h3&gt;

&lt;p&gt;I have heard countless times people describe continous integration in terms of tools. They think continous integration is the process of passing code changes through a tool which produces results ✅ at the end of the process. That thinking is even made worse with how some tools name themselves. i.e CircleCI, Gitlab CI e.t.c.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continous integration&lt;/strong&gt; is the act of developers merging their code changes together frequently.&lt;/p&gt;

&lt;h3&gt;
  
  
  The issue with branching.
&lt;/h3&gt;

&lt;p&gt;Most if not all of us are used to branching. Whenever there is a new feature we want to develop, we create a branch for it. If there is a bug, we create a branch to fix the bug. Branching has become part and parcel of our everyday work. We create branches to isolate our changes. But is creating branches the best way to work with your team? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oVMVTzXb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepractising.dev/images/branching.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oVMVTzXb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepractising.dev/images/branching.png" alt="branching" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below are some of the issues I see with branching.&lt;/p&gt;

&lt;h4&gt;
  
  
  Isolated development.
&lt;/h4&gt;

&lt;p&gt;When developers work on different branches they may not always be aware of what the other developers are doing. It is possible that the developers might be changing the same piece of code without them knowing. Distance is created because every developer will only be concerned with the changes they want to bring in therefore forming silos.&lt;/p&gt;

&lt;p&gt;Working in this way means developers hide changes from each other untill they are ready to show them. As developers we should be embracing change not hiding it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Complexity of conflicts.
&lt;/h4&gt;

&lt;p&gt;As the number of branches and the complexity of the codebase increase, so does the likelihood of conflicts. Complex conflicts can be challenging to resolve because they may involve changes in multiple files or dependencies. I know you have experienced this at least a couple times and its not fun to deal with. I have never met a developer who likes to resolve conflicts.&lt;/p&gt;

&lt;p&gt;Developers working in isolation on their branches may miss opportunities for collaboration and sharing of ideas, leading to missed improvements and innovation. The lack of collaboration inhibits collective ownership of the code. No developer feels its their responsibilty to make sure the code is stable and easy to work with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementing Trunk-Based Development.
&lt;/h3&gt;

&lt;p&gt;Have single branch, where your teams commit to thats it. But this creates other issues like,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How handle code reviews.&lt;/li&gt;
&lt;li&gt;What about big features?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Blindly implementing single branch for all your teams' work leads to alot of chaos. For trunk-based development to be successfull there are a couple of guidelines that you can follow.&lt;/p&gt;

&lt;h4&gt;
  
  
  Small changes.
&lt;/h4&gt;

&lt;p&gt;Every commit should be small, buildable and testable. The smaller the change between two working states the easier it is to find and fix any issue introduced by that change.&lt;br&gt;
How small is small? A small commit is a commit that addresses a single task or issue and makes a meaningful change to the codebase.&lt;/p&gt;

&lt;h4&gt;
  
  
  Frequent commits.
&lt;/h4&gt;

&lt;p&gt;You and your team need to commit frequently and push the commits. This ensures faster integration with everyone elses code. Frequent commits also reduces the likelyhood of hard to resolve merge conflicts. When you and your team are pushing regularly, it gives your team a change to see each others work, which encourages collaboration.&lt;/p&gt;

&lt;h4&gt;
  
  
  Keep the pipeline green.
&lt;/h4&gt;

&lt;p&gt;If for some reason the build is broken, then your team should drop everything they are doing to fix the build. This will ensure no problematic change makes it to production. Also your team should make it a habit to test and build on their own machines before pushing it to the build pipeline. 😉&lt;/p&gt;

&lt;h4&gt;
  
  
  Keep your builds fast ⚡
&lt;/h4&gt;

&lt;p&gt;When you are making small commits, you wouldn't want to be slowed by the build speed. You should strive to bring your build speed down to seconds. You could use strategies like cached builds or incremental builds to improve the speed of your builds.&lt;/p&gt;

&lt;p&gt;All the above guidelines are good, but still doesn't answer the questions like, code reviews and big features.&lt;/p&gt;

&lt;h3&gt;
  
  
  How handle code reviews.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You could review code after the integration after a section of code has received significant changes.&lt;/li&gt;
&lt;li&gt;You could introduce pair programming, were two people would work on a feature together. Since their is an extra eye on your work most issues will be caught by your programming pair. You could consider the commit you made reviewed when working with another person on a problem.&lt;/li&gt;
&lt;li&gt;If you are adventurous you could even try Mob programming. That is where you have more than 2 people working on a task. Mob programming is very effective when it comes to knowledge sharing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Handling big features.
&lt;/h3&gt;

&lt;p&gt;Since you will be doing small, single focused commits frequently, there is no way you will fit a big feature into a single commit. You will likely make more commits before a feature is considered done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One way to handle this is through feature flags&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lcrxe3Bg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepractising.dev/images/feature-flags.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lcrxe3Bg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepractising.dev/images/feature-flags.jpg" alt="feature-flags" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You would start by creating a feature flag for the feature you are working on and keeping it turned off. Once you complete all the work neccessary for the feature you would turn the feature on. After some monitoring, if you are convinced that the feature is working as intented in production, you will need to delete the feature flags from your code and the platform you use to manage the feature flags.&lt;/p&gt;

&lt;p&gt;Even if you are not ready to adopt trunk-based development, at least keep your commits small and focused on a single well defined task.✌️ &lt;/p&gt;

</description>
      <category>ci</category>
      <category>devops</category>
      <category>cd</category>
    </item>
    <item>
      <title>Being a good programmer is 3% talent and 97% not being distracted by the internet.</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Wed, 12 Aug 2020 04:25:08 +0000</pubDate>
      <link>https://forem.com/sadick/being-a-good-programmer-is-3-talent-and-97-not-being-distracted-by-the-internet-44j4</link>
      <guid>https://forem.com/sadick/being-a-good-programmer-is-3-talent-and-97-not-being-distracted-by-the-internet-44j4</guid>
      <description>

</description>
    </item>
    <item>
      <title>Mental Models: Array Indexing</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Thu, 07 May 2020 05:00:08 +0000</pubDate>
      <link>https://forem.com/sadick/mental-models-array-indexing-19o1</link>
      <guid>https://forem.com/sadick/mental-models-array-indexing-19o1</guid>
      <description>&lt;p&gt;Having arrays start at index zero is somewhat confusing at first. Naturally we start counting things from one. We see zero as representing nothing.&lt;/p&gt;

&lt;p&gt;The confusion comes from thinking of the index as an ordinal number. An ordinal number defines the position of something in a series i.e. &lt;code&gt;first&lt;/code&gt;, &lt;code&gt;second&lt;/code&gt;, &lt;code&gt;third&lt;/code&gt; e.t.c. This logically means we can't have an item occupying position zero in a series. If we think of the index as an ordinal number, the first element would be at &lt;code&gt;e[1]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your thinking should shift from thinking of index as an ordinal number. You should be thinking of the index as an offset from a starting point. From this thinking the first element would be a distance of zero from the beginning, hence &lt;code&gt;e[0]&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>dev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Universal next gen css-in-js library in under 1kb</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Tue, 18 Sep 2018 11:46:38 +0000</pubDate>
      <link>https://forem.com/sadick/universal-css-in-js-library-in-under-1kb-2p58</link>
      <guid>https://forem.com/sadick/universal-css-in-js-library-in-under-1kb-2p58</guid>
      <description>&lt;h1&gt;
  
  
  Introducing &lt;code&gt;scoped-style&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Scoped style aims to be a universal library that you can use to style your components while still maintaining a small footprint.&lt;/p&gt;

&lt;p&gt;It has currently been tested with react, preact and hyperapp. You can use the full power of css just as you are used to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add scoped-style
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scoped-style&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;// for react&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="c1"&gt;// for Preact&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;preact&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="c1"&gt;// for Hyperapp&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyperapp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;`
  background: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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="s2"&gt;gray&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  border: none;
  border-radius: 2px;
  :hover {
    padding: 10px;
  }
`&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&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="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Login&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&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="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Your rendering code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project is on &lt;a href="https://github.com/sadick254/scoped-css"&gt;github&lt;/a&gt;. Contributions are highly welcomed.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>Hot reloading preact with parcel, the missing doc</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Tue, 11 Sep 2018 14:10:27 +0000</pubDate>
      <link>https://forem.com/sadick/hot-reloading-preact-with-parcel-the-missing-doc-2j10</link>
      <guid>https://forem.com/sadick/hot-reloading-preact-with-parcel-the-missing-doc-2j10</guid>
      <description>&lt;p&gt;Today I was setting up a &lt;a href="https://preactjs.com/" rel="noopener noreferrer"&gt;preact&lt;/a&gt; app with &lt;a href="https://parceljs.org" rel="noopener noreferrer"&gt;parcel&lt;/a&gt; as the bundler. Before I could even start building the app, I suddenly hit a snag. Whenever I made a change to my components, my changes were being appended to the html doc instead of being replaced.&lt;/p&gt;

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

&lt;p&gt;It turns out parcel is not the issue, preact is. I went to their &lt;a href="https://preactjs.com/guide/differences-to-react#what-s-different-" rel="noopener noreferrer"&gt;docs&lt;/a&gt; as any developer would. I found out their their render by default appends to the node specified. The preact render function accepts a third argument which is supposed to be the node to be replaced.&lt;/p&gt;

&lt;p&gt;So to fix the appending problem, I needed to provide the third agrument.&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;preact&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Happy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&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;Happy&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&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="nc"&gt;Happy&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;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastChild&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now it behaves as expected. Maybe parcel should update their docs to include this. I wanted to make a pull request but their docs are not on github.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75yinquocorr4r439f5w.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75yinquocorr4r439f5w.gif" width="1345" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>parceljs</category>
      <category>beginners</category>
      <category>preact</category>
    </item>
    <item>
      <title>You don't need express to get started with socket.io</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Wed, 08 Aug 2018 06:55:10 +0000</pubDate>
      <link>https://forem.com/sadick/you-dont-need-express-to-get-started-with-socketio-4ieg</link>
      <guid>https://forem.com/sadick/you-dont-need-express-to-get-started-with-socketio-4ieg</guid>
      <description>

&lt;p&gt;The best place to get started with socket.io is their website. But once you access it you are given this example app demonstrating how to use socket.io.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'express'&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'http'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'socket.io'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sendFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'/index.html'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'connection'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a user connected'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'listening on *:3000'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are fairly new to node, this makes you think that express is needed in order to use socket.io. In the above example they include express to serve the index file which will be client app for your socket server. There is nothing wrong with the above approach but if lets say you don't know express, now you have one more thing to learn before using socket.io.&lt;/p&gt;

&lt;p&gt;It would be better if they didn't introduce an additional library in their example. Socket.io has another example using the node http server&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'http'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'socket.io'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'fs'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'/index.html'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Error loading index.html'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;end&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="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'connection'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'news'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'world'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'my other event'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But even this is a little bit too much. I prefer having the server and the client seperate. Therefore this would be my server.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"socket.io"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"user connected"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"welcome"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"welcome man"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And the client would include the socket.io client library and just plain html.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Socket io client&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"http://localhost:3000/socket.io/socket.io.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// use your socket&lt;/span&gt;
            &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"welcome"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// do something with the message.&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




</description>
      <category>javascript</category>
      <category>node</category>
      <category>beginners</category>
      <category>socketio</category>
    </item>
    <item>
      <title>How do you measure developer productivity in your team?</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Tue, 24 Jul 2018 16:11:48 +0000</pubDate>
      <link>https://forem.com/sadick/how-do-you-measure-developer-productivity-in-your-team-3jnh</link>
      <guid>https://forem.com/sadick/how-do-you-measure-developer-productivity-in-your-team-3jnh</guid>
      <description></description>
      <category>discuss</category>
    </item>
    <item>
      <title>139 Traits That Make A Better Programmer</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Mon, 23 Jul 2018 14:16:01 +0000</pubDate>
      <link>https://forem.com/sadick/139-traits-that-make-a-better-programmer-16fn</link>
      <guid>https://forem.com/sadick/139-traits-that-make-a-better-programmer-16fn</guid>
      <description>

&lt;p&gt;Lets face it, every developer wants to improve and become better. The big question that most developers ask is how will I do it. Here are a list of things you should keep in mind while programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Presentation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;As any discussion about code layout grows, the probability of it descending into a fruitless argument approaches one. You know the tabs vs spaces, bracket placement weather on new line or the same line.&lt;/li&gt;
&lt;li&gt;A good code format is not the one you think looks prettiest. A good format is the one that makes it easier to scan and read the code.&lt;/li&gt;
&lt;li&gt;Good code presentation reveals your code’s intent. It is not an artistic endeavor.&lt;/li&gt;
&lt;li&gt;We need good presentation to avoid making code errors. Not so we can create pretty ASCII art.&lt;/li&gt;
&lt;li&gt;We write code to be executed by a computer, but to be read by humans.&lt;/li&gt;
&lt;li&gt;If any man wishes to write a clear style, let him first be clear in his thoughts.&lt;/li&gt;
&lt;li&gt;Pick one layout style and use it consistently or adopt coding standard or style guide.&lt;/li&gt;
&lt;li&gt;If you’re working in a file that doesn’t follow the layout conventions of the rest of your project, follow the layout conventions in that file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Naming
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A good name is descriptive, correct, and idiomatic.&lt;/li&gt;
&lt;li&gt;You can only name something well if you know exactly what it is. Make sure you know what it is before giving cryptic names to variables.&lt;/li&gt;
&lt;li&gt;Avoid redundancy. It shows you didn’t think through the naming of what you are building. Be it a class or function or variables&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ItemList&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;numberOfItems&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// numberOfItems is unnecessarily long, repeating the word Item&lt;/span&gt;
&lt;span class="c1"&gt;// it could be renamed to size or even length&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Employ the capitalization conventions most often used in your language. Like in C# methods are capitalized Console.WriteLine("Hello World")&lt;/li&gt;
&lt;li&gt;Ensure that your names are accurate and avoid spelling mistakes.&lt;/li&gt;
&lt;li&gt;Never alter presentation and behavior at the same time. Make them separate version-controlled changes.&lt;/li&gt;
&lt;li&gt;Adapt your presentation style as you gain experience. As a beginner you don’t always start out with good code presentation, your are more concerned about whether the program works or not.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Write Less Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Writing lots of code does not mean that you’ve written lots of software. It may just mean you are written lots of bugs.&lt;/li&gt;
&lt;li&gt;More code means there is more to read and more to understand — it makes our programs harder to comprehend.&lt;/li&gt;
&lt;li&gt;The more code you have, the more places there are for bugs to hide and tracking them down may not be that easy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Avoid Unnecessary Code
&lt;/h3&gt;

&lt;p&gt;Common class of pointless code is the unnecessary use of conditional statements and tautological logic constructs. Flappy logic is the sign of a flappy mind.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// example&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expresion&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// which can be refactored to&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;expresion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Express code clearly and succinctly. Avoid unnecessarily long winded statements. They don’t add any value to your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Duplication
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Do not copy code sections. Factor them into a common function. Use parameters to express any differences.&lt;/li&gt;
&lt;li&gt;If you spot duplication, remove it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dead Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Dead code is code that is never run, that can never be reached.&lt;/li&gt;
&lt;li&gt;Tell your code to get a life, or get lost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Other manifestations of dead code include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions that are never called&lt;/li&gt;
&lt;li&gt;Variables that are written but never read&lt;/li&gt;
&lt;li&gt;Parameters passed to an internal method that are never used&lt;/li&gt;
&lt;li&gt;Enums, structs, classes, or interfaces that are never used&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Comments
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Good code does not need reams of comments to prop it up, or to explain how it works.&lt;/li&gt;
&lt;li&gt;Make sure that every comment adds value to the code. The code itself says what and how. A comment should explain why — but only if it’s not already clear.&lt;/li&gt;
&lt;li&gt;Do not remove code by commenting it out. It confuses the reader and gets in the way.&lt;/li&gt;
&lt;li&gt;Every day, leave your code a little better than it was. Remove redundancy and duplication as you find it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Improve Code by Removing It
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You can improve a system by adding new code. You can also improve a system by removing code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How dead code spring up during development&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Features are removed from an application’s user interface, but the backend support code is left in.&lt;/li&gt;
&lt;li&gt;Wizard-generated UI code inserts hooks that are frequently never used.&lt;/li&gt;
&lt;li&gt;Remove dead code wherever possible. It gets in the way and slows you down.&lt;/li&gt;
&lt;li&gt;It is safe to remove code that you might need in the future. You can always get it back from version control.&lt;/li&gt;
&lt;li&gt;Code cleanup should always be made in separate commits to functional changes.&lt;/li&gt;
&lt;li&gt;Dead code happens in even the best codebases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Be wary of the Past
&lt;/h3&gt;

&lt;p&gt;You thought it was perfect when you wrote it, but cast a critical eye over your old code and you’ll inevitably bring to light all manner of code gotchas.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Looking back at your older code will inform you about the improvement (or otherwise) in your coding skills.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to go about an existing codebase
&lt;/h3&gt;

&lt;p&gt;Coming into any large existing codebase is hard. You have to rapidly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discover where to start looking at the code&lt;/li&gt;
&lt;li&gt;Work out what each section of the code does, and how it achieves it&lt;/li&gt;
&lt;li&gt;Gauge the quality of the code&lt;/li&gt;
&lt;li&gt;Work out how to navigate around the system&lt;/li&gt;
&lt;li&gt;Understand the coding idioms, so your changes will fit in sympathetically&lt;/li&gt;
&lt;li&gt;Find the likely location of any functionality (and the consequent bugs caused by it)&lt;/li&gt;
&lt;li&gt;Your best route into code is to be led by someone who already knows the terrain. Don’t be afraid to ask for help!&lt;/li&gt;
&lt;li&gt;The best way to learn code is to modify it. Then learn from your mistakes.&lt;/li&gt;
&lt;li&gt;Many programmers, rather than putting in the effort to read and understand existing code, prefer to say “it’s ugly” and rewrite it.&lt;/li&gt;
&lt;li&gt;Be prepared to encounter bad code. Fill your toolbox with sharp tools to deal with it.&lt;/li&gt;
&lt;li&gt;Some filthy code was simply written by a less capable programmer. Or by a capable programmer on a bad day.&lt;/li&gt;
&lt;li&gt;Silence the feeling of revulsion when you encounter “bad” code. Instead, look for ways to practically improve it.&lt;/li&gt;
&lt;li&gt;You can’t expect any code, even your own, to be perfect.&lt;/li&gt;
&lt;li&gt;Follow the Boy Scout Rule. Whenever you touch some code leave it better than you found it.&lt;/li&gt;
&lt;li&gt;Make code changes slowly, and carefully. Make one change at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dealing with Errors
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Do not ignore possible errors in your code. Don’t put off handling errors until “later” (you won’t get around to it).&lt;/li&gt;
&lt;li&gt;Use exceptions well, with discipline. Understand your language’s idioms and requirements for effective exception use.&lt;/li&gt;
&lt;li&gt;Programmers must be made aware of programmatic errors. Users must be made aware of usage errors.&lt;/li&gt;
&lt;li&gt;It’s not good enough to log the error (somewhere), and hope that a diligent operator will notice an error and do something about it one day.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Be prepared for the Unexpected
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;At every step, consider all of the unusual things that might occur, no matter how unlikely you think they’ll be.&lt;/li&gt;
&lt;li&gt;Always consider errors that you can recover from, and write appropriate recovery code.&lt;/li&gt;
&lt;li&gt;Ensure that your error handling is idiomatic, and uses the appropriate language mechanisms.&lt;/li&gt;
&lt;li&gt;Consider all potential code paths as you write your code. Do not plan to handle “unusual” cases later: you’ll forget and your code will be buggy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bug Hunting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Programmers write code. Programmers aren’t perfect. The programmer’s code isn’t perfect. It therefore doesn’t work perfectly the first time. So we have bugs.&lt;/li&gt;
&lt;li&gt;We should always employ sound engineering techniques that minimize the likelihood of unpleasant surprises.&lt;/li&gt;
&lt;li&gt;Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.&lt;/li&gt;
&lt;li&gt;Reduce bugs to the simplest set of &lt;strong&gt;&lt;em&gt;reproduction&lt;/em&gt;&lt;/strong&gt; steps possible.&lt;/li&gt;
&lt;li&gt;Ensure that you are focusing on a single problem.&lt;/li&gt;
&lt;li&gt;Assertions and logging (even the humble console.log and nodejs assert) are potent debugging tools. Use them often.&lt;/li&gt;
&lt;li&gt;Binary chop problem spaces to get results faster.&lt;/li&gt;
&lt;li&gt;As you develop your software, invest time to write a suite of unit tests.&lt;/li&gt;
&lt;li&gt;Untested code is a breeding ground for bugs. Tests are your bleach.&lt;/li&gt;
&lt;li&gt;Learn how to use your debugger well. Then use it at the right times.&lt;/li&gt;
&lt;li&gt;Fix bugs as soon as you can. Don’t let them pile up until you’re stuck in a code cesspit.&lt;/li&gt;
&lt;li&gt;Debugging isn’t easy. But it’s our own fault. We wrote the bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Always test your code
&lt;/h3&gt;

&lt;p&gt;Unit tests specifically exercise the smallest “units” of functionality in isolation, to ensure that they each function correctly. This isolation specifically means that a unit test will not involve any external access: no database, network, or file system operations will be run.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quality is free, but only to those who are willing to pay heavily for it.&lt;/li&gt;
&lt;li&gt;To improve our software development we need rapid feedback, to learn of problems as soon as they appear. Good testing strategies provide short feedback loops.&lt;/li&gt;
&lt;li&gt;Write tests as you write the code under test. Do not postpone test writing, or your tests will not be as effective.&lt;/li&gt;
&lt;li&gt;All tests should run on your build server as part of a continuous integration tool chain.&lt;/li&gt;
&lt;li&gt;Test whatever is important in your application.&lt;/li&gt;
&lt;li&gt;Global variables and singleton objects are anathema to reliable testing. You can’t easily test a unit with hidden dependencies.&lt;/li&gt;
&lt;li&gt;Factoring your code to make it “testable” leads to better code design.&lt;/li&gt;
&lt;li&gt;Program testing can be used to show the presence of bugs, but never to show their absence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to deal with complexity
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better.&lt;/li&gt;
&lt;li&gt;Complexity is generally accidental, rarely something someone adds willfully.&lt;/li&gt;
&lt;li&gt;Defer design decisions until you have to take them. Don’t make architectural decisions when you don’t know the requirements yet. Don’t guess.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Practice Makes Perfect
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A programmer needs good taste and a sense of aesthetics to write exceptional code.&lt;/li&gt;
&lt;li&gt;Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.&lt;/li&gt;
&lt;li&gt;Good software development is not cowboy coding, throwing down the first code you can think of. It is a deliberate, considered, accurate endeavor.&lt;/li&gt;
&lt;li&gt;Good programmers work with humility. They admit that they don’t know it all.&lt;/li&gt;
&lt;li&gt;Good code and good coders are born from a desire to write the right thing in the right way.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Be a team player
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Programming teams have a set of rules. These rules define what we do and how we do it. But they also describe a coding culture.&lt;/li&gt;
&lt;li&gt;Don’t rely on vague unwritten team “rules.” Make the implicit rules explicit, and take control of your coding culture.&lt;/li&gt;
&lt;li&gt;Apply bug fixes to the root cause, not where symptoms manifest. Sticking plaster symptom-fixes do not lead to simple code.&lt;/li&gt;
&lt;li&gt;Avoid implicit assumptions in your code.&lt;/li&gt;
&lt;li&gt;Only write as much code as is needed. Anything extra is complexity that will become a burden.&lt;/li&gt;
&lt;li&gt;Stop and think. Don’t write stupid code.&lt;/li&gt;
&lt;li&gt;Admit to your mistakes and bad coding decisions. Learn from them.&lt;/li&gt;
&lt;li&gt;Have the courage to use your brain. Feel empowered to critique code and make decisions about how to improve it.&lt;/li&gt;
&lt;li&gt;Learn what makes software easy to change, and strive to craft software with these attributes.&lt;/li&gt;
&lt;li&gt;To modify code you need courage and skill. Not recklessness.&lt;/li&gt;
&lt;li&gt;Often it is best to make a series of frequent, small, verifiable adjustments, rather than one large sweeping code change.&lt;/li&gt;
&lt;li&gt;Avoid copy-and-paste coding. Factor your logic into shared functions and common libraries, rather than suffer duplicated code (and duplicated bugs).&lt;/li&gt;
&lt;li&gt;Write small, modular sections of code. Keep it clean and neat.&lt;/li&gt;
&lt;li&gt;Code should be “shared” because it is useful to multiple clients, not because the developers want to create a nifty shared library.&lt;/li&gt;
&lt;li&gt;Don’t dismiss other people’s code. It may be better to use existing libraries rather than write your own version.&lt;/li&gt;
&lt;li&gt;Creating software releases requires discipline and planning. It is more than hitting “build” in a developer’s IDE.&lt;/li&gt;
&lt;li&gt;Always build your software in a fresh checkout, from scratch. Never reuse old parts of a software build.&lt;/li&gt;
&lt;li&gt;Make your build as simple as a single step that automates all parts of the process. Use a scripting language to do this.&lt;/li&gt;
&lt;li&gt;Deploy your builds on a CI server to ensure their health. Make formal releases from the same system.&lt;/li&gt;
&lt;li&gt;Be in a state of continual learning. Always look to learn something new.&lt;/li&gt;
&lt;li&gt;Our learning is often too narrowly focused. Consider a wider sphere of reference. Draw inspiration from many fields.&lt;/li&gt;
&lt;li&gt;Takes notes as you learn. Even if you throw them away.&lt;/li&gt;
&lt;li&gt;If you can’t explain it simply, you don’t understand it well enough.&lt;/li&gt;
&lt;li&gt;Teach a topic to learn that topic well.&lt;/li&gt;
&lt;li&gt;I hear and I forget. I see and I remember. I do and I understand.&lt;/li&gt;
&lt;li&gt;Using what you just learned cements it in your memory. Try examples, answer questions, create pet projects.&lt;/li&gt;
&lt;li&gt;Be wary of stagnation. Seeking to become a better programmer, by definition, is not the most comfortable lifestyle.&lt;/li&gt;
&lt;li&gt;Expect to invest time and effort to grow your skill set. This is a worthwhile investment; it will repay itself.&lt;/li&gt;
&lt;li&gt;Do not make yourself “indispensable” by writing unreadable or unnecessary “clever” code.&lt;/li&gt;
&lt;li&gt;Honour software licenses.&lt;/li&gt;
&lt;li&gt;Don’t become a one-trick pony. Position yourself to face new challenges, learn, and grow as a developer.&lt;/li&gt;
&lt;li&gt;Love All Languages&lt;/li&gt;
&lt;li&gt;Learn languages that follow different idioms and paradigms.&lt;/li&gt;
&lt;li&gt;Consider also learning some “dead” languages that are no longer commonly used, to understand the history of your craft.&lt;/li&gt;
&lt;li&gt;A good programmer knows many languages, and multiple idioms, broadening their palette of solutions. It improves the code they write.&lt;/li&gt;
&lt;li&gt;Working with your programming language is a relationship you have to work at each day.&lt;/li&gt;
&lt;li&gt;To write the best code in a language, you should commit to its styles and idioms rather than force your own upon it.&lt;/li&gt;
&lt;li&gt;Good programmers are good communicators. They talk, write, code, listen, and read well.&lt;/li&gt;
&lt;li&gt;Don’t expect to become a language master overnight, and don’t get frustrated whilst you work at it.&lt;/li&gt;
&lt;li&gt;Concentrate effort on the most important things first. What is most urgent, or will produce the most value?&lt;/li&gt;
&lt;li&gt;If you do something often, make the computer do it for you. Automate it with a script.&lt;/li&gt;
&lt;li&gt;Split large tasks up into a series of smaller, well-understood tasks. You will be able to judge progress through these more accurately.&lt;/li&gt;
&lt;li&gt;Make sure you define “done.”&lt;/li&gt;
&lt;li&gt;If you can’t tell when it’s done, then you shouldn’t start it.&lt;/li&gt;
&lt;li&gt;Use tests written in code to define when your code is complete and working.&lt;/li&gt;
&lt;li&gt;Don’t do more work than necessary. Work until you’re “done.” Then stop.&lt;/li&gt;
&lt;li&gt;When facing a problem, make sure you’ve considered more than one approach to solve it. Only then should you start working on it.&lt;/li&gt;
&lt;li&gt;Purposefully place yourself beside excellent programmers.&lt;/li&gt;
&lt;li&gt;More comments do not necessarily make your code better. Communicative code does not need extra commentary to prop it up.&lt;/li&gt;
&lt;li&gt;Learn about development methodologies, trends, manifestos, and fads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;If you found this post helpful, please share it so that others can find it. You can follow me on&lt;/em&gt; &lt;a href="https://github.com/sadick254"&gt;&lt;em&gt;GitHub&lt;/em&gt;&lt;/a&gt; &lt;em&gt;and&lt;/em&gt; &lt;a href="https://www.linkedin.com/in/isaac-odhiambo-678b1547/"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. If you have any ideas and improvements feel free to share them with me.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;_Happy coding! _💪&lt;/p&gt;

&lt;p&gt;&lt;a href="https://goo.gl/w4Pbea"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EiHH_kD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/700/1%2APZjwR1Nbluff5IMI6Y1T6g%402x.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;





</description>
      <category>programming</category>
      <category>whatmakesaprogram</category>
      <category>softwaredevelopment</category>
      <category>programmer</category>
    </item>
    <item>
      <title>Programming revolves around these 3 things</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Tue, 17 Jul 2018 06:30:01 +0000</pubDate>
      <link>https://forem.com/sadick/programming-revolves-around-this-3-things-3a9h</link>
      <guid>https://forem.com/sadick/programming-revolves-around-this-3-things-3a9h</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1527427337751-fdca2f128ce5%3Fixlib%3Drb-0.3.5%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26s%3D7f0965bc37ef09044780baa8af91e2b3%26auto%3Dformat%26fit%3Dcrop%26w%3D750%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1527427337751-fdca2f128ce5%3Fixlib%3Drb-0.3.5%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26s%3D7f0965bc37ef09044780baa8af91e2b3%26auto%3Dformat%26fit%3Dcrop%26w%3D750%26q%3D80" alt="Photo by Christopher Robin Ebbinghaus on Unsplash"&gt;&lt;/a&gt;&lt;br&gt;
When you think about programming you often feel that there is a lot more in that space. But if you look at it carefully programming revolves around these 3 things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Input
&lt;/h3&gt;

&lt;p&gt;Input involves getting data from some source. It might sensors, keyboard or any source. You might have a program that gets user input via a keyboard and another one that gets data via a file or URL. For your program to be useful you must provide it some data to work on (from any source).&lt;/p&gt;

&lt;h3&gt;
  
  
  Processing
&lt;/h3&gt;

&lt;p&gt;Once data is in your program you have to process it in a meaningful way to solve your problem. The processing may involve, doing some arithmetic, making decisions based on certain conditions and looping through some things and performing actions on them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;After the processing on the data you expect your program to give you some kind of feedback. That feedback is what output is. It might give the feedback by displaying something on your monitor or by performing another visible action like maybe shutting down a computer or moving the arm of a robot.The feedback you get is dependent on what you want to achieve.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programmer</category>
    </item>
    <item>
      <title>A javascript story</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Mon, 09 Jul 2018 05:24:37 +0000</pubDate>
      <link>https://forem.com/sadick/a-javascript-story-1anm</link>
      <guid>https://forem.com/sadick/a-javascript-story-1anm</guid>
      <description>&lt;p&gt;Five modern javascript developers were locked in a room and told to build a single page web app without using any framework. We don't know what happened but when we came back they were long gone.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Building deploy ready PHP apps</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Sun, 08 Jul 2018 12:15:18 +0000</pubDate>
      <link>https://forem.com/sadick/building-deploy-ready-php-apps-1kfm</link>
      <guid>https://forem.com/sadick/building-deploy-ready-php-apps-1kfm</guid>
      <description>&lt;p&gt;&lt;strong&gt;What does deploy ready even mean.&lt;/strong&gt;&lt;br&gt;
It means that your application should be able to be deployed in any environment without changing the application code.&lt;/p&gt;

&lt;p&gt;To make sure your application is deploy ready, things that can change between deploys(staging, alpha or production) should not be hard coded in your app.&lt;/p&gt;

&lt;p&gt;I know you have come across or even written code like the one below while trying to make a database connection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$pdo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mysql:host=&lt;/span&gt;&lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="s2"&gt;;dbname=myDB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$pdo&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="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"root"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two things wrong with the above approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are hard-coding and exposing your database login credentials, which is just insecure&lt;/li&gt;
&lt;li&gt;When you deploy your app to other environments you have to edit the connection code so that connection doesn't fail (unless that environment has the exact config)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To remedy the above code, you need a way to supply the credentials without hard coding them. This is achievable by using environment variables.&lt;br&gt;
An &lt;a href="https://en.wikipedia.org/wiki/Environment_variable"&gt;environment variable&lt;/a&gt; is a dynamic-named value that can affect the way running processes will behave on a computer. In your case the dynamic value would be &lt;code&gt;database username, address, password&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting the environment variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you own the server you will be deploying to you can set the environment variables as  below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On windows server&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setx DB_NAME test
setx DB_HOST localhost
setx DB_PASSWORD password

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;On ubuntu server&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a terminal (by pressing CtrlAltT)&lt;/li&gt;
&lt;li&gt;sudo -H gedit /etc/environment&lt;/li&gt;
&lt;li&gt;Type your password&lt;/li&gt;
&lt;li&gt;Edit the text file just opened:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DB_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test
&lt;/span&gt;&lt;span class="nv"&gt;DB_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;localhost
&lt;span class="nv"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Save, then logout and log back in for the changes to take effect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Having set the environment variables you can now change your code to use the variables instead of hard coding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_USER'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HOST'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For those using a shared server with Apache. You will need to have an &lt;code&gt;.htaccess&lt;/code&gt; file on the root folder. Normally &lt;code&gt;public_html&lt;/code&gt;.&lt;br&gt;
To set the environment variables, add the following into the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;SetEnv&lt;/span&gt; &lt;span class="n"&gt;DB_USER&lt;/span&gt; &lt;span class="n"&gt;your_production_db_user&lt;/span&gt;
&lt;span class="n"&gt;SetEnv&lt;/span&gt; &lt;span class="n"&gt;DB_PASSWORD&lt;/span&gt; &lt;span class="n"&gt;your_production_db_password&lt;/span&gt;
&lt;span class="n"&gt;SetEnv&lt;/span&gt; &lt;span class="n"&gt;DB_NAME&lt;/span&gt; &lt;span class="n"&gt;your_prodution_db_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the variables to the server. This has one drawback since &lt;code&gt;getenv()&lt;/code&gt; only gets system environment variables. To remedy this you can merge both &lt;code&gt;getenv()&lt;/code&gt; and &lt;code&gt;$_SERVER&lt;/code&gt; to one array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I try as much as possible to avoid setting environment variables on my development machine, coz i just have so much going on on my machine. I What i normally do is have defaults in case the environment variable are not found on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_USER'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HOST'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'locahost'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that you have done that deploying comes very easy as you don't have to change anything in your code to make connection to a database. And you are also not exposing your database credentials.&lt;/p&gt;

</description>
      <category>php</category>
      <category>deploy</category>
      <category>showdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The not so secret life of Provider in Redux</title>
      <dc:creator>Sadick</dc:creator>
      <pubDate>Mon, 02 Jul 2018 12:50:17 +0000</pubDate>
      <link>https://forem.com/sadick/the-not-so-secret-life-of-provider-in-redux-59k4</link>
      <guid>https://forem.com/sadick/the-not-so-secret-life-of-provider-in-redux-59k4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.valentinog.com%2Fblog%2Fwp-content%2Fuploads%2F2017%2F12%2Fredux-react-tutorial-beginner-2018.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.valentinog.com%2Fblog%2Fwp-content%2Fuploads%2F2017%2F12%2Fredux-react-tutorial-beginner-2018.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have always asked myself what the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; does and why it is a neccessity while using redux.&lt;br&gt;
How does react-redux make it possible for me to access my store objects.&lt;/p&gt;

&lt;p&gt;My inquisitive nature led me to the react redux codebase. I expected to find a large compilcated &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; component, but to my suprise that wasn't the case.&lt;/p&gt;

&lt;p&gt;I have ommited some code for readability sake.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prop-types&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;getChildContext&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;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;render&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&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;Provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;childContextTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is the Provider doing
&lt;/h2&gt;

&lt;p&gt;Provider makes use react's context api. Context provides a way to pass data through the component tree without having to pass props down manually at every level.&lt;/p&gt;

&lt;p&gt;The provider makes &lt;code&gt;store&lt;/code&gt; accessible to its child components via the &lt;code&gt;getChildContext&lt;/code&gt; method. Therefore its children can access the &lt;code&gt;store&lt;/code&gt; with &lt;code&gt;props.context.store&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;Child&lt;/code&gt; can have access to the store without us passing it down explicitly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Provider&lt;/span&gt; &lt;span class="na"&gt;store=&lt;/span&gt;&lt;span class="s"&gt;{store}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;Child/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Provider&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also note the &lt;code&gt;childContextTypes&lt;/code&gt; that is defined on the provider class. This is needed so that react can know the shape of data we are sharing via the context.&lt;/p&gt;

&lt;p&gt;This is how the react-redux &lt;code&gt;connect&lt;/code&gt; function is able to get our store objects. Below is a simplified version of the connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&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="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nf"&gt;render&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;contextTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;App&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javscript</category>
      <category>react</category>
      <category>redux</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
