[{"data":1,"prerenderedAt":225},["ShallowReactive",2],{"articles":3,"article-en-when-you-should-duplicate-code":219},[4,21,33,46,60,72,81,90,100,111,121,130,141,151,166,177,187,200,209],{"slug":5,"locale":6,"title":7,"description":8,"publishedAt":9,"updatedAt":10,"tags":11,"cover":16,"minutes":17,"featured":10,"mostRead":18,"originalUrl":19,"originalLinked":18,"locales":20},"my-simple-strategy-for-3-268-5-star-chrome-extension-reviews","en","My Simple Strategy for 3,268 5‑Star Chrome Extension Reviews","Around 3.7% of my users leave a review. It comes down to asking at the right moment.","2025-07-28",null,[12,13,14,15],"Marketing","Side Projects","Side Hustle","Chrome Extension","\u002Fblog\u002Fmedia\u002Fmy-simple-strategy-for-3-268-5-star-chrome-extension-reviews\u002Fcover.webp",6,false,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fmy-simple-strategy-for-3-268-5-star-chrome-extension-reviews\u002F",[6],{"slug":22,"locale":6,"title":23,"description":24,"publishedAt":25,"updatedAt":10,"tags":26,"cover":29,"minutes":17,"featured":30,"mostRead":18,"originalUrl":31,"originalLinked":18,"locales":32},"lessons-from-a-bamboo-tree-staying-motivated-on-my-side-project","Five Years to 100K Users: The Bamboo Tree Story for Side Project Growth","For years almost nothing seemed to happen. Why I kept watering anyway.","2024-09-22",[27,28,13,14],"My Journey","Story","\u002Fblog\u002Fmedia\u002Flessons-from-a-bamboo-tree-staying-motivated-on-my-side-project\u002Fcover.webp",1,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Flessons-from-a-bamboo-tree-staying-motivated-on-my-side-project\u002F",[6],{"slug":34,"locale":6,"title":35,"description":36,"publishedAt":37,"updatedAt":10,"tags":38,"cover":41,"minutes":42,"featured":42,"mostRead":43,"originalUrl":44,"originalLinked":18,"locales":45},"3-practical-growth-hacks-i-applied-to-scale-my-chrome-extension-to-100k-users-without-any-marketing-budget","How I Grew My Chrome Extension to 100K Users Without Marketing Costs","Learning SEO, asking for reviews, and building ONE great product.","2024-06-18",[39,40,14,12,27],"Web Development","SEO","\u002Fblog\u002Fmedia\u002F3-practical-growth-hacks-i-applied-to-scale-my-chrome-extension-to-100k-users-without-any-marketing-budget\u002Fcover.webp",4,true,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002F3-practical-growth-hacks-i-applied-to-scale-my-chrome-extension-to-100k-users-without-any-marketing-budget\u002F",[6],{"slug":47,"locale":6,"title":48,"description":49,"publishedAt":50,"updatedAt":10,"tags":51,"cover":57,"minutes":42,"featured":10,"mostRead":18,"originalUrl":58,"originalLinked":18,"locales":59},"the-art-of-slow-growth-how-i-calmly-grew-my-chrome-extension-to-100k-users-in-5-years","The Art of Slow Growth: How I Calmly Grew My Chrome Extension to 100K Users In 5 Years","It took me over a year to get my first ten users. Why I stopped rushing.","2024-06-04",[52,53,39,54,55,56],"Entrepreneurship","marketing","#growth","startup","Startups","\u002Fblog\u002Fmedia\u002Fthe-art-of-slow-growth-how-i-calmly-grew-my-chrome-extension-to-100k-users-in-5-years\u002Fcover.webp","https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fhow-i-calmly-grew-my-chrome-extension-to-100k-users-in-5-years\u002F",[6],{"slug":61,"locale":6,"title":62,"description":63,"publishedAt":64,"updatedAt":10,"tags":65,"cover":67,"minutes":68,"featured":69,"mostRead":18,"originalUrl":70,"originalLinked":18,"locales":71},"3-unusually-painful-mistakes-on-my-side-project-journey-to-100k-users","3 Unusually Painful Mistakes on My Side Project Journey to 100K Users","Never questioning growth, building an audience too late, and not writing things down.","2024-05-03",[66,52,56],"solopreneur","\u002Fblog\u002Fmedia\u002F3-unusually-painful-mistakes-on-my-side-project-journey-to-100k-users\u002Fcover.webp",5,3,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002F3-unusually-painful-mistakes-on-my-side-project-journey\u002F",[6],{"slug":73,"locale":6,"title":74,"description":75,"publishedAt":76,"updatedAt":10,"tags":77,"cover":78,"minutes":17,"featured":10,"mostRead":18,"originalUrl":79,"originalLinked":18,"locales":80},"forget-about-marketing-focus-on-building-an-awesome-product","Forget About Marketing. Focus on Building An Awesome Product","Everyone says great products need a megaphone. Why I still put the product first.","2024-03-04",[52,56,53],"\u002Fblog\u002Fmedia\u002Fforget-about-marketing-focus-on-building-an-awesome-product\u002Fcover.webp","https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fforget-about-marketing-focus-on-building-an-awesome-product\u002F",[6],{"slug":82,"locale":6,"title":83,"description":84,"publishedAt":85,"updatedAt":10,"tags":86,"cover":87,"minutes":17,"featured":10,"mostRead":18,"originalUrl":88,"originalLinked":18,"locales":89},"5-reasons-why-side-projects-never-get-finished","5 Reasons Why Side-Projects Never Get Finished","Shiny objects, boredom, a lack of courage — and how to get back on track.","2023-08-01",[13],"\u002Fblog\u002Fmedia\u002F5-reasons-why-side-projects-never-get-finished\u002Fcover.webp","https:\u002F\u002Fweb-highlights.com\u002Fblog\u002F5-reasons-why-side-projects-never-get-finished\u002F",[6],{"slug":91,"locale":6,"title":92,"description":93,"publishedAt":94,"updatedAt":10,"tags":95,"cover":97,"minutes":17,"featured":10,"mostRead":18,"originalUrl":98,"originalLinked":18,"locales":99},"time-vs-dreams-why-i-decided-to-sell-my-b2b-saas-ai-business","Time Vs. Dreams: Why I Decided to Sell My B2B SaaS AI Business","ChatGPT fever, competitors with thousands of users within weeks, and too little time. Why I sold my AI business.","2023-07-12",[96,66,56,52],"side project","\u002Fblog\u002Fmedia\u002Ftime-vs-dreams-why-i-decided-to-sell-my-b2b-saas-ai-business\u002Fcover.webp","https:\u002F\u002Fblog.marius-bongarts.de\u002Ftime-vs-dreams-why-i-decided-to-sell-my-b2b-saas-ai-business",[6],{"slug":101,"locale":6,"title":102,"description":103,"publishedAt":104,"updatedAt":10,"tags":105,"cover":107,"minutes":108,"featured":10,"mostRead":18,"originalUrl":109,"originalLinked":18,"locales":110},"the-tech-stack-behind-web-highlights-a-chrome-extension-with-over-10-000-weekly-users","Web Highlights Tech Stack: Chrome Extension With 100k+ Users","Web Components, Vue.js and the rest of the stack behind the extension.","2023-02-27",[39,106,27],"Web Highlights","\u002Fblog\u002Fmedia\u002Fthe-tech-stack-behind-web-highlights-a-chrome-extension-with-over-10-000-weekly-users\u002Fcover.webp",9,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fthe-tech-stack-behind-web-highlights-a-chrome-extension-with-over-10-000-weekly-users\u002F",[6],{"slug":112,"locale":6,"title":113,"description":114,"publishedAt":115,"updatedAt":10,"tags":116,"cover":118,"minutes":42,"featured":10,"mostRead":18,"originalUrl":119,"originalLinked":18,"locales":120},"failing-forward-the-importance-of-publishing-your-side-projects","Failing Forward: The Importance of Publishing Your Side Projects","Publish your side projects, even if they fail — and why failing forward makes you more creative.","2023-02-20",[14,13,39,117,27],"Programming","\u002Fblog\u002Fmedia\u002Ffailing-forward-the-importance-of-publishing-your-side-projects\u002Fcover.webp","https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Ffailing-forward-the-importance-of-publishing-your-side-projects\u002F",[6],{"slug":122,"locale":6,"title":123,"description":124,"publishedAt":125,"updatedAt":10,"tags":126,"cover":127,"minutes":68,"featured":10,"mostRead":18,"originalUrl":128,"originalLinked":18,"locales":129},"rocketing-to-10-000-users-how-i-achieved-a-270-increase-in-just-9-months-with-my-chrome-extension","How I Increased Chrome Extension Users by 270% in 9 Months","Simple SEO, done consistently: the nine months that took the extension to 10,000 users.","2023-02-06",[12,40,14,106],"\u002Fblog\u002Fmedia\u002Frocketing-to-10-000-users-how-i-achieved-a-270-increase-in-just-9-months-with-my-chrome-extension\u002Fcover.webp","https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Frocketing-to-10-000-users-how-i-achieved-a-270-increase-in-just-9-months-with-my-chrome-extension\u002F",[6],{"slug":131,"locale":6,"title":132,"description":133,"publishedAt":134,"updatedAt":10,"tags":135,"cover":137,"minutes":138,"featured":10,"mostRead":18,"originalUrl":139,"originalLinked":18,"locales":140},"seo-strategies-i-used-to-gain-2-000-users-in-two-months","SEO Strategies I Used to Gain 2,000 Users In Two Months","A blog, backlinks and a cleaner site structure: how my user base grew 37% in two months.","2022-10-17",[40,12,39,136,27,28],"Software","\u002Fblog\u002Fmedia\u002Fseo-strategies-i-used-to-gain-2-000-users-in-two-months\u002Fcover.webp",8,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fseo-strategies-i-used-to-gain-2-000-users-in-two-months\u002F",[6],{"slug":142,"locale":6,"title":143,"description":144,"publishedAt":145,"updatedAt":10,"tags":146,"cover":147,"minutes":148,"featured":10,"mostRead":18,"originalUrl":149,"originalLinked":18,"locales":150},"my-journey-to-5000-users-with-a-web-pdf-highlighter-chrome-extension","How I Achieved 5000+ Users with My Chrome Extension","Just do it, do things that don’t scale, and talk about your product.","2022-10-10",[15,13,27,28],"\u002Fblog\u002Fmedia\u002Fmy-journey-to-5000-users-with-a-web-pdf-highlighter-chrome-extension\u002Fcover.webp",7,"https:\u002F\u002Fweb-highlights.com\u002Fblog\u002Fmy-journey-to-5000-users-with-a-web-pdf-highlighter-chrome-extension\u002F",[6],{"slug":152,"locale":6,"title":153,"description":154,"publishedAt":155,"updatedAt":10,"tags":156,"cover":163,"minutes":164,"featured":10,"mostRead":18,"originalUrl":10,"originalLinked":18,"locales":165},"are-web-components-dead","Are Web Components Dead?","Some say they died years ago, others call them the future. Where they show up today and what holds developers back.","2022-06-20",[157,39,158,159,160,161,162],"Web Components","software development","web developers","Programming Blogs","Programming Tips","Frontend Development","\u002Fblog\u002Fmedia\u002Fare-web-components-dead\u002Fcover.webp",10,[6],{"slug":167,"locale":6,"title":168,"description":169,"publishedAt":170,"updatedAt":10,"tags":171,"cover":174,"minutes":69,"featured":10,"mostRead":18,"originalUrl":175,"originalLinked":43,"locales":176},"how-to-compete-with-google-apple-microsoft-and-co","How to Compete with Google, Apple, Microsoft, and Co.","The giants set the standard for software. A solo developer can still win — by doing things that don’t scale.","2022-06-13",[66,172,52,173,39],"buildinpublic","SaaS","\u002Fblog\u002Fmedia\u002Fhow-to-compete-with-google-apple-microsoft-and-co\u002Fcover.webp","https:\u002F\u002Fmedium.com\u002Fdev-genius\u002Fhow-to-compete-with-google-apple-microsoft-and-co-315da7aa5376",[6],{"slug":178,"locale":6,"title":179,"description":180,"publishedAt":181,"updatedAt":10,"tags":182,"cover":184,"minutes":42,"featured":10,"mostRead":18,"originalUrl":185,"originalLinked":43,"locales":186},"rule-of-three-three-strikes-and-you-refactor","Rule of Three — Three Strikes And You Refactor","DRY is about knowledge, not code. Why I wait for the third copy before I abstract.","2022-05-02",[39,160,158,183],"Software Engineering","\u002Fblog\u002Fmedia\u002Frule-of-three-three-strikes-and-you-refactor\u002Fcover.webp","https:\u002F\u002Fjavascript.plainenglish.io\u002Frule-of-three-three-strikes-and-you-refactor-942d13e7d5cd",[6],{"slug":188,"locale":6,"title":189,"description":190,"publishedAt":191,"updatedAt":10,"tags":192,"cover":196,"minutes":148,"featured":197,"mostRead":18,"originalUrl":198,"originalLinked":43,"locales":199},"my-journey-to-the-first-999-with-my-side-project","My Journey to the First $ 9.99 with My Side Project","Four users after one month: me, my brother, my mum and a friend. How it all started.","2022-04-04",[160,96,39,193,194,195],"chrome extension","Build In Public","passive income","\u002Fblog\u002Fmedia\u002Fmy-journey-to-the-first-999-with-my-side-project\u002Fcover.webp",2,"https:\u002F\u002Fmedium.com\u002F@mariusbongarts\u002Fmy-journey-to-the-first-9-99-with-my-side-project-3edc13dd1f2d",[6],{"slug":201,"locale":6,"title":202,"description":203,"publishedAt":204,"updatedAt":10,"tags":205,"cover":206,"minutes":148,"featured":10,"mostRead":18,"originalUrl":207,"originalLinked":43,"locales":208},"will-web-components-replace-frontend-frameworks","Will Web Components Replace Frontend Frameworks?","Probably not — and that’s fine. They solve different problems and work well together.","2021-10-11",[39,158,183,162,157],"\u002Fblog\u002Fmedia\u002Fwill-web-components-replace-frontend-frameworks\u002Fcover.webp","https:\u002F\u002Fmedium.com\u002F@mariusbongarts\u002Fwill-web-components-replace-frontend-frameworks-535891d779ba",[6],{"slug":210,"locale":6,"title":211,"description":212,"publishedAt":213,"updatedAt":10,"tags":214,"cover":216,"minutes":148,"featured":10,"mostRead":18,"originalUrl":217,"originalLinked":43,"locales":218},"when-you-should-duplicate-code","When You SHOULD Duplicate Code","Duplicated code isn’t always duplicated knowledge. When copying is the cleaner choice.","2021-01-06",[160,39,158,215],"design patterns","\u002Fblog\u002Fmedia\u002Fwhen-you-should-duplicate-code\u002Fcover.webp","https:\u002F\u002Fmedium.com\u002F@mariusbongarts\u002Fwhen-you-should-duplicate-code-b0d747bc1c67",[6],{"slug":210,"locale":6,"title":211,"description":212,"publishedAt":213,"updatedAt":10,"tags":220,"cover":216,"minutes":148,"featured":10,"mostRead":18,"originalUrl":217,"originalLinked":43,"locales":221,"html":222,"highlights":223,"headings":224},[160,39,158,215],[6],"\u003Cp>Recently I published the article \u003Ca href=\"https:\u002F\u002Fjavascript.plainenglish.io\u002Fdry-your-wet-typescript-code-e3c777b3daf9\" target=\"_blank\" rel=\"noopener\">Prevent Duplicated TypeScript Code\u003C\u002Fa>. A good friend of mine approached me and said:\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“Great article, I learned a lot!”\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>I was a little bit astonished because he is a way better developer than me. I asked:\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“What exactly did you learn?”\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>He replied:\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“I never thought about the difference between code duplication and knowledge duplication. It was great that you focused on differentiating this.”\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>He was talking about \u003Cstrong>accidental duplication\u003C\u002Fstrong>. Removing it will make your code harder to read and harder to change in the future.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>\u003Cstrong>Accidental duplication is code that looks similar but represents different logic.\u003C\u002Fstrong>\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>The fact that my friend had the same perception as I had while writing the post made me write this article to explain with some examples how to identify the difference between \u003Cstrong>essential duplication\u003C\u002Fstrong> and \u003Cstrong>accidental duplication.\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Ch3 id=\"what-is-the-dry-principle-about\">What is the DRY principle about?\u003C\u002Fh3>\n\u003Cp>If you want to have a detailed introduction to the \u003Cstrong>“Don’t repeat yourself” (DRY) principle\u003C\u002Fstrong> I suggest reading my \u003Ca href=\"https:\u002F\u002Fjavascript.plainenglish.io\u002Fdry-your-wet-typescript-code-e3c777b3daf9\" target=\"_blank\" rel=\"noopener\">recent article\u003C\u002Fa> first. This article will only give a short introduction to the principle and focuses on the pitfalls of applying the DRY principle.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>The DRY principle states that duplication and repetition in code, that exists in two places and \u003Cstrong>repeats the same knowledge and business logic\u003C\u002Fstrong> should be avoided. The principle is credited to Andy Hunt and Dave Thomas and is stated in their book \u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002F0135957052\" target=\"_blank\" rel=\"noopener\">The Pragmatic Programmer\u003C\u002Fa>:\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>\u003Cem>“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” —\u003C\u002Fem> Andy Hunt and Dave Thomas\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Notice that Andy Hunt and Dave Thomas are pointing out “every \u003Cstrong>piece ofknowledge\u003C\u002Fstrong>” and \u003Cstrong>not\u003C\u002Fstrong> “every \u003Cstrong>piece of code\u003C\u002Fstrong>”. Understanding the difference is essential to identify accidental duplication.\u003C\u002Fp>\n\u003Ch3 id=\"knowledge-duplication\">Knowledge Duplication\u003C\u002Fh3>\n\u003Cblockquote>\n\u003Cp>“Are we looking at syntax duplication or knowledge duplication?” — Anthony Sciamanna\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>To spot knowledge duplication basically, two questions have to be answered affirmatively:\u003C\u002Fp>\n\u003Col>\n\u003Cli>\n\u003Cp>\u003Cem>Does code exist that looks identical?\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\n\u003Cp>\u003Cem>Does the code repeat the same knowledge and logic?\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Chr>\n\u003Ch4>#1 Example: Knowledge Duplication\u003C\u002Fh4>\n\u003Cp>Let’s have a look at this example:\u003C\u002Fp>\n\u003Cp>#1 Example: Knowledge Duplication\u003C\u002Fp>\n\u003Cp>We have two \u003Ccode>signUp\u003C\u002Fcode> functions. One in the client and the other in our server. Let’s answer our questions:\u003C\u002Fp>\n\u003Ch4>1. Does code exist that looks identical? ✅\u003C\u002Fh4>\n\u003Cp>The alarm bells should ring here for every developer. It is obvious that both functions are sharing duplicated code.\u003C\u002Fp>\n\u003Ch4>2. Does the code repeat the same knowledge and logic? ✅\u003C\u002Fh4>\n\u003Cp>This question is the harder one. If you are not sure you can ask a replacement question: \u003Cem>Does changing one code block lead to changing the other one?\u003C\u002Fem>\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“There is true duplication, in which every change to one instance necessitates the same change to every duplicate of that instance.” — Robert C. Martin\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>\u003Cem>I\u003C\u002Fem> consciously chose an easy example here. Obviously, the validation of credentials is the same for the \u003Ccode>signUp\u003C\u002Fcode> function in the client as the one in the server. If we for example chose to increase the needed password length to 7 we would need to change it in two places. If we forgot to change it in one place, it would lead to a bug.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>Since both questions are affirmed, we can confirm that there is some knowledge duplication in the code. Let`s refactor our code by extracting our code into helper functions. Since the client and the server are living in different environments we have to \u003Ca href=\"https:\u002F\u002Fjavascript.plainenglish.io\u002Fshare-code-between-react-client-and-express-server-5dc0977faa76\" target=\"_blank\" rel=\"noopener\">create a shared library\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>#1 Example: Knowledge Duplication\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cp>Notice that each function has only one responsibility to comply with the SOLID principles, in particular the \u003Cstrong>Single Responsibility Principle\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“The Single Responsibility Principle states that a given method\u002Fclass\u002Fcomponent should have a single reason to change” — Robert C. Martin in \u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002F0132350882\" target=\"_blank\" rel=\"noopener\">Clean Code\u003C\u002Fa>\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Looks much better and cleaner, right? Now we could change our credential validation in one single source of truth.\u003C\u002Fp>\n\u003Ch3 id=\"accidental-duplication\">Accidental Duplication\u003C\u002Fh3>\n\u003Cblockquote>\n\u003Cp>Duplication is far cheaper than the wrong abstraction\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Recognizing the difference between knowledge duplication and accidental duplication is even hard for experienced developers because a domain understanding of the code is needed. That is also why \u003Cstrong>static analysis tools\u003C\u002Fstrong> are great to detect duplicated syntax but they can not tell (at least not yet) if it is also a \u003Cstrong>duplication of knowledge\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Chr>\n\u003Ch4>#2 Example: Accidental Duplication\u003C\u002Fh4>\n\u003Cp>Let`s start with another example by looking at this code:\u003C\u002Fp>\n\u003Cp>#2 Example: Accidental Duplication\u003C\u002Fp>\n\u003Cp>And again, let’s check our questions:\u003C\u002Fp>\n\u003Ch4>1. Does code exist that looks identical? ✅\u003C\u002Fh4>\n\u003Cp>As well as the first example, this code contains some duplicated syntax. Both, the \u003Ccode>ProductService\u003C\u002Fcode> as well as the \u003Ccode>FeedbackService\u003C\u002Fcode> are duplicating this code block:\u003C\u002Fp>\n\u003Cp>#2 Example: Accidental Duplication\u003C\u002Fp>\n\u003Cp>We could easily outsource this block of code to the abstract superclass \u003Ccode>CRUDService\u003C\u002Fcode> . That would save us a few lines of duplicated code.\u003C\u002Fp>\n\u003Ch4>2. Does the code repeat the same knowledge and logic? ❌\u003C\u002Fh4>\n\u003Cp>Let`s start by asking the replacement question: \u003Cem>Does changing one code block lead to changing the other one?\u003C\u002Fem>\u003C\u002Fp>\n\u003Cp>Presuming our business logic changes:\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>\u003Cem>Feedback can now be created by every user while creating products still requires having the right permissions.\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>This would lead us to change the \u003Ccode>FeedbackService\u003C\u002Fcode> class but the \u003Ccode>ProductService\u003C\u002Fcode> class does not need to be changed. This means that we identified \u003Cstrong>accidental duplication\u003C\u002Fstrong> and we should not abstract our code.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“If two apparently duplicated sections of code evolve along different paths — if they change at different rates, and for different reasons — then they are not true duplicates” — Robert C. Martin\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Imagine having abstracted our code by cleaning up the duplicated code and not only our two example classes are inheriting from our superclass but many more. We would have ended up un-refactoring our code because we cleaned up accidental duplication. This is much worse than having some duplicated code.\u003C\u002Fp>\n\u003Ch3 id=\"minimizing-accidental-duplication\">Minimizing Accidental Duplication\u003C\u002Fh3>\n\u003Cp>Often you just can’t entirely remove accidental duplication, but you can minimize it by complying with the SOLID principles and using good naming.\u003C\u002Fp>\n\u003Ch4>#3 Example: Minimize Accidental Duplication\u003C\u002Fh4>\n\u003Cp>Let’s illustrate how to minimize accidental duplication by looking at this example:\u003C\u002Fp>\n\u003Cp>#3 Example: Minimizing Accidental Duplication\u003C\u002Fp>\n\u003Ch4>1. Does code exist that looks identical? ✅\u003C\u002Fh4>\n\u003Cp>Obviously, the functions \u003Ccode>toFileName\u003C\u002Fcode> and \u003Ccode>toFolderName\u003C\u002Fcode> are both transforming a string to an underscore string. The code is exactly the same, therefore duplicated code exists.\u003C\u002Fp>\n\u003Ch4>2. Does the code repeat the same knowledge and logic? ❓\u003C\u002Fh4>\n\u003Cp>To answer this question let`s go ahead and apply the DRY principle \u003Cstrong>incorrectly.\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cp>We have noticed that the functions \u003Ccode>toFileName\u003C\u002Fcode> and \u003Ccode>toFolderName\u003C\u002Fcode> are identical. The obvious solution would be to merge both functions into one \u003Ccode>toFileOrFolderName\u003C\u002Fcode> function. Now we can use it in our \u003Ccode>saveFile\u003C\u002Fcode> method:\u003C\u002Fp>\n\u003Cp>#3 Example: Minimizing Accidental Duplication\u003C\u002Fp>\n\u003Chr>\n\u003Cp>\u003Cem>\u003Cstrong>Why is that wrong?\u003C\u002Fstrong>\u003C\u002Fem>\u003C\u002Fp>\n\u003Cp>Imagine it was decided that file names should now also have a timestamp in front of their name. A new developer in the project should implement this new requirement and is facing our \u003Ccode>toFileOrFolderName\u003C\u002Fcode> function. What I often see is a solution like this:\u003C\u002Fp>\n\u003Cp>#3 Example: Minimizing Accidental Duplication\u003C\u002Fp>\n\u003Cp>By eliminating our original functions we have caused our new function \u003Ccode>toFileOrFolderName\u003C\u002Fcode> to do more than one thing, that is violating the \u003Cstrong>Single Responsibility Principle\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Cp>The fact that our original two functions do the same thing is an \u003Cstrong>accident\u003C\u002Fstrong>. One transforms file names and the other folder names. We don`t want the caller of \u003Ccode>toFileName\u003C\u002Fcode> to know anything about folder names and we don`t want the caller of \u003Ccode>toFolderName\u003C\u002Fcode> to know anything about file names.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>\u003Cem>\u003Cstrong>How to minimize the duplication correctly?\u003C\u002Fstrong>\u003C\u002Fem>\u003C\u002Fp>\n\u003Cp>Let`s restore our initial \u003Ccode>toFileName\u003C\u002Fcode> and \u003Ccode>toFolderName\u003C\u002Fcode> functions and get rid of the low-level duplication by creating the function \u003Ccode>toUnderscore\u003C\u002Fcode> :\u003C\u002Fp>\n\u003Cp>#3 Example: Minimizing Accidental Duplication\u003C\u002Fp>\n\u003Cp>By following the \u003Cstrong>Single Responsibility Principle\u003C\u002Fstrong> each function maintains a single level of abstraction and has only one single reason to change.\u003C\u002Fp>\n\u003Cp>Even though we didn`t eliminate the accidental duplication entirely we minimized it by getting rid of the low-level duplication of transforming a string to underscore.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>Theoretically, we should now be able to differentiate between essential and accidental duplication… \u003Cstrong>But what if we are not sure?\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Ch3 id=\"rule-of-three\">\u003Cstrong>Rule of Three\u003C\u002Fstrong>\u003C\u002Fh3>\n\u003Cblockquote>\n\u003Cp>“Three strikes and you refactor”\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Source: \u003Ca href=\"https:\u002F\u002Fgiphy.com\u002Fgifs\u002Fdallasmavs-YlkCKp0EttSa7jxg6y\" target=\"_blank\" rel=\"noopener\">https:\u002F\u002Fgiphy.com\u002Fgifs\u002Fdallasmavs-YlkCKp0EttSa7jxg6y\u003C\u002Fa>\u003C\u002Fp>\n\u003Cp>Spotting knowledge duplication isn’t easy and cleaning up accidental duplication is far more harmful than having duplicated code.\u003C\u002Fp>\n\u003Cp>The Rule of Three 3️⃣ basically defines that when you spot some duplicated code and the first two cases aren’t enough to clearly identify shared knowledge, \u003Cstrong>wait for the third duplicate\u003C\u002Fstrong> before you refactor.\u003C\u002Fp>\n\u003Cblockquote>\n\u003Cp>“It’s really hard and feels terrible, but close your eyes and try it anyway.” — \u003Ca href=\"https:\u002F\u002Fwww.justinweiss.com\u002Farticles\u002Fi-dry-ed-up-my-code-and-now-its-hard-to-work-with-what-happened\u002F\" target=\"_blank\" rel=\"noopener\">Justin Weiss\u003C\u002Fa>\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Cp>Martin Fowler defined the Rule of Three in his book \u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002F0134757599\" target=\"_blank\" rel=\"noopener\">\u003Cem>Refactoring: Improving the Design of Existing Code\u003C\u002Fem>\u003C\u002Fa>\u003Cem>:\u003C\u002Fem>\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\n\u003Cp>\u003Cem>The first time you do something, you just do it.\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\n\u003Cp>\u003Cem>The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway.\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\n\u003Cp>\u003Cem>The third time you do something similar, you refactor.\u003C\u002Fem>\u003C\u002Fp>\n\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"final-thoughts\">Final Thoughts\u003C\u002Fh3>\n\u003Cp>Duplicated code is one of the major reasons for technical debt and bugs in software. That`s why the DRY principle is one of the most valuable ones in software development. But, applying it correctly is even more important.\u003C\u002Fp>\n\u003Cp>Remember, whenever you spot dome duplicated code ask yourself: \u003Cem>“Am I looking at\u003C\u002Fem>\u003Cem>\u003Cstrong>duplicated syntax\u003C\u002Fstrong>\u003C\u002Fem>\u003Cem>or\u003C\u002Fem>\u003Cem>\u003Cstrong>duplicated knowledge\u003C\u002Fstrong>\u003C\u002Fem>*?”.* And if you are not sure, apply the \u003Cstrong>Rule of Three\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>Thanks for reading!\u003C\u002Fp>\n\u003Cp>Want to learn more about how I scaled my \u003Ca href=\"https:\u002F\u002Fchromewebstore.google.com\u002Fdetail\u002Fweb-highlights-pdf-web-hi\u002Fhldjnlbobkdkghfidgoecgmklcemanhm\" target=\"_blank\" rel=\"noopener\">Chrome Extension\u003C\u002Fa> to almost 100,000 users as a solopreneur? \u003Ca href=\"https:\u002F\u002Fmedium.com\u002F@mariusbongarts\u002Fsubscribe\" target=\"_blank\" rel=\"noopener\">Subscribe to my stories\u003C\u002Fa> or follow me on \u003Ca href=\"https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fmarius-bongarts-6b3638171\u002F\" target=\"_blank\" rel=\"noopener\">LinkedIn\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Ftwitter.com\u002FMariusBongarts\" target=\"_blank\" rel=\"noopener\">Twitter\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>If you read a lot online, make sure to check out my \u003Ca href=\"https:\u002F\u002Fchromewebstore.google.com\u002Fdetail\u002Fweb-highlights-pdf-web-hi\u002Fhldjnlbobkdkghfidgoecgmklcemanhm\" target=\"_blank\" rel=\"noopener\">Chrome Extension\u003C\u002Fa> loved by 90,000+ active user — it’s free:\u003C\u002Fp>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Fweb-highlights.com\u002F\" target=\"_blank\" rel=\"noopener\">web-highlights.com\u003C\u002Fa>\u003C\u002Fp>\n",[],[],1796321908970]