Chapter 11. Debugging

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. – Brian Kernighan

Microsoft Dynamics NAV 2013 introduces a brand new debugger. Debugging will no longer be a painful task in Microsoft Dynamics NAV. Conditional breakpoints, debugging other user sessions, and debugging C/AL code in the RTC client instead of incomprehensible C# code. All these new features will convert the debugging experience to a happy experience.

The following topics are covered in this chapter:

  • The art of debugging
  • Starting the debugger
  • Placing breakpoints
  • Line-by-line execution
  • Code coverage

The art of debugging

By definition, debugging is a methodical process of finding and reducing the number of bugs in an application. Normally, the first step in debugging is to attempt to reproduce the problem. On some occasions, the input of the program may need to be simplified to make it easier to debug. Then you use the debugger tool to examine the program stats (values of variables, call stacks, and so on) and track down the origin of the problem(s), to finally be able to fix it.

Debugging however, can do so much more than just solving issues. It is a fantastic way to understand how an application works. You could just open the involved object, read the written code, and follow it up. But it will be hard.

First of all, because Dynamics NAV code is run after an event occurs. If you take a look at an object, you will see code in the events, but it will be hard to know when an event occurs, or which event is the one that first causes the code to be executed.

It will also be hard to just read the code because you don't know which values a variable is taking. If you turn the debugger on, you read the code with a specific example that makes variables take specific values. And this is really helpful!

Of course, this means that depending on specific variable values, some lines of the code won't be executed and you won't be able to follow them. Therefore, you will have to create significant and varied examples in order to cover all (or almost all) code in a given object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset