<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Bartosz Krajka</title>
<atom:link href="https://bartoszkrajka.com/feed/" rel="self" type="application/rss+xml" />
<link>https://bartoszkrajka.com</link>
<description>Personal blog</description>
<lastBuildDate>Fri, 13 Nov 2026 09:43:35 +0000</lastBuildDate>
<language>en-US</language>
<item>
<title>Poor, fractured mind</title>
<link>https://bartoszkrajka.com/2026/11/13/poor-fractured-mind/</link>
<pubDate>Fri, 13 Nov 2026 09:43:35 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1561</guid>
<description>You have a side project? How cute. I feel like these days, with AI assistance, having one side project is considered rookie numbers. New workflows involve waiting. You give an LLM a task, and off it goes. Whether we&apos;re talking about an LLM as an assistant, an agent loop, or a software factory, every once [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">You have a side project? How cute.</p>



<p class="wp-block-paragraph">I feel like these days, with AI assistance, having <em>one</em> side project is considered rookie numbers.</p>



<p class="wp-block-paragraph">New workflows involve waiting. You give an LLM a task, and off it goes. Whether we're talking about an LLM as an assistant, an agent loop, or a software factory, every once in a while you free your attention.</p>



<p class="wp-block-paragraph">What to do with this free time? Maybe I'll finally review that vibe-coded feature. Or think about what to build next. Or do the laundry.</p>



<p class="wp-block-paragraph">Or… why not start another LLM session?</p>



<!--more-->



<p class="wp-block-paragraph">And when two LLMs are busy thinking, why not a third?</p>



<p class="wp-block-paragraph">With two basic subscriptions, three concurrent AI-assisted projects feel to me like a reasonable number. My attention ends up distributed roughly like this:</p>



<ul class="wp-block-list">
<li>60% &#8211; The One Thing. It's probably still a good idea to have top priority</li>



<li>30% &#8211; The Something Else. I mean, the other subscription have to pay for itself</li>



<li>10% &#8211; The Maybe That Thing Too. Because sometimes the first two are both thinking</li>
</ul>



<p class="wp-block-paragraph"><strong>The upside?</strong> It's genuinely cool. You can make meaningful progress on three projects in a single evening. Nowadays, two basic subscriptions can get you surprisingly far, without running into usage limits every 30 minutes. Good luck trying to develop three software projects at once five years ago.</p>



<p class="wp-block-paragraph"><strong>The downsides?</strong> Constant context switching &#8211; I don't believe three projects can get enough love and attention this way. And mind you, attention to detail is becoming more and more valuable now that <a href="https://seldo.com/posts/we-are-all-product-engineers-now/">everyone is basically a product engineer</a>.</p>



<p class="wp-block-paragraph">Plus, there's another slight inconvenience: <strong>the human brain turns into a salad</strong>.</p>



<p class="wp-block-paragraph">Our attention has been under attack for quite some time anyway (by doomscrolling, notifications, etc). I've spent pretty much my entire career trying to protect my attention, ideally by staying in <a href="https://goodreads.com/book/show/28383248-deep-work?utm_source=chatgpt.com">deep work</a> for hours. </p>



<p class="wp-block-paragraph">Now, ironically, the very tools that make me so much more productive seem to be pulling me in the opposite direction.</p>



<p class="wp-block-paragraph">And the worst part? It's working. I have 14 side projects, literally. Some even close to finish (finally! After all these years!). I'm getting more done than ever, so I'm not exactly complaining. </p>



<p class="wp-block-paragraph">But somewhere between the second and third LLM session, I can hear my poor mind crying for help.</p>



<p class="wp-block-paragraph">What helps me:</p>



<ul class="wp-block-list">
<li>Mediate (or swim &#8211; it's the same thing)</li>



<li>Read books &#8211; brains seem to like that</li>



<li>Do something <strong><em>truly monumental</em></strong> without LLMs &#8211; like writing a blog post (not even <a href="https://terriblesoftware.org/2026/10/02/the-brain-sandwich/">the brain sandwich</a> helps, I realized)</li>



<li><a href="https://www.goodreads.com/en/book/show/197773418-slow-productivity">Slowing down</a> in general isn't a bad idea either</li>
</ul>



<p class="wp-block-paragraph">Those are nice ways to recharge, sure, but I'd rather stop frying my brain in the first place. Perhaps the tools themselves should be designed differently.</p>



<p class="wp-block-paragraph">My bet is that a properly designed software factory could actually be the savior here. Not a fully autonomous one &#8211; I don't believe in those yet. But one designed around managing human attention, rather than maximizing the number of agents or their output.</p>



<p class="wp-block-paragraph">(And yes, that's one of my side projects too). </p>
]]></content:encoded>
</item>
<item>
<title>Friendship ended with RVM, now rbenv is my best friend</title>
<link>https://bartoszkrajka.com/2026/04/22/friendship-ended-with-rvm-now-rbenv-is-my-best-friend/</link>
<pubDate>Wed, 22 Apr 2026 07:27:26 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1551</guid>
<description>After about 10 years, I had to break up with RVM &amp;#8211; mostly because a third party (Claude Code) wouldn&apos;t cooperate. RVM works through shell functions. When you install it, it wraps your cd command with a custom function that checks .ruby-version on every directory change. This only works in interactive shells that have loaded [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">After about 10 years, I had to break up with RVM &#8211; mostly because a third party (Claude Code) wouldn't cooperate.</p>



<p class="wp-block-paragraph">RVM works through <strong>shell functions</strong>. When you install it, it wraps your <code>cd</code> command with a custom function that checks <code>.ruby-version</code> on every directory change. This only works in interactive shells that have loaded <code>.zshrc</code>, where RVM had a chance to set this up.</p>



<p class="wp-block-paragraph">rbenv works through <strong>shims</strong>. It puts a directory of tiny wrapper scripts (<code>~/.rbenv/shims/</code>) at the front of your PATH. Every time you call <code>ruby</code>, <code>bundle</code>, <code>rake</code>, or any ruby binary, you're actually calling a shim. The shim reads <code>.ruby-version</code> from the current directory (walking up the tree if needed) and delegates to the right ruby version. It relies on standard PATH behavior rather than shell hooks.</p>



<h2 class="wp-block-heading">Where this starts to matter</h2>



<p class="wp-block-paragraph">Any tool that spawns subshells &#8211; CI runners, editors, AI coding assistants &#8211; often uses non-interactive shells that skip <code>.zshrc</code>. With RVM, that means version switching won't happen unless you explicitly source it. With rbenv, as long as <code>~/.rbenv/shims</code> is in PATH, everything behaves the same as in your terminal.</p>



<p class="wp-block-paragraph">This was the original motivation: Claude Code spawns a fresh non-interactive subshell per Bash call, so RVM's setup never ran and version switching simply didn't happen.</p>
]]></content:encoded>
</item>
<item>
<title>webfilterproxyd causes bundler SSL errors</title>
<link>https://bartoszkrajka.com/2026/02/19/webfilterproxyd-causes-bundler-ssl-errors/</link>
<pubDate>Thu, 19 Feb 2026 07:24:28 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1541</guid>
<description>So, I had this ongoing issue with bundler: TL;DR I asked Claude Code to fix that for me and, quite surprisingly, it did. The culprit was webfilterproxyd which macOS sets up for when you enable web content filtering (in System Settings). I&apos;ve seen plenty of resources about bundler SSL errors, but I haven&apos;t found any [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">So, I had this ongoing issue with bundler:</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>Errno::ECONNRESET: Connection reset by peer - SSL_connect
(...)/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in &#39;OpenSSL::SSL::SSLSocket#connect_nonblock&#39;
(...)/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in &#39;Net::Protocol#ssl_socket_connect&#39;
(...)/.rbenv/versions/3.4.1/lib/ruby/3.4.0/net/http.rb:1736:in &#39;Net::HTTP#connect&#39;
(...)/.rbenv/versions/3.4.1/lib/ruby/3.4.0/net/http.rb:1636:in &#39;Net::HTTP#do_start&#39;
(...)/.rbenv/versions/3.4.1/lib/ruby/3.4.0/net/http.rb:1631:in &#39;Net::HTTP#start&#39;</code></pre></div>



<h2 class="wp-block-heading">TL;DR</h2>



<p class="wp-block-paragraph">I asked Claude Code to fix that for me and, quite surprisingly, it did.  </p>



<p class="wp-block-paragraph">The culprit was <code>webfilterproxyd</code> which macOS sets up for when you <a href="https://support.apple.com/en-gb/guide/mac-help/mchl8490d51e/26/mac/26">enable web content filtering</a> (in System Settings).</p>



<p class="wp-block-paragraph">I've seen plenty of resources about bundler SSL errors, but I haven't found any that link them to <code>webfilterproxyd</code>. So I'm leaving this here in case it helps someone else.</p>



<!--more-->



<h2 class="wp-block-heading">Whole story</h2>



<p class="wp-block-paragraph">I had this error for a long time. Simple fixes like reinstalling or recompiling Ruby kept failing. And I really did not want to reinstall my entire OS. I was going around in circles and often got misled by ChatGPT and Google.</p>



<p class="wp-block-paragraph">While scripts like <a href="https://github.com/rubygems/ruby-ssl-check/blob/master/check.rb">check.rb</a> and <a href="https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb">doctor.rb</a> are super useful and might help you debug <em>your</em> bundler SSL issues, they weren't so helpful with <em>mine</em>:</p>



<pre class="wp-block-code"><code>  Trying connections to https://rubygems.org:

  Bundler:       ❌ failed     (Connection reset by peer - SSL_connect)
  RubyGems:      ❌ failed     (Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://rubygems.org))
  Ruby net/http: ❌ failed

  Unfortunately, this Ruby can't connect to rubygems.org. 😡

  Even worse, we're not sure why. 😕</code></pre>



<p class="wp-block-paragraph">Because in my day-to-day job I worked with Claude Code with some success, I decided to give it a go. It had already proved useful not only for writing code but also for analysing and using the terminal.</p>



<p class="wp-block-paragraph">Prompt? Super simple. I literally just asked &#8220;halp&#8221;:</p>



<pre class="wp-block-code"><code>I ran check.rb can got this error:

&lt;output here&gt;

I was trying to fix that for a long time, don't want to reinstall entire system. Halp?</code></pre>



<p class="wp-block-paragraph">And halp it did! First, it told me to reinstall Ruby, which I knew would not help. Then the miracle happened (highlight mine):</p>



<pre class="wp-block-code"><code>⏺ Bash(ruby -ropenssl -rnet/http -e "
      http = Net::HTTP.new('rubygems.org', 443)…)
  ⎿  opening connection to rubygems.org:443...
     opened
     starting SSL for rubygems.org:443...
     … +2 lines (ctrl+o to expand)

⏺ The TCP connection opens but fails immediately when starting SSL. Let me test with Ruby 3.3.6 to see if this is a Ruby 3.4.1 specific issue:

⏺ Bash(~/.rbenv/versions/4.0.1/bin/ruby -rnet/http -e "uri = URI('https://rubygems.org'); Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| puts http.head('/…)
  ⎿  Error: Sibling tool call errored

⏺ <strong>Wait! I see something interesting</strong> - Ruby 3.3.6 shows peeraddr=127.0.0.1:10011 which means there's a local proxy running on port 10011! Let me check your proxy settings:

⏺ Bash(lsof -i :10011)
  ⎿  COMMAND     PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
     ZoomUpdat  4880 bartoszkrajka   30u  IPv4 0x97dad948ef274a55      0t0  TCP localhost:49683->localhost:10011 (ESTABLISHED)
     Vivaldi   15035 bartoszkrajka   19u  IPv4 0x2e3e4ee0554961f4      0t0  TCP localhost:49267->localhost:10011 (ESTABLISHED)
     … +17 lines (ctrl+o to expand)

⏺ Found the culprit! There's something running on port 10011 that's acting as a local proxy. Vivaldi browser, Zoom, and other apps are connecting to it. Let me find what's actually listening on that port:

⏺ Bash(ps aux | grep -i proxy | grep -v grep)
  ⎿  root              1942   0,1  0,2 417001968  39792   ??  Ss   15wrz25  95:10.49 /System/Library/PrivateFrameworks/WebContentAnalysis.framework/Resources/webfilterproxyd
     bartoszkrajka    14650   0,0  0,0 426916544   8128   ??  S    10sty26   0:00.25 /System/Library/Frameworks/Security.framework/Versions/A/Resources/CloudKeychainProxy.bundle/Contents/MacOS/CloudK
     eychainProxy
     … +5 lines (ctrl+o to expand)

⏺ There's something listening on port 10011. I see webfilterproxyd which is macOS's web content filtering proxy (often used with parental controls or MDM). This is intercepting your SSL connections!</code></pre>



<p class="wp-block-paragraph">It wanted to continue the investigation, but for me that was enough! I remembered that some time ago I had set up my macOS to <a href="https://support.apple.com/en-gb/guide/mac-help/mchl8490d51e/26/mac/26">filter out</a> some web pages in the browser. I can then safely say I've cooperated with Claude, rather than relying on it entirely 😅.</p>



<p class="wp-block-paragraph">Apparently that thing spawns <code>webfilterproxyd</code>. I just turned that thing off, restarted the OS, and voilà. No more SSL errors.</p>



<p class="wp-block-paragraph">The whole thing cost me less than $1 and took maybe 10 minutes, including the OS restart.</p>



<p class="wp-block-paragraph">Honestly, that is impressive. To figure this out on my own, I would have had to dust off my knowledge of networking and Unix tools. And even then, I am not sure I would find a local proxy running on port 10011 an <em><strong>interesting</strong></em> fact.</p>



<p class="wp-block-paragraph">So folks, remember that <code>webfilterproxyd</code> can cause bundler SSL errors. And hats off to Claude Code for its impressive analytical power.</p>
]]></content:encoded>
</item>
<item>
<title>Bad modules, good modules</title>
<link>https://bartoszkrajka.com/2024/05/30/good-modules/</link>
<pubDate>Thu, 30 May 2024 17:01:43 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1506</guid>
<description>Is this a good module or not? My answer: can&apos;t tell. It depends on how the module interacts with other modules. What would make it a bad module?</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">Is this a good module or not?</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="378" height="476" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules.jpg" alt="" class="wp-image-1508" srcset="/wp-content/uploads/2024/05/Good-modules.jpg 378w, /wp-content/uploads/2024/05/Good-modules-238x300.jpg 238w" sizes="auto, (max-width: 378px) 100vw, 378px" /><figcaption class="wp-element-caption">An arrow = a dependency. Is this a good module? </figcaption></figure>
</div>


<p class="wp-block-paragraph">My answer: <strong>can't tell</strong>. It depends on how the module interacts with other modules.</p>



<h2 class="wp-block-heading">What would make it a bad module?</h2>



<!--more-->



<h3 class="wp-block-heading">1. Plenty of deps</h3>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="628" height="477" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-1.jpg" alt="" class="wp-image-1509" srcset="/wp-content/uploads/2024/05/Good-modules-1.jpg 628w, /wp-content/uploads/2024/05/Good-modules-1-300x228.jpg 300w" sizes="auto, (max-width: 628px) 100vw, 628px" /><figcaption class="wp-element-caption">It's clearly a bad module, the boundary doesn't make sense</figcaption></figure>
</div>


<h3 class="wp-block-heading">2. A sibling module</h3>



<p class="wp-block-paragraph">If there is many deps but from a limited number of modules, that's still a bad design but with a clear fix. </p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="628" height="477" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-2.jpg" alt="" class="wp-image-1510" srcset="/wp-content/uploads/2024/05/Good-modules-2.jpg 628w, /wp-content/uploads/2024/05/Good-modules-2-300x228.jpg 300w" sizes="auto, (max-width: 628px) 100vw, 628px" /><figcaption class="wp-element-caption">Module D has an unhealthy interest in Module A.</figcaption></figure>
</div>


<p class="wp-block-paragraph">Fix: modules A and D should become one module. Unpack Module D into Module A.</p>



<p class="wp-block-paragraph">What happens then?</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="628" height="477" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-3.jpg" alt="" class="wp-image-1511" srcset="/wp-content/uploads/2024/05/Good-modules-3.jpg 628w, /wp-content/uploads/2024/05/Good-modules-3-300x228.jpg 300w" sizes="auto, (max-width: 628px) 100vw, 628px" /><figcaption class="wp-element-caption">You should combine A and D. Results in much healthier external relations. Cohesion increased.</figcaption></figure>
</div>


<h3 class="wp-block-heading">3. It's the only module</h3>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="378" height="476" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-4.jpg" alt="" class="wp-image-1513" srcset="/wp-content/uploads/2024/05/Good-modules-4.jpg 378w, /wp-content/uploads/2024/05/Good-modules-4-238x300.jpg 238w" sizes="auto, (max-width: 378px) 100vw, 378px" /><figcaption class="wp-element-caption">Only module. Por que?</figcaption></figure>
</div>


<p class="wp-block-paragraph">I will argue that if there is only one module, the modularization is clearly wrong too.</p>



<p class="wp-block-paragraph">Why? <strong>Modules come with a cost.</strong> When you make a module, it creates a boundary between some regions of the code. This boundary is desired when the system is bigger. But when it's not&#8230; Why adding that cost in the first place?</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="343" height="390" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-5.jpg" alt="" class="wp-image-1515" srcset="/wp-content/uploads/2024/05/Good-modules-5.jpg 343w, /wp-content/uploads/2024/05/Good-modules-5-264x300.jpg 264w" sizes="auto, (max-width: 343px) 100vw, 343px" /><figcaption class="wp-element-caption">Leave it like this. Why adding code?</figcaption></figure>
</div>


<p class="wp-block-paragraph">Don't solve the problem that you don't have. Single-module design is a solution without a problem yet.</p>



<h2 class="wp-block-heading">What would make it a good module?</h2>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="628" height="477" src="https://bartoszkrajka.com/wp-content/uploads/2024/05/Good-modules-4-1.jpg" alt="" class="wp-image-1514" srcset="/wp-content/uploads/2024/05/Good-modules-4-1.jpg 628w, /wp-content/uploads/2024/05/Good-modules-4-1-300x228.jpg 300w" sizes="auto, (max-width: 628px) 100vw, 628px" /><figcaption class="wp-element-caption">Good module!</figcaption></figure>
</div>


<p class="wp-block-paragraph">The relation of the external deps to the internal deps is low.</p>



<p class="wp-block-paragraph">This graph shows high <a href="https://en.wikipedia.org/wiki/Cohesion_(computer_science)">cohesion</a>. Cohesion is everything when it comes to designing modules.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">BTW. The direction of the arrows doesn't make a difference, I added it for the sake of misleading</p>
</blockquote>



<h2 class="wp-block-heading">Summary</h2>



<ul class="wp-block-list">
<li>You can't judge a module by only its internal structure. without seeing what it looks like in relation to other modules</li>



<li>You have to examine outside interaction</li>



<li>Modules make sense when there is more than one of them</li>



<li>Good module has high <a href="https://en.wikipedia.org/wiki/Cohesion_(computer_science)">cohesion </a>&#8211; everything inside is interconnected but everything outside is highly isolated too</li>
</ul>
]]></content:encoded>
</item>
<item>
<title>How to write tests</title>
<link>https://bartoszkrajka.com/2024/04/29/how-to-write-tests/</link>
<pubDate>Mon, 29 Apr 2024 05:52:44 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1472</guid>
<description>First &amp;#8211; realize what constitutes good tests. The answer: little (ideally: zero) false positives. Feel free to read my previous article that elaborates on this topic. But how exactly? Here is my answer:</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">First &#8211; realize what constitutes good tests. </p>



