- Which changed lines of code belong to a specific ticket in the issue tracker? Example: after deploying the version of our application including feature #42 the application crashes often with a memory leak. We need to review all changed lines of code for e.g. unexpected side effects.
- Why has a specific piece of code been implemented in the way it is? Example: the business expert believes that there is an error in the computation of discount rates for our customers. We need to read the corresponding code, understand the computation of discounts and explain it to the business expert. After that the expert states that this is a bug we are responsible for. Now we have to proof that the implemented behavior has been specified by showing when and were (e.g. a specification document).
All in both examples we need a mapping between code and spec-documents (e.g. issues in the issue tracker like Atlassian JIRA):
- We know the issue and need the changed lines of code.
- We know the changed lines of code and need the issue.
How could this relation be realized in the code? A simple approach could be to mention the issue id in the commit comments of the version control, e.g. "Fix issue #42: fix memory leak by clearing the cache regularly". With this approach were are able to identify all changed files for a given issue as well as the issue for a changed file.
But in case of modified existing code this approach might be too crude. We need the issue more granular per lines. It would be possible to extract this information from the file's version-history of the version control. But this could be very time consuming. This is why I started in my current project to mark changed lines with an inline comment:
// Changes due to issue #42
…
doSomeStuff();
…
// End changes due to issue #42
This has the big advantage to identify changed lines per issue with a simple full text search. But there is also a big disadvantage: after some changes the readability of the code decreases due to the marker-comments:
// Changes due to issue #42
…
doSomeStuff();
…
// Changes due to issue #07
…
doSomeMoreStuff();
…
// End changes due to issue #42, #07
Yet I do not know a sophisticating solution to this disadvantage and would be pleased about comments by the readers of blog :). Feel free to post your experiences and opinions.