{"id":7438,"date":"2024-01-12T12:10:18","date_gmt":"2024-01-12T11:10:18","guid":{"rendered":"https:\/\/kabisa.nl\/?p=7438"},"modified":"2024-01-17T10:12:41","modified_gmt":"2024-01-17T09:12:41","slug":"do-repeat-yourself","status":"publish","type":"post","link":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/","title":{"rendered":"Do Repeat Yourself"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"7438\" class=\"elementor elementor-7438\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e74ba16 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e74ba16\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;jet_parallax_layout_list&quot;:[]}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ccec6d4\" data-id=\"ccec6d4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6b076b0 elementor-widget elementor-widget-text-editor\" data-id=\"6b076b0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>One of the first things we teach aspiring software engineers is the principle &#8220;Don&#8217;t Repeat Yourself&#8221;. The notion that as software engineers we should never write the same code twice. Duplication makes our code harder to change. So to prevent this, we learn to take all cases of the oh so dreaded duplication away.<\/h3>\n<h2>But is it always worth it?<\/h2>\n<div>\n<div>Most of the time, the principle applies and will make the codebase better. So, after learning this, it&#8217;s quite likely each and every case of duplication becomes one we fight. Before we know it we are waging war against duplication and exterminating it left and right using our favourite weapons &#8211; refactoring it into a function, utility class or even a standalone library for others to use.<\/div>\n<div>&nbsp;<\/div>\n<div>But is it always worth it? Is abstracting <em>each and every<\/em> duplication away worthy of your precious time? And if not for time &#8211; is it always beneficial for maintainability?<\/div>\n<div>&nbsp;<\/div>\n<div><b>Here, I&#8217;ll say it:<\/b><\/div>\n<\/div>\n<div>&nbsp;<\/div>\n<blockquote>\n<p>In some cases DRY is not worth it.<\/p>\n<p>In some cases DRY does not help, but harms maintainability..<\/p>\n<\/blockquote>\n<p>Before burning me at the stake \ud83d\udd25, please let me explain&#8230;<\/p>\n<h2>Abstractions<\/h2>\n<p>Refactoring something specific, like extracting duplicated lines to a generic function, is an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Abstraction_(computer_science)#:~:text=In%20software%20engineering%20and%20computer%20science%2C%20abstraction%20is%20the%20process%20of%20generalizing%20concrete%20details%2C\">abstraction<\/a> &#8211; albeit on a granular scale.<\/p>\n<p>Refactoring a duplicated piece of code into the right abstraction is very satisfying. Especially when the moment of change inevitably knocks on your door. The business changes, so the code needs to change. Oh, how convenient! We abstracted this code into a function and now we only have to change it in one place instead of having to change it throughout the whole codebase.<\/p>\n<p>It&#8217;s the moment of validation for our choices of the past. The indisputable proof we made the right choice. \ud83d\udcaa<\/p>\n<p>In this case it was worth the time that was invested into the refactor. It made our lives easier when change was needed.<\/p>\n<h2>A bad abstraction<\/h2>\n<p>But in other cases creating an abstraction that looks very similar to the abstraction above, can make our lives <em>harder<\/em>.<\/p>\n<p><strong>Let&#8217;s take a look at an example.<\/strong><\/p>\n<p>Once again we extract some duplication between two classes into a helper function while simultaneously dreaming of the moment of validation &#8211; which will surely arrive soon. We wait a while and surely enough, the business changes again. Of course, now we need to update the software.<\/p>\n<p>We refine the change and give it quite a low estimate, as we expect to be able to easily implement the change. This is part of the <em>clean code territory<\/em> in the project after all! \ud83c\udf89<\/p>\n<p>But instead of being met with the happy experience of convenience, we notice that it&#8217;s now a little harder to add the new business rules than before.<\/p>\n<p>Apparently, only the behaviour of one of the two original classes needs to be changed. As we already invested the time to create this beautiful abstraction, we absolutely can&#8217;t revert back to the old ways. That would feel bad, since then we would be unconsciously admitting we made the wrong choice in the past. \ud83e\udd14<\/p>\n<p>So we decided to just add a parameter to the extracted function. I mean, just one more function parameter is still readable. We can implement this change pretty quickly. Nothing wrong with just a single parameter, right? And anyway, we might be able to benefit from the abstraction <a href=\"https:\/\/en.wikipedia.org\/wiki\/You_aren%27t_gonna_need_it\">in the future.<\/a><\/p>\n<h3><i>And today, a bad abstraction was born.<\/i><\/h3>\n<p>And the 6 other engineers that touched the code after us? They will surely keep the abstraction in place. Someone spent effort on creating this abstraction, so it should be there for a good reason! Undoing this work and going back to the original duplication sounds like madness, it&#8217;d be almost insulting to the person who created it.<\/p>\n<p>So some of them add a few positional parameters, others add parameters with default values and the last one even adds a few keyword arguments:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-36d7aa2 elementor-section-stretched elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"36d7aa2\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;stretch_section&quot;:&quot;section-stretched&quot;,&quot;jet_parallax_layout_list&quot;:[]}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-edbe691\" data-id=\"edbe691\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d50bb22 elementor-widget elementor-widget-code-highlight\" data-id=\"d50bb22\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard word-wrap\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>public void generate(Data data, MailData mailData, sendMail = false, type = Type.A, alsoGenerateY = true) \/* etc... *\/ {\n    generateX(data)\n\n    \/\/ Parameters and checks keep getting added.\n    \/\/ Complexity keeps rising over time, at some\n    \/\/ point it becomes unmaintainable.\n    if (sendMail) {\n        if (type != Type.B && mailData != null) {\n            sendMail(mailData);\n        }\n\n        if (alsoGenerateY && type != Type.A && mailData.X == true) {\n            generateY(data)\n        }\n    }\n}\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-747b217 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"747b217\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;jet_parallax_layout_list&quot;:[]}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ac32b96\" data-id=\"ac32b96\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8aa0aea elementor-widget__width-initial elementor-widget elementor-widget-text-editor\" data-id=\"8aa0aea\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 300;\">The code is dryer than the Sahara at high noon, but the cycle goes on, and on, and on\u2026<\/span><\/p><p><strong>What do you think about this? Let me know through the contact form below. \ud83d\udc47<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>One of the first things we teach aspiring software engineers is the principle &#8220;Don&#8217;t Repeat Yourself&#8221;. The notion that as software engineers we should never write the same code twice. Duplication makes our code harder to change. So to prevent this, we learn to take all cases of the oh so dreaded duplication away. But [&hellip;]<\/p>\n","protected":false},"author":24,"featured_media":7491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149],"tags":[],"class_list":["post-7438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.4 (Yoast SEO v28.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Do Repeat Yourself | Kabisa Software Artisans<\/title>\n<meta name=\"description\" content=\"One of the first things we teach aspiring software engineers is the principle &quot;Don&#039;t Repeat Yourself&quot;. The notion that as software engineers we should\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Do Repeat Yourself | Kabisa Software Artisans\" \/>\n<meta property=\"og:description\" content=\"One of the first things we teach aspiring software engineers is the principle &quot;Don&#039;t Repeat Yourself&quot;. The notion that as software engineers we should\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/\" \/>\n<meta property=\"og:site_name\" content=\"Kabisa Software Artisans\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/kabisaict\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-12T11:10:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-17T09:12:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/Do-Repeat-Yourself-Blog-Post.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jordy van Vorselen\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jordy van Vorselen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Do Repeat Yourself | Kabisa Software Artisans","description":"One of the first things we teach aspiring software engineers is the principle \"Don't Repeat Yourself\". The notion that as software engineers we should","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/","og_locale":"en_US","og_type":"article","og_title":"Do Repeat Yourself | Kabisa Software Artisans","og_description":"One of the first things we teach aspiring software engineers is the principle \"Don't Repeat Yourself\". The notion that as software engineers we should","og_url":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/","og_site_name":"Kabisa Software Artisans","article_publisher":"https:\/\/www.facebook.com\/kabisaict","article_published_time":"2024-01-12T11:10:18+00:00","article_modified_time":"2024-01-17T09:12:41+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/Do-Repeat-Yourself-Blog-Post.png","type":"image\/png"}],"author":"Jordy van Vorselen","twitter_misc":{"Written by":"Jordy van Vorselen","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#article","isPartOf":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/"},"author":{"name":"Jordy van Vorselen","@id":"https:\/\/kabisa.nl\/en\/#\/schema\/person\/716c9164afca3600898fd02a66807da8"},"headline":"Do Repeat Yourself","datePublished":"2024-01-12T11:10:18+00:00","dateModified":"2024-01-17T09:12:41+00:00","mainEntityOfPage":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/"},"wordCount":693,"commentCount":0,"publisher":{"@id":"https:\/\/kabisa.nl\/en\/#organization"},"image":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#primaryimage"},"thumbnailUrl":"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/featured-image-jordy-do-repeat-yourself.png","articleSection":["Tech blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/","url":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/","name":"Do Repeat Yourself | Kabisa Software Artisans","isPartOf":{"@id":"https:\/\/kabisa.nl\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#primaryimage"},"image":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#primaryimage"},"thumbnailUrl":"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/featured-image-jordy-do-repeat-yourself.png","datePublished":"2024-01-12T11:10:18+00:00","dateModified":"2024-01-17T09:12:41+00:00","description":"One of the first things we teach aspiring software engineers is the principle \"Don't Repeat Yourself\". The notion that as software engineers we should","breadcrumb":{"@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#primaryimage","url":"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/featured-image-jordy-do-repeat-yourself.png","contentUrl":"https:\/\/kabisa.nl\/wp-content\/uploads\/2024\/01\/featured-image-jordy-do-repeat-yourself.png","width":4000,"height":2828},{"@type":"BreadcrumbList","@id":"https:\/\/kabisa.nl\/en\/insights\/do-repeat-yourself\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kabisa.nl\/en\/"},{"@type":"ListItem","position":2,"name":"Insights","item":"https:\/\/kabisa.nl\/en\/insights\/"},{"@type":"ListItem","position":3,"name":"Do Repeat Yourself"}]},{"@type":"WebSite","@id":"https:\/\/kabisa.nl\/en\/#website","url":"https:\/\/kabisa.nl\/en\/","name":"Kabisa Software Artisans","description":"Mission-critical Software for Hightech, Fintech &amp; E-commerce","publisher":{"@id":"https:\/\/kabisa.nl\/en\/#organization"},"alternateName":"Kabisa","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kabisa.nl\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/kabisa.nl\/en\/#organization","name":"Cloud Legends","alternateName":"Kabisa","url":"https:\/\/kabisa.nl\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kabisa.nl\/en\/#\/schema\/logo\/image\/","url":"https:\/\/kabisa.nl\/wp-content\/uploads\/2022\/12\/kabisa-favicon.png","contentUrl":"https:\/\/kabisa.nl\/wp-content\/uploads\/2022\/12\/kabisa-favicon.png","width":512,"height":512,"caption":"Cloud Legends"},"image":{"@id":"https:\/\/kabisa.nl\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/kabisaict","https:\/\/x.com\/kabisasoftware"],"description":"Software Development is onze core-business. Kabisa ontwikkelt innovatieve maatwerk software die naadloos aansluit bij de behoeftes van klanten en eindgebruikers. Dat doen we in nauwe samenwerking in elke fase van het proces: co-creatie noemen we dat.","email":"info@kabisa.nl","telephone":"0495 430 798","legalName":"Kabisa B.V.","foundingDate":"2006-01-01","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"51","maxValue":"200"}},{"@type":"Person","@id":"https:\/\/kabisa.nl\/en\/#\/schema\/person\/716c9164afca3600898fd02a66807da8","name":"Jordy van Vorselen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/596a0dd1050d3a63f6fcfbf1e354e84e855fb318cf5a01ada02a70813f7f2de5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/596a0dd1050d3a63f6fcfbf1e354e84e855fb318cf5a01ada02a70813f7f2de5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/596a0dd1050d3a63f6fcfbf1e354e84e855fb318cf5a01ada02a70813f7f2de5?s=96&d=mm&r=g","caption":"Jordy van Vorselen"}}]}},"_links":{"self":[{"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/posts\/7438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/comments?post=7438"}],"version-history":[{"count":22,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/posts\/7438\/revisions"}],"predecessor-version":[{"id":7492,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/posts\/7438\/revisions\/7492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/media\/7491"}],"wp:attachment":[{"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/media?parent=7438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/categories?post=7438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kabisa.nl\/en\/wp-json\/wp\/v2\/tags?post=7438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}