I often have code based on a specific, well-defined algorithm. It is well commented and seems correct. For most datasets, the algorithm works fine.
But then rib cases, special cases, heuristics are added to solve specific problems with specific data sets. As the number of special cases grows, comments become more and more hazy. I am afraid to come back and look at this code after a year or so and try to remember why every special case or heuristic was added.
Iβm sometimes sorry that there is a way to insert or link graphics in the source code, so I could say that "on the graph of this dataset this feature caused an incorrect procedure here, so why this code fragment was added."
What are some best practices for handling such situations?
Special cases are always required to handle these unusual / edge cases. How can it be controlled so that the code is relatively readable and understandable?
Let's look at an example related to recognizing functions with photos (not quite what I'm working on, but the analogy seems to be appropriate). When I find a specific picture for which the general algorithm does not work, and I need a special case, I record this information as best as possible in a comment (or as someone suggested below, a descriptive name for the function). But what is often missing is a permanent link to a specific data file that demonstrates the behavior in question. Although my comment should describe the problem and probably say βsee the file foo.jp for an example of this behavior,β this file is never in the source tree and could easily get lost.
In such cases, do people add data files to the source tree for reference?
c ++ c literate-programming
loneRanger
source share