Blogs

Mark Miller

  • Duplicate Detection and Consolidation in CodeRush for Visual Studio

         

    CodeRush 11.2 introduces a new feature we’re very excited about. It’s called Duplicate Detection and Consolidation (DDC) and it’s revolutionary.

    Background

    Duplicate code, sometimes referred to as clones, is a cluster of code blocks that are functionally equivalent (or nearly equivalent) spanning across two or more locations within a solution. Duplicate code is expensive to maintain because:

    1. Multiplied bugs. A bug in one clone means there’s a bug in all the copies. This can lead to a continued, repeated release of previously-fixed bugs as each copy of the bug is individually discovered by a customer and then fixed by the team.
    2. Flexibility barriers. If the copied code needs to be more flexible, changes need to be made across all the copies or ideally, the copies need to be consolidated first. Unfortunately consolidation is a high-risk, error-prone, time-consuming activity.
    3. Increased ramp-up time. Copy the code and new developers trying to get up to speed will have twice as much code to read and understand. If discovered, duplicated code tends to be harder to understand than normal code because the reader must not only understand functionality, but also understand the reason behind the duplication.

    Reaching into the Future

    Because duplicate code is such an expensive problem, for years tools have been developed to detect duplicate code, each achieving various degrees of success. So you might wonder, after so many years of development, what makes CodeRush’s DDC so revolutionary?

    1. Speed. CodeRush has the fastest duplicate code detection available for .NET. It’s 17 times faster than the duplicate code detection currently available in the Visual Studio 11 preview.
    2. Integration. DD runs in a background thread while you work in Visual Studio. Duplicate code is highlighted on screen so you know exactly what you’re working with before you change the code.
    3. Functional Equivalence. The CodeRush duplication detection engine is built to understand functionally equivalent code. In 11.2, we take baby steps in this direction. However, by 12.1 we expect to really be blowing minds in this area, matching structurally distinct yet functionally equivalent blocks of code.
    4. Consolidation. CodeRush is the first and only tool on this planet to offer the ability to immediately consolidate duplication into a single block of code, directly from the IDE. Not only is CodeRush first, but Team CodeRush has delivered an impressive solution.

    The Complexity of Consolidation

    To give you an idea of just how impressive duplicate consolidation is, let’s take a look at what needs to happen to consolidate:

    1. You need to understand not only the similarities, but also the differences among the code blocks. Differences can be parameterized.
    2. If the duplicate blocks of code are functionally equivalent but structurally distinct, then a decision needs to be made - upon which of the duplicate blocks should we base the consolidation?
    3. You need to offer a variety of consolidation solutions so the developer can pick the one that fits best. For example, you could consolidate to a new method in a class, create a new ancestor class, or create a new helper class.
    4. You need to understand and respect project boundaries. In many cases duplication between projects survives beyond initial discovery because consolidating is time consuming and may require the creation of a new project.  If a new project is created, the appropriate references need to be added. Regardless of whether we’re creating a new project or moving code from one existing project to another, we need to verify that we can do this without creating any circular references.
    5. Types need to be correctly resolved. You might have two classes with the same name declared in different namespaces in your solution. The consolidated code must have the correct namespace imports to ensure that all the types are correctly resolved.

    As a result, the steps to consolidate by hand are many, complex, error-prone, and high-risk. Only the best developers are brave enough to venture forth in this domain, and if they do, they are best advised to bring a paired programmer along for the ride.

    Enter CodeRush 11.2

    This changes everything. From this day forward, the quality of code is going up. Let’s take a simple example. I have a class named Mortal, which looks like this:

    public class Mortal
    {
      protected List<Mortal> friends = new List<Mortal>();
     
    public string Name { get; set; }
    }

    And a descendant named Human, which has a FindHuman method:

    public class Human : Mortal
    {
     
    public Mortal FindHuman(string name)
      {
       
    Mortal mortal = null;
        foreach (Mortal friend in friends)
        {
         
    if (String.Compare(friend.Name, name, false) == 0)
          {
           
    Console.WriteLine("Found a Human: " + friend.Name);
            mortal = friend;
           
    break;
          }
        }
       
    return mortal;
      }
    }

    So far so good. But now, let’s do something incredibly dangerous. We’re going to make a copy of this Human class and perform a search and replace, “Human” for “Martian”…

    public class Martian : Mortal
    {
      public Mortal FindMartian(string name)
      {
        Mortal mortal = null;
        foreach (Mortal friend in friends)
        {
          if (String.Compare(friend.Name, name, false) == 0)
          {
            Console.WriteLine("Found a Martian: " + friend.Name);
            mortal = friend;
            break;
          }
        }
        return mortal;
      }
    }

    But let’s continue to change the code. Let’s introduce a few local variables, rename “mortal” to “myFavoriteMartian”, remove the unnecessary curly braces around the if-block, and change case-sensitivity of the String.Compare call so it ignores case (as one might expect with Martian names)…

    public class Martian : Mortal
    {
      public Mortal FindMartian(string name)
      {
        Mortal myFavoriteMartian = null;
        bool ignoreCase = true;
       
    string msg = "Found a Martian: ";
       
    foreach (Mortal friend in friends)
          if (String.Compare(friend.Name, name, ignoreCase) == 0)
          {
            Console.WriteLine(msg + friend.Name);
            myFavoriteMartian = friend;
            break;
          }
        return myFavoriteMartian;
      }
    }

    And now we have some code that is functionally equivalent, but structurally distinct. Can CodeRush find this? It can, providing we drop the Analysis Level down to 2, so the detection engine can see this smaller code block (the default level is set to 3, which is a slightly larger block):

    BlockSettings

    Here’s what the code looks like inside Visual Studio:

    HumansAndMartians

    On the left of the gutter in each view, you see a thin purple vertical bar. This means duplicate code exists elsewhere. Also, in the bottom right, the “!!” icon signals CodeRush has detected duplicates inside the solution. If you hover over the icon in the bottom right, a hint appears to explain the status.

    DuplicatesFound

    You can click the icon to see a summary of all duplicate clusters found inside the new Duplicate Code tool window. In this case, our simple example, only one cluster is found:

    DuplicateCodeWindow

    On the left is a list of all clusters found, sorted by redundancy (the total amount of redundant code that could be removed if consolidated). Note that because we are sorting by redundancy, it’s possible for a very small block of code (duplicated many times) to appear above a very large duplicate block of code (that only appears twice).

    On the right is a preview of the duplicate code. You can double-click any duplicate code preview to be taken directly to that location. When you do this, CodeRush immediately presents the consolidation hint, which looks like this:

    ConsolidationHint

    Notice the mouse is positioned right over the “Next duplicate block” button, in case you want to navigate and compare the blocks. This might be useful when it’s time to consolidate. The block you consolidate from determines the structure of the consolidated block. So let’s consolidate from the FindMartian method. Click the “Next duplicate block” button, then move the mouse over the “to the base class” consolidation option. You’ll see a preview hint that looks like this:

    ConsolidationHint2

    Notice the parameters to FindMartianExtracted – CodeRush takes the code that differs between the blocks and turns them into parameters. Press Enter to apply the consolidation. The target picker will appear letting you select the location of the consolidated method.

    TargetPicker

    The target picker shows the block of code that will be inserted. It’s based upon the structure of the method where we initiated the consolidation (FindMartian). Let’s press Escape to cancel and back out of this, and then see what happens when we initiate consolidation from the other duplicate…

    ConsolidateFromHuman

    Now consolidate to the base class Mortal. We’ll see the target picker. Notice how the FindHumanExtracted consolidated code in the preview below differs from the FindMartianExtracted consolidated code in the preview shown two screen shots above.

    TargetPicker2

     Just use the up/down arrow buttons to select a location and press Enter to accept it. Now we’re left with a small task of coming up with good names for the consolidated method and its parameters.

    RenamingParameters

    And the calling code is simplified:

    CallingCodeSimplified

    And that’s it (for a simple consolidation example)!

    An Even Bigger Example

    But what happens when the project is much bigger? The good news is, that the detection scales well for large solutions, taking only seconds (at most a few minutes) to scan thousands of files for duplicates at the default settings (Analysis Level set to 3). Let’s take a look at DDC with the source to Umbraco.

    Here’s cluster #4 selected. The Lowest and Highest methods inside the ExsltMath class:

    Cluster4Umbraco

    Nearly identical blocks of code. However note the real difference is in the operator used to compare t against min (and max). On the left you have “t < min”, and on the right you have “t > max”. Can CodeRush consolidate this duplicate? It can. Here’s the preview hint:

    PreviewHintUmbraco

    And after consolidation (and renaming the method, the “min” local, and the “func” parameter), I get this:

    AfterConsolidation

    And now the quality of the code is much higher than it was before.

    Remember, CodeRush has the fastest duplicate code detection available for .NET. It works in the background and shows when you’re working inside a method that is cloned. Consolidation is based on the structure of the method you start from. While CodeRush can consolidate many kinds of duplicate blocks, not all duplicate blocks can be consolidated automatically (trust me, this is an incredibly challenging problem to solve). But we’re working on making the consolidation engine even smarter and even more extensive as we approach the 12.1 release (and we expect to blow your mind again with that one).

    Do me a favor, kids: Tell every developer you know about CodeRush’s Duplicate Detection and Consolidation. DDC is truly revolutionary; help us spread the word.

  • Advanced CodeRush Plug-ins: Converting an Object Initializer into a Constructor

         

    Today Rory Becker and I presented an Advanced CodeRush Plug-ins session, showing how to create CodeProviders and RefactoringProviders. These providers show up on the CodeRush/Refactor menu, like this:

    RefactoringMenu

    The session included several moments where we tasted sweet success, and at least one tough coding segment where we were pushing through some challenging code.

    The new feature converts code like this:

      Box box = new Box() { Height = 33, Width = 44, Depth = 22 };

    into this:

      Box box = new Box(33, 44, 22);

    and creates a constructor if needed.

    At the end of the two-hour session, we were left with a refactoring that worked, but a CodeProvider that needed more effort. The CodeProvider was challenging because it needed to modify code in two places (it is adding a constructor and replacing the object initializer with a call to new constructor), potentially in two files.

    Here’s an overview of the points we learned in the session:

    1. The Expressions Lab can reveal many of the hidden details behind the source code you want to analyze or generate.

    2. The ObjectCreationExpression class represents a call to a constructor.

    3. ObjectCreationExpression elements have three interesting properties:

    • Arguments – the parameters to the constructor call, if any
    • ObjectType – a reference to the type being constructed
    • ObjectInitializer – an ObjectInitializerExpression (if the constructor call includes an initializer).
    4. ObjectInitializerExpression has one interesting property:
    • Initializers – a collection of MemberInitializerExpressions
    5. MemberInitializerExpression has two interesting properties:
    • Name – the property name being assigned.
    • Value – the value assigned to the property in the initializer expression.
    6. MemberInitializerExpression also has an interesting method, Resolve, which allows us to determine the type of the initializer argument.

    7. We can use the FileChange object to queue up changes to multiple files.

    At the end of the webinar, we encountered an issue where the CodeProvider wouldn’t generate any code. The problem was due to this line of code which set the source file Path property of a FileChange instance to the folder holding the text document (but not the actual file name):

      newConstructor.Path = CodeRush.Documents.ActiveTextDocument.Path;

    it should have been this:

      newConstructor.Path = CodeRush.Documents.ActiveTextDocument.FileNode.Name;

    Correcting the two places where we set FileChange’s Path property enabled the plug-in to generate code correctly. We’ll record a part 2 to this webinar where we’ll see this fix and wrap up all remaining issues:

    1. Fix the FileChange code generation.
    2. Add code that transfers parameters to the properties.
    3. Declare parameters in the developer’s preferred style.
    4. Test, and handle any new issues found.
  • New CodeRush Feature: Quick Pair (Parens, Brackets, Quotes, etc.) for Visual Studio

         

    Today was the first CodeRush Feature Wednesday webinar presented by Rory Becker and myself. And for our first feature we decided to implement something I wanted – a better way to enter paired delimiters in code. When entering paired delimiters, there seem to be a number of common scenarios:

    • Enter the pair and move on (for example, parens in a C# method call that takes no arguments)
    • Enter the pair and place the caret between the pair (but then you have the challenge of moving outside the pair)
    • Surround a selection with the pair

    To implement this feature, in the webinar we created a new Action called QuickPair which accepts leading and trailing delimiters, and an optional third parameter to determine whether the caret goes inside the delimiters or to the right outside the delimiters.

    You can download and install the feature here:

    http://code.google.com/p/dxcorecommunityplugins/wiki/CR_QuickPair

    This plug-in includes shortcut bindings based on the US keyboard. You may need to change these bindings to match your keyboard locale settings. For example, on a US keyboard, the parens are located above the 9 and 0 keys, respectively, like this:

    90

     

    The curly braces are above the brackets:

    Brackets

     

    The angle brackets are above the comma and period keys:

    AngleBrackets

     

    And the double-quote is above the apostrophe (and the key to the left is the semi-colon):

    Quote

     

    With each of these key pairs, we’ve assigned two functionalities. The left key (e.g., Ctrl+[ ) places the caret between the two delimiters (adding a field, so you can just press Enter to get to the right of the delimiter pair), and the right key (e.g., Ctrl+] ) places the caret after the two delimiters (no fields needed). If there’s a selection, the left key will embed the selection within the delimiters (maintaining the original selection), and the right key will embed the selection within the delimiters, extending the selection to include the delimiters. Examples of all the bindings created in the webinar appear below.

    Given these key positions, the table below shows available functionality (the “|” character indicates the caret position and the blue background indicates the selection, after code is inserted):

    On a US Keyboard, press this: to get this:
    (no selection)
    or to modify a selection:
    Ctrl+(   (|)   (My Selection)
    Ctrl+)   ()|   (My Selection)
    Ctrl+[   [|]   [My Selection]
    Ctrl+]   []|   [My Selection]
    Ctrl+Shift+{   {|}   {My Selection}
    Ctrl+Shift+}   {}|   {My Selection}
    Ctrl+Shift+<   <|>   <My Selection>
    Ctrl+Shift+>   <>|   <My Selection>
    Ctrl+;   "|"   "My Selection"
    Ctrl+"   ""|   “My Selection”
    Ctrl+=   (|) =>   (My Selection) =>

    You may notice a lack of symmetry with the Ctrl+= binding (there is no corresponding binding to place the caret to the right of the lambda operator). I omitted this binding due to a lack of a suitable neighboring key to the equals sign. If you want to correct this asymmetry and add your own binding, feel free to. After installing this plug-in, you may view or change the shortcuts bindings in the IDE\Shortcuts options page. The QuickPair bindings are in the Code\QuickPair folder:

    QuickPairBindings

    Have a request for a new feature? Email roryb@devexpress.com and let us know what you’d like to see us build for you on CodeRush Feature Wednesdays.

  • Get Your CodeRush Training Here

         

    Here’s a summary of CodeRush training videos created so far, to help you find relevant training quickly:

     

    1.       Introduction to Features

    a.       Getting Started/Configuration

    2.       Navigation

    3.       Working with Selections and the Clipboard

    4.       Consume-first Declaration

    5.       Declaring and Refactoring:

    a.       Properties

    b.      Events

    6.       Refactoring in-depth:

    a.       Introduction

    b.      Changing Signatures

    c.       Conditionals

    d.      Declaration and Initialization

    e.      Dead Code

    f.        Expressions

    g.       Formatting and Structure

    h.      Lambda Expressions and Anonymous Methods

    i.         Loops & Blocks

    j.        Moving and Extracting Methods

    k.       Properties and Fields

    l.         Strings

    7.       Language/Framework follow-up:

    a.       ASP.NET

    b.      C++

    c.       MVC

    d.      Working with Color

    e.      WPF and Silverlight

    f.        XAF

    8.       Advanced Topics

    a.       CodeRush Template Deep Dive

    b.      TextCommands

    9.   Creating Plug-ins

    a.       Introduction – Actions and Tool Windows

    b.      Text Commands, StringProviders and ContextProviders

    c.       TextDocument and TextView

     

    Nearly every Tuesday at 12:00 noon Pacific time Rory Becker and I host a CodeRush training webinar, where we dive into a particular topic and answer questions from viewers. You can see a list of upcoming CodeRush webinars here.

  • Visual Studio Features Built Instantly for CodeRush Developers

         

    This week Rory and I continue our path-rip through the space time continuum by responding to customer requests yet again with mind-numbing development speed.

    Earlier today this question appeared on twitter:

    Request

    Joe needs to convert a method call with positional arguments (the old way of passing arguments), into a named argument call. For example, he wants to change something like this:

    RegisterDev("Mark", "Miller", 0);

     to this, in C#:

    RegisterDev(firstName: "Mark", lastName: "Miller", id: 0);

    Definitely a useful refactoring. Here’s how we built it:

    1. Create a new plug-in.
    2. Drop a RefactoringProvider on the design surface
    3. Fill out properties for the refactoring (Name, Description, AutoUndo)
    4. Handle three events (CheckAvailability, Apply, & PreparePreview)

    Within an hour the feature was implemented and published (working in C# and VB), ready for consumption by CodeRush devs, prompting this response from Joe:

    ResponseFromJoe

    But this isn’t unique. Over the last two weeks we’ve released a number of new features, all built and delivered on the same day they were requested (most in under an hour from the original request)…

    SurlyDev

    pajacobs

    Apeoholic

    Need a feature? Just let us know. CodeRush can do anything, and if the feature isn’t there, we can likely add it easily. Tell us on Twitter what you want CodeRush to do (include the word “CodeRush” in your tweet), and lets see if we can keep up the pace. Smile

  • Importing Namespace References for Extension Methods in CodeRush for Visual Studio

         

    From feature request to binary delivery in less than four hours. Here’s the timeline:

    At 10:06 this morning, Apeoholic tweets the following question:

    Is there a way to get #CodeRush to suggest namespace usages for extension methods?

    Which led to the following discussion with one of our CodeRush devs on IM:

    [10:08] Mark: Hey Alex, I have this question in a tweet -- "Is there a way to get #CodeRush to suggest namespace usages for extension methods?"
    [10:09] Alex: Hi Mark, I'm not sure what he means…
    [10:10] Mark: I think he's talking about adding namespace imports when an extension method is at the caret.
    [10:10] Mark: I'm wondering if VS fails to do this.
    [10:10] Alex: I suppose VS does it, doesn’t it?
    [10:10] Mark: Check it for me.
    [10:12] Alex: OK, VS fails to do this.
    [10:13] Alex: And we don't have such feature
    [10:13] Mark: Can we write this as a plug-in?
    [10:13] Alex: Of course, but this will take time.
    [10:14] Mark: What's the challenging part of this?
    [10:14] Alex: Find and resolve all the extension methods
    [10:15] Mark: Create a spike -- work on this for an hour and see what you get.
    [10:15] Mark: Then send me that source and I can finish it up
    [10:15] Alex: ok
    [10:15] Mark: Then I'll have Rory put it on the community site.
    [10:15] Alex: k

    Which led to the development of the feature, testing, a few changes, and then this IM with Rory Becker:

    [13:06] Mark: I had Alex create a plug-in spike for a feature request to add missing namespace references for extension methods (something VS does not do)
    [13:06] Rory: cool
    [13:06] Mark: I'm going to send this to you. Can you get this on the community plug-in site today?
    [13:06] Rory: yeah sure, no problem

    At 14:05, we published the feature on the community site.

    Here’s the feature in action:

    AddNamespaceReference

    Here’s the link to the feature on the CodeRush community plug-ins site: http://code.google.com/p/dxcorecommunityplugins/wiki/CR_ExtensionMethodsHelper

    We are likely to roll this functionality into a future version of CodeRush. If you have a CodeRush question or feature request, we want to hear from you. Post a comment below or include “#CodeRush” in your tweets and we’ll respond in a timely manner.

  • Creating CodeRush Plug-ins: Actions and Tool Windows

         

    Today Rory and I presented a webinar called Creating CodeRush Plug-ins: Actions and Tool Windows. In it, we created a tool window that displays all Markers dropped throughout all open files. To see how we built this, watch the webinar here, which should be published in the next 24 hours if it isn’t available already.

    MarkersToolWindowScreenShot

    The source to this plug-in can be found on the CodeRush community plug-in site, located here.

  • High-speed MVC Development in Visual Studio with CodeRush and DevExpress MVC Extensions

         

    If you saw our Using CodeRush with MVC webinar, Rory and I introduced new templates that make it easy to exploit the MVC Extensions from DevExpress. These templates will likely be integrated into CodeRush 11.1, however you can install and start using them right now (installation instructions appear below).

    Templates

    Controls

    Template        Control                     
    xb Button
    xc Calendar
    xcb ComboBox
    xde DateEdit
    xgv GridView
    xhe HtmlEditor
    xhl HyperLink
    xi Image
    xl Label
    xlb ListBox
    xm Menu
    xmo Memo
    xnb NavBar
    xp PopupControl
    xpg PageControl
    xrb RadioButton
    xrbl RadioButtonList
    xrp RoundPanel
    xs Splitter
    xse SpinEdit
    xtb TextBox
    xte TimeEdit
    xtv TreeView
    xu UploadControl

    Items, Nodes, Groups, Panes, and Tab Pages

    These templates make it easier to create elements inside the MVC controls. Copy the reference that will own these elements (e.g., “settings”, “settings.Properties”,  “firstMenu”,  etc.) to the clipboard before expanding.

    Template    Calls Use Inside              
    ga Groups.Add() NavBar
    ia Items.Add() ComboBox, ListBox, Menu, RadioButtonList
    na Nodes.Add() TreeView
    pa Panes.Add() Splitter
    tpa TabPages.Add()    PageControl

    Other Templates

    Template    Expansion
    xrs RenderScripts
    xrss RenderStyleSheets

    Installation

    To install, follow these steps:

    1. Right-click and save each of the templates below.

    HTML_MVC_DevEx Extensions.xml
    CSharp_ASP.NET_MVC_DevEx Extensions.xml

    IMPORTANT:  For VB developers, we have two sets of templates to choose from.

    2. Start Visual Studio if it’s not running already.

    3. From the DevExpress menu, select Options.

    4. Navigate to the Editor\Templates options page.

    5. IMPORTANT: Change the Language combo box at the bottom of the Options dialog to HTML.

    LanguageHtml

    6. Right-click the template TreeView and choose Import Templates….

    7. Select the HTML_MVC_DevEx Extensions xml file downloaded in step one, and click Open.

    8. If you see a Category Exists warning message, click OK.

    CategoryExists

    Next, we need to install the templates for adding items, groups, nodes, panes, and tab pages. These templates must be imported into the appropriate language group of templates.

     

    If You Work in Visual Basic…

    1. IMPORTANT: Change the Language combo box at the bottom of the Options dialog to Basic.

    LanguageBasic

    2. Right-click the template TreeView and choose Import Templates….

    3. Select the Basic_ASP.NET_MVC_DevEx Extensions xml file downloaded in step one, and click Open.

    4. If you see a Category Exists warning message, click OK.

     

    If You Work in C#…

    1. IMPORTANT: Change the Language combo box at the bottom of the Options dialog to CSharp.

    LanguageCSharp

    2. Right-click the template TreeView and choose Import Templates….

    3. Select the CSharp_ASP.NET_MVC_DevEx Extensions xml file downloaded in step one, and click Open.

    4. If you see a Category Exists warning message, click OK.

     

    Testing

    After importing the MVC Extension templates as shown above, click OK to close the Options dialog. Inside an MVC application, open an aspx file, go to an empty line, and expand one or more of the templates on this page.

    MVC TreeView expansion

  • Updating Plug-ins on the Community Site

         

    Update: The content at the community site has been updated, and nearly all the plug-ins there currently build with 10.2.

     

    Binary plug-in compatibility across versions of the DXCore is a huge priority for us. For most of our releases, we’ve delivered on that intention; after updating you could simply continue to use a plug-in compiled for a previous version. In a few releases, we required a recompile but no source code changes to the plug-in. In 2010, we introduced changes that meant the code had to change in a few plug-ins that were still using the obsolete architecture, and we moved our parsers out to a separate DLL.

     

     

    There are CodeRush and DXCore plug-ins out on the community site in need of updates to match the architectural changes introduced in 10.1 and 10.2. Here’s where things currently stand at the community site:

     

    No Changes Needed

    The following plug-ins compile:

    • CR_BlockPainterPlus
    • CR_CCConsole
    • CR_ClearAllMarkers
    • CR_CodeIssuesContrib
    • CR_CreateTestMethod
    • CR_DeclareClassInProject
    • CR_DrawLinesBetweenMethods
    • CR_ExecuteScript
    • CR_GenerateTest
    • CR_JumpToImplementation
    • CR_Loop
    • CR_MetricShader
    • CR_NavigateToTest

    Need References

    The following plug-ins need to add a reference to DevExpress.DXCore.Parser:

     

    • CR_CodeBlockContentProviders 
    • CR_ColorizeMemberNames 
    • CR_CreateDelegate
    • CR_CreateHeader
    • CR_DumbAss_Issues
    • CR_EnhancedForEach
    • CR_EasyGoto – also Specific Version needs to be set to false for DevExpress.CodeRush.Library
    • CR_EventHandlerCheckTC
    • CR_ExceptionHelper – also needs ambiguous Xml references changed to System.Xml and needs a change to DxCoreEvents1_EditorPaintForeground handler which uses m_Highlighter
    • CR_Execute
    • CR_MoveFile
    • CR_MsdnBclHelp
    • CR_MultiFileTemplates
    • CR_NavigationContrib
    The following plug-ins need references to both DevExpress.DXCore.Controls.Utils.v6.3 and DevExpress.DXCore.Parser.
    • CR_Initials
    • CR_MarkerExtensions
    • CR_mdMarkerExtensions (also needs to change LocatorBeacon to GdiLocatorBeacon)

     
    The following plug-ins need to set the Specific Version property to false for DevExpress.DXCore.Parser:

    • CR_NavigateToDefinition
    • CR_MethodNameReformatting
    • CR_MethodPreview


     
    The following plug-in needs a reference to DevExpress.DXCore.Controls.Utils.v6.3 (with its Specific Version property to false)

    • CR_ClassCleaner

     

    Code Changes Required

    These plug-ins require some changes to the source code to meet the recent architecture changes.

    CR_Colorizer

    Needs reference to DevExpress.DXCore.Parser.
    Adding this reference and recompiling produces this error:
    Error    1    'DevExpress.CodeRush.Core.TextView' does not contain a definition for 'Repaint' and no extension method 'Repaint' accepting a first argument of type 'DevExpress.CodeRush.Core.TextView' could be found
     
    We recommend fixing with this code:

      IGdiTextView gdiTextView = CodeRush.TextViews.Active as IGdiTextView;
      if (gdiTextView != null)

        gdiTextView.Repaint();


    CR_NCover
    Could not locate the assembly "Typemock.ArrangeActAssert, Version=5.3.1.0, Culture=neutral, PublicKeyToken=3dae460033b8d8e2, processorArchitecture=MSIL".

    It also needs DevExpress.DXCore.Parser and DevExpress.DXCore.Platform references.


    CR_ExtractHqlNamedQuery
    Specific Version needs to be set to False for all DXCore assemblies
    Needs references to DevExpress.DXCore.Controls.Utils.v6.3 and DevExpress.DXCore.Parser.
    Also, the findFileInSolution method needs this change:

      SolutionElement solution = currentProject.Solution as SolutionElement;

      foreach (var project in solution.AllProjects)

    And this:

      SourceFile namedQueriesXmlFile = getNamedQueriesXmlFile(hqlQueryElement.Project as ProjectElement);


    Working to Make this Better

    Both Rory Becker (CodeRush evangelist) and the CodeRush team are working right now to update the plug-ins at the community site. If you’re an author of one of these plug-ins, I encourage you to update your source code using the hints on this page (it might be a good idea to check first to make sure the fix hasn’t already been submitted). I want to thank you for your patience and support as we go through the 50+ plug-ins and update them accordingly. In the future as we prepare to release, the CodeRush team will check the new build against all the plug-ins on the community site and if there are any issues, we’ll either change things on our side or connect with the plug-in author and get them to change their code before we ship.

    Our commitment is to a strong plug-in community. We will invest whatever it takes to support the plug-in community and make transitions to future versions as painless as possible.

  • WPF & Silverlight Grids – Faster Creation Using CodeRush Templates and a Custom Plug-in

         

    A few days ago a customer asked for a faster way to create WPF and Silverlight grids. Rory Becker and I recorded a video showing how to create this feature in CodeRush. Rory and I discuss and build the feature in about 30 minutes.

    Here’s the final version of the feature in action (the mnemonic is “g” followed by the dimensions of the grid, so “g2x3” creates a 2x3 grid):

    GridTemplateExpansion

    In the video Rory and I show how we built this feature step-by-step. We create a template and add a custom plug-in to make the template more dynamic and intelligent. You can follow along with the video to create this yourself and learn about templates and plug-ins, or you can follow the download instructions below if you simply want the feature. Here’s the video (be sure to watch it through to the end – I added a video update where I improved the template to make it even easier to use):

    BuildingGridsFasterVideoLink2

    Installing the Smart Grid Templates

    1. Right-click and download this Smart Grid templates link.
    2. Start Visual Studio.
    3. From the DevExpress menu, select Options.
    4. Inside the Editor folder, select the Templates options page.
    5. IMPORTANT: In the Language combo box at the bottom of the Options page, make sure XAML is selected:

      LanguageXaml
    6. Right-click the template tree list and choose Import Templates….

      Import Templates
    7. Navigate to the folder where you downloaded the Smart Grid templates. Select XAML_SmartGrid.xml and click Open. The smart grid templates will appear inside the template tree list.

      SmartGridTemplatesImported
    8. Click OK to close the Options dialog.
    9. From the DevExpress menu, selection About…. The DXCore About box will appear.

      DXCoreAbout
    10. Click the Settings… button. A Windows Explorer window will appear.
    11. Navigate to the Settings.xml\Core folder inside Explorer.
    12. Download and save the Numbers dynamic list to this folder.
    13. Back on the DXCore About box, click the Plug-ins… button. This will open two more Windows Explorer windows (Bin\PlugIns and Community\PlugIns). Download and save the
    14. Download and unzip the CR_Loop binary to the Bin\PlugIns folder (latest CR_Loop source is here if you’re interested).
    15. Click OK on the DXCore About box.
    16. Restart Visual Studio.
  • Mads Torgersen on the Future of C# and the New Async Keyword

         

    I had the pleasure of interviewing Mads Torgersen, product manager for the C# language at Microsoft. Mads talks about the new async and await keywords coming in C# 5.0, the criteria behind C# design choices, and C# futures.

    Enjoy!

    MadsTorgersenInterview

  • Upcoming CodeRush Webinars

         

    Join us every Tuesday at 12:00pm Pacific time for an in-depth dive into CodeRush with Mark Miller and Rory Becker. Here's what we have coming up:

     

    4 Jan 2011
    Navigation with CodeRush
    Mark Miller and Rory Becker reveal powerful CodeRush features that help you get to where you want to be, featuring Quick Nav, Recent Files, Bookmarks, Markers, Structural Navigation, Tab to Next Reference, Jumping to Member Overrides, Base Types, Interface Implementers, Camel Case navigation and more.

     

    11 Jan 2011
    Consume-first Declaration with CodeRush
    Mark Miller and Rory Becker show how to write consumption code first (which can improve the quality of your API), and then use CodeRush to generate and fill in the missing pieces.

     

    18 Jan 2011
    Declaring and Refactoring Properties with CodeRush
    Mark Miller and Rory Becker reveal everything you need to know about working with properties in CodeRush.

     

    25 Jan 2011
    Declaring and Refactoring Events with CodeRush
    Mark Miller and Rory Becker reveal everything you need to know about working with events in CodeRush.

     

     

  • Visual Studio’s Greatest Test Runner? Take a Look at CodeRush 10.2

         

    CodeRush 10.2 was released last week and the Test Runner that ships inside appears to be the greatest Test Runner available for .NET development.

    So before I show you why the CodeRush Test Runner is the best, let’s first consider the criteria by which we might judge greatness. I suggest greatness can be measured in one or more of the following:

  • Native support for your test frameworks
  • Ability to run unit tests quickly
  • A user interface prioritizing clarity over noise
  • Ability to run and debug a single test
  • If you can think of important criteria that isn’t listed above please let me know in a comment below. However, if your criteria for greatness is listed above, we have really good news for you: The CodeRush Test Runner is going to impress you.

     

    Native Test Framework Support

    The CodeRush Test Runner natively supports NUnit, MSTest, xUnit, MbUnit and Silverlight. Native support means CodeRush fully supports each framework, so new extensions and new features added to the framework can be exploited immediately without needing an update from DevExpress. No other test runner out there has built-in native support for all these testing frameworks.

     

    Performance

    The CodeRush Test Runner is the fastest test runner available for .NET. With our new multi-threaded run option, you can run tests in multiple assemblies in separate threads, resulting in a test run that is up to three times as fast as the competition.

    TestRunCompareTime3

    Like waiting? You don’t have to. CodeRush finishes your multi-assembly test run up to three times faster.

     

    Run & Debug a Single Test

    Seems like a simple request, but being able to run and debug a single test is important, especially to Silverlight developers. CodeRush is currently the only unit test framework that lets you run or debug a single test in all frameworks supported, including Silverlight. Not even Visual Studio’s built-in test runner can do this.

     

    Clarity in the User Interface

    The CodeRush Test Runner user interface delivers more clarity and less noise than any of the competing test runners, helping you see essential information quickly.

    Here’s the output of a failed test in CodeRush:

    CodeRushTestRunnerResultsLineView

    Differences between expected and actual values are highlighted automatically.

    Redundant details (e.g., “String lengths are both 28. Strings differ at index 4.”) are removed to reduce noise and enhance clarity. CodeRush is the only test runner that visually highlights differences between expected and actual results like this.

    If you right-click the debug output…

    TestRunnerMenu

    you can change the call stack display from line view to tree view, which groups methods by parenting class, like this:

    CodeRushTestRunnerResultsTreeView

    You may find this call stack view more interesting as methods are grouped by owning class.

    You can change the syntax highlight colors in the DevExpress Options dialog on the Unit Testing\Test Runner Window options page:

    OptionsUnitTesting

    Note: If you don’t see this options page, change the Level combo box from "New User” to “Advanced”.

    AdvancedLevel

     

    Compare Results with the Competition

    Compare the readability of the CodeRush Test Runner results with similar results from competing test runners.

    Competitor #1:

    TestDrivenDotNetResults2

    This competing test runner (shown above) does not ship a test result tool window for Visual Studio, so test results can only be viewed through the Output window (the CodeRush Test Runner can send output here as well if needed). Note that only the first change is shown (the letter “f” in “fox”). Subsequent differences (e.g., “dog” vs. “log”) are much harder to see and must be determined by visually scanning and comparing the results.

     

    Competitor #2:

    resharperResult2 

    This competitor makes the most important information harder to read by including redundant details (e.g., “String lengths are both 28”) in the results. Paradoxically, the essential information is rendered in black text on a gray background. Contrast for important information needs to be higher so it’s easy to see. And just like competitor #1, only the first difference is shown.

     

    Competitor #3:
    JustCodeResults2

    This competitor shows the results in a variable-width font, so the difference indicator actually points to the wrong character (e.g., the “h” in “The” – but there’s no difference there). Also, this competitor wraps the results in the window, which can make reading the call stack more challenging.

     

    Here is the result from CodeRush Test Runner again:

    CodeRushTestRunnerResultsLineView

    Which presentation do you prefer to read?

     

    In-source Test Result Icons

    CodeRush also makes it easier to work with tests in the source code, with test result icons appearing next to each test case. In the screenshot below, the first test has not run yet (TestTube), however the next two tests have run, one passing (TestPassed) and the other failing (TestFailed):

    TestMethodIcons

     

    If your hand is on the mouse, you can click the icon to bring up a test case menu, which allows you to run or debug that test.

    TestCaseMenu

     

    Test fixtures & namespaces containing unit tests have icons summarizing the run results of their contents. For example, the namespace below and the test fixture both have a red “X” (TestFailed), indicating they contain at least one test which has failed:

    TestCaseParents

     

    If you hover the mouse over one of these test fixture icons, you can see a summary of results for unit tests in this class.

    TestRunSummary

     

    If you click one of these test fixture or test namespace icons, a popup menu appears that allows you to run or debug all tests contained within.

    RunAllContainedTests

     

    If your hands are on the keyboard, don’t worry – CodeRush gives you powerful commands to run test cases without reaching for the mouse.

     

    Full Keyboard Control

    CodeRush offers full keyboard control over your test runs from inside Visual Studio. The keyboard shortcuts for running tests that ship with 10.2:

    Shortcut   Behavior
    Ctrl+T, S   Run all tests in the solution
    Ctrl+T, P   Run all tests in the active project
    Ctrl+T, F   Run all tests in the active file
    Ctrl+T, R   Run active test
    Ctrl+T, D   Debug active test
    Ctrl+T, T   Show the CodeRush Test Runner

    If you prefer the Visual Studio shortcuts, CodeRush ships an alternate collection of bindings reflecting those commands. You can change the bindings for any of these commands if you like.

     

    What’s Coming in 2011

    OK, so we just shipped 10.2, so it seems a bit crazy to tell you what’s coming in 11.1. But, you know, things get a little crazy over here at DevExpress from time to time. Our intention is to continue to maintain test runner dominance among all .NET alternatives, including Visual Studio. With that in mind, we will add support for even more testing frameworks, add more commands for controlling which test cases to run, and we’re working on improving visualization of code coverage, as well as a bigger feature we are going to save for later discussions.

  • Minority Report Meets Visual Studio

         

    One of the cool things I get to do here at DevExpress is explore new technologies to interface humans with machines, and more specifically, developers with their code. In the past you’ve seen us write code with chopsticks, super models, guitars, and our minds. With the release of Microsoft’s Kinect, we knew it wouldn’t be long before we’d be working on an interface for Visual Studio to let you write code with your hands, Minority Report style.

    SelectPreview

    Navigating, coding, declaring, refactoring, testing – you’ll do it all with your hands. As with everything else we build here at DevExpress, our intention is to craft a great user interface around this technology. An experience that's as efficient at writing code as using the keyboard and mouse. And we expect to make the source code available so you’ll be able to play with it yourself.

    Don't be surprised if you see this at a major developer conference in the very near future. Stay tuned.

  • Science of Great UI & Windows Phone 7

         

    The Windows Phone 7 release is imminent. Here are screenshots of two versions of the start page tiles:

    Originals

    When I first saw this screenshot I noticed a few variances from the guidelines presented in my Science of Great UI talk.

    One of the things I mention in my talk is that everything presented onscreen is information (everything – data, background, borders, etc.), and not all information has the same relevance. Since our eyes are attracted to great contrast, relevant information should be rendered in a higher contrast than less important information.

    When I look at the screenshots above, my eyes are primarily attracted to the large black “+” sign formed by the proximity of the top four tiles (in bright amber or blue) over the black background. The sharp edges of the borders attract my eyes. After that the bright tiles themselves attract my eyes. However the data that varies inside the tiles (presumably the important information), is rendered in a much lower contrast – white on a highly saturated light background.

    Here’s my redesign of the front page, using the guidelines from the Science of Great UI session:

    Redesign

    Here you can see I’m placing a higher emphasis on the actual data inside the tiles, and a lower emphasis on the tile background itself. Also, I’ve softened the edges of the tiles with a subtle gradient to lower their contrast against the black background. I’ve increased the size of the time – an important piece of information that is now easier to see. And since we’re showing the time, I added the day and date as well near the top. The final change was a redesign of the high-contrast button (the arrow pointing to the right).

    Here are the original (on the left) and the redesign (on the right):

    SideBySide

    What do you think?

Next page »
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.