<p class="wp-block-paragraph">The answer: little (ideally: zero) false positives. Feel free to read <a href="https://bartoszkrajka.com/2024/03/20/tests-should-give-confidence/">my previous article</a> that elaborates on this topic.</p>



<p class="wp-block-paragraph">But how exactly? Here is my answer:</p>



<!--more-->



<h2 class="wp-block-heading">1. Avoid false positives</h2>



<p class="wp-block-paragraph">That's tautological, but has to be said.</p>



<p class="wp-block-paragraph">Anything that can lead to false positives has to be reduced to a minimum. It's enough justification to any further action. Once you internalize it you might produce the rest of the article on your own. </p>



<p class="wp-block-paragraph">The counter-example is a beautiful <strong>test coverage of 100%, all tests pass, while the app does not</strong> <strong>work</strong>.</p>



<p class="wp-block-paragraph">Your goal is the oracle that you can trust. Confront your tests with reality and correct them if they produce false positives.</p>



<h2 class="wp-block-heading">2. Avoid false negatives</h2>



<p class="wp-block-paragraph">Although they aren't as bad as false positives, you should avoid false negatives too. The oracle shouldn't be wrong one way or another.</p>



<p class="wp-block-paragraph">A false negative slows you down but doesn't directly hurt your customers. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">The cutest example of false negatives from my personal career was when the tests didn't pass&#8230; on Mondays. Every other workday they worked fine and made a perfect oracle but Mondays &#8211; nah man, it's all red.</p>
</blockquote>



