开发者

How to organize libraries of utility functions?

I need to come up with a better way to manage my utility functions. Currently, functions are pasted from other projects into the solution where they are needed, as they are needed. Definitely not the way to go. It's a huge PITA! Especially painful when these functions change over time due to a variety of reasons.

I'm think I want to create a project "GenFunc" and place all my general purpose utilities in that project. Then when I need to use the functions, reference the output of GenFunc from my other projects. This would require me to be disciplined and make an effort to create all general functions in GenFunc but it would save me from copying and pasting code all the time.

What are the drawbacks of my proposed function class?

I imagine having multiple libraries - math, string manipulation, data stuff, engineering stuff, etc.

How do you handle this situation? 开发者_StackOverflowWe all have utility libraries that are not dev project specific, right?


Yes, having a "utility" project is very common. In most places it's just a single project though - not split out into maths, string manipulation etc. If it gets really large that might make sense, but for most places a single library works well enough, just using appropriate namespaces within the project to split the functionality up.

The only drawback I've come across is in terms of versioning - if you have different projects which use different versions, you either need to be absolutely backward-compatible at all times, or build/ship the exact right version with each project, which can be annoying.


If your source control repository supports branching then you should consider adding your new library to source control and branching it into any solutions that will need to reference it.

This provides advantages in terms of versioning. A team responsible for a project that has a reference to the library can decide on both the version that they are going to code against and the timing of any upgrades. They can merge the desired version of the library into their branch on a schedule that they decide.

This will also work in reverse. You will have the option of merging changes made to the library within the scope of a project back into the main branch for the library so that other projects can have access to them.

You will find some more details (and some other options) in the guidance from Patterns & Practices here.


What you can do is have said function library, and then copy it into your projects specifically, unless you can design said functions without the minor changes from version to version.

this way, you can always be sure you have the right version.

In java, at least, you could also write your class and then extend it if you need to override particular methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