<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Test Driven Development on  rlang // tech</title>
    <link>https://blog.rlang.tech/tags/test-driven-development/</link>
    <description>Recent content in Test Driven Development on  rlang // tech</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <copyright>Rico Lang (CC BY 4.0)</copyright>
    <lastBuildDate>Fri, 05 Sep 2025 23:34:00 +0200</lastBuildDate>
    <atom:link href="https://blog.rlang.tech/tags/test-driven-development/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The Joy of Test Driven Development</title>
      <link>https://blog.rlang.tech/posts/the-joy-of-test-driven-development/</link>
      <pubDate>Fri, 05 Sep 2025 23:34:00 +0200</pubDate>
      <guid>https://blog.rlang.tech/posts/the-joy-of-test-driven-development/</guid>
      <description>&lt;img src=&#34;tdd.png&#34; alt=&#34;TDD cycle&#34;&gt;&lt;p&gt;At the moment I&amp;rsquo;m working on a project where I&amp;rsquo;m more of a YAML engineer than anything else. During this time, I kind of enjoy getting my hands on actual code again, but most of the time, writing code is a rarity for me. So, whenever I find a cool idea to work on, I usually start a new side project. Something I try to incorporate as soon as possible is &lt;strong&gt;Test Driven Development (TDD)&lt;/strong&gt;.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<img src="tdd.png" alt="TDD cycle"><p>At the moment I&rsquo;m working on a project where I&rsquo;m more of a YAML engineer than anything else. During this time, I kind of enjoy getting my hands on actual code again, but most of the time, writing code is a rarity for me. So, whenever I find a cool idea to work on, I usually start a new side project. Something I try to incorporate as soon as possible is <strong>Test Driven Development (TDD)</strong>.</p>
<p>While I agree that initially TDD may not fit into the ideation phase of your
project where you&rsquo;re still trying to figure what you&rsquo;re doing, but as soon as you&rsquo;re evolving TDD really speeds up your
development.</p>
<p>Let me show you how TDD can up your coding game ! 🚀</p>
<h2 id="refactoring-becomes-part-of-your-workflow">Refactoring Becomes Part of Your Workflow</h2>
<p>While I was working on my side project, something I immediately noticed after applying TDD to it was that refactoring became a part of my development workflow. That&rsquo;s a great thing, right? I mean, how many times have you looked at code thinking:</p>
<blockquote>
<p>&ldquo;Damn
that thing should&rsquo;ve been
refactored a long time ago&rdquo;.</p>
</blockquote>
<p>With TDD, you&rsquo;re refactoring your code more often, simply because you&rsquo;re wiring it directly into your workflow. Every test you write forces you to think about the design of your code, and since writing tests has now become a first-class citizen in your code, you&rsquo;re more likely to refactor your code so that it remains easy to test.</p>
<h2 id="shorter-feedback-cycles">Shorter Feedback Cycles</h2>
<p>By practicing TDD, you&rsquo;re forcing yourself into a constant feedback loop, iterating on the implementation and the design of the code. By writing the test first, you&rsquo;re already investing in the design because you have to think about what your function will return, whether it has a side effect you need to capture, and so on. This leaves you with code that is testable right from the start and easy to refactor later on, since you already have tests covering your existing functionality. As you&rsquo;re in a constant cycle of writing a test, implementing the functionality, and refactoring your code, your feedback loop is way shorter than writing the implementation, starting up the application, and refactoring/fixing bugs afterward.</p>
<h2 id="less-cognitive-complexity">Less cognitive complexity</h2>
<p>Test-driven development encourages you to think about one thing at a time, which really helps to reduce the cognitive complexity during the implementation and while reading the code. More often than not, we get assigned features that contain a lot of business rules, errors, and edge cases. Keeping track of all those things during development can be a real pain.</p>
<p>TDD can help you manage this complexity. If done properly, the acceptance criteria of your feature directly translate to the tests you write. So, in a test-driven fashion, you start writing a test for your first acceptance criterion, implement it, and move on to the next one. This way, you can focus on one part of your feature at a time, and you don&rsquo;t have to worry about introducing yet another edge case, since your tests have your back right from the beginning. If you don&rsquo;t use TDD, you might be inclined to implement all the acceptance criteria at once, thus putting a huge load on your brain.</p>
<h2 id="separating-business-logic-from-side-effects">Separating Business Logic from Side Effects</h2>
<p>Another benefit of Test Driven Development that I absolutely love is that it forces you to keep your business logic <a href="https://en.wikipedia.org/wiki/Pure_function">pure</a> and keeps the side effects on the edges of your application. Side-effectful code can really be a nightmare to test or debug, as it does things you might not expect it to do.</p>
<p>Since TDD enforces your code to be testable, naturally, you tend to push side-effectful code, such as network requests, to the edges of your application so that your business logic is deterministic.</p>
<h2 id="tldr">TL;DR</h2>
<p>Test-driven development is obviously not a silver bullet, and it has to fit your development workflow. In most cases, I think TDD brings a lot to the table and will generally produce better code.</p>
<p>In essence, I&rsquo;d suggest you give it a try, since there is much to gain and not much to lose anyway. Take a <a href="https://kata-log.rocks/tdd">kata</a> and check it out!</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