<p class="wp-block-paragraph">Though you should have a strong preference. False negatives are bad but false positives are your Nemesis.  </p>



<h2 class="wp-block-heading">3. Test user journey</h2>



<p class="wp-block-paragraph">This is the cornerstone argument against class tests.</p>



<p class="wp-block-paragraph">Users don't run your classes in isolation.</p>



<p class="wp-block-paragraph">Users use the app as a subsequent chain of input and output.</p>



<p class="wp-block-paragraph">Tests that give confidence should mimic this behavior as closely as possible. </p>



<p class="wp-block-paragraph">Think web app. Users don't care if a controller works fine. It only matters if a request is processed as expected.</p>



<h3 class="wp-block-heading">3a. Class != unit</h3>



<p class="wp-block-paragraph">Unit tests are OK but don't equate &#8220;unit&#8221; with &#8220;class&#8221; or &#8220;method&#8221;. </p>



<p class="wp-block-paragraph">A unit generally goes beyond one class. </p>



<p class="wp-block-paragraph">Read <a href="https://bartoszkrajka.com/2023/11/23/unit-tests-can-and-should-go-through-many-classes/">this article</a> that explains it more.</p>



<h3 class="wp-block-heading">3b. End-to-end is king</h3>



<p class="wp-block-paragraph">You should aim for end-to-end tests first and only go lower if you have a good reason (combinatorial explosion, expensiveness).</p>



<p class="wp-block-paragraph">I don't hate fast and easy tests like class tests. However, they don't give enough confidence.</p>



<h3 class="wp-block-heading">3c. Blackbox setup</h3>



<p class="wp-block-paragraph">Don't set up the state. Set up the SUT the same as your user would. </p>



<p class="wp-block-paragraph"><strong>Bad</strong>: <code>GIVEN user is created in the database...</code></p>



<p class="wp-block-paragraph"><strong>Better</strong>: <code>GIVEN user made a correct register request...</code></p>



<h2 class="wp-block-heading">4. Test on production-like env</h2>



<p class="wp-block-paragraph">Notice how this subtly means you should test on something that resembles &#8220;environment&#8221;. You will need that end-to-end tests, period.</p>



<h3 class="wp-block-heading">4a. Production-like data</h3>



<p class="wp-block-paragraph">Use as real data as possible on dev envs. Incorrect data used on devs are the source of incidents.</p>



<p class="wp-block-paragraph">Trick &#8211; copy data from production to dev daily. You can anonymize them, if that makes problem.</p>



<h3 class="wp-block-heading">4b. Ensure specific versions of the packages</h3>



<p class="wp-block-paragraph">In the tests, use the exact packages that your production app will.</p>



<p class="wp-block-paragraph">Use <code>npm ci</code> instead of <code>npm i</code> and make sure your <code>package.json</code> is not too permissive.</p>



<h2 class="wp-block-heading">5. Avoid test doubles</h2>



<p class="wp-block-paragraph">Users don't use doubles in their journey.</p>



<p class="wp-block-paragraph">Whenever you use a double in your test, <strong>you set up a fake stage</strong>. This risks a false positive &#8211; when your double fulfills the expectations but real dependency does not.</p>



<p class="wp-block-paragraph">If you can avoid test doubles in your tests &#8211; that's a huge step towards the oracle.</p>



<p class="wp-block-paragraph">This isn't to say that you shouldn't ever use doubles. Rather, <strong>don't overuse them</strong>. If you don't see a good reason why to use one &#8211; don't.</p>



<h2 class="wp-block-heading">6. Use doubles properly</h2>



<p class="wp-block-paragraph">You will still need <em>some</em> doubles, that's for sure. The way you write your doubles makes a big difference. 4 subsequent rules are explaining what makes good doubles.</p>



<h3 class="wp-block-heading">6a. Doubles only on boundaries</h3>



<p class="wp-block-paragraph">There are places for test doubles that makes perfect sense. It's system boundaries (database, network, file system). The reasons are well-known &#8211; predictability and speed.</p>



<p class="wp-block-paragraph">Using doubles on the boundaries between modules &#8211; it's questionable. A big yes, if modules are cohesive and independent. No, if modules intercommunicate back and forth.</p>



<p class="wp-block-paragraph">In other words, if you really have modules, use doubles; if your modules are only a facade &#8211; don't bother.</p>



<h3 class="wp-block-heading">6b. Thin doubles </h3>



<p class="wp-block-paragraph">When you use doubles, make them as thin as possible. </p>



<p class="wp-block-paragraph">Remember that you're replacing real code. You better make sure that you're replacing as little as possible.</p>



<p class="wp-block-paragraph">In other words, stick to <a href="http://xunitpatterns.com/Humble%20Object.html">Humble Object</a> pattern.</p>



<p class="wp-block-paragraph">An antipattern would be a rich repository. When you're using complex SQL in a layer that will be replaced by doubles &#8211; such doubles need to be complex. This again risks false positives.</p>



<h3 class="wp-block-heading">6c. Contract tests</h3>



<p class="wp-block-paragraph">How do you test doubles?</p>



<p class="wp-block-paragraph">If you use thin doubles and only in the right places, chances are you don't need to test doubles. </p>



<p class="wp-block-paragraph">But, doubles always add risk. If you want to increase your confidence about your doubles, use <a href="https://martinfowler.com/bliki/ContractTest.html">contract tests</a>. </p>



<h3 class="wp-block-heading">6d. Prefer fakes over mocks</h3>



