Clone Detective

I read an InfoWorld article by Paul Krill entitled “Cloned Code Finder Offered For Visual Studio”. It announced a web based product from Microsoft called the Clone Detective. This is a tool that works with Visual Studio. If analyzes C# source code, and locates duplicate code. It has been released under the Apache 2.0 license. That means the software is free to use. It also means that you can use it in other open source projects as well as in proprietary projects.

There is a plan to release future Clone Detective versions that work with other popular languages such as C++ and Visual Basic. There is also a plan to add “fuzzy clone detection” to the tool in the future. This will allow you to locate code that is not an exact cut and paste, but close to it.

It is too bad that this product only analyzes C# right now. Almost all the code on my current project is written in C++. It is a huge legacy project around 15 years old. Some of the code was well thought out and designed well. However there are a lot of places where changes were hacked in. So I know we have a load of code that was cut and pasted. It would be nice to refactor a lot of that code to make a cleaner code base. It is possible to do this manually. However it would be nice to use a tool to analyze the code and at least find the places where we have duplicate code.

I might write up some dummy projects using C# just to give Clone Detective a spin. Of course I will use poor practices while coding up this sample app. And I will cut and paste galore. However I will make a few changes in the code copies and see how well the detective can, well, detect.

StyleCop

Microsoft has released StyleCop 4.3 to the developers. StyleCop is a source code analysis tool for the C# programming language. It has been used at Microsoft internally for many years. The tool enforces the best practices in source code. It is similar to another tool from Microsoft called FxCop. However StyleCop works on source code, while FxCop works on binary files.

StyleCop does not focus on the design of code. Instead it focuses on the layout, readability, and documentation in the code. The overall goal is to produce code that others can easily read. The rules which the tool enforces cannot be easily configured. The tool implements around 200 best practices in the code. Some of these are location of brackets, spacing, ordering of elements, and variable naming. The tool can be run within the Visual Studio IDE. It can also be integrated with builds.

There was a lot of interesting feedback to the release of StyleCop. Many people including myself were interested in a tool like this for other programming languages. There is also a great desire to disable and configure the rules enforced by the tool. Users have commented that some of the rules are just plain silly. The VS Law program performs a similar function for Visual Basic code. Some developers worried that this tool would be used by control freaks for evil purposes.

Unfortunately we code almost exclusively in C++ on my current project. So StyleCop would not be of much use. However we try to cover best practices when doing peer reviews. It would be nice it we could delegate that task to a tool such as StyleCop. Come on Microsoft. Hook us up.

Visual Studio Uninstall

A system administrator cloned a development machine for me, and provided me with a virtual machine to use for development. I got some code that I needed to change. Then I figured up Visual Studio 2005. The C++ compiler immediately complained that I needed to repair the Visual Studio installation. So I got the install media and attempted a repair. The repair warned that I might not have enough disk space for the install. Then it kept requiring a reboot. However when I rebooted the install did not pick back up. I went through the repair a couple more times until I gave up.

At this point I decided to uninstall Visual Studio 2005 and try again. So I used Windows Add/Remove programs. I selected Visual Studio 2005 and chose to remove it. This removal took quite a long time. At the end of the install I got a horrible warning message. Microsoft wanted me to manually go in, find out if any listed components were present on my system, then remove them one at a time. What the heck is this? The install program was smart enough to know what items to install. Can’t it also uninstall them without me prodding it for every component? Bad form Microsoft.

Just so you don’t think I am overreacting, take a look at the warning message for yourself:

Next Step: Uninstall additional components

Additional components might have been installed on your computer by Visual Studio during setup.
These components must be manually uninstalled using Add or Remove Programs in the order listed below.

Note: Uninstalling these components might affect other applications you have installed that rely on these components.

The following components might have been installed with Visual Studio:

Microsoft MSDN 2005 Express Edition
Microsoft Visual Studio 2005 Tools for Office Runtime Language Pack
Microsoft Visual Studio 2005 Tools for Office Runtime
Microsoft Device Emulator version 1.0
Microsoft .NET Compact Framework 1.0
Microsoft .NET Compact Framework 2.0
Microsoft SQL Mobile 2005 Development Tools
Microsoft Visual J# 2.0 Redistributable Package
Microsoft Visual J# 2.0 Redistributable Language Pack
Microsoft Document Explorer 2005
Microsoft Document Explorer 2005 Language Pack
Microsoft Data Access Components 2.8 SP1 (Windows 2000 only)
The following components might have been installed with SQL Server Express, and need to be removed in the order listed below:
Note: Uninstall of the SQL Express instances will leave behind the user-created databases, which can then be re-attached to the new instance.

Microsoft SQL Server 2005 Express CTP
Microsoft SQL Server 2005 Express Tools CTP
Microsoft SQL Server Setup Support Files
Microsoft SQL Native Client
The following components must be uninstalled last:


MSXML 6.0 Parser and SDK (only on 32bit)
MSXML 6.0 Parser and SDK x64 (Only on 64bit)
Microsoft .NET Framework 2.0 Language Pack
Microsoft .NET Framework 2.0

Midori Operating System

I recently read an article online at Software Development Times. It was about a new operating system from Microsoft called Midori. The unusual thing about this operating system is that it is not a new version of Windows. It is instead based upon another research operating system from Microsoft called Singularity. Midori is meant to coexist with old Windows applications. However it does get rid of dynamic link libraries. It also builds Service Oriented Architecture into the runtime. The API is object oriented. Application created for the new operating system will be written in .NET languages. This project falls under the Microsoft Research division.

Since the Midori Operating System is based on Singularity, I thought I would mention a bit about it. Singularity is another operating system from Microsoft Research that was released in 2007. It is a microkernel operating system. It has some unique characteristics. Applications run in one process (address space). The kernel, device drivers, and application are all written in managed code. The goal is for the operating system to be highly dependable. Low level interrupt code is written in a combination of assembly and C programming languages. The hardware abstraction layer (HAL) is written in C++.

The Midori Operating System is being written with the Bartok compiler. The Bartok compiler is yet another project out of Microsoft Research. It is intended for writing efficient code needed to write operating systems. The compiler itself is written in C#. This compiler was also used to write a lot of the Singularity operating system. This operating system allows an application running in it to choose a version of components (such as garbage collection) at run time.

Obviously there are some very interesting projects coming out of Microsoft Research. I wonder if any of these will reach a production status on par with something like Microsoft Visual Studio.