Debugger, F# Language

By Jeff Cogswell  |  Posted 2010-04-23

Visual Studio 2010 Makes Solid Progress

Microsoft's flagship product for developers, Visual Studio 2010, represents a substantial improvement over Visual Studio 2008, with enhancements to the tool's core functionality and its handling of ASP.NET, C#, C++ and VB. What's more, along with the VS 2010 release Microsoft has updated .NET Framework to Version 4.

All told, I'm very pleased with the update, and am looking forward to switching my own projects over from VS 2008 (and some that are even still on VS 2005). With that said, I think the ASP.NET elements of the IDE (integrated development environment) are lacking: AJAX is still missing from a lot of the product, and the AJAX extensions that are available feel somewhat hacked. A lot of Web development takes place on the client side these days, and while Visual Studio has solid support for JavaScript, I suspect a lot of Web developers will still find themselves using other tools.

I tested Visual Studio 2010 Professional Edition, which is priced starting at $799 for a full version or $549 for an upgrade version. Full information on the various available editions can be found here.

Core functionality

One of the first enhancements to the IDE that jumped out at me was the capability VS 2010 offers for navigating a call hierarchy. Over the years, many of us have discovered the important Go to Definition and Find All References menu items, allowing us to quickly navigate through our code. But we still often have to do a lot of searching if we're trying to trace through the code during development. The Call Hierarchy window expands on these concepts, giving us a way to drill down visually through the call references, showing "calls to" and "calls from" a function.

The code editor has lots of improvements, partly because it now uses WPF (Windows Presentation Framework). The zoom feature is nice. Now you can quickly zoom in and out just like you can in a word processor such as Microsoft Word. And when you click on a variable or identifier, every occurrence of the variable throughout the document gets a faint highlight over it.

One really interesting feature is called Generate from Usage. Previous versions of Visual Studio had a handy feature called Generate Method Stub. This was activated through a pop-up menu when you typed a function call for a function that doesn't exist. If you typed myfunc(2), the first letter would have a bar under it, which would trigger a dropdown menu for the Generate menu item. Clicking it would create an empty method based on the types in the function call. (In the case of myfunc(2), the generated function would take a single integer parameter, for example.) This feature has been expanded on for other identifiers besides methods. For example, if I type this:

anothervar = 10;

then the "a" will have a bar under it with a dropdown menu with two options: Generate Property Stub, and Generate Field Stub, the first of which creates a property (with a "set" and "get"), the latter of which generates a simple private member variable, like so:

public int anothervar { get; set; }


private int anothervar;

Other improvements include enhancements to IntelliSense and improvements to the live semantic errors (the squiggly underlines that appear in your code).

.NET 4.0 and C# 4.0

Version 4.0 of C# now supports support for late binding, type equivalence support, and Covariance and Contravariance. The type equivalence support is pretty important because it allows you to embed another assembly's types right in your own assembly so that you can reference those types without having to reference the other assembly at runtime. Why is that a good thing? Because that way you can link at runtime to different versions of that other assembly, which in the past has been very difficult.

The fourth version of the .NET framework itself also brings a lot of improvements. For example, there's a new class called Tuple that can greatly simplify your life if you're accustomed to languages like Python. Here's an example line of C# code:

var primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19);

This isn't quite as elegant as tuples in languages such as Python where you can just do this:

primes = (2, 3, 5, 7, 11, 13, 17, 19)

The difference, of course, is that in Python tuples are built right into the language. In C#, you're using a .NET class called Tuple. And indeed the Tuple class only supports up to eight items in its constructor, as that's how many overloads the constructor has. But you can add more items to the Tuple after you've created it. (But that, of course, goes against the tuple concept in other languages such as Python where they're supposed to be immutable. But that's OK. Different languages, different rules.)

I was surprised to see memory-mapped files included in the list of new features. Memory-mapped files are something we Win32 programmers from days of old used to use both for managing large amounts of virtual memory and for creating our own customized file formats. (If you're not familiar with memory-mapped files, think of them as similar to the memory swap files, except instead of being managed by the operating system, they're separate files managed by your application.) Technically, you could always use memory-mapped files in .NET by calling directly into the Win32 API. But now there's a .NET class, called MemoryMappedFile, specifically for them.

If you have experience in older C/C++ languages, you know what a welcome relief the .NET IO classes were, especially the File, Directory and Path classes. For some reason, traversing files and subdirectories had always been a pain in the rear. I remember fighting with the God-forsaken file-searching routines in C, and their abysmal Win32 API equivalents. Microsoft certainly simplified these activities with the .NET classes (as did the creators of other languages such as Python). And now in .NET they're even easier. The newest version of the Directory class includes methods that return enumerations. That means you can use LINQ on them.

In terms of architecture, there are a lot of improvements to .NET. For example, there's an entire set of classes now for supporting multicore, parallel programming and even LINQ. (This might look familiar. That's because it is. Microsoft released an early version of these classes called .NET Parallel Extensions, and they ran under .NET 3.5. I took these classes for a spin and they're really great. For example, there's a Parallel.For method that functions very much like a traditional for loop, except the code inside the loop runs in parallel for each iteration rather than sequentially. Indeed, using some tracing tools, by creating a parallel for loop with many iterations, I was able to see that they were being distributed among the cores of my CPU. Very cool.

There are lots of small, miscellaneous improvements to .NET as well. Several additional classes now support a Parse and TryParse method like we already have in Int32 and others. (Examples include Enum, which will come in handy, and Guid, which may occasionally be useful.) There's a new generic collection class called SortedSet (which technically speaking in mathematical terms is an oxymoron, but you get the idea).