<p class="wp-block-paragraph"><a href="https://bartoszkrajka.com/2018/06/29/dont-test-implementation/">Mocks test implementation</a>. Fakes patch the gap so that you can test the behavior.</p>



<p class="wp-block-paragraph">There is this old discussion about <a href="https://team-agile.com/2021/02/06/chicago-and-london-style-tdd/">London vs Chicago</a>. When it comes to confidence and no-false-positiveness, Chicago wins hands down.</p>



<h2 class="wp-block-heading">7. Test as little as possible (given enough confidence)</h2>



<p class="wp-block-paragraph">You don't want to over-test your app. You want some time for writing features. Write only as many tests as it takes to give you confidence. </p>



<p class="wp-block-paragraph">Don't cheat! Don't feel confident if reality shows you otherwise.</p>



<h3 class="wp-block-heading">7a. Don't test framework</h3>



<p class="wp-block-paragraph">Start your tests <em>after</em> the framework gives you freedom.</p>



<p class="wp-block-paragraph">You can assume the framework you use works fine (and other 3rd parties). If it doesn't and has some bugs &#8211; fix them in the framework, rather in your app.</p>



<p class="wp-block-paragraph">Exception &#8211; end-to-end. If you can afford it, treat your framework as one of the layers in your end-to-end tests.</p>



<h3 class="wp-block-heading">7b. <a href="https://bartoszkrajka.com/2018/07/17/dont-test-data/">Don't test data</a></h3>



<h3 class="wp-block-heading">7c. <a href="https://bartoszkrajka.com/2018/06/29/dont-test-implementation/">Don't test implementation</a></h3>



<h2 class="wp-block-heading">8. 1 &gt; 0</h2>



<p class="wp-block-paragraph">In the spirit of tule 6, start with one and see what happens. Often a single test is enough as an incidents catcher.</p>



<p class="wp-block-paragraph">One end-to-end test can catch typos or orchestration incidents.</p>



<p class="wp-block-paragraph">This is especially useful when you have a test suite full of class tests and never or rarely test the integration. Start with one end-to-end test. It's often enough.</p>



<h3 class="wp-block-heading">8a. Boot up the app</h3>



<p class="wp-block-paragraph">This is an especially useful type of &#8220;single test&#8221;. </p>



<p class="wp-block-paragraph">Make sure your app boots up &#8211; do your <code>docker up</code> on the CI.</p>



<h3 class="wp-block-heading">8b. New bug = new test</h3>



<p class="wp-block-paragraph">If you want your incident to never happen again, write a test case that covers it.</p>



<p class="wp-block-paragraph">It's a super simple yet super useful technique of how to increase confidence over time.</p>



<h2 class="wp-block-heading">9. Assert important things</h2>



<p class="wp-block-paragraph">You are responsible for recognizing what's important in your app.</p>



<p class="wp-block-paragraph">If your logs are important &#8211; assert it!</p>



<p class="wp-block-paragraph">If your data is important and/or often overlooked &#8211; assert it! (<em>this is obviously at odds with paragraph 7b but that's the whole point of this bullet</em>).</p>



<h3 class="wp-block-heading">9a. Automate what you verify anyway</h3>



<p class="wp-block-paragraph">You're often testing your app manually. Try to find a way to automate it. If you verify it, it must be important.</p>



<p class="wp-block-paragraph">Examples:</p>



<ul class="wp-block-list">
<li>Chances are you test your web app in the browser. Cypress automates user journeys in the browser, that's a good way to start automating! (remember paragraph 3?)</li>



<li>Chances are you're testing via Swagger &#8211; there is nothing simpler than automating it.</li>



<li>If you're constantly <code>console.log</code> intermediate results, maybe write a test and assert their correctness.</li>
</ul>



<h2 class="wp-block-heading">10. Think broad</h2>



<p class="wp-block-paragraph">Remember &#8211; a false positive is when the app is facing an &#8220;incident&#8221; but your test had not caught it beforehand.</p>



<p class="wp-block-paragraph">Think of an &#8220;incident&#8221; in broad terms:</p>



<ul class="wp-block-list">
<li>bug</li>



<li>missed requirement</li>



<li>not enough specification</li>



<li>infrastructure failure</li>



<li>the app fails to boot up</li>



<li>anything that makes your app not work correctly on prod</li>
</ul>



<p class="wp-block-paragraph">Try and catch all of them in your test.</p>



<h3 class="wp-block-heading">10a. Think outside the box</h3>



<p class="wp-block-paragraph">Remember, your goal is to avoid false positives. Your non-goal is to do what others do and write what others write.</p>



<p class="wp-block-paragraph">Examples:</p>



<ul class="wp-block-list">
<li>start where you are, add tests progressively (see rule new bug = new test)</li>



<li>delete the existing test base if it produces lots of false positives</li>



<li>write exploratory tests for that nasty API that changes too frequently</li>
</ul>



<h3 class="wp-block-heading">10b. Don't make excuses</h3>



<p class="wp-block-paragraph">There are many reasons why tests don't catch incidents:</p>



<ul class="wp-block-list">
<li>tests are poorly written</li>



<li>there aren't enough of them</li>



<li>test environments were different</li>



<li>test data was different</li>



<li>error in a third-party</li>



<li>the incident couldn't be caught by test. </li>
</ul>



<p class="wp-block-paragraph"><strong>Only the last one is a fair reason. </strong>Don't overuse it. If something really can't be tested automatically &#8211; always test it manually.</p>



<p class="wp-block-paragraph"><strong>Don't use other reasons as an excuse. </strong>Don't take defensive approaches &#8220;<em>oh, it's not my job to integrate platforms; mine works as expected</em>&#8220;. It's your job and <a href="https://blog.codinghorror.com/the-first-rule-of-programming-its-always-your-fault/">it's your fault</a> if something goes wrong.</p>



<h2 class="wp-block-heading">11. Right-shift your reality check</h2>



<p class="wp-block-paragraph">In security, there is the notion of <a href="https://www.perforce.com/blog/sca/what-is-shift-left-security#:~:text=In%20software%20development,%20shift%20left,before%20the%20software%20is%20released.">left-shift security</a> &#8211; to catch errors as early in the process as possible.</p>



<p class="wp-block-paragraph">In terms of confidence, you should think the opposite. The later in the process, the more valuable reality check it makes.</p>



<h3 class="wp-block-heading">11a. End user first</h3>



<p class="wp-block-paragraph">Your goal is confidence in the app in the market. </p>



<p class="wp-block-paragraph">Prefer validation from: (the higher the better)</p>



<ol class="wp-block-list">
<li>market</li>



<li>end user</li>



<li>stakeholders</li>



<li>PO</li>



<li>QA</li>



<li>development</li>
</ol>



<h3 class="wp-block-heading">11b. Early integration</h3>



<p class="wp-block-paragraph">If you develop only one platform (eg. a backend server without control on frontends), aim for as early integration as possible.</p>



<p class="wp-block-paragraph">There is no way integration goes smoothly and without incidents. Catch them as soon as possible.</p>



<h3 class="wp-block-heading">11c. Don't trust tests on dev</h3>



<p class="wp-block-paragraph">Confidence in the early stages (eg. after QA) means nothing if leads to incidents in later stages (eg. on prod). </p>



<p class="wp-block-paragraph">If you are confident in the lower stages, don't take for granted that higher ones will go equally well.</p>



<h2 class="wp-block-heading">12. Know your limits</h2>



<p class="wp-block-paragraph">You can't tests everything automatically. Aesthetics, UX &#8211; these things can't be enclosed in frames of automated tests.</p>



<p class="wp-block-paragraph">Minimize the scope of your manual tests but execute them. And execute them honestly.</p>
]]></content:encoded>
</item>
<item>
<title>Tests should give confidence</title>
<link>https://bartoszkrajka.com/2024/03/20/tests-should-give-confidence/</link>
<pubDate>Wed, 20 Mar 2024 09:28:00 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1439</guid>
<description>This is the most important, yet the most unspoken trait of good tests. Tests should be the oracle. If all tests are green &amp;#8211; the app will work on prod. If at least one test is red &amp;#8211; the app won&apos;t work. Think Continuous Delivery. Every step in the process has to be automated. When [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">This is the most important, yet the most unspoken trait of good tests. <strong>Tests should be the oracle.</strong> </p>



<p class="wp-block-paragraph">If all tests are green &#8211; the app will work on prod. If at least one test is red &#8211; the app won't work.</p>



