Tuesday, February 19, 2013

Refactoring with Telerik JustCode (Part 2)


In part one of this series we talked about the basics, like downloading JustCode, installing it and going through the basic settings using the “Getting Started Wizard”.

Just Code Options

From within Visual Studio go to JustCode=>Options… The JustCode options window will show up.
As you can see, the options are divided into the following sections:
  • General
  • Navigation
  • Refactoring
  • Visual Features*
  • Code Analysis*
  • Code Style*
  • Code Cleaning
  • Code Templates*
  • ToDo Navigator
  • Keyboard Shortcuts
  • Cloud Sync*
  • Unit Testing
  • Options Sharing
All entries marked with a “*” have subentries, those can be expanded by clicking the small grey arrow on the left.
Tip: If you mess-up your settings, under the “General” tab you can find the “Reset Settings” button to load the defaults.

General Settings

Import Formatting Options from Visual Studio

If you have pre-defined your code formatting settings in Visual Studio (which can be done in the VS Tools=>Options dialog) you can import those settings and align the JustCode-CodeFormatter with your personal formatting options.

Generated Members

During your coding sessions, you will type eventually members into your code, that don’t exist at the time of typing. JustCode offers you options to create method-stubs or members for your classes. The first option “Put NotImplementedException in generated code” inserts the exception code into the method of the generated stub, to ensure that you are not able to execute the method, until it was implemented.
The “Add auto-implemented properties when adding stubs for required members where possible” adds auto-implemented properties without backing fields.

Quick Fixes

To navigate directly to generated/fixed code after a “quick-fix”, you can set the “Navigate to generated code” option.

Typing Assistance

Helps with common typing tasks, like closing braces, moving semicolon to the end of the line.
Tip: If you see some strange behavior like two brackets have been added instead of one bracket at the end of your expression, it could be possible that the JustCode settings collide with the settings of the “Productivity Power Tools” extension for VS.

Enable verbose logging

This adds additional information’s to the JustCode-logfile if activated.
Tip: Changed settings will be marked as “dirty” when they have been changed. This will be indicated by an asterisk behind the option, that was changed (also it will be indicated for the whole category on the left):

Proxy settings

JustCode will use the default proxy to check for updates.


The navigation settings explain themselves pretty good. One thing to point out is the “Automatic decompilation of metadata members”, that will not only show the metadata of the members, but the full code de-compiled at your fingertips. That’s great for tracking down bugs.


This are mainly security options to avoid problems with refactorings that affect multiple files. It’s better to confirm such modifications if the modifications affect multiple files. For example the “Open all files with changes” option, will enable you to undo all changes for the files after the changes have been applied. “Show help popup” will show a useful popup that explains, how to apply the changes, or how to cancel the current refactoring. “Show name suggestions for Introduce… refactorings”, will come up with suggestions for introduce field or variables refactorings based on the JustCode coding styles.

Visual Features

Disable Visual Studio smart tags

You all know the smart tags Visual Studio shows by pressing “CTRL” + “.” – those little office like pop-ups, indicated by a fine underline of the current code. Functions like “Implement Interface” are offered via smart tags. This option makes it possible to disable those.

Color identifiers

This adds another level of syntax-highlighting to Visual Studio.

Show info stripe bar

This is the additional bar on the right side of the Visual Studio editor window (the code window) that indicates warnings or errors found by JustCode through code analysis. Errors and warnings are indicated by different colors showing small markers at the current position where the error/warning was found by JustCode. The markers (stripes) look like little bars, that are stacked within the stripe bar. By clicking the stripes you will be navigated to the according line of code in the code editor. JustCode offers then quick-fixes for the errors/warnings indicated.
info stripebar

Show underlinings for dead code

Really nice feature to show you parts of your source-code that is “dead”, not used anymore.

Structural Highlighting

One of the features that helps you, to identify, for example structures of complicated if-statements very easily. You can see where one outer block starts and ends, where inner blocks start and end, and how many levels deep those statements are nested.
structural highlighting

Visual Aid

