<?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: Michael Knepprath</title>
    <description>The latest articles on DEV Community by Michael Knepprath (@mknepprath).</description>
    <link>https://dev.to/mknepprath</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%2F198868%2F799e2e2b-c4f0-456e-9fba-264ae6d9d1cb.jpg</url>
      <title>DEV Community: Michael Knepprath</title>
      <link>https://dev.to/mknepprath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mknepprath"/>
    <language>en</language>
    <item>
      <title>Code Should Breathe</title>
      <dc:creator>Michael Knepprath</dc:creator>
      <pubDate>Wed, 07 Aug 2019 11:28:50 +0000</pubDate>
      <link>https://dev.to/mknepprath/code-should-breathe-336k</link>
      <guid>https://dev.to/mknepprath/code-should-breathe-336k</guid>
      <description>&lt;p&gt;&lt;em&gt;Note: This is my opinion. If you have thoughts or concerns, that's fine - feel free to &lt;a href="https://twitter.com/mknepprath"&gt;message me&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In programming, there can be an obsession with brevity, compactness and cleverness (i.e. magic). How much can I do in one line? How few lines can I have in my component? How much can I abbreviate my variable names? All of this leads to the code equivalent of hyperventilation.&lt;/p&gt;

&lt;p&gt;What if we let our code breathe a little? "Breathing room" here is defined as extra lines and empty space within code. Here are a couple ways this can be accomplished.&lt;/p&gt;

&lt;h1&gt;
  
  
  Use Blank Lines To Create Sections
&lt;/h1&gt;

&lt;p&gt;A List Apart had a great article about the use of whitespace in web design entitled simply, Whitespace. This piece refers to a concept called &lt;strong&gt;active whitespace&lt;/strong&gt;, "whitespace added to a composition to better emphasize or structure, information." In code, use whitespace (blank lines) to clearly separate imports, methods, and so on. Here's an example from this website:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// External&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;parse&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;date-fns/parse&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;Link&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;next/link&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;withRouter&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;next/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Components&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Page&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;core/page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Data&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;posts&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;../posts.json&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="nx"&gt;Writing&lt;/span&gt; &lt;span class="kd"&gt;extends&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;Component&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, of course, there are examples of great whitespace usage in the official React docs. See the code examples in the &lt;a href="https://reactjs.org/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class"&gt;Adding Lifecycle Methods to a Class&lt;/a&gt; section. From the A List Apart article, " [W]hitespace creates breathing room and balance. It’s important."&lt;/p&gt;

&lt;h1&gt;
  
  
  Lint Rules
&lt;/h1&gt;

&lt;p&gt;If a lint rule exists that enforces adding more lines and space, implement it. One example: &lt;a href="https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-closing-bracket-newline.md"&gt;vue/html-closing-bracket-newline&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="c"&gt;&amp;lt;!-- Example A: --&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt;
   &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"foo"&lt;/span&gt;
   &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   baz
 &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

 &lt;span class="c"&gt;&amp;lt;!-- Example B: --&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt;
   &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"foo"&lt;/span&gt;
   &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bar"&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   baz
 &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Given the two options above, &lt;strong&gt;Example B&lt;/strong&gt; allows for more breathing room. It's easier to understand at a glance. Multiply &lt;strong&gt;Example A&lt;/strong&gt; by a dozen elements with varying numbers of attributes and it becomes increasingly difficult to see where attributes end and text/nested elements begin. I propose that when choosing between two lint rule options, always choose the one that adds more lines and space.&lt;/p&gt;

&lt;h1&gt;
  
  
  Close Blocks Clearly
&lt;/h1&gt;

&lt;p&gt;While I do enjoy the simplicity of &lt;a href="https://pugjs.org/api/getting-started.html"&gt;Pug&lt;/a&gt;, the template engine formerly known as Jade, I do believe some human processing speed is lost due to the lack of closing tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Example A (Pug) --&amp;gt;&lt;/span&gt;
.fancy-link
    a(href="/")
    | Home
.fancy-link
  a(href="/about")
    | About

&lt;span class="c"&gt;&amp;lt;!-- Example B --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fancy-link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Home
    &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fancy-link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        About
    &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While I love the brevity of Pug here, I personally think there's too much left to the imagination. Again, multiply &lt;strong&gt;Example A&lt;/strong&gt; by a dozen different, nested elements and it becomes dense and difficult to parse.&lt;/p&gt;

&lt;h1&gt;
  
  
  Breathe!
&lt;/h1&gt;

&lt;p&gt;On a fun website called &lt;a href="https://www.dwitter.net/"&gt;Dwitter&lt;/a&gt;, contributors are challenged to see what they can create with 140 characters (or less) of JavaScript. While limiting characters can be a fun constraint, this isn't code I want to read on a day-to-day basis. Instead, let's luxuriate in the fact that we have room to breathe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rKSbujTW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4navxlkxzsyyfea1n0nq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rKSbujTW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4navxlkxzsyyfea1n0nq.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codequality</category>
    </item>
  </channel>
</rss>