ASP.NET has many improvements as well. For starters, the caching mechanism has been improved to include cache provider extensions, letting you (or a third party) create, as the documentation says, "more intelligent output-caching strategies for Websites." And if you've worked on Website development at all, then you know just how important this is for keeping a fast, optimal Web server.

Next up with ASP.NET is a possible fix to something that's been a bit of a gripe of mine for some time. In the past, if an ASP.NET server was sitting idle for a while, after the first request it would take quite a while for the server to wake back up. This can be embarrassing for a business for many reasons: The Web server may appear slow to a potential customer, or, worse, if the customer is tech-savvy, he or she may recognize that nobody has been to the site for as little as a few minutes or as much as days or weeks. To help fix this problem, the new version of ASP.NET supports preloading of Web applications, provided you're using IIS (Internet Information Services) 7.5 on at least a Windows Server 2008 R2. (An upgrade may be in your future.)

Additional improvements include permanently redirecting a page, sessions state compression, enhancements to the way CSS is handled and even embedding view state for individual controls, which gives you more power over which controls maintain their view state. Additionally, the HttpBrowserCapabilities class has been updated to recognize several newer browsers, including the iPhone browser, so that you can write code that displays differently based on these browsers.

For LINQ programmers using ASP.NET, there's also a new QueryExtender control to help you with filters and WHERE clauses. Additionally, MVC is now built in, instead of an extra download.

And here's an interesting improvement: dynamic data and scaffolding. This isn't actually new, but was introduced two years ago with the ASP.NET 3.5 Extensions as a separate download. But what is new is that it's now built into Visual Studio 2010 and ready for you to use. It's interesting because it allows you to quickly generate an ASP.NET application that features grid controls with direct access to the data. But is this very useful?

Initially, not really. I would hope that an ASP.NET programmer wouldn't just throw together this default application and deliver it as-is. It's ugly and not at all user-friendly, and it makes it too easy for the users to destroy the data. So what's the point? Well, you can go in and modify the templates and add on to the code and build an application from this, which is what I suspect Microsoft actually has in mind; from there you could create a more useful application. I'd be curious to see what kind of applications developers come up with. However, I should note that the whole thing is still very much traditional ASP.NET, in that the grids aren't AJAX-powered.

C++ Language, WPF

But let's not forget there's this other language (which I've written a few books about) called C++. Now remember: There are two aspects to C++ in Visual Studio. There's the native C++ that gets compiled to native Intel assembly code (for developing Win32 applications), and there's the managed C++, which gets compiled to intermediate code for running under the .NET framework.

The C++ compiler now supports many features of the new C++0x language, which should become a standard very soon. For example you can now use lambda functions in your C++ code.

Further, believe it or not, MFC is still alive and well and includes support for Windows 7 features as well as Office features such as the Ribbon. (That almost makes me want to go back to using MFC again after all these years. But maybe not.) And remember ATL? To quote the great Homer Simpson: "Is that thing still around?"

Indeed it is.
And let's not forget the C++ standard library, which now includes many of the C++0x features. (But why "many" and not "all" of the features? Because the C++0x standard hasn't been finalized yet.)


Now here's a question for the current Visual Studio developers: Do you use WPF? I'm guessing not. Over the past few years of being active in the Visual Studio community, it's become clear to me that the majority of programmers using Visual Studio have, for various reasons, ignored WPF, even though developing desktop applications is arguably much easier in WPF than with the older .NET forms approach. Yet, for some reason, WPF hasn't been embraced by a very high percentage of developers. It's hard to say why that is, but perhaps that will change with Visual Studio 2010, especially considering that much of Visual Studio itself has been redesigned using WPF.

WPF is now considered to be Version 4 (apparently to match the version numbers of everything else here), and with it comes a few new controls, including Calendar, DataGrid, DatePicker and WebBrowser. There are improvements to maintaining visual state, as well as support for touch input. The text rendering is also greatly improved. Microsoft was hit with a lot of complaints over text rendering early on in both Silverlight and WPF. Initially the company's execs tried to convince us that the new text rendering was somehow better, even though to most of us with normal vision the text was ugly and blurry. They apparently listened and now the text is rendered much better, even allowing you to use ClearType.

And finally, going back to the IDE, the designer has been improved in its XAML support for both WPF and Silverlight. Here is more information on WPF's improvements, as well as the designer's improvements.

Debugger, F# Language

The debugger has greatly improved. You can have greater control over your breakpoints, including the ability to label them and even import and export them. (I'm not sure when you'd need to import and export them, but I imagine there might be the occasional need for it.) The thread debugging window has been improved; this is good because the previous one kind of stunk.

Also, the watch windows have an interesting improvement. Previously you could call functions in your watch windows. That's an important feature, but it can also create problems if those functions modify the state of your program (change variables, and so on). That can totally screw up your debugging session. Now the watch window includes an icon that will warn you that refreshing the value will require other threads to run, which could cause side effects.

There's also improved support for debugging parallel applications. I don't have room here to describe this feature in detail, but consider this: Today's processors have multiple cores, which you can use for creating parallel applications. Visual Studio now gives you more ability to debug such applications.

F# Language

Microsoft is really pushing its new F# language. I have no complaints there. This language now ships with Visual Studio, instead of being a separate download. If you're interested in a modern language based on some really cool languages (ML and OCaml), then you might want to check this out.

Rocket Fuel