Cymon
Cymon

Reputation: 107

Preventing creep and dependencies in shared code

At work we have several C# projects and occasionally we share classes and functions between them. However sometimes that code is embedded in classes that bring along dependencies that people don't want to deal with for the sake of one function. So the end up copying and pasting the one or two functions or classes into their code.

This strikes me as bad.

But if we break this out into it's own shared tool project to avoid the flotsam then someone will add their own functions and classes and soon enough we'll be right back where we were. Or they end up editing the code and breaking code in another project they're not aware of.

How do properly share but not step on each other's toes? Is copy-pasting the right choice in the end?

Upvotes: 2

Views: 58

Answers (1)

Chamila Chulatunga
Chamila Chulatunga

Reputation: 4914

Copy pasting is an often chosen path, but is almost always the wrong choice.

The best way to deal with this is to isolate the shared code in ways that make it meaningful for other parts of the codebase to consume. E.g. if unwanted dependencies are a problem, localise the resolution of them to the places that actually need them.

On the issue of proliferation of unnecessary classes/methods, that really has to be managed with guidelines and governance.

Upvotes: 1

Related Questions