<?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: Danny Verpoort</title>
    <description>The latest articles on DEV Community by Danny Verpoort (@dannyverp).</description>
    <link>https://dev.to/dannyverp</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%2F286129%2F8e5b983b-2092-471f-857e-4879396c36e2.jpeg</url>
      <title>DEV Community: Danny Verpoort</title>
      <link>https://dev.to/dannyverp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dannyverp"/>
    <language>en</language>
    <item>
      <title>An alternative or simpler way to event stream with or without Kafka</title>
      <dc:creator>Danny Verpoort</dc:creator>
      <pubDate>Fri, 30 Apr 2021 14:08:32 +0000</pubDate>
      <link>https://dev.to/dannyverp/an-alternative-or-simpler-way-to-event-stream-with-or-without-kafka-1b4l</link>
      <guid>https://dev.to/dannyverp/an-alternative-or-simpler-way-to-event-stream-with-or-without-kafka-1b4l</guid>
      <description>&lt;p&gt;Alright hear me out, I know I'm over-engineering this hobby project but I could use some advice.&lt;/p&gt;

&lt;p&gt;In the Netherlands, emergency services receive their alerts via texts on pagers. I've bought a receiver that makes it possible to (legally!) intercept these messages and it's churning away gathering all the alerts.&lt;/p&gt;

&lt;p&gt;I'm also into microservices and now I've got something that's steadily producing data that I can eventually show in a web interface. Now let's say that I would like to use an event bus to introduce the data captured from the alerts to the microservices which parse it and store some data (i.e. about which types of units, what kind of locations, etc.).&lt;/p&gt;

&lt;p&gt;I've set up a cheap Kubernetes cluster in Google making use of GitLab CI/CD, Terraform, and some helm charts with KubeIP and Traefik. This is all running fine.&lt;/p&gt;

&lt;p&gt;Now comes the challenging part. I would love to try to use Kafka to publish the events in my microservice network but geez does it become complicated there. I've found some Helm charts &lt;a href="https://github.com/confluentinc/cp-helm-charts"&gt;here&lt;/a&gt; which seem to be meant for development, testing, or proof of concept services but it seems to contain more than just Kafka and Zookeeper. Looking at the documentation for real production data it seems like an even more daunting task.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Now here's my question:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What's your advice for running an event bus in a Kubernetes environment for a hobby project where I'm not necessarily afraid to learn new stuff? I'd love to hear your advice for either a bare-bone Kafka approach or any other products you could advise. Keep in mind that the budget is pretty much non-existent because It's a hobby project.&lt;/p&gt;

&lt;p&gt;That's enough making my life unnecessarily complicated for today! :)&lt;/p&gt;

</description>
      <category>help</category>
      <category>kubernetes</category>
      <category>eventdriven</category>
      <category>kafka</category>
    </item>
    <item>
      <title>My beef 🥩 with Javascript and ReactJS ⚛️</title>
      <dc:creator>Danny Verpoort</dc:creator>
      <pubDate>Tue, 10 Nov 2020 19:54:03 +0000</pubDate>
      <link>https://dev.to/dannyverp/my-beef-with-javascript-and-reactjs-3d5o</link>
      <guid>https://dev.to/dannyverp/my-beef-with-javascript-and-reactjs-3d5o</guid>
      <description>&lt;p&gt;So, this article has two purposes. The first purpose is for me to vent a little bit about my experience working with ReactJS. At the end of the day, the purpose is to hear back from the community and learn a thing or two about how to solve the problems I ran into and what I could have done better.&lt;/p&gt;

&lt;p&gt;I recently started an open-source project based on GitHub's Markdown profile feature. The goal is to make it easy to include awesome features for your own GitHub profile. I started off with a NextJS project which I would export with GitHub Actions and then publish through Github Pages. During development, I ran into some hardship using the ReactJS framework feature. Let's have a look at the issues.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://markdownprofile.com/" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0n633gyifhk4pn3mg7c1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/dannyverp" rel="noopener noreferrer"&gt;
        dannyverp
      &lt;/a&gt; / &lt;a href="https://github.com/dannyverp/markdownprofile" rel="noopener noreferrer"&gt;
        markdownprofile
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Markdown Profiles is a project that generates markdown files for those that want an awesome Github profile.It provides several templates for you to use.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h1&gt;
  
  
  Interfaces
&lt;/h1&gt;

&lt;p&gt;I've been working with object-oriented programming for a while so it's hard for me to let go of the habits I picked up there. However, to find out that Javascript doesn't do easily do interfaces was a terrible shock to me. I mean how can you adhere to SOLID principles if your language doesn't even feature interfaces?&lt;/p&gt;

