Improve Your Coding Skill by Listening to the Debugger

If you want to improve your coding acumen, you don’t always need expensive learning aids or online classes. Use your compiler’s debugger to discover new programming techniques created by masters of development.

Many developers ignore the debugger built into their programming environment unless their application has a flaw that defies any other form of analysis. I’ve seen developers stare at the screen looking for a flaw in their code, rather than break out the debugger, because their perception is that debuggers are both hard to use and useless at providing help.

However, smart developers not only use the debugger every time there’s an application error, but they also use it to discover new programming techniques.

First, throw out your old assumptions. Most IDEs include a usable debugger today. Gone are the nearly useless debuggers that provided false leads and didn’t include even the barest functionality needed to locate errors in application code. Modern debuggers provide a wealth of information (at times, almost too much; a novice developer can end up looking at the wrong window for the needed information).

But you should take this a step further. Professional developers listen to the debugger to determine what it has to say about the code loaded in their IDE. It doesn’t matter which programming product you use or which language your application relies upon; the debugger can be a useful training aid. Want to teach yourself a new skill, or understand how to improve your coding practices? All you need is the source code for an expertly written application that demonstrates a technique you want to learn. Fortunately, the Internet is abounding with useful examples. Places such as SourceForge, The Code Project, and PlanetSourceCode likely have the source you need. All you need is the means to explore the source code you download and that means is your debugger.

The process for using this technique is simple: Find the area of the application that contains the code for the new technique you want to learn and then single step through the code. Watching the process your debugger goes through as it traces through the code helps you see how the technique works.

Before you proceed any further, I do want to warn you to download code from a place you trust. Don’t rely on the code of some site you’ve never visited before which none of your friends have used. Just as with anything else on the Internet, it’s possible to get dangerous coding examples that won’t teach you anything and might just compromise your system in some way. It’s important to be a wary developer when it comes to code found on external sites.

Seeing is Believing

When you read about how a piece of code works, the problem is that you have to visualize the code in your head. You can’t see the code in action. It’s akin to trying to decipher how a car engine works just by reading about it. Yes, it can be done, but when you see a car engine in action, especially using one of those cut-away views of the engine provided in a demonstration model, you can understand what’s going on better. The difference is between seeing a concrete example of the code in action and an abstract presentation of the code. Concrete examples are easier to understand and they stick with us better.

Another problem with written examples is that you find yourself not believing the code works. The problem becomes worse when you actually try the code and find that it doesn’t work. Often, the code is correct, but you made a typo or the author forgot to include some special requirement for running the example. When you have example code that actually runs on the system and work through it with the debugger, you believe in the code—you can see that it works and performs the desired task with your own eyes.

Theory is Fine, Real World is Better

In many written examples, the author expounds theoretical information that may not help you in a real world situation. Yes, a developer does need to know some amount of theory in order to take information sources and form them into a working application. However, at some point, theory just doesn’t provide enough useful information. Most of us require a look at how things work in the real world before we can create usable applications that actually perform the task that they’re designed to do. Working through applications that you find online using the debugger fulfills this role.

Using the debugger also lets you play “what if” with the code. Playing is an important part of any learning experience. Beginning with a coding example you know works and modifying it a little to see what the changes do to it is an important way to learn new techniques. You tweak a bit here and twist a little there to see what happens to the working example as you make changes. After you make each change, you use the debugger to step through the new application form and see how the changes work.

Some languages also contain hidden features. For example, when you rely on a declarative expression, you can’t really see what’s going on. The compiler decides how to perform the task at run time. The only way to see how your declarative expression really works is to run the debugger. Better debuggers show the intermediate steps that the application takes as a result of the declarative statement, making it easier for you to create a better declarative statement in the future. A technique that’s hidden during coding becomes visible with the debugger, helping you to understand the abstraction you created with code through concrete observation.

Avoiding the Example Trap

Working examples show you how things work in the real world. However, working examples can also teach poor coding techniques. The idea is to take the principle, the way that the code can work, away from your research and then combine that knowledge with coding practices observed by your organization. If you’re an independent developer, use best coding practices for your application language. Some examples are great at showing a technique, but not how you should actually code that technique in a production application.

A Improved Way to Learn

The debugger method of learning to code is so useful that I’ve begun incorporating it into my books. Two of my recent books use the technique to help the reader see how the code works, rather than having me blandly explain it to them. So far, readers really seem to like the new approach. They’re finding that the debugger approach does teach good programming principles in a way that sticks better than simply reading about it.

Since I started doing this, I’ve noticed a few other people using the same approach to teach good coding practices. Relying on your debugger to learn coding helps you understand the way things work better. More importantly, as this technique catches on as a learning tool, I expect that more people will use it to teach real world programming.

The debugger supplied with just about any IDE provides enough features to allow you to single step through and application and discover precisely how it works. This process may seem laborious the first time or two that you use it, but eventually you’ll find that it provides a quick way to learn new techniques in a manner that you won’t easily forget. Learning techniques that work and that you can actually remember to use is the essence of any good training program. 

 

See also:

 

subscribe-to-our-blog


Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox