<?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: Johannes Vollmer</title>
    <description>The latest articles on DEV Community by Johannes Vollmer (@johannesvollmer).</description>
    <link>https://dev.to/johannesvollmer</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%2F40785%2Ff7d711cf-f8bd-44ee-ab44-6db5a8049917.png</url>
      <title>DEV Community: Johannes Vollmer</title>
      <link>https://dev.to/johannesvollmer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johannesvollmer"/>
    <language>en</language>
    <item>
      <title>Announcing Regex Nodes, a visual editor for Regular Expressions</title>
      <dc:creator>Johannes Vollmer</dc:creator>
      <pubDate>Tue, 30 Jul 2019 11:56:29 +0000</pubDate>
      <link>https://dev.to/johannesvollmer/announcing-regex-nodes-a-visual-editor-for-regular-expressions-4id1</link>
      <guid>https://dev.to/johannesvollmer/announcing-regex-nodes-a-visual-editor-for-regular-expressions-4id1</guid>
      <description>&lt;p&gt;Hi! In this post, I am present to you what I have built to simplify creating regular expressions for JavaScript: &lt;a href="https://johannesvollmer.github.io/regex-nodes/" rel="noopener noreferrer"&gt;Regex Nodes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Warning: The presented project is still work in progress and some features might be missing or may not work as intended. It does not work on mobile devices. See the &lt;a href="https://github.com/johannesvollmer/regex-nodes" rel="noopener noreferrer"&gt;github project&lt;/a&gt; for more information on which features are planned.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What are Regular Expressions?
&lt;/h1&gt;

&lt;p&gt;Regular expressions are used to find certain patterns inside a given text. For example, it can be used to extract all images from an html page. The way to use regular expressions in JavaScript is to just type a textual representation of the pattern inbetween two slashes:&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;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&amp;lt;img.*&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;&amp;gt;/gim&lt;/span&gt;
&lt;span class="nx"&gt;htmlSourceCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This code will search the &lt;code&gt;htmlSourceCode&lt;/code&gt; for any occurrence of &lt;code&gt;&amp;lt;img&lt;/code&gt; followed by the lowest repetition (&lt;code&gt;*?&lt;/code&gt;)  of any character (&lt;code&gt;.&lt;/code&gt;), followed by a &lt;code&gt;&amp;gt;&lt;/code&gt;. After the slash, we tell JavaScript to be case insensitive and to look for multiple matches, not just for the first.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Approach of the Editor
&lt;/h1&gt;

&lt;p&gt;The editor visualizes all components of a regex with a separate "Node".&lt;br&gt;
Those atomic components can be composed by connecting the properties of the nodes. That way, you can compose complex regular expressions &lt;br&gt;
without having to deal with overly complex text lines.&lt;/p&gt;

&lt;p&gt;The following image shows the editor with the aforementioned regular expression.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://johannesvollmer.github.io/regex-nodes/?expression=LzxpbWcuKj8%2BL2dpbQ%3D%3D" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fakdj0ezvcc4fv8n5uqe1.png" alt="Filter Image Tags in the "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the center, the white rectangles describe the hierarchy of the expression.&lt;br&gt;
The rightmost node is the top-level operator, which combine the atomic nodes on the left hand side to a single regular expression.&lt;/p&gt;

&lt;p&gt;To edit a regular expression, simply visit &lt;a href="https://johannesvollmer.github.io/regex-nodes/" rel="noopener noreferrer"&gt;the online editor&lt;/a&gt;, paste the expression &lt;code&gt;/&amp;lt;img.*?&amp;gt;/gim&lt;/code&gt; where it says "Add Nodes" at the top, and then click the first suggestion. Be aware that padding spaces in the regular expression will not be ignored and may lead to unexpected results.&lt;/p&gt;

&lt;p&gt;To see how this specific regex works, you will also have to &lt;strong&gt;edit the example text by clicking the button at the top right and then paste some HTML&lt;/strong&gt;, as the default example text does not contain any image tags. &lt;/p&gt;
&lt;h1&gt;
  
  
  Why Nodes?
