How To Navigate through your Code Faster

This article teaches techniques developers can use to navigate code faster and comprehend it better.

(Originally published at delphi-expert.com on May 14, 2004)

This is the third in our 4-part series outlining the results of our study into how Castalia helps developers become more productive.  Previously, we reported on reducing work by reducing keystrokes and writing quality code faster with live error checking.  This week we'll discuss code navigation, developer habits, and how Castalia helped our test subjects navigate their code better.

Navigating code is the process of finding a specific location in code.  It may be a procedure, a variable reference, or a class declaration.  As developers gain experience, they develop various code navigation habits.  In the absolute worst case, a developer may open the file that contains what he wants to see (assuming he knows which file it is!), and scroll his editor up and down until he finds what he's looking for.  Most developers combine this approach with some of the tools that Delphi provides, like text searching and the Code Explorer.

We discovered, however, that those who take advantage of all that Castalia has to offer can move around their code almost four times as fast as those who do not.

So what are these developers taking advantage of that's making them so much more productive?  How are they getting ahead of the competition?

The programmers who were best able to find their way around their code habitually made use of Castalia's Navigation Toolbar.  The Navigation Toolbar allows a developer to jump quickly to the declaration of any class in a unit, or any method in a unit.

For example, one developer had a unit that was roughly 2000 lines of code containing 5 classes and 120 methods.  While writing one method, the developer could jump to the declaration of any other method in the same class by selecting the method from the methods combo box, taking only two mouse clicks to get there.  This developer increased his navigation speed even more when he learned that he could use the keyboard to do the same.  The Ctrl + Alt + P keyboard shortcut selects the methods combo box.  Press the down arrow to view the dropdown, and start typing the name of the method you want to see.  As soon as the method you want is selected, press enter and the cursor will be placed right at the beginning of the method.

Every navigation tool in Castalia has a keyboard shortcut, so you can navigate your code in the quickest way possible without ever taking your hands off of the keyboard:

  • Used Units dropdown: Ctrl + Alt + U
  • Unit Sections: Ctrl + Alt + S
  • Class List: Ctrl + Alt + C
  • Procedure/Method list: Ctrl + Alt + P
  • Push a bookmark on the bookmark stack: F2
  • Pop a bookmark off of the bookmark stack: Esc.

Each of these can be modified from the defaults to suit your preferences.

Here are some other things that we observed highly productive developers doing to navigate code better:

Use the "Find References" refactoring liberally: Place the cursor over any variable name, type name, or any other word in the editor, and invoke the "Find References" refactoring.  Castalia will quickly identify all references to the selected word in your current project.  This is very useful for finding where a procedure is called or a where a variable might be modified.

Use the bookmark stack: Castalia's bookmark stack is a stack of specific locations in code.  Press <F2> to push the location of the cursor onto the stack.  Press <Esc> to pop the top location off of the stack and move the cursor to that location.  Since reading code is not a linear process like reading a novel, it is difficult to remember where you've been in order to backtrack.  Each time you navigate to a new location in code, you can push a bookmark on the stack, leaving a trail of bread crumbs in your code that you can use to follow back to where you were.

I hope you'll find these tips helpful as you become a more productive developer.  Next week we'll finish off the series by talking about refactoring and how Castalia can help you to make existing code work better without the risk of breaking anything.

 

Share this article!

Follow us!

Find more helpful articles: