1

One of the last projects I worked on had a lot of deprecated methods. Are there any good strategies for making sure that the use of these methods actually decreases over time? The example below is Python-specific, but this question really applies to all languages.

I've read a little bit in the past about adopting informal policies that apply to every commit such as "number of lines not covered by the test suite is not allowed to grow" or "coverage percentage must not decrease" as a means of improving test coverage that doesn't involve dropping everything. That's also sort of the angle that I'm approaching this from. What's a measurable criterion that someone can look at to determine whether their commit is polite or not.

Here's what an example might look like. Suppose I have a RequestTask that used to have a group_id, but doesn't anymore. The validate_group_id method is now deprecated and just calls validate_request_id. The group_id instance variable has been replaced with a property. Here's a skeleton file.

class RequestTask:
    ...
    def validate_request_id(self):
        ...

    # deprecated method
    def validate_group_id(self):
        return self.validate_request_id()

    @property
    def group_id(self):
        return None

Let's further suppose that we can't just change all the code that calls the deprecated methods right now, due to time constraints.

I want to make sure that code calling these deprecated methods eventually gets changed.

  • What are some good strategies for tracking whether use of deprecated methods and APIs is actually decreasing over time?
  • If necessary, what's a good way to enforce a policy that WILL lead to non-use of deprecated methods?
  • Is it even a good idea to attempt something like this?

1 Answer 1

3

The principle would be the same in this and the test coverage case. To implement it you would do something like during builds, either statically or dynamically, compiling a list of all functions/methods calling the deprecated method and saving ot. If that list ever gets a new item, fail the build

In order to track calls you can do this by either analysing source code / binaries (e.g. in dotNet this is quite straightforward with Nunit) or by tracking the calls live and recording them during tests (relies on a good test suite and ability to inspect the call stack).

For python in particular this SO answer shows how to trace these calls dynamically. I doubt source/byte-code analysis would work for such a dynamic language.

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.