&lt;/h1&gt;

&lt;p&gt;Nodes are more verbose than a textual regex, but enable you to understand even the most complex expressions. Also, the design of the editor will naturally prevent you from accidentally producing an incorrect regular expression. &lt;/p&gt;

&lt;p&gt;This really sets regex nodes apart from other regex tools, where the user must first come up with a regular expression that will be checked afterwards.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;As I have not yet done any user experience research on the interface design, I will just list the basic functionality here, in case you're stuck and don't see how to do a specific thing. However, learning by trying before looking things up is what I would recommend.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Select a node&lt;/strong&gt; by clicking with your left mouse button. 
Selecting a node will display its regular expression at the bottom. 
You can lock your selection to the currently selected node by toggling 
the padlock at the bottom left. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move a node&lt;/strong&gt; by dragging with your left mouse button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect or disconnect properties&lt;/strong&gt; by dragging with your right mouse button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move the view&lt;/strong&gt; by scrolling, or by dragging with your middle mouse button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add a node&lt;/strong&gt; by clicking into the "Add Nodes" text field 
and choosing the desired node type. You can also paste a regular expression here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edit the example text&lt;/strong&gt; which is displayed in the background 
by clicking on the button at the top right.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Finally
&lt;/h1&gt;

&lt;p&gt;Thanks for reading! I hope you will find this editor useful for your own regular expressions. &lt;/p&gt;

&lt;p&gt;Keep in mind that this editor is still work-in-progress, and I cannot make any guarantees concerning the reliability of the editor. Also, this App does not support mobile devices yet. To see what features are planned, see the github project. Don't hesitate to post an issue on github if something comes to your mind regarding the regex editor.&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/johannesvollmer" rel="noopener noreferrer"&gt;
        johannesvollmer
      &lt;/a&gt; / &lt;a href="https://github.com/johannesvollmer/regex-nodes" rel="noopener noreferrer"&gt;
        regex-nodes
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Visualize and edit regular expressions for use in javascript. 
    &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;Regex Nodes&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://johannesvollmer.github.io/regex-nodes/" rel="nofollow noopener noreferrer"&gt;This node-based regular expression editor&lt;/a&gt;
helps you understand and edit regular expressions for use in your Javascript code.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If your regular expressions are complex enough to give this editor relevance
you probably should consider not using regular expressions, haha.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Why Nodes?&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;One of the problems with regular expressions is
that they get quite messy very quickly. Operator
precedence is not always obvious and can be misleading.
Nodes, on the other hand, are a visual hierarchy. A text-based regex
cannot simply be broken into several lines or indented,
because that would alter the meaning of the expression.&lt;/p&gt;
&lt;p&gt;The other major benefit of nodes is that the editor will prevent you from
producing invalid expressions. Other regex editors analyze the possibly incorrect
regular expression that the user has come up with. The node editor will
allow you to enter your intention and generate a correct regular expression.&lt;/p&gt;
&lt;p&gt;In addition, nodes…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/johannesvollmer/regex-nodes" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Have fun!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>elm</category>
    </item>
    <item>
      <title>The Foo, the Bar, the Ugly</title>
      <dc:creator>Johannes Vollmer</dc:creator>
      <pubDate>Wed, 31 Jan 2018 23:33:28 +0000</pubDate>
      <link>https://dev.to/johannesvollmer/the-foo-the-bar-the-ugly-5c71</link>
      <guid>https://dev.to/johannesvollmer/the-foo-the-bar-the-ugly-5c71</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="http://cinetropolis.net/scene-is-believing-the-good-the-bad-and-the-ugly/"&gt;Image source: cinetropolis.net&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When I learned my first programming language, Java, I just threw my questions into google. The web™ offers tons of helpful guides, and of course we all know StackOverflow, but theres a minor problem with many of them.&lt;/p&gt;

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

&lt;p&gt;Examples are undeniably one of the most effective way of learning. They are essential for any programming tip, tutorial, or guide. Glady, the majority of guides do have them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Specifically: Bad Code Examples
&lt;/h2&gt;

