HACKER Q&A
📣 Bandera09

How can I prevent code duplication?


I write utilities in c++, I have been working in this direction for half a year. Relatively new, I've been facing the problem of duplicate code in recent days.

How can I prevent code duplication? I understand that it takes a lot of time, but I still don’t know how to do tests well, and there are still a lot of projects to write and they are similar


  👤 stop50 Accepted Answer ✓
I prevented reuse for a lot of stuff by defining generic interfaces and made code reuse easier, for example: i have an python library for access of an server and someone wrote an ansible module with it. I packaged it for multiple distribution ways (internal pip, rpm package for multiple rhel versions, even a docker image on oir internal registry), so they can access and use it.