&lt;p&gt;The use case I had here was that I wanted to make it easy for other contributors to extend the markdown template website with new templates. I was going to create an interface that could be implemented and would contain all the methods that I use on the main page to render and update the templates. I ended up creating a template class which would simply chuck errors for methods that weren't implemented. A bit like such:&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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&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;error&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/dist/build/output/log&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Template&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;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;throw&lt;/span&gt; &lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The render method is used to render the Template's form. Please implement a form!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lv47x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lv47x.jpg" alt="methods, methods everywhere"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Methods, methods everywhere!
&lt;/h1&gt;

&lt;p&gt;Why is it that everything seems to be migrating functions? What have classes ever done wrong to you? I mean how are you supposed to easily keep track of objects that were returned from an API. Aren't you supposed to have high cohesion in your code? I'd love to have my data objects all within my classes. I'll be eternally (or at least a while) indebted to someone who (links me an article that) thoroughly explains to me why functional components are better.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lv7m8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lv7m8.jpg" alt="design patterns meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Tracking global states
&lt;/h1&gt;

&lt;p&gt;So I've got a system where users need to log in. Once they're logged in I want to be able to access the current user throughout my entire web app. I couldn't for the life of me figure out how to create something like a singleton in my application to track one sole instance of that user object. I found some documentation but it was mostly "we don't advice you do this". Admittedly a singleton is somewhat of an anti-pattern but that doesn't mean it suddenly completely ceased to be useful. How would I go about solving the above use case? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fhg1.funnyjunk.com%2Fthumbnails%2Fcomments%2FHere%2Bya%2Bgo%2B_3edbeeb76358d7676f0a26ee4d701873.gif" 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%2Fhg1.funnyjunk.com%2Fthumbnails%2Fcomments%2FHere%2Bya%2Bgo%2B_3edbeeb76358d7676f0a26ee4d701873.gif" alt="Rainbow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Ok, it's also been great
&lt;/h1&gt;

&lt;p&gt;I can keep on ranting for a while but these three things have so far been my biggest pain points. The experience has also been great compared to the old school jQuery way of doing things. Javascript has come a long way and I hope it will keep doing great things in the future. But it also bugs beyond belief. Now's your chance to bash me and prove me wrong!😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lvh3j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F4lvh3j.jpg" alt="bothersome JS"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>codenewbie</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Insights in Cyclomatic and Cognitive Complexity in Your Application</title>
      <dc:creator>Danny Verpoort</dc:creator>
      <pubDate>Fri, 10 Apr 2020 10:55:26 +0000</pubDate>
      <link>https://dev.to/dannyverp/insights-in-cyclomatic-and-cognitive-complexity-in-your-application-485j</link>
      <guid>https://dev.to/dannyverp/insights-in-cyclomatic-and-cognitive-complexity-in-your-application-485j</guid>
      <description>&lt;p&gt;Everybody who's ever been exposed to a legacy codebase knows the feeling of not having any idea where to get started. You start opening some random files, looking through the code, hoping to get a grasp on how this project works. You size up the project and try to pinpoint problem areas that are suitable for the first refactoring attempts.&lt;/p&gt;

&lt;p&gt;I wished that developers included more documentation and diagrams so others can more easily get an oversight of how things work. This would help in preparing roadmaps and communicating the effort to clean up technical debt to product departments and management. Luckily enough I came across a toolset that helped me size up the cyclomatic and cognitive complexity in the codebase and coordinate the refactoring efforts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XlkfRU8s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2A0fb9EVRZHYAwFkAf3UBc9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XlkfRU8s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2A0fb9EVRZHYAwFkAf3UBc9g.png" alt="Elasticsearch"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;a href="https://softvis3d.com/sonar/project/extension/softvis3d/overview_page?id=org.elasticsearch:elasticsearch"&gt;Elasticsearch project complexity visualized&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is cyclomatic complexity?
&lt;/h2&gt;

&lt;p&gt;Cyclomatic complexity is a quantitative indication of how difficult the code is to comprehend. If a program is drawn out as a graph with vertices (nodes) and edges then the following calculation results in the cyclomatic complexity:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;M = E - N + 2P&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where M is the resulting complexity, E is the number of edges, N is the number of vertices and P is the number of possible exit points.&lt;br&gt;
Let's take the following PHP code and calculate the cyclomatic complexity:&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="cp"&gt;&amp;lt;?php&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;getWords&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"one"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"a couple"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;few&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"lots"&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;The above code can be translated in the following graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kVPUzk1f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AyLE8BJ5A2IXA8N-Fc-y72A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kVPUzk1f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AyLE8BJ5A2IXA8N-Fc-y72A.png" alt="graph of simple php script"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the graph, there are 5 vertices, 7 edges. In simple cases likes these we consider the return points as a single string return. Throwing an exception would be an example where we can consider two exit points. This leads to the following cyclomatic complexity calculation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;M = E - N + 2P&lt;/code&gt;&lt;br&gt;
&lt;code&gt;E = 7&lt;/code&gt;&lt;br&gt;
&lt;code&gt;N = 5&lt;/code&gt;&lt;br&gt;
&lt;code&gt;p = 1&lt;/code&gt;&lt;br&gt;
&lt;code&gt;M = 7- 5+ 2 * 1= 4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To give you a general idea of how this quantitive data transfers into a feeling of complexity, here's how the Software Engineering Institute classed different levels of cyclomatic complexity:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;1–10 a simple program, without much risk&lt;/li&gt;
&lt;li&gt;11–20 more complex, moderate risk&lt;/li&gt;
&lt;li&gt;21–50 complex, high risk &lt;/li&gt;
&lt;li&gt;&amp;gt;50 an untestable program, very high risk&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Where does cognitive complexity come in?
&lt;/h2&gt;

