72
you are viewing a single comment's thread
view the rest of the comments
[-] Deely@programming.dev 11 points 1 year ago

Erm. Duplication of code is ok. Removing absolutely every duplicate function is just premature optimization imho.

If you have two different customers with slightly different workflow then go ahead and create two mostly the same functions. When you will have 4 different customers with slightly different workflow, then its a time for refactoring, maybe extract basic same functionality into separate function/object, maybe introduce dynamic workflow using finite automata, maybe extract these functionality to separate modules.. but never do it prematurily.

Imho, sometimes ,removing of duplication very much increases complexity and code became hard to understand and hard to modify.

[-] RagingNerdoholic@lemmy.ca 8 points 1 year ago* (last edited 1 year ago)

https://en.m.wikipedia.org/wiki/Rule_of_three_(computer_programming)

Copy for twice, abstract for thrice. I've followed this since I learned it and it's served me well.

Edit: Wikipedia links are fucky

[-] avalokitesha@discuss.tchncs.de 3 points 1 year ago

My understanding of that article was that it was not necessarily about duplicated code, but duplicated data. If you have two places storing the same data, and different parts of your app go to each of it, you need to somehow keep them in sync, and that's often a pain.

I'm trying to be very rigorous about avoiding that, duplicated code I'm a bit less rigorous about.

[-] Von_Broheim@programming.dev 2 points 1 year ago* (last edited 1 year ago)

Microservices and document db's go brrrrrrr. Data duplication is completely fine as long as there is only one source of truth that can be updated, all copies must be read only. Then the copies should either regularly poll the source or the source should publish update events that the copies can consume to stay in sync. It's simple stuff but keeps your system way more available and fast than having multiple services talk to a shared db or worse, multiple services constantly fetching data through a proxy.

[-] Chunk@lemmy.world 2 points 1 year ago

While you may be correct, if you're on a dogmatic team, work with dogmatic people, or are a part of a dogmatic company, you probably need to avoid duplication. This is because duplicate code is an easy thing for a reviewer to nitpick and reviewing code can sometimes be more about showing off and less about ensuring code quality.

this post was submitted on 07 Aug 2023
72 points (97.4% liked)

Programming

17314 readers
67 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS