[Obsolete]


To really know how it feels from the inside, I have started to contribute with an open source project. NHibernate goal is to try and port the successful Hibernate persistence layer from Java to C#. Curiously, my first contribution was not to add code but to delete it: it so happens that another contributor created a StringHelper.Join() method to concatenate an array of strings into one string. Of course this is exactly what is done by the .NET Framework String.Join() method.

Here is where the fun begins: StringHelper.Join() was already used in a number of places inside NHibernate, so we had the case of a very early obsolete function. We want to get rid of these now obsolete calls but we have developers around the world working in a very loosely (lousely?) coupled way. How do we disseminate the change without wreaking havoc?

Enter the [Obsolete] attribute: I used it before the StringHelper.Join() definition with a message like this:

[Obsolete("Please use the String.Join() instead of this method as it does the same. StringHelper.Join() will throw an error in a couple of weeks"]

Once I committed this small change, as other members of the team update the project, they will start to receive a compilation warning (and in a couple of weeks a compilation error) that points them in the right direction. So, thanks to [Obsolete], we have a smooth way to get rid of mistakes on the definition of interfaces.

No Comments