&lt;p&gt;Now lay the code we've just seen beside the following code:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nf"&gt;sumOfPrimes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;j&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="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;continue&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="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;i&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="n"&gt;total&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;Both of these code snippets have a cyclomatic complexity of 4 whilst this code is clearly much harder to understand. Cyclomatic complexity is simply bound to the number of lines of code and the number of control structures (if, while, switch) used. We miss a form of context to judge the complexity of the code.&lt;br&gt;
SonarQube came up with the concept of cognitive complexity in order to introduce a more contextualized form of quantitive data on code complexity. The complexity is assessed based on these three basic rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ignore structures that allow multiple statements to be readably * shorthanded into one.&lt;/li&gt;
&lt;li&gt;Increment (add one) for each break in the linear flow of the code.&lt;/li&gt;
&lt;li&gt;Increment when flow-breaking structures are nested.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you would like to further understand the context of cognitive complexity, check out the &lt;a href="https://www.sonarsource.com/resources/white-papers/cognitive-complexity"&gt;whitepaper SonarQube published on the matter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But how does this help us? Well following the rules of cognitive complexity the first code example boils down to a cognitive complexity of 1 whilst the second example is a complexity of 7. This shows the contrast between the Cognitive and Cyclomatic Complexities and how cognitive Complexity judges more based on the code's context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Great, but how does this help me in large codebases?
&lt;/h2&gt;

&lt;p&gt;So obviously we're not going to calculate the cognitive complexity of every method within our codebase. How does this concept help us determine the paths to take inside our project?&lt;/p&gt;

&lt;p&gt;This is where the combination of SonarQube and the plugin SoftVis3d come into play. Using this plugin you can visualize your codebase based on the lines of code, issues, expected bugs, security vulnerabilities, cyclomatic complexity, cognitive complexity, etc. The code is sorted by directory and each file is represented as a bar chart. You could also consider this a house or flat in a neighborhood if you will.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ciVlfqxn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/0%2AC-6g1J-KwHA9Nd6E.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ciVlfqxn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/0%2AC-6g1J-KwHA9Nd6E.jpg" alt="SonarQube SoftVis3D example screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we pick the building height as the number of lines of codes and the floor space as cognitive complexity the most ideal situation would be a nice suburb with small houses and nice gardens. However, in some cases, you might end up with the New York City skyline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WuRq_3E1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1000/0%2A-0R0yns2BqfwexAX.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WuRq_3E1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1000/0%2A-0R0yns2BqfwexAX.jpg" alt="A picture of the suburban neighborhood you're looking for"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Eventually, this helps you tear down the flats and replace them with small buildings where you have your concerns separated and your coupling kept to a minimum. If you're looking for a nice example to see the idea in action check out ElasticSearch's public SonarQube.&lt;/p&gt;

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

&lt;p&gt;We've looked at the concept of cognitive complexity which gives us some insights into the structural complexity of our codebase. In order to fill the gap of not having contextualized quantitative data SonarQube has invented cognitive complexity which is a more in-depth analysis of the complexity. In the end, we plotted this data into SoftVis3D which gave us a visualized idea of the structure of our codebase.&lt;/p&gt;

&lt;p&gt;At Takeaway we're always looking to improve the quality of our work. We manage our complexity and quality using SonarQube and the SoftVis3D plugin amongst other cool tools. Make sure to check out our careers page to discover Tech jobs at Takeaway.com!&lt;br&gt;
If you've got any thoughts, questions or concerns reach out in the comment or get in touch on twitter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.sonarsource.com/resources/white-papers/cognitive-complexity"&gt;https://www.sonarsource.com/resources/white-papers/cognitive-complexity&lt;/a&gt;&lt;br&gt;
&lt;a href="https://resources.sei.cmu.edu/asset_files/Handbook/1997_002_001_16523.pdf"&gt;https://resources.sei.cmu.edu/asset_files/Handbook/1997_002_001_16523.pdf&lt;/a&gt;&lt;br&gt;
&lt;a href="https://softvis3d.com/sonar/project/extension/softvis3d/overview_page?id=org.elasticsearch:elasticsearch"&gt;https://softvis3d.com/sonar/project/extension/softvis3d/overview_page?id=org.elasticsearch:elasticsearch&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sonarqube</category>
      <category>complexity</category>
      <category>refactoring</category>
      <category>visualisation</category>
    </item>
  </channel>
</rss>