&lt;p&gt;Unfortunately, someone once decided it was a good idea to do code examples using completely fictional identifiers without any meaning; the good, the bad, the ugly: &lt;code&gt;Foo&lt;/code&gt;, &lt;code&gt;Bar&lt;/code&gt;, and &lt;code&gt;Baz&lt;/code&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They have been used to name entities such as variables, functions, and commands whose exact identity is unimportant and serve only to demonstrate a concept. &lt;em&gt;&lt;a href="https://en.wikipedia.org/w/index.php?title=Foobar&amp;amp;oldid=804411222"&gt;Wikipedia&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why are these words bad?
&lt;/h2&gt;

&lt;p&gt;Let's have a look at an example of (an example using these keywords). OMG so meta! &lt;br&gt;
This example demonstrates how &lt;strong&gt;interfaces&lt;/strong&gt; in Java work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bar&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bar"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Baz&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Baz"&lt;/span&gt;&lt;span class="o"&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;// ... later&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;baz&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Admit it: You didn't &lt;em&gt;really&lt;/em&gt; read this example. It's just not fun to read. Relations between classes, interfaces and methods can only be learned by carefully reading the source code, maybe even only when already knowing a little bit about interfaces.&lt;/p&gt;

&lt;p&gt;A key property of examples is that they can be related to. Thus, choosing a fictional and meaningless word contradicts the very definition of 'example'. By using &lt;code&gt;Foo&lt;/code&gt;, you fail to provide context. &lt;/p&gt;

&lt;h2&gt;
  
  
  What should we do instead?
&lt;/h2&gt;

&lt;p&gt;Wouldn't this example of interfaces be much easier to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;SomethingThatPurrs&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;purr&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;SomethingThatPurrs&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;purr&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"*purring cat*"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Kitten&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;SomethingThatPurrs&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt; 
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;purr&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"*purring kitten*"&lt;/span&gt;&lt;span class="o"&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;// ... later&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeThatThingPurrSomehow&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SomethingThatPurrs&lt;/span&gt; &lt;span class="n"&gt;purring&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;purring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;purr&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cats and Kittens create a context. It's suddenly very easy to see that both of them can purr, and how SomethinThatPurrs should somehow relate to both. That's because you know that cats and kittens both purr.&lt;/p&gt;

&lt;p&gt;I've seen beginners wondering what &lt;code&gt;Foo&lt;/code&gt; and &lt;code&gt;Bar&lt;/code&gt; actually mean, until someone tells them that there is no hidden meaning with that. Some even think that Foo and Bar are funny, which in turn motivates teachers to construct examples using these names.&lt;/p&gt;

&lt;p&gt;In my opinion, when trying to explain a concept, one should do all that can be done in order to help the learnee. Providing context by using specific names and well-known concepts helps a lot.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Foo and Bar do not provide context&lt;/li&gt;
&lt;li&gt;Examples should provide as much context as possible&lt;/li&gt;
&lt;li&gt;Foo and Bar are uncreative and boring&lt;/li&gt;
&lt;li&gt;Kittens are cute and inspiring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;Foo&lt;/code&gt; and &lt;code&gt;Bar&lt;/code&gt; are said to origin in the military acronym "FUBAR", which expands to "Fucked up beyond all recognition". What a coincidence.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mentoring</category>
      <category>java</category>
      <category>foo</category>
      <category>teaching</category>
    </item>
    <item>
      <title>Don't be a Bracist</title>
      <dc:creator>Johannes Vollmer</dc:creator>
      <pubDate>Fri, 10 Nov 2017 16:43:04 +0000</pubDate>
      <link>https://dev.to/johannesvollmer/dont-be-a-bracist-2on</link>
      <guid>https://dev.to/johannesvollmer/dont-be-a-bracist-2on</guid>
      <description>&lt;p&gt;&lt;em&gt;Trigger warning: This post assumes that racism should be avoided.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Despite being a student, I already know how time-consuming it can be to dig through other people's work. But there's a particular habit that makes reading code less awkward, and we all know it: Proper Formatting.&lt;/p&gt;

