Visual C++ 2005 IDE Enhancements, Part 2


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

In a continued examination of the new Visual C++ 2005 IDE Enhancements, this article looks at the code definition window, editor enhancements, changes to class view, and finally, one of the big new additions to Visual C++: the class diagram.

IntelliSense Revisited (Briefly)

Part 1 of this series on the Visual C++ 2005 IDE covered enhancements to IntelliSense as they relate to macros and displayed a screen shot of the IntelliSense tool-tips for the MAX macro. Zobiuk posted a comment on the article, stating that the particular example I chose to illustrate IntelliSense support for macros has actually worked in Visual C++ for a couple of versions. Zobiuk is correct. I simplified the point in that section to such an extent that it was no longer entirely correct. Thanks to Zobiuk for pointing this out. I appreciate all feedback and act upon it if needed.

The full story on C++ macro IntelliSense is it has been around for a while, but it suffered from bugs related to the way it tracked macro state. These bugs could cause serious problems in the IDE when macro IntelliSense was triggered (this post on microsoft.public.dotnet.languages.vc describes an occurrence of this problem). Visual C++ 2005 fixes this problem, making macro IntelliSense much more useful in this version. Developers who turned off IntelliSense to avoid problems like this should give the improved IntelliSense a try once Visual C++ 2005 hits the streets.

Code Definition Window

Presenting developers with information about the types that they are using to write their code is an ongoing challenge for the IDE. The information has to be relevant, presenting the information has to be non-intrusive, and retrieving the information has to be speedy. IntelliSense plays a major role in providing information on types that are currently available, the methods that these types expose, and the parameters that need to be passed to these methods. If a developer wants to see an overview of a type, he or she needs to locate and open the header file if the type is defined in a traditional C++ manner, or open the object browser if the type is expressed in a binary file like a COM type library or .NET assembly.

To support an easier model than the snakes-and-ladders hunt through nested includes and to end the disconnect between the text-centric editor and the graphic-centric object browser, Visual C++ 2005 introduced a new window called the Code Definition Window. The Code Definition Window automatically provides a header file-style view of the type that the text insertion point is currently within or near. If the type is defined in a header file, the IDE displays the header file in the Code Definition Window. Figure 1 shows the header file that defines std::vector automatically, displayed as code that uses the vector template is being written.

Figure 1: Code Definition Window from Header File

If the definition of the type is contained in a binary file such as a .NET assembly, the IDE generates an equivalent header file declaration for the Code Definition Window. This feature does not work in the current beta of Visual C++, but it works for C#. Figure 2 shows a generated C# file for System.String. The method implementations obviously are missing, but the generated code does include method- and parameter-level comments that are the same as those in the MSDN documentation.

Figure 2: C# Code Definition Window from .NET Assembly

Presenting all this in a single screen continues the trend toward converging all the information that a developer needs into a single view. The Code Definition Window eliminates the need to tab between the MSDN documentation, the object browser, and header files to find information about a type; it automatically locates and displays all the information as the code is being written.

Editor Enhancements

The code editor is the core of the IDE, and it is therefore not surprising that it has been enhanced in a number of ways. One of the more retro enhancements is the ability to emulate the Emacs and Brief editors. While this enhancement will hold little interest to those used to the Visual Studio editor short-cuts, for organizations where development teams have been reluctant to standardize on Visual Studio because of familiarity with these other editors, the emulation support will be a welcome addition.

To enable the emulation modes, choose Tools | Options, and configure as appropriate on the Text Editor dialog (see Figure 3).

Figure 3: Configuring Emacs or Brief Emulation

One of the more mundane but useful editor enhancements is the margin coloring that indicates lines of code that have been modified since the source file was opened (shown in green) and lines of code that have been modified since the source file was saved (shown in gold). Figure 4 shows this change tracking.

Figure 4: Editor Change Tracking

While this change tracking does not in any way replace the need for a source control tool, it does enable a quick check before a save or a build to ensure that all the changes are correct and that inadvertent modifications have not been made.

The ability to customize the editor has been dramatically expanded in Visual Studio 2005. A setting that may have been represented by a single check-box or drop-down in Visual Studio 2003 may now have dozens of different options that allow the setting to be fully customized. For example, the number of items in the Fonts and Colors option dialog that can have separate settings applied has increased from eight in Visual Studio 2003 to 23 in the current November 2004 CTP release of Visual Studio 2005.

The final noteworthy editor enhancement is the enhanced ability to display Unicode text and to use it as variable names in a C++ project. An attempt to use a non-ASCII variable name in Visual C++ 2003 produces an error: error C3209: '????' : Unicode identifiers are not yet supported. In Visual C++ 2005, the code shown in Figure 5 saves, compiles, and runs correctly. The Simplified Chinese text shown is AltaVista.com's translation of Hello World.

Figure 5: Enhanced Unicode Support

Visual C++ 2005 IDE Enhancements, Part 2


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Class View Filtering

The Visual Studio 2005 Class Viewer features two panes: one for types and namespaces, and the other for properties, members, and methods. The CommentedClass example from last month's article is shown in Figure 6 (displayed in the Class View window).

Figure 6: New Class View Window

Class View now can filter the types and namespaces that are displayed. In Figure 6, "Commented*" has been used to filter the view to display only those types whose names started with "Commented", which in this case is only a single class. As the number of types within a solution grows, the usefulness of this features increases exponentially.

Class Diagram

The addition of a built-in, UML-like modeling tool to Visual C++ is an addition that many developers will welcome with open arms. This section does not deliberate why the modeling is UML-like rather than pure UML, except to say that the most common answer from Microsoft seems to be that UML is not powerful enough to model the features of .NET in a neat and convenient form.

For developers who have endured the pain of round-trip engineering through tools like Rational Rose, the fact that Visual Studio class diagrams offer trip-less modeling will be a welcome relief. The models are trip-less in the sense that code and diagrams are automatically kept up to date with each other, and there is no notion of one artifact being out of date with the other. Class diagrams are actually separate project files that allow the classes that are relevant to a particular view of the system to be added to a diagram. New classes can be dragged onto a diagram from the toolbox shown on the left of Figure 7, and existing classes can be dragged onto the design surface from the class view. A class can be shown in summary form, like frmStatus in Figure 7, or in an expanded form, like frmMain and frmAbout. A grid control called class details shows the methods, properties, and fields of a class in a hierarchical table. The class details grid is the most convenient way to alter a method, field, or property, though this can also be accomplished directly in the diagram.

Figure 7: Class Diagram

As you can see from the context menu in Figure 7, the class diagram surface supports many of the features traditionally associated with the class view and text editor windows, such as the abilities to add various code elements to a type and refactor a class (the refactoring support in Visual Studio 2005 will be covered in an upcoming article), and support for overriding inherited methods.

More to Come

Next month, the tour of new IDE features will continue with coverage on refactoring support within the IDE and the new build system.

This article was originally published on March 9th, 2005

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date