On Getting Rid Of Common Libraries… What About Don’t Repeat Yourself?

6 commentsWritten on May 2nd, 2009 by
Categories: Opinions

Just wanted to post a small reaction to Ayende's dismissal of Util & Common Libraries. In his post, Ayende goes over everything that Rhino.Commons (his own library) offers and why he's not using it anymore. If you go over the list of everything in the library, i can definitely see why. As Ayende says, it's the garbage bin for anything that he came up with in the past couple of years, regardless of how many projects would actually reuse each specific part.

At work we have also have something like this, though in some ways it's smaller in scale, and in some ways it offers a bit more than Rhino Commons. A lot of it is based, or are further developed versions of, the infrastructural bits that i've posted on this blog in the last year. We also have some other interesting things in there that my coworkers wrote. We took the opposite direction however.

We started off with putting these classes in each project where we could use them. But since a lot of that stuff was still being modified or extended on a semi regular basis, we were constantly making the same changes or additions in multiple places, which violates the Don't Repeat Yourself principle. Essentially, it was duplicate code, just spread in multiple projects. Obviously, this brought along all of the same problems that duplicate code usually brings with it.

So we set out to figure out to best way to deal with this, and i even asked you guys about it. We eventually ended up moving these bits to some sort of in-house library/framework that all (or most) of our applications now use. While i was the one who was hesitant at first to go with a reusable library/framework (due to some bad experiences with it in the past), i'm now very glad we actually did do it.

We did go for multiple assemblies (ie: web, silverlight, service layer, ...) instead of putting everything in one big assembly though we did try to follow my 'one assembly per physical deployment' rule.

Bugs get fixed in one place and one place only. The only repetitiveness we have to endure when fixing a bug in the library is making sure we can merge the fix to previous versions and updating the referenced binaries in each project that uses it. That's it. New stuff only gets added when it's been proven to be useful in more than one project. We don't just add new things like that, unless it really makes sense to do so.

I think most of the problems that Ayende now sees with Rhino Commons can be avoided by splitting things up a bit more, and by being more restrictive as to what actually makes it into the library. Versioning suddenly becomes pretty important as well. These are all things that i always felt where somewhat missing with Rhino Commons. That's not to criticize the project because i do think there's a lot of valuable stuff in there, but in it's current form it's just not very well suited to be reused by other projects.

Having said all that, i'm not saying that reusable libraries/frameworks are the best thing since sliced bread either. They require a lot of discipline and it's easy to get tripped up simply by adding something or making a minor change where you didn't really think all of the consequences through. But the downsides of dealing with these libraries are usually smaller than the downsides of having the same code spread out over multiple projects.

  • http://morten.lyhr.dk Morten Lyhr

    Compile it all into one assembly, with different namespaces, and use ILMerge to get
    ‘one assembly per physical deployment‘ rule again.

    /Morten Lyhr

  • http://www.kenegozi.com/blog Ken Egozi

    something like svn:externals could serve as a good answer.
    a single repository in the company for the good-stuff. Every project gets full source control access (thus can fix things and step into if needed), and every project can point to a specific version to avoid dependency hell.

  • http://davybrion.com Davy Brion

    @Ken

    What happens when 2 projects point to the same specific version, and someone from project A makes a change in the external common stuff that has an impact on project B?

  • http://www.filip.duyck.org efdee

    I had the feeling that Ayende was mostly complaining about the fact that alot of what’s in Rhino Commons isn’t being reused, it’s just in there because it was used in another project and, at that time, seemed to have potential for reuse.

    In contrast, it sounds like what you are describing are pieces of code that are actively being reused and maybe could be considered micro-frameworks in their own respect (which I don’t think Ayende was referring to).

    Maybe you should refactor these micro-frameworks away from your “common” library and see what is left in the latter afterwards, and how reusable that is.

    Ofcourse, maybe I myself misunderstood both blog posts ;)

  • http://jack-fx.com/blog/ Jack

    While, I also use my common library. with my lib, I can write applications fast, so I like my library. After seeing your article, I think I do need to upgrade my library often but not give it up.

  • http://neilmartinagile.wordpress.com neil martin

    I think it depends on what you are doing for research projects or slow moving projects i tend to have a static library against which i know my code will compile and work i tend to put this in the lib folder i also tend to create dll references to anything that this might need form other dll’s i have built in this fashion i ensure that this code is statically versioned and just works.

    When i am dealing with production code i tend to use SVN: external style model and share a lib. When i deploy frameworks and the likes i tend to merge them into sensible grouped dll’s such as

    .Objects
    .Tests
    .Tests.Object

    Inside this are a number of folders so the code is split down further into sensible groups within the dll’s.

    neil