Tooled up

by Simon Bisson

Code better and faster by adding plug-ins to Visual Studio. Simon Bisson looks at some of the tooling for .NET and C++ coders.

HardCopy Issue: 63 | Published: May 20, 2014

Microsoft’s Visual Studio IDE is not just a proprietary tool for building .NET and native code on Windows and Windows Phone. It’s an extensible platform that lets you add support for new languages, for delivering apps to additional platforms, and for managing cloud services. This is down to its Visual Studio Industry Partner (VSIP) programme which gives third parties access to the Visual Studio IDE, allowing them to integrate their own tools and features into Visual Studio.

Intel Parallel Studio XE 2013

Most development support extensions for Visual Studio are platform agnostic, in that they can be used with Intel, AMD, and even ARM processors. That’s not the case with the latest release of Intel’s Parallel Studio, as it’s most definitely targeted at Intel’s own silicon, with the intent of helping you build code that can take full advantage of all the features offered by the current generation of multi-socket, multi-core motherboards. If you’re building large scale mathematical modelling or simulation apps, you’re going to need a tool to help you fine tune your code to get the absolute best from your silicon. It’s also cross-platform, so you can use it to build apps for Windows or for Linux.

Parallel Studio includes not just diagnostic and language tools. There’s also three new compilers: one for C++, one for C and one for Fortran. There’s no compiler support for .NET languages, which run through a JIT compiler (though there is some C# support in Parallel Studio’s analysis tooling). Instead the compilers and language features in Intel’s tools are targeted at native code, with libraries that aim to help you get the most from multi-threaded applications.

The most important part of the suite is Advisor XE, a threading prototyping tool. You can use this to analyse your code and determine where you’ll get the most performance boost from parallelism, and to highlight where you might get thread synchronisation issues.

Intel’s libraries make writing parallel code easier. This is especially the case for its core Threaded Building Blocks library, which in conjunction with graph-based design tools simplifies the process of implementing key parallel-programming algorithms. While you can always write your own parallel libraries, using proven industry standard tools makes a lot of sense, especially when they’re designed to work well across multiple processors and multiple cores. Threaded Building Blocks come with tools for working with shared memory and for handling scheduling, allowing code performance to scale as you add cores and memory.

You can get additional performance from your parallel apps with another Parallel Studio module, VTune Amplifier. This analyses your code, profiling a range of languages with parallel constructs, including C, C++, C#, Fortran and Java. It will even work with assembly language. VTune Amplifier collects GPU as well as CPU data, and will help you sort and visualise its results. There’s also the option of working outside the IDE to automate tests, and to collect data from remote servers.

Finding problems in parallel code can be an issue, as it can be hard to replicate the conditions which cause a crash. Intel’s Parallel Studio includes tools for finding threading errors, in the shape of Inspector XE. Used in conjunction with existing compilers and debugging tools, you can isolate intermittent and non-deterministic errors, as well as monitoring the system heap. Used with Intel’s compilers you also get support for static analysis and pointer checkers, which can help ensure application security.

Intel Parallel Studio is a powerful tool, and one that’s well worth considering if you’re building large and complex parallel processing applications. While you might not yet use it for consumer apps, it’s worth considering for cloud services, and for large and complex mathematical modelling and simulation apps – so ideal if you’re building code for oil exploration or for Formula 1 teams.

With VSIP extensions you can be building Ruby on Rails apps, driving Azure, and working with a source control platform while delivering a UI on an iPad, all from the same familiar IDE. So why not use extensions to improve the way you code? There’s plenty of scope here: tools to help you make your programs more secure, tools to help you refactor and rework your code, tools to help you deliver applications that take advantage of the multi-core, multi-processor world we live in.

There’s an ever growing array of VSIP partners and extension developers, and it’s likely to grow as Microsoft continues to open source key Visual Studio elements through its .NET Foundation. That includes its new Roslyn compiler, which opens up the internals of the compiler to tools, giving you new and better ways to visualise changes to code, and the ability to quickly test and debug sections of code as you write them.

 

Tooling for .NET

The release of Roslyn at BUILD 2014 marked something of a resurgence in the fortunes of .NET, which had languished as Microsoft pushed development of WinRT applications for Windows 8. But now WinRT and .NET apps can work together, and there’s even the option of delivering native .NET code. At last the future for .NET is clear. And it’s not just Windows that’s benefiting; Microsoft’s relationship with cross-platform .NET vendor Xamarin is going from strength to strength, letting you build .NET apps that run on iOS and Android, as well as Windows.

Microsoft’s own .NET tooling is powerful, but not perfect. So how can we go about making Visual Studio better for .NET developers? One option is JetBrains’ ReSharper, which works to improve your code across the whole range of .NET languages and associated technologies.

One of the more important features of ReSharper is its on-the-fly code quality analysis. It’ll monitor the code you’re writing, whether it’s for a XAML C# application or an ASP.NET web app with CSS and client-side JavaScript, letting you know if your code contains errors or can be improved using any of ReSharper’s other capabilities. You’re not limited to just the code you’re writing either, as ReSharper is aware of the files that make up a project, and the structure of the code in those files. You can jump to any place in your code at any time, and track specific variables, functions and types throughout your code.

If ReSharper spots an error in your code it warns you, and at the same time provides quick-fixes that can help solve problems before they affect your application. Its helpers go a lot further, with a whole range of add-ons. Some extend Visual Studio’s IntelliSense code completion tools, while others handle code transformations and importing namespaces – or simply keeping your code tidy and making sure you have access to the right documentation.

JetBrains ReSharper screenshot

A helpful suggestion from JetBrains ReSharper

Keeping code tidy isn’t just about making it more readable – though that helps when you’re handing code over to co-workers or to test and production. It’s also about handling coding standards when working as part of a team, and making sure that you don’t clutter up an application with unused code.

ReSharper is probably best known for its refactoring tools. These automate the process of identifying sections of code that can be refactored – identifying methods that can be shared, or elements that can be split into smaller methods. The result is code that’s easier to maintain and easier to extend, especially if it’s refactored to take advantage of common design patterns. ReSharper’s built-in unit testing tools ensure that refactored code maintains functionality, keeping applications running while you rejuvenate your legacy code.

Telerik is probably best known for its UI tools, but it also offers a range of tooling to help you write code. Its JustCode Visual Studio extension is a suite of tools that aid with various common coding problems. The result is a powerful tool with one aim: to make you a better coder, and save you time. You’ll find it useful if you work on different test machines, but want a consistent development environment wherever you are: settings are stored in the cloud and applied to all your JustCode installs.

Telerik JustCode screenshot

Telerik’s JustCode identifies a missing bracket.

One of JustCode’s key features is the ability to quickly navigate around your code. With many projects now targeting multiple platforms (something that’s going to become more common with the arrival of Windows Universal Apps), there’s a need to quickly get to the right symbol and to the right error. You can also jump straight to the implementations of an interface, or to the type of an expression, so you can ensure you’re using them consistently.

Coding standards are an important part of making sure application development is consistent throughout an organisation. Telelrik’s tools help enforce those standards, with the ability to ensure formatting is consistent through all your and your colleagues’ files. It doesn’t just handle spacing and line indentation; it also manages just how code constructs are ordered, as well as automating the creation of Using directives in your code.

JustCode helps you customise the Visual Studio environment. It can colour-code code elements that aren’t managed by IntelliSense’s colourings, making them clearer and easier to spot amongst hundreds or thousands of lines of code. It’ll even close braces for you automatically, so you don’t have to go back and check to find just where you left out a set, and giving your code a chance to compile first time! JustCode’s formatting tools will also automatically format your code when you close a set of braces.

Making code easy to read and understand is a perennial problem, especially if you’ve been working on an app for some time. How about getting rid of unused code? JustCode will highlight unused sections of code, allowing you to quickly remove dead code that only makes your code unreadable. Similarly it identifies types that are missing, and prompts you to add the appropriate Using statement. It’ll even help rename files so names match types they contain, making it much easier to go right to the file that contains the class you want to edit, or share with another project.

There’s also integration with other Telerik tools, including the JustTrace profiling framework. Using JustTrace in conjunction with JustCode’s unit tests means you can make app performance part of your test cycle; after all, slow code that passes unit tests will still need reworking to pass user acceptance!

PostSharp screenshot

PostSharp makes use of Aspect Oriented Programming techniques.

PostSharp takes a different approach to helping you write code, guiding you in working with Aspect Oriented Programming and automating certain key design patterns. It’s a technique that helps identify common code elements that can be shared across different applications. Such common code elements or ‘crosscuts’ are called ‘aspects’. Taking crosscuts and embedding them in aspects makes it easier to write business logic that is clearer and easier to understand, with much of the repetition handed over to aspects.

You do need to change the way you think about code to use PostSharp, but it’s a beneficial change. Once installed it works alongside the Visual Studio .NET compiler to handle the deployment and compilation of aspects, including obfuscating aspect code in applications that you plan on sharing. There’s support for automating certain key aspect patterns, for example aspects that handle exceptions. Aspects are implemented as attributes on a method, with the associated code applied on compilation. That way you get the benefits of the code, without having to write it.

One advantage of Aspect Oriented Programming is the ability to declaratively apply aspects to a range of methods with a compiler directive. This lets you use aspects in your code without having to modify existing code; an approach that makes PostSharp an ideal tool for adding instrumentation and exception handling to applications. Other common code that can be implemented as aspects include role-based security, ensuring only the right user gets access to specific functions and data.

NCover screenshot

NCover’s tools help you create effective tests.

NCover’s tools add code coverage to Visual Studio. Understanding what code has been tested, and more importantly, what code hasn’t, is an important part of ensuring code quality. If you can see the code that isn’t being tested, then you’re in a position to write better tests. Using NCover Bolt from inside Visual Studio lets you launch tests without leaving your code, with a graphical view of all the possible paths that can be taken. You can use this to define new tests, or ensure that you’ve set up the appropriate starting conditions for your test so that all your code is tested. You can also change the order in which tests run, ensuring that tests which have failed are the ones that run first.

 

Tooled up for C++

While Visual Studio is often viewed solely as a .NET development environment, Microsoft’s C++ compiler remains a key part of the package, delivering native code to Windows and Windows Phone. C++ is compiled directly to machine code, so it’s important to have good code from the start. That’s where Gimpel’s FlexeLint and PC-lint come in, adding tooling to Visual Studio for handling static analysis.

Building on the familiar UNIX lint tools, Gimpel’s family of Windows Lint applications go further than the syntax checking tools built into Visual Studio. Designed to analyse all the files in your code, including C modules, the tools deliver messages that indicate the quality of your code, highlighting errors as well as displaying informational messages.

While PC-lint is for Windows and DOS only, FlexeLint is for cross platform developers, and runs on most common flavours of UNIX. It’s distributed as source code and you need to integrate it with Visual Studio yourself. PC-lint doesn’t just support Microsoft’s C++ compilers; it’ll also work with gcc.

Once installed, PC-lint will handle the checking of variable initialisations, types checking, and the semantics of your code. There’s even the option of creating your own semantic rules, as well as finding unused macros, types, classes and the like in your code; giving you cleaner, easier to read code without confusing non-functional sections.

While you can run PC-lint from inside Visual Studio yourself, a range of third-party tools helps integrate PC-lint more effectively. Cleanscape’s C++ Lint wraps PC-lint and gives you a graphical user interface, with hyperlinks to code editors, as well as automated integration with Visual Studio and access to the familiar PC-lint command line. Similarly Riverblade’s Visual Lint and LintProject automate static analysis of your code in Visual Studio, with LintProject able to work against Visual Studio solution files.

Visual Studio remains the premiere Windows development environment. But it can always be improved. These extensions and add-ons offer deep integration and a range of features that can be combined to help you write better, more readable code. It also helps you create code that’s easier to test, and can be proved to have been tested. If you’re working on a large project with a team of developers, it’s well worth considering make them part of your standard installation: it’ll make your life a lot easier.

Find Out More

Full details for all these products are available on the Grey Matter website at www.greymatter.com. You can also call Grey Matter on 01364 654100 or email maildesk@greymatter.com if you would like to discuss your needs further.

Veeam Availability Suite banner
 Microsoft Azures ads