<?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: David Lambauer</title>
    <description>The latest articles on DEV Community by David Lambauer (@davidlambauer).</description>
    <link>https://dev.to/davidlambauer</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F157463%2Fdfd8f2f9-f648-4b0a-97ed-2174167e54da.jpg</url>
      <title>DEV Community: David Lambauer</title>
      <link>https://dev.to/davidlambauer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidlambauer"/>
    <language>en</language>
    <item>
      <title># 5 Tips for better code readability</title>
      <dc:creator>David Lambauer</dc:creator>
      <pubDate>Sun, 11 Aug 2019 10:44:13 +0000</pubDate>
      <link>https://dev.to/davidlambauer/5-tips-for-better-code-readability-1f13</link>
      <guid>https://dev.to/davidlambauer/5-tips-for-better-code-readability-1f13</guid>
      <description>&lt;p&gt;Recently, I was hired to refactor a huge codebase that was messed up for years. The project was a Magento 2 project with more than 30 custom modules. The modules basically did everything you shouldn't do in Magento. I didn't find any tests or documentation. No static code analysis, nothing. The fact, that there aren't any tests is the reason for the messed up code base. &lt;/p&gt;

&lt;p&gt;While I was studying the code, I stumbled over the same ugly patterns over and over. This article is a small summary of the 5 worst patterns. &lt;/p&gt;

&lt;h2&gt;
  
  
  #1 - Chained Function Calls
&lt;/h2&gt;

&lt;p&gt;Chaining... Look at the following:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0dwfd8dhq68mitpxnc62.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0dwfd8dhq68mitpxnc62.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chained function call are hard to debug, harder to read and difficult to understand. While debugging, you have to evaluate each of the function calls or step into them instead of just jumping over them... &lt;/p&gt;

&lt;p&gt;A better approach would be:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6ux41pq1w4cnpl4obn0s.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6ux41pq1w4cnpl4obn0s.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #2 - Yoda Style
&lt;/h2&gt;

&lt;p&gt;It might be a preference of some, but for me yoda style is one of the most unreadable style ever. Maybe my brain is not fast enough to evaluate the condition, maybe yoda style is the pure evil. &lt;/p&gt;

&lt;p&gt;Here's why:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj92s6ulf0y6db2zuvb15.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj92s6ulf0y6db2zuvb15.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do me a favor and stop doing it &amp;lt;3. &lt;/p&gt;

&lt;p&gt;This feels so much more natural:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdf5955hor9acmas8nwfb.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdf5955hor9acmas8nwfb.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #3 - Missing early exits
&lt;/h2&gt;

&lt;p&gt;Fail fast, fail loud. That's a common statement when writing public functions. I often see functions doing a lot of stuff before they fail because a given parameter has a value that was not expected. Fail fast, fail loud. Validate incoming params first, fail if they're not matching the requirements of the functions, otherwise continue;&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw0plrcz0uhbtdte5j67r.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw0plrcz0uhbtdte5j67r.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Invert the conditions and add early exits. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1g6ixv6ea3cnykrjxnk.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1g6ixv6ea3cnykrjxnk.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #4 - Unnecessary else statements
&lt;/h2&gt;

&lt;p&gt;When an if block is guaranteed to exit control flow when entered, it is unnecessary to add an else statement. Exits can be returns, throws, continues, breaks.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F38umdjq40hm3e58r05xe.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F38umdjq40hm3e58r05xe.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would say, that else-statements aren't necessary in most cases. Isn't the following code much better to read?&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7npldpxdg7lqpnxl4hv3.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7npldpxdg7lqpnxl4hv3.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #5 - Naming...
&lt;/h2&gt;

