1

This is a general question. One of my colleague was using a class I wrote and he wanted to use a dll created for the class rather than adding the class to his solution because of some efficiency problem. Is it always better to use a dll rather than writing a class?

Thanks.

4 Answers 4

6

Not sure I understand your question, but it sounds like you're asking whether you should share source code or share the copiled code.

Copying source code is rarely a good idea if you're really trying to reuse the code (rather than using it as a jump-off point for something else). Over time, separate copies can change in their own ways, and thus multiplying the effort it would take to maintain the code.

If you share the compiled library, it can be maintained on its own and fixes/changes distributed to consumers.

3

It's better to only have the source code in one place, and reuse it, generally. This isn't for efficiency reasons - it's to have one place to fix bugs, add features etc.

3
  • 1
    I've seen this go sour in cases where code was not really intended for re-use originally, yet it gets modified by different people for different purposes. The simple, focused class turns into a hydra.
    – Dan Bryant
    Commented Sep 27, 2010 at 13:47
  • @Dan: Yes, there does have to be a certain amount of discipline involved - and designing a clean API can be challenging. Still, I'd say it usually beats copying.
    – Jon Skeet
    Commented Sep 27, 2010 at 14:01
  • Thanks for your replies and comments. My colleague used the executable of my application instead of using the only one class that he wanted to use.
    – shanthiram
    Commented Sep 27, 2010 at 14:58
1

It's best to have the source in one place. If you want to use the same file in another project I'd advice you to link to the file instead.

Do this by choosing add existing file and then choose link instead of add in the dialog (click the triangle in the bottom right corner).

1

Add a reference to the C# project that contains the class you want to use. Even if you get a whole bunch of other classes that you won't use, it allows the changes to the class that you do need to be made in the referenced project, which makes it easier to maintain, as Jon mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.