<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0' xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Artur Krajewski</title>
    <description>Holistic software developer in .NET world</description>
    <link>https://arturkrajewski.silvrback.com/feed</link>
    <atom:link href="https://arturkrajewski.silvrback.com/feed" rel="self" type="application/rss+xml"/>
    <category domain="arturkrajewski.silvrback.com">Content Management/Blog</category>
    <language>en-us</language>
      <pubDate>Sun, 27 Oct 2019 16:50:39 +0100</pubDate>
    <managingEditor>krajek.dev@gmail.com (Artur Krajewski)</managingEditor>
      <item>
        <guid>http://blog.arturkrajewski.com/chain-of-responsibility-pattern-for-handling-cross-cutting-concerns#48236</guid>
          <pubDate>Sun, 27 Oct 2019 16:50:39 +0100</pubDate>
        <link>http://blog.arturkrajewski.com/chain-of-responsibility-pattern-for-handling-cross-cutting-concerns</link>
        <title>Chain of Responsibility pattern for handling cross-cutting concerns</title>
        <description></description>
        <content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>

<p>I recall that in my junior years as a professional developer lot of systems I worked on introduced tons of duplication in regards to cross-cutting concerns. For example, most of the application-layers` methods would follow such a template:</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="n">ResultClass</span> <span class="nf">DoSomething</span><span class="p">(</span><span class="n">InputClass</span> <span class="n">input</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">Log</span><span class="p">.</span><span class="n">Information</span><span class="p">(</span><span class="s">&quot;DoSomethin started&quot;</span><span class="p">);</span>
    <span class="n">using</span><span class="p">(</span><span class="kt">var</span> <span class="n">unitOfWork</span> <span class="p">=</span> <span class="n">unitOfWorkProvider</span><span class="p">.</span><span class="n">Get</span><span class="p">())</span> <span class="p">{</span>
        <span class="c1">// .. actual work </span>
        <span class="n">unitOfWork</span><span class="p">.</span><span class="n">Complete</span><span class="p">();</span>
    <span class="p">}</span>
    <span class="n">Log</span><span class="p">.</span><span class="n">Information</span><span class="p">(</span><span class="s">&quot;DoSomething completed&quot;</span><span class="p">);</span>       
<span class="p">}</span>
</pre></div>
<p>Code regarding the unit of work, logging, error handling, etc. was mostly copied from method to method without much of a thought. Obviously, such an approach regularly resulted in various bugs. Sometimes the <code>Complete</code> method would be accidentally lost during the copying, other times log message was not adjusted so it conveyed incorrect information.</p>

<p>Additionally, adding any other cross-cutting concern was out of the question because it would impact all methods in all services. </p>

<p>At that time, I thought that only compilation-time tools like postsharp could help us, by generating a &quot;boilerplate&quot; code automatically. Luckily, later I realized that standard design patterns were perfectly capable of handling cross cutting concerns without compromising SOLID or DRY principles.</p>

<h1 id="constructing-better-alternative">Constructing better alternative</h1>

<p>In general, the code I showed above followed the abstract pattern.</p>
<div class="highlight"><pre><span></span>Handle concern A
Handle concern B
Handle concern C, ...
Do Actual Work
Complete concern ... , C
Complete concern B
Complete concern A
</pre></div>
<p>We could point out that basically we first build the stack of concerns and after the actual work is done we pop each concern and complete it. That could be a major design tip for us. We could devise a solution based on the actual stack of objects each handling some cross-cutting concern.</p>

<p>Obviously, for this approach to be extensible, each &quot;handler&quot; should not know about other handlers, yet, they need to cooperate. Order of the handlers does matter, so some kind of root object must be responsible for arranging them.</p>

<p>That&#39;s when our pattern comes into play. It is designed to do exactly what we just described. If you don&#39;t know this pattern already take a look at those great explanations on <a href="https://refactoring.guru/design-patterns/chain-of-responsibility">refactoring.guru</a> or <a href="https://sourcemaking.com/design_patterns/chain_of_responsibility">sourcemaking.com</a></p>

<h1 id="chain-of-responsibility-in-the-wild">Chain of responsibility in the wild</h1>

<p>Although almost no one declares their system as implementing a chain of responsibility pattern, most successful, extensible libraries do, in one form or the other. Let&#39;s take a look at a few examples</p>

<h3 id="asp-net-core-middlewares">ASP.NET Core middlewares</h3>

<p>Maybe one of the most familiar ones is the concept of <code>ASP.NET Core</code> middleware. The documentation defines middleware following:</p>

<blockquote>
<p>Middleware is software that&#39;s assembled into an app pipeline to handle requests and responses. Each component:</p>

<ul>
<li>Chooses whether to pass the request to the next component in the pipeline.</li>
<li>Can perform work before and after the next component in the pipeline.</li>
</ul>
</blockquote>

<p>As in every application of design pattern, they have their own vocabulary to describe actors in this system. Still, the cooperation pattern is implementing a chain of responsibility.</p>

<p><img alt="Silvrback blog image " src="https://silvrback.s3.amazonaws.com/uploads/341090cc-fe88-4a1e-b6aa-06a90dbeb1d0/request-delegate-pipeline.png" /></p>

<h3 id="mediatr-behaviors">MediatR behaviors</h3>

<p>MediatR is a library that on the top level implements the mediator pattern. It introduces an abstraction layer between the source of the command and its handler. However, each command, before it will be passed to the handler is processed by all registered pipeline behaviors. </p>

<p>Take a look at typical behavior for wrapping action in a transaction scope. Again, we can see the familiar <code>next</code> parameter wrapped by some logic preceding and following the invocation.</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">class</span> <span class="nc">TransactionalBehavior</span><span class="p">&lt;</span><span class="n">TRequest</span><span class="p">,</span> <span class="n">TResponse</span><span class="p">&gt;</span> <span class="p">:</span> <span class="n">IPipelineBehavior</span><span class="p">&lt;</span><span class="n">TRequest</span><span class="p">,</span> <span class="n">TResponse</span><span class="p">&gt;</span> <span class="p">{</span>
    <span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">TResponse</span><span class="p">&gt;</span> <span class="n">Handle</span><span class="p">(</span><span class="n">TRequest</span> <span class="n">request</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="n">cancellationToken</span><span class="p">,</span> <span class="n">RequestHandlerDelegate</span><span class="p">&lt;</span><span class="n">TResponse</span><span class="p">&gt;</span> <span class="n">next</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">using</span> <span class="p">(</span><span class="kt">var</span> <span class="n">tx</span> <span class="p">=</span> <span class="k">new</span> <span class="n">TransactionScope</span><span class="p">(</span><span class="n">TransactionScopeAsyncFlowOption</span><span class="p">.</span><span class="n">Enabled</span><span class="p">))</span>
        <span class="p">{</span>
            <span class="k">await</span> <span class="nf">SomeMethodInTheCallStackAsync</span><span class="p">()</span>
                <span class="p">.</span><span class="n">ConfigureAwait</span><span class="p">(</span><span class="k">false</span><span class="p">);</span>

            <span class="n">tx</span><span class="p">.</span><span class="n">Complete</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
<h3 id="angular-interceptors">Angular interceptors</h3>
<div class="highlight"><pre><span></span><span class="kd">@Injectable</span><span class="p">()</span>
<span class="kr">export</span> <span class="kr">class</span> <span class="nx">AuthorizationInterceptor</span> <span class="kr">implements</span> <span class="nx">HttpInterceptor</span> <span class="p">{</span>
    <span class="nx">intercept</span><span class="p">(</span><span class="nx">req</span>: <span class="kt">HttpRequest</span><span class="o">&lt;</span><span class="nx">any</span><span class="o">&gt;</span><span class="p">,</span> <span class="nx">next</span>: <span class="kt">HttpHandler</span><span class="p">)</span><span class="o">:</span> <span class="nx">Observable</span><span class="o">&lt;</span><span class="nx">HttpEvent</span><span class="o">&lt;</span><span class="nx">any</span><span class="o">&gt;&gt;</span> <span class="p">{</span>
        <span class="nx">token</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">auth</span><span class="p">.</span><span class="nx">getToken</span><span class="p">()</span> <span class="c1">// auth is provided via constructor.</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
          <span class="c1">// Logged in. Add Bearer token.</span>
          <span class="k">return</span> <span class="nx">next</span><span class="p">.</span><span class="nx">handle</span><span class="p">(</span>
            <span class="nx">req</span><span class="p">.</span><span class="nx">clone</span><span class="p">({</span>
              <span class="nx">headers</span>: <span class="kt">req.headers.append</span><span class="p">(</span><span class="s1">&#39;Authorization&#39;</span><span class="p">,</span> <span class="s1">&#39;Bearer &#39;</span> <span class="o">+</span> <span class="nx">token</span><span class="p">)</span>
            <span class="p">})</span>
          <span class="p">);</span>
        <span class="p">}</span>
        <span class="c1">// Not logged in. Continue without modification.</span>
        <span class="k">return</span> <span class="nx">next</span><span class="p">.</span><span class="nx">handle</span><span class="p">(</span><span class="nx">req</span><span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p><a href="https://gist.github.com/nanotroy/1f01024432f3d113b50aa290443e86bc#file-interceptor-js">Snippet source</a></p>

<p>Same story. If you know what to look for (request object <code>req</code> and <code>next</code> handler) you immediately recognize the chain of responsibility pattern.</p>

<p>For more examples of angular interceptors take a look at this <a href="https://blog.angularindepth.com/top-10-ways-to-use-interceptors-in-angular-db450f8a62d6">post from angulardepth.com</a></p>

<h3 id="others">Others</h3>

<ul>
<li>Serilog enrichers</li>
<li>NServiceBus pipeline behaviors</li>
<li>ASP.NET MVC filters</li>
<li>Entity Framework interceptors</li>
</ul>

<h2 id="applying-the-pattern-in-applications">Applying the pattern in applications</h2>

<p>To use this pattern effectively you need to first identify all composition roots in your application. By composition root, I mean every kind of entry point to your application. Typical ones include:</p>

<ul>
<li>Web endpoint</li>
<li>Message queue listener</li>
<li>Batch jobs</li>
<li>Background tasks</li>
</ul>

<p>It is necessary to devise a solution per composition-root because cross-cutting concerns are going to be specific for each entry-point. As an example, your web endpoints will probably need some kind of &quot;authorization handler&quot; whereas message queue listeners probably not. On the other hand, both endpoints could use the same &quot;transactions handler&quot;. </p>

<p>After you identified the composition roots you need to make sure that each composition root&#39;s dependency injection container can be configured independently. Obviously we aim to use full-blown DI for our solution and common configuration for all composition roots would render our efforts unnecessarily harder or even impossible for less sophisticated containers.</p>

<p>In the end, set up a &quot;pipeline&quot; in front of each of your composition roots. Each request/action should go through the pipeline and be processed by handlers of cross-cutting concerns. The actual handler executing the core logic should be free of dependencies to cross cutting concerns, focused on domain logic.</p>

<p><strong>From my experience, such setup is the pillar of SOLID architecture and maintainable software.</strong></p>

<p>Among many concerns that could be handled in such a manner you can find:</p>

<ul>
<li>Logging</li>
<li>Transactions</li>
<li>Authorization</li>
<li>Profiling</li>
<li>Exception-handling</li>
<li>Throttling</li>
<li>Caching</li>
<li>Retrying</li>
<li>Timeouts</li>
</ul>

<h1 id="summary">Summary</h1>

<p>Hopefully, I conveyed the following key points:</p>

<ul>
<li>Chain of responsibility it a simple yet powerful solution to handling cross-cutting concerns.</li>
<li>Many extensible libraries implement the pattern, knowingly or not.</li>
<li>You should have a &quot;pipeline&quot; in front of each composition root&#39;s entry-point.</li>
</ul>
]]></content:encoded>
      </item>
      <item>
        <guid>http://blog.arturkrajewski.com/serilog-for-microservice-architecture#48077</guid>
          <pubDate>Sun, 29 Sep 2019 18:02:39 +0200</pubDate>
        <link>http://blog.arturkrajewski.com/serilog-for-microservice-architecture</link>
        <title>Serilog for Microservice architecture</title>
        <description></description>
        <content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>

<p>Below you will find some valuable practices I introduced for my current employer during last year.<br>
If you already use <code>Serilog</code> and want to improve your logging process, be my guest.</p>

<h3 id="1-aggregate-all-the-logs-streams-in-one-system">1. Aggregate all the logs streams in one system</h3>

<p>That may be a no-brainer for experienced developers of distributed systems, but still, it is worth mentioning explicitly. You should have one place where all the logs are stored. I have been using Seq but lots of other products are available. </p>

<p>Having one dedicated system makes it so much easier to extract information from the data. It is also more efficient in terms of computing resources. Last, but not least, it is easier to configure and maintain one system.</p>

<h3 id="2-apply-properties-to-identify-each-service">2. Apply properties to identify each service</h3>

<p>After all log streams are forwarded into one system, you will need a flexible way to filter them. One way to distinguish events from various services is to enrich events with a <code>Service</code> property on the code level.</p>
<div class="highlight"><pre><span></span><span class="n">loggerConfiguration</span>
    <span class="p">.</span><span class="n">Enrich</span><span class="p">.</span><span class="n">FromLogContext</span><span class="p">()</span>
    <span class="p">.</span><span class="n">Enrich</span><span class="p">.</span><span class="n">WithProperty</span><span class="p">(</span><span class="s">&quot;Service&quot;</span><span class="p">,</span> <span class="s">&quot;OrderService&quot;</span><span class="p">)</span>
</pre></div>
<p>That way, however, we are hardcoding deployment-side configuration. Much more flexible approach is to use server-side property enrichment.</p>

<p>Seq has the ability to apply properties at the time of arrival from the source system. API keys are used to differentiate log events.</p>

<p>After a few attempts to structure those properties, I found out that the two-level hierarchy of properties is the most useful. The first level is for <code>Application</code> (for example &quot;Shop&quot;) whereas the second level represents a <code>Service</code> within the application. Of course, general services that live outside any particular application are enriched only with &#39;Service&#39; property.</p>

<p><img alt="Silvrback blog image" src="https://silvrback.s3.amazonaws.com/uploads/d5d40c55-4df5-44e7-87e7-a805b4b83e0f/seq_applied_properties.png" /></p>

<h3 id="3-correlate-log-events-related-to-a-request-end-to-end">3. Correlate log events related to a request end-to-end</h3>

<p>When any kind of request arrives at the edges of your system, it should immediately get a globally unique identifier which should be attached to all the log events generated in response. The identifier should be persisted through time and space.</p>

<p>A typical scenario that illustrates the lifetime of the correlation id:</p>

<ol>
<li>User clicks some button on your web/mobile app.</li>
<li>The application generates GUID and attaches it as an HTTP header.</li>
<li>Backend server recognizes the header and enriches all the subsequent events. </li>
<li><p>Backend server decides that it needs to send some asynchronous message via service bus. Message metadata is filled with correlation id.</p></li>
<li><p>Another service receives the message, recognizes the correlation id and again uses <code>.PushProperty</code> to enrich its log events. </p></li>
<li><p>In the end, the service decides to prepare an email to be sent later. Correlation id is persisted along to be used when the time to send the email will come.</p></li>
</ol>

<p>This example shows how correlation id should be alive as long as any consequence of the initial request is in progress. Practice shows that company-wide correlation id is a crucial part of microservices architecture.</p>
<div class="highlight"><pre><span></span><span class="k">using</span> <span class="p">(</span><span class="n">LogContext</span><span class="p">.</span><span class="n">PushProperty</span><span class="p">(</span><span class="s">&quot;CorrelationId&quot;</span><span class="p">,</span> <span class="n">correlationId</span><span class="p">))</span>
<span class="p">{</span>
    <span class="k">await</span> <span class="nf">next</span><span class="p">(</span><span class="n">context</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>Note that every system in the chain should expect correlation id to be passed but generate its own if none is received. That would ensure that area as big as possible is covered.</p>

<h3 id="4-install-serilog-exceptions-package">4. Install Serilog.Exceptions package</h3>

<p><code>Serilog.Exceptions</code> is an innocuously simple but indispensable tool. Without it, your exceptions are going to be logged using <code>.ToString()</code> which almost always skips some important pieces of information. The package will destructure your exceptions (including lists, dictionaries, nested objects and so on) and attach rich representation to your log events. </p>

<p>If you are using EntityFrameworkCode, there is an additional must-have package <code>Serilog.Exceptions.EntityFrameworkCore</code>.</p>

<p>BTW, I am the maintainer of the <code>Serilog.Exceptions</code> package. Visit <a href="https://github.com/RehanSaeed/Serilog.Exceptions">github page</a> for details.</p>

<h3 id="5-install-seriloganalyzer-package">5. Install SerilogAnalyzer package</h3>

<p>Just do it. It uses Roslyn code analyzer infrastructure to pinpoint common pitfalls even before the code is compiled. There is no reason to refuse getting free help :-).</p>

<h3 id="6-use-fatal-and-error-only-for-events-that-need-human-attention">6. Use Fatal and Error only for events that need human attention</h3>

<p>That point may be controversial but bear with me for a sec. In Serilog, we have six levels of log events: Fatal, Error, Warning, Information, Debug and Verbose. There is no logging semantics attached to any level. It is your choice as a developer on how to treat them. You could log events with exceptions at <code>Debug</code> level or use <code>Fatal</code> level to notify that user has provided an incorrect password.</p>

<p>On the other hand, levels can serve us best, if there will be some rules governing them, so the person analyzing the logs would be able to make sense of them. I found that if events related to known and anticipated situations like provided incomplete data for HTTP request(for example user did not provide mandatory last name) are logged on level Error, that the level is no longer indicator of a real problem. On the other hand, when only the unexpected exceptions and errors are logged on the <code>Error</code> level, we could take a glance at the logs and find &quot;real problems&quot; with our services.</p>

<p>Some of the expected situations I had moved to Information or Warning levels:</p>

<ul>
<li>Transient errors from systems like databases or event buses. They will happen, even more in the cloud environment.</li>
<li>User requests validation errors. Assuming that your UI guides the user, there is noting erroneous about this situation.</li>
<li>Rejected requests from the system under maintenance. Again, they are expected so there is nothing to do about that.</li>
</ul>

<h3 id="7-configure-alerts-for-errors">7. Configure alerts for errors</h3>

<p>The more services your organization has the harder it is to keep up and analyze all the logs. Instead of polling your logging server once in a while I advise you to set up some automated process that would monitor some carefully chosen metrics and alert development team when they are exceeded.</p>

<p>Typical metric to be monitored are &quot;errors/minute&quot;, &quot;percentage of failed requests&quot; or <br>
90th percentile of request processing time above threshold&quot;.</p>

<p>However, no metric makes sense for everybody, so you will just need to select those that work for you.</p>

<h3 id="8-correlate-on-various-levels">8. Correlate on various levels</h3>

<p>In one of the previous points, we discussed correlation id related to some external endpoint. This kind of correlation is the most important one, but not the only useful one. </p>

<p>You can correlate log events related to a particular run of the batch process. If the batch process is transforming files, you can then recursively correlate events related to particular file. ASP.NET Core automatically correlates event that happed within the connection by enriching events with <code>ConnectionId</code> property.</p>

<p>You will thank yourself if you will specify lots of those &quot;correlation-scopes&quot;. When you have a problem and need to understand what happened based on logs, they will be your best friend.</p>

<h3 id="9-each-state-change-should-emit-the-event-on-the-information-level">9. Each state change should emit the event on the Information level</h3>

<p>Even the smallest action matter when you are trying to analyze a particular scenario from logs. Adopt the rule of leaving at least one log event for each state change.</p>

<h3 id="10-dont-forget-to-closeandflush">10. Don&#39;t forget to <code>.CloseAndFlush</code></h3>

<p>By default <code>Serilog</code> sends log events asynchronously. That means that there is a chance that your application could end before all the events are actually sent over the network. It is especially important for batch applications, that starts and stops on a regular basis. </p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">static</span> <span class="k">async</span> <span class="n">Task</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">try</span>
    <span class="p">{</span>
        <span class="kt">var</span> <span class="n">host</span> <span class="p">=</span> <span class="n">hostBuilder</span><span class="p">.</span><span class="n">Build</span><span class="p">();</span>
        <span class="k">await</span> <span class="n">host</span><span class="p">.</span><span class="n">RunAsync</span><span class="p">();</span>
    <span class="p">}</span>
    <span class="k">catch</span> <span class="p">(</span><span class="n">Exception</span> <span class="n">e</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">Log</span><span class="p">.</span><span class="n">Fatal</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s">&quot;Unexpected exception caught, shutting down&quot;</span><span class="p">);</span>
        <span class="k">throw</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">finally</span>
    <span class="p">{</span>
        <span class="n">Log</span><span class="p">.</span><span class="n">CloseAndFlush</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Explicitly flushing the buffer is not necessary for non-static loggers that are disposed of when they are done.</p>
]]></content:encoded>
      </item>
      <item>
        <guid>http://blog.arturkrajewski.com/always-be-closing#44611</guid>
          <pubDate>Mon, 15 Oct 2018 16:20:40 +0200</pubDate>
        <link>http://blog.arturkrajewski.com/always-be-closing</link>
        <title>Always be closing!</title>
        <description></description>
        <content:encoded><![CDATA[<p>Just like the effective salesperson is the one closing the sales, effective engineers and managers in our industry are the ones that can deliver business value. Deliver without &quot;, but&quot;, deliver without TODOs, without creating a mess and without putting dust under the carpet.</p>

<p>I will describe what I mean by &quot;closing&quot; in software development and why I think it is a very valuable and practical principle to follow.</p>

<h2 id="the-opposite-of-closing">The opposite of closing</h2>

<p>Let&#39;s start from the opposite side and take a look at a few examples of behaviour I am sure everybody can relate to. </p>

<ul>
<li><p>Probably you worked with an analyst or product owner who often argues that additional requirements shall be part of next release after the scope has already been fixed. He may extend user stories after they have been developed. He tries to fix UX problems before users even have a chance to touch the product. He may tolerate but does not accept the idea of iterative development.</p></li>
<li><p>You may know or work with managers who almost always say yes to a neat idea, but initial enthusiasm is rarely followed with any plan of action, not even mentioning successful implementation.</p></li>
<li><p>Almost every larger project I saw have a huge backlog with hundreds of old user stories that nobody will ever consider for the upcoming sprints. Same goes for piles of TODOs scattered around the code, doomed to be forgotten, but still adding complexity. </p></li>
<li><p>Developers that have an unbearable number of topics &quot;open&quot;. The most pathological example I saw was a guy with tens of open issues in the tracker. There was no way to tell what this person was working on.</p></li>
</ul>

<p>I can extend the list even more but I think you get the idea by now. Even though the behaviours I just described are from different branches and one may think they have nothing to do with other, I suggest that there is one underlying principle. </p>

<p>Those kinds of behaviour emerge when people, for some reason, can&#39;t mentally close topics they started in the past. They cannot accept that &quot;later means never&quot; and &quot;there is no trying&quot;. I think it is caused by that tempting feeling of hope that &quot;in the future&quot; we will have some free time and we will fix the problem at hand. So, just in case, we keep that &quot;TODO: design to be improved&quot; comment that week from now, nobody will remember what was about. Just in case, we keep backlog with years of work, when we are not even sure if the project will last 6 more months.</p>

<p>Unfortunately, reality does not care about our hopes and dreams. I have yet to see a phase in the project when the team would have some &quot;free time&quot; to fix TODOs. Your neat idea from last week, if not aggressively pursued will perish under the road roller of new more important work items.</p>

<h2 id="better-alternative-closing-mindset">Better alternative: closing mindset</h2>

<p>People are ridiculously bad at remembering stuff, especially in the complex and ever-changing field of software development. Therefore, we need to work in such a way that leaves minimal (even better nothing) amount of information to remember. Every time we have something &quot;open&quot; it takes our brain capacity and prevents us from focusing. </p>

<p>The closing mindset I advocate here means being realistic about ourselves and give up unfounded hope for &quot;better&quot; times. Either I am committed to the issue at hand and develop a plan to implement it immediately or not. In the latter case, we still need to apply closing mindset and either forget about the issue(remove user story, delete the todo etc.) or schedule plan to review the issue with a deadline.</p>

<p>Let&#39;s see how &quot;closing&quot; mindset works in examples:</p>

<ul>
<li><p>During sprint planning, product owner sees that one of the user stories is not groomed enough, there are many questions regarding business impact or implementation details. He immediately says &quot;put that out of the sprint&quot;, which immediately shuts down unnecessary discussion and sends clear message that only well understood can be committed to. Developers feel respected and can commit to other well-specified user stories for that particular iteration.</p></li>
<li><p>During code review, the developer finds out few TODOs left by a fellow colleague. She refuses to accept those and suggests either to remove them or add appropriate entries to the issue tracker, which can be later prioritized. The fellow developer, fixes one of the TODOs immediately, because it was really important but removes the others, which were not worth the effort. Code stays clean, and trust between developer is maintained.</p></li>
<li><p>During the implementation phase of the iteration, the business analyst discovers that one user story could be improved by using some other user interface approach. He asks the developer directly if he can implement it on time. Developer kindly responds that it was not what the team committed to and asks the product owner to choose one of the alternatives. Either kill the sprint and start a new one or carry on with previous design and prioritize new idea for next iteration. Management does not want to disrupt developers and carries on with the sprint. During the next sprint planning, it turned out that there are many other more important user stories and proposed improvement was never implemented. Development time was saved and the team stayed on track to deliver the final product.</p></li>
</ul>

<p>These are just a few examples of situations that happen all the time in real projects. By following the &quot;closing&quot; mindset we are gaining lots of advantages.</p>

<h2 id="how-exactly-it-helps">How exactly it helps?</h2>

<ul>
<li><p><strong>Builds trust.</strong> How can I trust that a developer is going to deliver when I can see tons of open issues he/she left in the past? How can you trust a manager that raises your hopes and promises to apply some changes for the better, but then forgets about them? Answer &quot;yes&quot; to few questions, but then commit 100% to them. If for some reason you need to back up from the promise, do that in the spirit of self-responsibility and explicitly close the topic.</p></li>
<li><p><strong>Encourages focus.</strong> Having a minimal number of clearly defined goals is a huge performance boost. Some distractions, like TODOs scattered here and there are relatively small, while others like extending the scope of user story during sprints are devastating. All of them, however, degrade performance and morale of the team.</p></li>
<li><p><strong>Maintains alignment</strong> between various stakeholders. Just think about the clarity that short backlog brings to the table. Anyone can take a look and instantly know the priorities of the project in a given point of time.  </p></li>
<li><p><strong>Keeps morale high</strong>. Completing a successful iteration is one of the most gratifying moment for the development team. After a few successful sprints teams seem to get into the habit of &quot;winning&quot; which is huge in terms of team-bonding. However, this can be easily disrupted by constantly changing goals or leaving some work behind, for &quot;later&quot;. Managers often are not aware of how much does overall mess demoralize developers.</p></li>
</ul>
]]></content:encoded>
      </item>
  </channel>
</rss>