When and why to use the Obsolete attribute?

3

At least on the projects I worked with, I see no point in using the Obsolete " in methods that are no longer used. What I do, and I see people doing is removing or commenting codes that are no longer used / obsolete.

When and why should I use the Obsolete attribute?

    
asked by anonymous 11.02.2017 / 13:11

1 answer

4

In simple, internal things (no one outside of your team or yourself will use your code ) you do not even have to use it. You have full control over the use and if that was used, you can quickly with help from the IDE, and who knows some plugin , change everything that uses what was deprecated .

In codes that are used extensively and / or made available to third parties, this type of marking is critical. You can not remove something that may be in use by a third party. It has to show that its use is not ideal, make the compiler indicate this to it. It may be that in future versions you can even remove it, but the normal thing is until you never remove it, unless you launch an all-new product.

This attribute is a semantic documentation to indicate that that code should not be used in future projects and if possible should switch to something more modern where it has already been used.

It is common to use a short message indicating what to use instead.

It is possible to indicate whether it will generate a warning or compilation error. Ideally, start with a warning and document when it will become error. It is good to launch at least one version of the software giving obsolescence error before removing the code. When removing the error will be another and will not give any indication that it has become obsolete.

    
11.02.2017 / 13:24