We have a class in which mainly data processing(XML nodes) is done by mainly 3 methods. Now code in itself strictly follows DRY principle. For e.g.

  1. Process Children (reads data from child nodes)
  2. Process Choose Element (conditional data check)
  3. Extract Single Field (extract data from single node with no children)

To give you overview ,Say we reach node A, then we call ProcessChildren() and if any children is Choose then we would call ProcessChoose(). Then we would call recursively ProcessChildren() result and so worth. Though this code is easy to read and overall bugs are removed but debugging is very difficult since one functions to another and so on. Is there any way we could remove this debugging hurdle so that debugging is easy?

  • 4
    Do you expect to debug these three methods over and over again? Why? Don't you reach the point where these methods are doing what they should? Or are you talking about debugging code which uses these methods (which is an entirely different question)? – Doc Brown Jan 4 '16 at 14:31
  • 4
    In what way is debugging such mutually recursive functions a hurdle for you? Personally, I don't really find it harder than other debugging tasks. – Bart van Ingen Schenau Jan 4 '16 at 15:09
  • @BartvanIngenSchenau: if a recursive function has some internal state and / or a long(ish) argument list, it becomes mentally straining to understand what is happening where after several levels of recursive calls. – 9000 Jan 4 '16 at 16:17
  • @DocBrown- Sorry for late response.Yes I expect to debug this methods since they do very important job in our application. Well I have almost reached a point where they work as they should. I am not sure I am getting your last question clearly. – Sachin Sharma Jan 6 '16 at 13:08

Debugging is easy when you don't need it at all.

You have three methods. If each of them is correct, you likely won't need to debug a combination of them.

  • Split the three methods into smaller parts, each clearly defined. Do this until the correctness of each part is completely obvious, because of its simplicity.
  • Write unit tests for each method. Cover both correct and incorrect input. Pay attention to corner cases.

You have done this, but you still have trouble understanding what's up?

Maybe debugging by manually stepping through each line is too slow, you lose track of what's happening.

  • Add large amounts of logging to your methods. Log the arguments passed, all the interesting intermediate state (which you should have as little as possible), maybe some context like neighboring nodes of the XML tree. Make sure line numbers are logged.
  • Try to use conditional breakpoints, so that the debugger activates only when something interesting is happening.

Chances are that looking at the detailed log would give you a better picture than constantly changing variables in the debugger window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.