The visual aid in JustCode is something like extended smart tags for Visual Studio packed into a menu. You place the cursor over a code element like a variable for example, and you get a small stripe underneath the selected code element. By hovering over the small stripe with your mouse or by pressing “CTRL” + “`” (depending on your keyboard layout) you can open the Visual Aid menu.
The Visual Aid menu shows you four main menu entries, where you can reach the current operations for the selected piece of code. You can use your mouse to navigate the menu, or simply (which I prefer) using the arrow keys.
The options allow you to adjust the size of the menu header, collapse additional commands (to keep the menu shorter) and to view keyboard shortcuts for the commands. You can also disable the Visual Aid tag if you wish. To get a more compact view of the Visual Aid menu, you can choose to show just the first letters of the sections like Fix “F”, Code “C” and so on.
Additionally you can choose what happens in “Mouse Mode” and “Keyboard Mode”

Code analysis

Code analysis gives you the possibility to analyze your code for “errors” that are not standard syntax errors, like forgetting a semicolon, or a closing brace. The analysis options check also for logical errors that are not visible at first sight like empty statements, unused local variables, or variables that have an assignment, but are never used. I like to call it an “analytical cleanup” of your code. Also think about things like class-names that don’t match file-names in your project, which is unclean coding. Useless using directives are also indicated, as naming conventions inconsistencies.
You can set the level for each of the “Problems” that can be identified by clicking the icons near the problem description. There are three levels available:
  • Error
  • Warning
  • Don’t show
This gives you a good level of customization, to adjust code analysis for your individual needs. Quick and easy.
This can be done for a bunch of languages and additionally for CSS, XAML and XML.


Hints are like additional little helpers to make your life much easier. Like for example showing a color-choosing dialog in XAML, when you want to set a background-color. Or hairy things like “join nested if statement” that enables you to make on if statement out of two statements that are nested, which is a big plus for the readability of your code.
You can read more about Hints here:
Quick Hints
Hints are available currently for
  • C#
  • CSS
  • JavaScript
  • Less
  • VB.NET
  • XAML Markup

Code Style

Common => File Header Text

This enables you to create templates for file-headers, that can be inserted by the “Introduce Header” function by pressing “CTRL-R, CTRL-H”. It comes in very handy, for example after you coded for a while, and you want to insert a consistent header into all the files you have created. Devs tend to be lazy and to automate things- that’s exactly what happens here. Nobody really likes to write documentation.
You can insert anything you need, like copyright, company information’s and such. Define it ones, and re-use it. You have additional “Tags” like variables in you can insert into your header-template like
  • The current date
  • The logged-in user as author
  • The project name
  • And the file name
You can read more about this feature here:
Introduce Header
For every single language you can set the code-cleaning options separately. I will examine some of the options regarding C# with you. I would suggest you take your time, maybe with your team, to set the coding-rules here, you want to use, and make the configuration available on the cloud, so that everybody uses the same settings. Going trough each of this options will be much easier if you already have coding-guidelines, if not it is time to define some.
Beneath the C# node, you will find the following categories:
  • General
  • Indentation
  • Spacing
  • Blank Lines
  • Ordering
  • Brace Positions
  • Wrapping
  • Using directives
  • Naming Conventions
If you want to read more about coding-guidelines, here is a very nice project on codeplex “Coding Guidelines” that can give you  a good overview, on how to structure your coding-guidelines. And remember this is not a standard that must be followed. This are only suggestions.


Choose if you want to insert documentation for generated members (which I really like) or if you want to adjust lines on autoformat, or adjust spaces on auto-formatting code.
Another option I prefer is the “Use ‘this’ qualifier for field or member access” which enhances code-readability.
You can decide how “var” is being used for members introduced by JustCode.
You can read more about this option here:
Code Style

Block usage

This section is let’s you define, how to use block elements like if-statements, for-statements and so on.
You have always three options for each entry:
  • Always
  • Always except for single-line statements
  • Only if necessary


Indentation let’s you choose how you want to handle indentation of common statements like switch-case, or if you like to indent multi-line statements and much more. I choose to keep all of them active, except for goto-labels which I generally don’t use.
A very nice feature of the options window is, that you can see a sample for each and every option shown in the ! “Indentation” section. This helps a ton to make the right decisions.
You can explore the sections “Spacing”, “New Lines” and “Blank lines” by yourself, because I would sit here for a week, explaining every single option possible. Through the samples section in the lower portion of the window it should be very easy to understand each one of the single options.


This is another powerful instrument to make your code more readable and where you have the possibility to apply a standard for your source-files. Developers can code freely and apply the formatting rules later with the help of JustCode in a fraction of a second. No bad vibes anymore, because of moving fields properties and other elements by hand. Order the different elements also alphabetically and by access modifiers, or static and non-static types. You got a plethora of options here to adjust the placement of the code-elements according to your needs.


Set all required options for brace positions in your code. This includes various notation formats coming from C++ and/or Perl. This is just a question of taste and religion.
Here is a nice discussion on StackOverflow, why this or that style is better:
Opening Curly Barcket (Brace) position on code
The other good thing is, that you can see again, how your code will look like after applying those rules directly in the lower part of the options window.

Using Directives

In this section you specify the using directives that should always be imported and never removed. Additionally you can specify here, how the using directives should be ordered.

Naming conventions

For me, one of the most important settings regarding code-styles and code-formatting. Here you can setup, which style, out of the following styles should be used, to name members, Exception Types, Events etc. :
  • PascalCase
  • camelCase
  • camel_Underscore
  • Pascal_Underscore
  • Sentence_Underscore
  • lower_underscore
  • Disabled
You can even set allowed acronyms, longer than two characters to be excluded by the naming conventions. Those will not be re-formatted then.
Yeah, plenty of options that are worth to be examined and set for your team, or yourself. Do it once and enjoy later.

Code cleaning

For code-cleaning you can define different profiles. You choose one specific profile to be set as the default profile. You can set the code-cleaning options for a broad set of programming languages and markup languages:
  • C#
  • VB.NET
  • JavaScript
  • HTML
  • XAML Markup
  • XML
  • Razor
  • CSS
  • Less
The options are quite self-explanatory. For me the most important settings to activate are:
  • Format code
  • Reorder and Format code
  • Arrange “this” qualifier
  • Introduce File Header Text
  • Move types to separate files
  • Remove unused variables
Adjust those settings according to your needs, create different profiles if needed and think about the productivity boost of this options.

Code Templates

Writing the same code over and over again – boring and time consuming. Visual Studio comes with a handy feature to define your own code templates. Because the notation is complicated and time consuming, there is a plethora of tools out there in the wild to work with code-templates.
JustCode offers you an easy way to add new code templates and how to handle and activate code templates. A great feature is, that you don’t have to browse anymore through your templates by using the acronyms directly from the code-editor within Visual Studio.


You can set the options here, on how to expand the acronyms:
  • Space
  • Shift+Space
  • Tab (my preference)
The other three options are:
  • Enable code templates (use them or not)
  • Show suggestions in code templates (easier to find)
  • Show code templates in the Visual Aid menu (my preference)
You can define code templates for the following languages:
  • C#
  • JavaScript
  • VB.NET
You can find an excellent article on how to use and configure code templates by Chris Eargle here:
JustCode Code Templates

ToDo Navigator

The ToDo Navigator is a separate window offered by JustCode that enables you to browse your ToDo comments or strings easily from Visual Studio. You can add different keywords that will be recognized as ToDo comments and organize your work with this simple tool.
You can add new entries, clone existing entries and you can edit the patterns (regular expressions) that will extract your ToDo entries from your code.

Keyboard Shortcuts

This section is quite self-explanatory, too. You can choose from pre-defined profiles which include:
  • JustCode Visual Studio (my preference)
  • JustCode
  • R# IDEA
  • R# Visual Studio
You can preview the shortcuts before applying the shortcut profiles. Choose the one the fits best for you.

Cloud Sync


Syncing your settings to the cloud is quite easy. You just login with your Telerik account data, and press “Upload JustCode Settings”. To download your settings you simply press “Download JustCode Settings” – that’s it.
You can also sync your Visual Studio settings to the cloud. Just think of a fresh Visual Studio installation you have to do after a crash of your system or because you have a brand new developer machine you need to setup all your software again. This will help, for sure.

Cloud Backup Settings

You can even create backups from the settings you pushed to the cloud. Just enter a name for your backup and click on “Create”. You will see a new entry in the backup list, with the name you defined before, containing also a revision number and a JustCode version number. For the Visual Studio settings backup you will se the name you defined before, the Visual Studio Version and the Visual Studio edition (like Ultimate).

Unit Testing

You can configure, if JustCode should create Shadow-copies of the assemblies being tested, and you can choose your preferred browser to execute JavaScript tests.

Options Sharing

You can share your options with your team-members by creating a new options file, that will be located in the same folder as your current solution. The naming schema for the file is [YOURSOLUTIONANME].jcsettings.xml. These are solution wide settings, managed for a specific solution.
Working through the set of options available for JustCode should give you a brief overview of the feature-set offered by JustCode.
In the next part of this series, I will show you JustCode in action.

No comments:

Post a Comment