&lt;p&gt;Old but gold. People still give a sh*t about how they name things. Naming is hard, I know. Nevertheless, here are some rules of thumb for many use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Suffix Class Names with their purpose.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CreateCustomerAccountService&lt;/li&gt;
&lt;li&gt;ImportProductManager&lt;/li&gt;
&lt;li&gt;ProductToArrayMapper&lt;/li&gt;
&lt;li&gt;ProtectHttpConnectionsGuard&lt;/li&gt;
&lt;li&gt;DateTimeHelper&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Try to find meaningful variable names and add the following names to your variable-name blacklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;$data --&amp;gt; $productData&lt;/li&gt;
&lt;li&gt;$params --&amp;gt; $requestParams&lt;/li&gt;
&lt;li&gt;$model --&amp;gt; $product&lt;/li&gt;
&lt;li&gt;$message -&amp;gt; $userFlashMessage&lt;/li&gt;
&lt;li&gt;$id --&amp;gt; $cartId&lt;/li&gt;
&lt;li&gt;$item --&amp;gt; $cartItem&lt;/li&gt;
&lt;li&gt;$connection --&amp;gt; $redisConnection&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Explicit function names. We all know, that our functions shall only do one thing. This in mind, there can be functions similar to each other but having different interfaces. Let's imagine a CustomerMapper Class, mapping customer data. Methods can be named like:&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;mapToArray(Customer $customer)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;mapToJson(Customer $customer)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;mapToArrayById(int $customerId)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;mapToJsonByEmail(string $email)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;For sure, we all work with return types nowadays but it's still a good idea to declare function names that return a boolean like so (Thank for the hint &lt;a href="https://dev.to/pujansrt"&gt;Pujan Srivastava&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hasStock() : bool&lt;/li&gt;
&lt;li&gt;isGuest() : bool&lt;/li&gt;
&lt;li&gt;canBeAddedToCart() : bool&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: Snippets are meaningless examples.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Have an additional tip? Looking forward to hear it&lt;/p&gt;

</description>
      <category>php</category>
      <category>codequality</category>
      <category>refactorit</category>
      <category>devlive</category>
    </item>
    <item>
      <title>Architectural Decision Records in a Nutshell</title>
      <dc:creator>David Lambauer</dc:creator>
      <pubDate>Mon, 29 Apr 2019 05:39:36 +0000</pubDate>
      <link>https://dev.to/davidlambauer/architectural-decision-records-in-a-nutshell-no0</link>
      <guid>https://dev.to/davidlambauer/architectural-decision-records-in-a-nutshell-no0</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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1ndo03z60fqdiqacifeb.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1ndo03z60fqdiqacifeb.jpg" alt="Photo by Amelie Ohlrogge on Unsplash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Developers know that software architecture is important stuff.&lt;/p&gt;

&lt;p&gt;For novice developers, though, there may be a bit of confusion on how much control one may have in the architecture of a piece of software. This is where Architectural Decision Records come in.&lt;/p&gt;

&lt;p&gt;But just what are ADRs, and why are they so important for developers to learn about? Let’s dive into everything you need to know about ADRs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Architectural Decision Records?
&lt;/h2&gt;

&lt;p&gt;Architectural Decision Records (ADRs) are documents that capture a vital architectural decision made, plus its context and consequences. ADRs are common practice in software development and software architecture. ADRs are typically used in addition to common documentation but provide a sort of history. &lt;/p&gt;

&lt;p&gt;An Architectural Decision (AD) itself is a software design choice, one that addresses an important requirement in the system. Architectural Decision Logs (ADL) are collections of all ADRs that have been created and maintained for a certain project or organization. An Architecturally Significant Requirement (ASR) is a specific requirement that has a quantifiable effect on the architecture of a software system. All of these titles are used within the topic of architecture knowledge management (AKM).&lt;/p&gt;

&lt;h2&gt;
  
  
  How and Where to Use ADRs?
&lt;/h2&gt;

&lt;p&gt;There are various areas one can use ADRs in a project and a number of steps one can take to implement them:&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision enforcement and enactment
&lt;/h3&gt;

&lt;p&gt;ADs are used primarily in software design, so they have to be communicated to and accepted by the people that fund, develop, and operate the system. This often includes sponsors, stakeholders, and producers but also the developer team itself.&lt;/p&gt;

&lt;p&gt;Architecturally apparent coding styles and code reviews will need to be implemented. They should focus on architectural concerns and decisions. ADs also have to be considered when modernizing a software system in software evolution and implementing new elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision-sharing
&lt;/h3&gt;

&lt;p&gt;Using ADRs for decision-sharing is definitely optional, but many ADs reoccur across projects. Because of this, experiences with past decisions in the project can be valuable assets when employing a new and outward knowledge management strategy. Keep in mind that group decision making is often an active research topic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision documentation
&lt;/h3&gt;

&lt;p&gt;Many templates and tools for decision capturing exist. Look into agile communities, such as &lt;a href="https://adr.github.io/" rel="noopener noreferrer"&gt;M. Nygard's ADRs&lt;/a&gt;. You can also look into traditional software engineering and architecture design processes, such as table layouts suggested by IBM.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision guidance
&lt;/h3&gt;

&lt;p&gt;Quite a few decision-making techniques exist. These include general techniques and software architecture-specific ones, such as dialogue mapping.&lt;/p&gt;

&lt;h3&gt;
  
  
  Identifying decisions
&lt;/h3&gt;

&lt;p&gt;Ask yourself (or your team): Just how urgent and how important is the architectural design for this project? Does it have to be figured out now, or can it wait until we can figure more stuff out?&lt;/p&gt;

&lt;p&gt;This is where having a good team in. Having a mix of personal and collective experience, in addition to recognized design methods and practices, can help substantially with decision identification.&lt;/p&gt;

&lt;p&gt;Ideally, you should create and maintain a decision backlog that works with the product backlog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Decision Record Example
&lt;/h2&gt;

&lt;p&gt;To give you a brief example of how am ADR might look like, I've added an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 1. Use Typescript for all JS related tasks

## Status

Accepted

## Context

The Frontend Team encountered that the Frontend Code Base is growing too fast. Due to that, the code quality suffers. 

## Decision

Introducing a static-typed language as a superset of Javascript shall help to deal with this situation. All JS related tasks will now be written in TypeScript.


## Consequences

All components of the Frontend Workflow have to be refactored to the new built. In addition, all old plain js files should be rewritten in TypeScript. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>decisionrecord</category>
      <category>architecture</category>
      <category>softwaredesign</category>
    </item>
  </channel>
</rss>