<p class="wp-block-paragraph">Think Continuous Delivery. Every step in the process has to be automated. When tests are green, there is no room for extra human checks before going prod. The decision (deploy &#8211; no deploy) is handed over to your tests. </p>



<p class="wp-block-paragraph">Do you trust your tests this much? <em>Is this even possible</em> to be this confident about tests?</p>



<!--more-->



<h2 class="wp-block-heading">What test tests?</h2>



<p class="wp-block-paragraph">We are used to thinking that tests prove the correctness of the code, or more precisely: disprove its falseness.</p>



<p class="wp-block-paragraph">A natural question that springs to mind is: <strong>what proves the correctness of the tests themselves</strong>?</p>



<p class="wp-block-paragraph">&#8220;<em>You should write tests for your tests, he he xD</em>&#8221; &#8211; that's a common reaction. It fails to amuse me. First of all &#8211; tests for your tests do exist (see <a href="https://stryker-mutator.io/">mutation tests</a>) but I'm not a fan. </p>



<p class="wp-block-paragraph">There is a better way to verify your tests. It's infallible and very personal to each project.</p>



<p class="wp-block-paragraph">This way is <strong>the</strong> <strong>reality check</strong>.</p>



<h2 class="wp-block-heading">Reality check</h2>



<p class="wp-block-paragraph">Deploy your app to prod and see if it does the job. </p>



<p class="wp-block-paragraph">Because programming is hard and because you have to keep delivering, inevitably &#8211; there is an incident (think a bug or a crash; the broader the better).</p>



<p class="wp-block-paragraph"><strong>The incident means a false positive from your tests.</strong> Tests are supposed to catch all the incidents. The oracle has failed.</p>



<p class="wp-block-paragraph"><strong>In other words, false positives disprove the correctness of the tests.</strong></p>



<p class="wp-block-paragraph">Your app has many incidents? Your tests are bad.</p>



<p class="wp-block-paragraph">Your app has no incidents? Your tests are good enough. For now (until the next incident).</p>



<p class="wp-block-paragraph">That's what I envision when I think of &#8220;<em>tests test your code and code tests your tests</em>&#8220;.</p>



<h2 class="wp-block-heading"><strong>No-false-</strong>positiveness is king</h2>



<p class="wp-block-paragraph"><strong>No-false-positiveness </strong>(for the lack of a better word) <strong>is the most important trait of a test suite</strong>.</p>



<p class="wp-block-paragraph">Yes, tests should be as fast as possible. But if your fast tests lead to false positives &#8211; are they useful? Class tests (often <a href="https://bartoszkrajka.com/2023/11/23/unit-tests-can-and-should-go-through-many-classes/">wrongly called unit tests</a>) tend to be extremely fast but do not catch integration errors. Not a fan.</p>



<p class="wp-block-paragraph">Yes, code coverage is nice. But 100% coverage doesn't guarantee no-false-positiveness. In contrast, code with 20% can give perfect confidence (eg. when a critical path is tested in and out, and the rest of the app never causes a problem).  </p>



<p class="wp-block-paragraph">Yes, tests should precisely tell you where the problem is. Class tests can do that, but often you sacrifice no-false-positiveness to get there, which isn't the best of deals.  </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">You can see a pattern here. I'm not a fan of class tests. A test suite that only consists of class tests has many traits but <strong>no-false-positiveness</strong> isn't one.</p>
</blockquote>



<h2 class="wp-block-heading"><strong>No-false-positiveness</strong> builds confidence</h2>



<p class="wp-block-paragraph">Hopefully, nobody deploys the app knowing it will cause incidents. Rather the incidents are surprising. At least I want to believe so.</p>



<p class="wp-block-paragraph">If you have a sane sense of confidence, it is proportional to the amount of incidents that have happened recently.</p>



<p class="wp-block-paragraph">You shouldn't feel confident if every deploy leads to many incidents.</p>



<p class="wp-block-paragraph">On the other hand, if your app has few incidents, your tests are good, even if, for example, they are written in an unorthodox manner.</p>



<p class="wp-block-paragraph">If there are incidents &#8211; fear not. Fix it and adapt the tests. Mend the oracle. Every fixed incident should increase your confidence. </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="711" height="202" src="https://bartoszkrajka.com/wp-content/uploads/2024/03/incidents1.drawio-1.png" alt="" class="wp-image-1464" srcset="/wp-content/uploads/2024/03/incidents1.drawio-1.png 711w, /wp-content/uploads/2024/03/incidents1.drawio-1-300x85.png 300w, /wp-content/uploads/2024/03/incidents1.drawio-1-676x192.png 676w" sizes="auto, (max-width: 711px) 100vw, 711px" /></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">Funny thing: if you have a strong feedback loop, you can start with any code and tests and you'll end up with perfect code and tests. </p>



<p class="wp-block-paragraph">The opposite is also true. No matter how perfect your product is, poor feedback loop will ruin it.</p>
</blockquote>



<h2 class="wp-block-heading">Sounds trivial?</h2>



<p class="wp-block-paragraph">I may sound too trivial. Inspect and adapt, right?</p>



<p class="wp-block-paragraph">But there is a reason why I write this article. This is already too difficult to do for many devs.</p>



<p class="wp-block-paragraph">I've seen many examples of people trying to negotiate with reality. People writing &#8220;perfect test suite&#8221; but resulting in more and more incidents, yet refusing to abandon their beliefs.</p>



<p class="wp-block-paragraph">Picture this &#8211; <strong>the tests has 100% code coverage. Plenty of class tests. 100% pass. App doesn't work.</strong></p>



<p class="wp-block-paragraph">Are these good tests?</p>



<p class="wp-block-paragraph">I've met many devs who say yes. How would you explain the goal of your test suite if you answered &#8220;yes&#8221;?</p>



<p class="wp-block-paragraph">Don't want to be right. Let your prod tell you the truth, that's all you need.</p>



<h2 class="wp-block-heading">100% confidence?</h2>



<p class="wp-block-paragraph">I don't think 100% confidence is achievable. The reason: you can't just freeze your app, find out all the incidents, and fix them all.</p>



<p class="wp-block-paragraph">Because you have to deliver new features. Also, the environment (libraries, cloud) evolves. It obscures the whole learning process.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="761" height="321" src="https://bartoszkrajka.com/wp-content/uploads/2024/03/incidents2.drawio.png" alt="" class="wp-image-1465" srcset="/wp-content/uploads/2024/03/incidents2.drawio.png 761w, /wp-content/uploads/2024/03/incidents2.drawio-300x127.png 300w, /wp-content/uploads/2024/03/incidents2.drawio-676x285.png 676w" sizes="auto, (max-width: 761px) 100vw, 761px" /></figure>



<p class="wp-block-paragraph">You'll never reach 100%, even if there wasn't an incident for a long time. There are too many cases to cover and product.</p>



<p class="wp-block-paragraph">It's a process. and you should accept this. Work iteratively. Don't be 100% confident but try to reach it.</p>



<h2 class="wp-block-heading">It's no-false-positiveness first, not tests</h2>



<p class="wp-block-paragraph">I would not care about tests if I ever saw a better way to ensure no-false-positiveness.</p>



<p class="wp-block-paragraph">Tests are automatic and deterministic way to:</p>



<ul class="wp-block-list">
<li>prove the correctness of the new code</li>



<li>prove no regression</li>
</ul>



<p class="wp-block-paragraph">That is a huge confidence boost when it comes to predicting no incident. The day I find a tool that gives me all that confidence is the day I quit bitching about writing good tests.</p>



<h2 class="wp-block-heading">Summary</h2>



<ul class="wp-block-list">
<li>I want to write tests so that they produce no false positives. I aim for the infallible oracle.</li>



<li>This is the only measure of good tests.</li>



<li>You should build your confidence on the reality check of the app. Otherwise, you're being unrealistic.</li>



<li>Programming is hard, you won't get 100% confidence. Reality will try to ruin it for you. But keep trying.</li>



<li>Count false positives and reduce to zero. That's all it takes</li>
</ul>



<p class="wp-block-paragraph"><a href="https://bartoszkrajka.com/2024/04/29/how-to-write-tests/">In the next article </a>I shared concrete ideas on how to write tests that give more confidence.</p>
]]></content:encoded>
</item>
<item>
<title>The simplest dependency injection</title>
<link>https://bartoszkrajka.com/2024/02/19/the-simplest-dependency-injection/</link>
<pubDate>Mon, 19 Feb 2024 08:49:47 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1384</guid>
<description>Consider a method that calculates some ETA: Notice how add3WorkingDays depends on the time when it&apos;s called (result is initially now). Because of that, you&apos;d have trouble writing reliable unit tests for this. My recommendation: change the implicit dependency of now to explicit one and inject it: It takes only so much to implement dependency [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">Consider a method that calculates some ETA: </p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>class Calendar {
  add3WorkingDays(): Date {
    const result = new Date();
    let daysAdded = 0;
    while (daysAdded &lt; 3) {
      result.setDate(result.getDate() + 1);
      if (this.isWorkingDay(result)) {
        daysAdded++;
      }
    }
    return result;
  }

  isWorkingDay(date: Date): boolean {
    const day = date.getDay();
    return day !== 0 && day !== 6;
  }
}</code></pre></div>



<p class="wp-block-paragraph">Notice how <code>add3WorkingDays</code> depends on the time when it's called (<code>result</code> is initially now). Because of that, you'd have trouble writing reliable unit tests for this. </p>