&lt;p&gt;There are many online guides on how to format your code. Most IDE's even have a nifty tool that automatically formats your source files. But theres a tiny inconsistency which many of those tools and guides choose to ignore. &lt;/p&gt;

&lt;h2&gt;
  
  
  Common Brace Indentation
&lt;/h2&gt;

&lt;p&gt;This post is all about the formatting of parantheses to group arguments and (curly) braces to group statements. JS, Java, C++, Rust, C and hundreds of other languages use these in a similar manner. Let's have a look at how braces are usually indented in Java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside KittenFactory&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Kitten&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getKittensByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="n"&gt;ageFilter&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;AgeFilter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;useHands&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasAnyGloves&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeWatch&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enableGloves&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&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="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKittens&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We start to see a pattern here: Closing braces are indented to the same level as their parent method head or if-keyword. Content inside braces is indented one level more than their parent keyword and closing brace. But now, let me throw that same code with an alternative indentation style at you (sorry, mobile phone users):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Kitten&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getKittensByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="n"&gt;ageFilter&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;AgeFilter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;useHands&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasAnyGloves&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeWatch&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enableGloves&lt;/span&gt;&lt;span class="o"&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="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKittens&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;);}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In case you are considering to write a comment about a missing closing brace, look again. It's right there. I hope you enjoy that feeling of confusion, because there's more:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Kitten&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getKittensByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Filter&lt;/span&gt; &lt;span class="n"&gt;ageFilter&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;AgeFilter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useGloves&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;useHands&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
                    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasAnyGloves&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeWatch&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
                                                   &lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enableGloves&lt;/span&gt;&lt;span class="o"&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="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKittens&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ageFilter&lt;/span&gt;&lt;span class="o"&gt;);}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Paranthesis Indentation
&lt;/h2&gt;

&lt;p&gt;I feel your confusion and disrespect, yet I can sense a weird feeling of familiarity deep inside of you. It's because we all have seen it before, but not with braces, but with parantheses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKittensByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                        &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;glovesAreAvailableFor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                                                   &lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                                                   &lt;span class="nc"&gt;Location&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="o"&gt;)));&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Heck, this formatting even was found in &lt;a href="http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html"&gt;Oracle's formatting guide&lt;/a&gt; (officially outdated).&lt;/p&gt;

&lt;p&gt;Wow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative Indentation
&lt;/h2&gt;

&lt;p&gt;This style of indentation greatly reduces readability. The important source code moves more and more to the right, far away from all the other code. Also, you can see a bunch of closing brackets cuddling at the end. Imagine having to debug a missing parantheses in such a function call. It's a mess. But fear not! There &lt;em&gt;are&lt;/em&gt; alternatives! And we already use them, but with braces, and not with parantheses. Have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKittensByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;glovesAreAvailableFor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Location&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Yep, it's that simple. This style has some remarkable benefits: Linebreaks actually move code back to the left, and you can easily see, which closing bracket belongs to which function call. That's why we use that style for braces, after all. Also, having one special formatting rule less seems to be easier anyway.&lt;/p&gt;

&lt;p&gt;That same indentation style can also be applied to if-statements and function parameter definitions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filterType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasGloves&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;canUseGloves&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// '&amp;amp;&amp;amp;' is important, so place it left&lt;/span&gt;
&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enableGloves&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setAllFieldsAtOnce&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;fluffiness&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;minAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;maxAge&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fluffiness&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fluffiness&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MAX_VALUE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;So, &lt;strong&gt;please don't be a bracist&lt;/strong&gt;. Pay parantheses the same respect as braces. They deserve it! In the end, they are both used to group elements. Plus, your code will be much more readable.&lt;/p&gt;

&lt;p&gt;I am aware that you may not be in the position to change the coding style at your company, but you can at least share this idea with friends and coworkers.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed my first post ever on dev.to!&lt;/p&gt;

</description>
      <category>readability</category>
      <category>style</category>
      <category>cleancode</category>
      <category>codequality</category>
    </item>
  </channel>
</rss>