<p class="wp-block-paragraph">My recommendation: <strong>change the implicit dependency of <code>now</code> to explicit one and inject it</strong>:</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>  add3WorkingDays(date: Date): Date {
    const result = new Date(date);
    // no changes from here</code></pre></div>



<p class="wp-block-paragraph">It takes only so much to implement <a href="https://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a>, the most overcomplicated technique in the history of programming. You don't need frameworks, containers, service locators, interfaces, or decorators. You only need to know how to parameterize a method.</p>



<p class="wp-block-paragraph">Oh, by the way, we changed the interface of the method too. We have to change all the callers:  <code>calendar.add3WorkingDays()</code> -&gt; <code>calendar.add3WorkingDays(new Date())</code></p>



<p class="wp-block-paragraph">Does this mean you don't want to introduce dependency injection later in the project, to avoid risky refactors? No. You can still have DI without changing the interface <strong>using the default parameter</strong>:</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>  add3WorkingDays(date: Date = new Date())</code></pre></div>



<!--more-->



<p class="wp-block-paragraph">This way all the callers of <code>add3WorkingDays</code> can stay unchanged and, at the same time, all your unit tests can use the parameter to test the method properly.</p>



<h2 class="wp-block-heading">Other useful examples</h2>



<h3 class="wp-block-heading">1. Validation rules</h3>



<p class="wp-block-paragraph">When the list of rules is long and much easier to comprehend in isolation, you can inject a 1-item array in tests. Don't forget to use types, so that your tests are reliable.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>const DEFAULT_RULES: Rule[] = [
  {
    errorMessage: &#39;Password must be at least 10 characters long&#39;,
    predicate: (password: string) =&gt; password.length &gt;= 10,
  },
  {
    errorMessage: &#39;Password must contain at least one number&#39;,
    predicate: (password: string) =&gt; /[0-9]/.test(password),
  },
  {
    errorMessage: &#39;Password must contain at least one special character&#39;,
    predicate: (password: string) =&gt; /[!@#$%^&*()_+{}\[\]:;&lt;&gt;,.?~\\]/.test(password),
  },
  {
    errorMessage: &#39;Password must contain at least one lowercase letter&#39;,
    predicate: (password: string) =&gt; /[a-z]/.test(password),
  },
  {
    errorMessage: &#39;Password must contain at least one uppercase letter&#39;,
    predicate: (password: string) =&gt; /[A-Z]/.test(password),
  }
]

class PasswordValidator {
  constructor(readonly rules: Rule[] = DEFAULT_RULES) { }

  validate(password: string): ValidationResult {
    const errors = this.rules.reduce((errors: string[], rule: Rule) =&gt; {
      if (!rule.predicate(password)) {
        errors.push(rule.errorMessage);
      }
      return errors;
    }, []);

    return {
      success: errors.length === 0,
      errorMessages: errors,
    };
  }
}

// in production
new PasswordValidator();

// when you test a single rule
new PasswordValidator([{
  errorMessage: &#39;Password must contain at least one special character&#39;,
  predicate: (password: string) =&gt; /[!@#$%^&*()_+{}\[\]:;&lt;&gt;,.?~\\]/.test(password),
}])

// when you test what happes when your predicate fails
new PasswordValidator([{
  errorMessage: &#39;Error message that always shows&#39;,
  predicate: () =&gt; false
}])</code></pre></div>



<h3 class="wp-block-heading">2. Random number generator</h3>



<p class="wp-block-paragraph">Make <code>Math.random</code> an explicit dependency.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>class Random {
  constructor(readonly getNumber: () =&gt; number = Math.random) { }

  getRandomInt(min: number, max: number): number {
    return Math.floor(this.getNumber() * (max - min)) + 1;
  }
}

console.log(new Random(() =&gt; 1.0).getRandomInt(1, 10)); // prints &quot;10&quot;
console.log(new Random(() =&gt; 0.5).getRandomInt(1, 10)); // prints &quot;5&quot;
console.log(new Random(() =&gt; 0.0).getRandomInt(1, 10)); // prints &quot;1&quot;</code></pre></div>



<h3 class="wp-block-heading">3. Logger</h3>



<p class="wp-block-paragraph">Instead of using <code>console.log</code> you can hide the concrete implementation of it behind an interface. This way it's easily replaceable eg. in tests when you don't want to pollute your console. Note how the interface is a useful feature here.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>interface Print {
  log(...data: any[]): void;
}

class Logger {
  constructor(readonly print: Print = console) { }

  log(message: string): void {
    this.print.log(message);
  }
}

class NoopPrint implements Print {
  log(): void {
    // noop
  }
}

new Logger().log(&#39;Hello&#39;); // prints &quot;Hello&quot;
new Logger(new NoopPrint()).log(&#39;Hello&#39;); // prints nothing</code></pre></div>



<h3 class="wp-block-heading">4. Config / <code>process.env</code></h3>



<p class="wp-block-paragraph">Once again, make it an explicit dependency.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>class Config {
  constructor(readonly env: NodeJS.Dict&lt;string&gt; = process.env) { }

  get(key: string): string | undefined {
    return this.env[key];
  }
}

const stubConfig = { &#39;NODE_ENV&#39;: &#39;not real env&#39; }

console.log(new Config().get(&#39;NODE_ENV&#39;)); // prints your NODE_ENV
console.log(new Config(stubConfig).get(&#39;NODE_ENV&#39;)); // prints &quot;not real env&quot;</code></pre></div>



<h3 class="wp-block-heading">5. Web MVC-ish</h3>



<p class="wp-block-paragraph">Typically, in a web framework, you have layers of classes (like services or repositories). If you follow that structure without giving it too much thinking your integration tests require a real database connection.</p>



<p class="wp-block-paragraph">Here is how to do this with simple dependency injection:</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-ts" data-lang="TypeScript"><code>class User {
  id: string;
  name: string;
}

const nullUser = new User();

interface UserRepository {
  get: (id: string) =&gt; User;
}

class SQLUserRepository implements UserRepository {
  get(id: string) {
    // SQL queries and whatnot; for now, just return a new user
    return new User();
  }
}

class InMemoryUserRepository implements UserRepository {
  constructor(readonly records: User[] = []) {
  }

  get(id: string) {
    return this.records.find((record) =&gt; record.id === id) ?? nullUser;
  }
}

class UserService {
  constructor(private userRepository: UserRepository = new SQLUserRepository()) { }

  authUser(id: string): boolean {
    const user = this.userRepository.get(id);
    if (user === nullUser) {
      return false;
    }
    return true;
  }
}

// in production
new UserService()

// in tests - initialize with empty database
new UserService(new InMemoryUserRepository())

// in tests - initialize with non-empty database
new UserService(new InMemoryUserRepository([{ id: &#39;1&#39;, name: &#39;John Doe&#39; }]))</code></pre></div>



<p class="wp-block-paragraph">Note how there are two instances of dependency injection here. You can inject a <code>UserRepositry</code> (you don't have to, but you want it in your tests). And you can inject initial values to <code>InMemoryUserRepository</code> (again, you don't have to).</p>



<h2 class="wp-block-heading">Dependency injection for testability</h2>



<p class="wp-block-paragraph">Think of your code as potentially called by different types of callers. These different callers may need to inject dependencies according to their needs. One of the callers is always tests &#8211; think of what to inject to make your code testable. </p>



<h2 class="wp-block-heading">Takeaways</h2>



<ul class="wp-block-list">
<li>Dependency injection is not a pattern, should be written all lowercase. Don't be fooled by people who say that you need DI containers/service locators/frameworks to implement dependency injection.</li>



<li>You can have dependency injection in a very simple way &#8211; add another parameter to your constructor, function, or method.</li>



<li>The hard part is: some dependencies are implicit; first you have to recognize that and make them explicit, after that dependency injection should be straightforward.</li>



<li>You can leverage the default parameter to introduce dependency injection without changing the callers' code.</li>



<li>Always inject dependencies that are inconvenient for tests</li>
</ul>
]]></content:encoded>
</item>
<item>
<title>Don&apos;t automate everything. Go Elon instead.</title>
<link>https://bartoszkrajka.com/2024/01/11/dont-automate-everything-go-elon-instead/</link>
<pubDate>Thu, 11 Jan 2024 07:27:34 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1388</guid>
<description>If you &amp;#8220;automate everything&amp;#8221; you end up with cargo-cult of your process. What you should do instead is employing Elon&apos;s 5 steps protocol (&amp;#8220;the Algorithm&amp;#8221;) that consists of in order: Always. In. That. Order. If you automate something that meets unnecessary requirements &amp;#8211; you&apos;re doing it wrong. If you automate something that shouldn&apos;t even exist [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">If you &#8220;automate everything&#8221; you end up with cargo-cult of your process.</p>



<p class="wp-block-paragraph">What you should do instead is employing <a href="https://www.corporate-rebels.com/blog/musks-algorithm-to-cut-bureaucracy">Elon's 5 steps protocol</a> (&#8220;the Algorithm&#8221;) that consists of <strong>in order</strong>: </p>



<ol class="wp-block-list">
<li>Question (requirements)</li>



<li>Delete</li>



<li>Simplify / Optimize</li>



<li>Accelerate (cycle time)&nbsp;</li>



<li>Automate</li>
</ol>



<p class="wp-block-paragraph">Always. In. That. Order.</p>



<p class="wp-block-paragraph">If you automate something that meets unnecessary requirements &#8211; <strong>you're doing it wrong</strong>.</p>



<p class="wp-block-paragraph">If you automate something that shouldn't even exist &#8211; <strong>you're doing it wrong</strong>.</p>



<p class="wp-block-paragraph">If you automate something before you try and simplify it real hard &#8211; <strong>you're doing it wrong</strong>.</p>



<p class="wp-block-paragraph">If you automate something prior to accelerating it's cycle time &#8211; <strong>you're doing it wrong</strong>.</p>



<p class="wp-block-paragraph">Every such automation helps cultivate current pathology.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">Possibly the most common error of a smart engineer is to&nbsp;<strong>optimise a thing that should not exist,</strong></p>
<cite>Elon</cite></blockquote>



<p class="wp-block-paragraph">What a waste it is to automate &#8220;everything&#8221;!</p>



<p class="wp-block-paragraph"><strong>Automate aggressively but first </strong>own the progress and make sure you automate the right thing.</p>
]]></content:encoded>
</item>
<item>
<title>Unit tests can (and should!) go through many classes</title>
<link>https://bartoszkrajka.com/2023/11/23/unit-tests-can-and-should-go-through-many-classes/</link>
<pubDate>Thu, 23 Nov 2023 07:42:25 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1333</guid>
<description>We often design our code so that one procedure comprises many classes, often grouped by layers. For example, in web dev, that could be controllers, models, repositories, etc: Layers are good. Often at least two layers are desirable for maintainability: domain and low-level. If you&apos;re like me, you like 2-5 layers but not too many. [&amp;hellip;]</description>
<content:encoded><![CDATA[<p class="wp-block-paragraph">We often design our code so that one <em>procedure</em> comprises many classes, often grouped by layers. For example, in web dev, that could be controllers, models, repositories, etc: </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="551" height="211" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic1.drawio-3.png" alt="" class="wp-image-1360" srcset="/wp-content/uploads/2023/11/pic1.drawio-3.png 551w, /wp-content/uploads/2023/11/pic1.drawio-3-300x115.png 300w" sizes="auto, (max-width: 551px) 100vw, 551px" /></figure>



<p class="wp-block-paragraph">Layers are good. Often at least two layers are desirable for maintainability: domain and low-level. If you're like me, you like 2-5 layers but not too many. </p>



<p class="wp-block-paragraph">Now how do you test such code? It comes naturally to want to test each component separately and mock out the collaborators from other layers. I believe it's because unit tests are said to be run “in isolation”:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="541" height="311" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic2.drawio-1.png" alt="" class="wp-image-1367" srcset="/wp-content/uploads/2023/11/pic2.drawio-1.png 541w, /wp-content/uploads/2023/11/pic2.drawio-1-300x172.png 300w" sizes="auto, (max-width: 541px) 100vw, 541px" /></figure>



<p class="wp-block-paragraph"><strong>My advice &#8211; don't automatically do this. Aim for this instead:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="621" height="241" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic3.drawio.png" alt="" class="wp-image-1362" srcset="/wp-content/uploads/2023/11/pic3.drawio.png 621w, /wp-content/uploads/2023/11/pic3.drawio-300x116.png 300w" sizes="auto, (max-width: 621px) 100vw, 621px" /></figure>



<h1 class="wp-block-heading">Why is it better?</h1>



<!--more-->



<h3 class="wp-block-heading">More certainty</h3>



<p class="wp-block-paragraph">The goal<sup data-fn="7681e338-212c-425b-98cf-f78c660c7a83" class="fn"><a href="#7681e338-212c-425b-98cf-f78c660c7a83" id="7681e338-212c-425b-98cf-f78c660c7a83-link">1</a></sup> of automated tests is to ensure the app works as intended. In your app, the <strong>classes are not run in isolation from each other</strong>. The execution of a procedure goes through all the layers, and so should the tests.</p>



<p class="wp-block-paragraph">Sheer class tests don't make enough of a <a href="https://www.yegor256.com/2022/07/05/safety-net.html">safety net</a> or an oracle. I bet you can remember code having 100% test coverage by singular class tests, yet still failing in production. </p>



<p class="wp-block-paragraph">While asserting the behavior of a single class <em>can</em> give some certainty, asserting the behavior of the entire execution flow gives much more of it. </p>



<h3 class="wp-block-heading">Better specification</h3>



<p class="wp-block-paragraph">One class can be relatively easy to understand, especially if you have small classes. </p>



<p class="wp-block-paragraph">Testing small methods of small classes often looks ridiculous:</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>describe(&#39;.toString()&#39;, () =&gt; {
  it(&#39;formats number&#39;, () =&gt; {
    expect(toString(5)).toEqual(&#39;5&#39;);
  })
})</code></pre></div>



<p class="wp-block-paragraph">Such tests are better than none but don't help too much in understanding the code. We can often do better. </p>



<p class="wp-block-paragraph">Good spec offers a <em>triangulation</em> &#8211; a different way of looking at code instead of blindly repeating what's in the code.</p>



<p class="wp-block-paragraph">The collaboration of classes is usually harder to comprehend. That's when the tests can help too. Expecting a certain behavior from a group of classes in the form of a test can be massively helpful in understanding what's going on in the system.</p>



<h3 class="wp-block-heading">Allows easier refactoring</h3>



<p class="wp-block-paragraph">Now that's a biggie.</p>



<p class="wp-block-paragraph">You want to test behavior, not implementation. <a href="https://www.youtube.com/watch?v=EZ05e7EMOLM">Ian Cooper explained it best</a>.</p>



<p class="wp-block-paragraph">You want your tests to treat your SUT as a black box. </p>



<p class="wp-block-paragraph">If you class-test your system, you do the opposite. <strong>Class tests effectively cement your implementation</strong>. They effectively discourage changes to particular classes, because it takes more hassle. </p>



<p class="wp-block-paragraph">Think about what happens when you want to bypass <strong>one class</strong> by removing one layer. You not only need to change tests of that class but also mocks of collaborator's tests:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="521" height="311" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic4.drawio-2.png" alt="" class="wp-image-1368" srcset="/wp-content/uploads/2023/11/pic4.drawio-2.png 521w, /wp-content/uploads/2023/11/pic4.drawio-2-300x179.png 300w" sizes="auto, (max-width: 521px) 100vw, 521px" /></figure>



<p class="wp-block-paragraph">If instead, you access your classes by a top-level class, you do not need to change the tests at all:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="611" height="301" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic5.drawio-1.png" alt="" class="wp-image-1366" srcset="/wp-content/uploads/2023/11/pic5.drawio-1.png 611w, /wp-content/uploads/2023/11/pic5.drawio-1-300x148.png 300w" sizes="auto, (max-width: 611px) 100vw, 611px" /></figure>



<p class="wp-block-paragraph">Imagine how easy it is to change internals in the latter case. You can change your &#8220;black box&#8221; to a different implementation, merge classes, split classes, use 3rd parties, etc. <strong>You can do all that anytime with no changes to the tests</strong>. They constantly serve you as a safety net. How cool is that?</p>



<p class="wp-block-paragraph">This is the game changer if you play long-term. <strong>Implementation should be subject to frequent change. You want your tests to support you in this</strong>, not push you away! In order to achieve that you should do away testing every single class &#8211; a ball and chain when it comes to refactoring.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h1 class="wp-block-heading">But is it <em>unit</em> test?</h1>



<p class="wp-block-paragraph">A common reaction is that it's not a unit test if you test more than one class. You're testing integration.</p>



<p class="wp-block-paragraph">I strongly disagree. In my opinion, the most common mistake devs make when it comes to testing is <strong>equating unit tests with class tests</strong>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">unit ≠ class<br>unit test ≠ class test</p>
</blockquote>



<h3 class="wp-block-heading">What's a unit anyway?</h3>



<p class="wp-block-paragraph">There is no consensus on what a unit is. The definitions are vague.  More often instead of definitions you can find traits of unit tests. Unit tests should be: </p>



<ul class="wp-block-list">
<li>fast</li>



<li>repeatable</li>



<li>deterministic</li>



<li>cheap</li>
</ul>



<p class="wp-block-paragraph">None of this is violated by testing more classes at once.</p>



<p class="wp-block-paragraph">There is also one more trait that is more questionable and it's <strong>isolation</strong>. As I said in the beginning, unit tests are also said to be <strong>isolated</strong> and this word must carry more confusion.</p>



<p class="wp-block-paragraph"><strong>I'd argue the isolation of unit tests means the isolation from other tests</strong>. You should be able to run a particular test case without depending on others. </p>



<p class="wp-block-paragraph">You are not meant to always isolate all collaborators. </p>



<p class="wp-block-paragraph">Yes, units should not always go through the entire system. The unit can't cross <em>something</em>. But this <em>something</em> is bigger than just a class.</p>



<h3 class="wp-block-heading">Tests should be useful</h3>



<p class="wp-block-paragraph">After all, if they are not useful, why use them?</p>



<p class="wp-block-paragraph">From my experience, the useful definition of unit tests is:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>Unit test</strong> &#8211; the most granular test in your system that fits in memory and doesn't cross <strong><em>modules</em></strong>. </p>



<p class="wp-block-paragraph">In contrast &#8211; <strong>integration tests</strong> indicate there are more granular tests below them.</p>
</blockquote>



<p class="wp-block-paragraph">Unit tests should not cross well-defined modules and should not use external 3rd parties like databases and networking.</p>



<p class="wp-block-paragraph">If such a unit test covers your whole system &#8211; great!</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h1 class="wp-block-heading">Avoid combinatorial explosion</h1>



<p class="wp-block-paragraph">Okay, so you test as many classes at once as possible. But should you always test all of the layers? Of course not. Your main enemy is the combinatorial explosion of test cases.</p>



<p class="wp-block-paragraph">Imagine you have a domain that can produce 5 different numbers and another class that can present those numbers in 5 different ways. </p>



<p class="wp-block-paragraph">Each class separately can be covered by 5 test cases. Testing them both  combined with an equal level of coverage would take 5*5 = 25 test cases:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="511" height="372" src="https://bartoszkrajka.com/wp-content/uploads/2023/11/pic6.drawio.png" alt="" class="wp-image-1369" srcset="/wp-content/uploads/2023/11/pic6.drawio.png 511w, /wp-content/uploads/2023/11/pic6.drawio-300x218.png 300w" sizes="auto, (max-width: 511px) 100vw, 511px" /></figure>



<p class="wp-block-paragraph">You may want to:</p>



<ol class="wp-block-list">
<li>Focus on writing exhaustive class tests (these will be your unit tests)</li>



<li>Write <strong>only some</strong> black-box tests as integration tests</li>
</ol>



<p class="wp-block-paragraph">This is a very good idea. My point is that a combinatorial explosion is hard to notice from a distance. Like every other design concept should not be predicted but dealt with only after it's become a real problem.</p>



<p class="wp-block-paragraph">My rule of thumb is to <strong>start with end-to-end</strong>. And when combinatorial explosion starts to cripple &#8211; only then split the tests into more. </p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h1 class="wp-block-heading">Summary</h1>



<ul class="wp-block-list">
<li>Don't equate unit tests with class tests. This is lazy.</li>



<li>You can write unit tests that go through many classes in multiple layers.</li>



<li>Not only you can do it, but you should. Testing cooperation of many classes is more reliable, makes for better documentation, and most of all &#8211; allows for safe refactoring.</li>



<li>You should aim to test as many real classes at once as possible while still avoiding the combinatorial explosion of test cases. Start with end-to-end testing of your modules.</li>



<li>You don't have to mock every collaborator of your system under test. Mock on boundaries &#8211; 3rd parties or modules</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>


<ol class="wp-block-footnotes"><li id="7681e338-212c-425b-98cf-f78c660c7a83"><em>One of</em> the goals. But the most important one <a href="#7681e338-212c-425b-98cf-f78c660c7a83-link" aria-label="Jump to footnote reference 1">↩︎</a></li></ol>]]></content:encoded>
</item>
<item>
<title>Making sense is overrated</title>
<link>https://bartoszkrajka.com/2023/04/18/making-sense-is-overrated/</link>
<pubDate>Tue, 18 Apr 2023 06:44:30 +0000</pubDate>
<guid isPermaLink="false">https://bartoszkrajka.com/?p=1145</guid>
<description>Test first? How do I test something that is not yet written? And before all, why? It makes no sense. Try it a few times and you&apos;ll see how powerful it is! Open–closed principle? The more I close my code to modification, the more closed it gets for extention. You can&apos;t have both. It makes [&amp;hellip;]</description>
<content:encoded><![CDATA[<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">Test first? How do I test something that is not yet written? And before all, why? <em><strong>It makes no sense.</strong></em></p>
</blockquote>



<p class="wp-block-paragraph">Try it a few times and you'll see how powerful it is!</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">Open–closed principle? The more I <em>close </em>my code to modification, the more <em>closed</em> it gets for extention. You can't have both. <strong><em>It makes no sense.</em></strong></p>
</blockquote>



<p class="wp-block-paragraph">Only until you realize that it's actually possible &#8211; with interfaces or other dependency inversion techniques.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">The best code comment is the one that never existed? Comments are the only thing that allows me to navigate my messy code. You want me to stop writing them? <em><strong>It makes no sense.</strong></em></p>
</blockquote>



<p class="wp-block-paragraph">Yes, stop writing comments and delete all of them. But only after you clean up the code to the extent that comments are not needed. <a href="https://bartoszkrajka.com/2018/03/05/uncle-barteks-attitude-towards-code-comments-examples/">There are ways to do it</a>.</p>



<!--more-->



<p class="wp-block-paragraph">These ideas feel absurd the first time you encounter them. Yet, they start making sense after some consideration or trying them out in practice.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">Knowledge is generally additive. You learn something new that adds to all the previous knowledge you had learned. </p>



<p class="wp-block-paragraph">However, sometimes you can encounter a <a href="https://en.wikipedia.org/wiki/Paradigm_shift">paradigm shift</a>. Learning a new thing <em>undermines</em> or <em>contradicts</em> some of the previous knowledge you had learned. You need to redefine some ideas (<em>tests</em>) or see the bigger picture (<em>long-term effect of code comments</em>).</p>



<p class="wp-block-paragraph">If you are familiar with <a href="https://en.wikipedia.org/wiki/List_of_cognitive_biases">cognitive biases</a>, this shouldn't be surprising to you. Humans tend to perceive reality wrong all the time. Not always. But all the time. The sense that things make to you or not is more like your opinion than a fact. </p>



<p class="wp-block-paragraph">Rejecting nonsense ideas is like rejecting opinions because they are different than yours. This leads to a spiral of <a href="https://en.wikipedia.org/wiki/Confirmation_bias">confirmation bias</a>. </p>



<p class="wp-block-paragraph">Plus, opinions are opinions. What if you are the one who's wrong?</p>



<p class="wp-block-paragraph">Sometimes to embrace the new you need to see the bigger picture or redefine some ideas. Powerful ideas are beyond your current level of sensibility.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">I'd go as far as actively seek &#8220;stupid but there is something to it&#8221; ideas. I think they are so powerful <strong>because</strong> they don't make sense. The reason why I'm this patient with such ideas might be my strong <a href="https://www.gallup.com/cliftonstrengths/en/252260/ideation-theme.aspx">Ideation theme</a>.</p>
</blockquote>



<h2 class="wp-block-heading">So what to do?</h2>



<p class="wp-block-paragraph">I want to be clear that I'm <em>not expressing a preference for nonsense</em>. I'm not saying you should reject sensibility altogether. Most ideas would still make sense. I'm only saying that some of them will not make sense at the first glance.</p>



<h3 class="wp-block-heading">The bad</h3>



<p class="wp-block-paragraph">The bad is to automatically say &#8220;no&#8221; to ideas because they make no sense, without deeper consideration.</p>



<p class="wp-block-paragraph">The negation of this is also bad &#8211; to automatically assume that &#8220;something makes sense&#8221; means it's the only reasonable way of thinking.</p>



<h3 class="wp-block-heading">The good</h3>



<p class="wp-block-paragraph">The good is to be open-minded to new ideas, even if they seemingly don't make sense. Maybe there is something to it&#8230;?</p>



<p class="wp-block-paragraph">The good is to keep asking yourself &#8220;What if I'm wrong?&#8221;. When considering a nonsense idea, try to answer: &#8220;What would need to happen for this to be true?&#8221;</p>



<p class="wp-block-paragraph">The good is to experiment. Listen to Kent Beck:  </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">If an idea is obviously bad, find a cheap way to try it; if it works it's extremely interesting</p>
</blockquote>



<h2 class="wp-block-heading">Examples</h2>



<p class="wp-block-paragraph">Here are a few examples of beliefs that I consider true, even though initially they used to make no sense to me. Feel free to ask for more explanation if you need it!</p>



<ul class="wp-block-list">
<li>The only way to go fast is to go well</li>



<li>Refinements should be as <strong>short</strong> as possible</li>



<li>Deploy directly to production</li>



<li>The target number of questions in communication is 0</li>



<li>You can't afford cheap things</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph"><em>PS. The top image is generated by DALL-E (prompt: making sense is overrated). I love the vibe of irony and meme-ability of this one!</em></p>
]]></content:encoded>
</item>
</channel>
</rss>
