Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Code Metrics – Class Coupling

    • 4 Comments

    SKU: Premium, Ultimate

    Versions: 2008, 2010

    Code: vstipTool0133

     

     

    As we continue looking at code metrics in Visual Studio (see vstipTool0129, “Calculating Metrics”), it’s time to look at class coupling. Class coupling also goes by the name Coupling Between Objects (CBO) as originally defined by [CK94]. Basically, class coupling is a measure of how many classes a single class uses. A high number is bad and a low number is generally good with this metric. Class coupling has been shown to be an accurate predictor of software failure and recent studies have shown that an upper-limit value of 9 is the most efficient [S2010].

     

    According to the MSDN documentation, class coupling “[m]easures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types.”

     

    The concepts of coupling and cohesion are clearly related. To keep this discussion on topic, I will not get into depth with cohesion other than to give a brief definition from [KKLS2000]:

    “Module cohesion was introduced by Yourdon and Constantine as ‘how tightly bound or related the internal elements of a module are to one another’ [YC79]. A module has a strong cohesion if it represents exactly one task […], and all its elements contribute to this single task. They describe cohesion as an attribute of design, rather than code, and an attribute that can be used to predict reusability, maintainability, and changeability.”

     

     

    Class Coupling Example

    Let’s look at class coupling in action. First, create a new console application and create a new class called Person with some properties in it then immediately calculate the code metrics:

    image

     

    Notice the class coupling is 0 since this class doesn’t use any other classes. Now create another class called PersonStuff with a method that creates an instance of Person and sets the property values. Calculate the code metrics again:

    image

     

    See how the class coupling value goes up? Also notice that, no matter how many properties we set, the class coupling value just goes up by 1 and not by some other value. Class coupling measures each class only once for this metric no matter how much it is used. In addition, can you see that DoSomething() has a 1 but the constructor, PersonStuff(), has a 0 for its value? Currently there is no code in the constructor that is using another class.

     

    What if we put code in the constructor that used another class? Here is what you get:

    image

     

    Now the constructor clearly has code that uses another class and the class coupling metric shows this fact. Again, you can see the overall class coupling for PersonStuff() is 1 and DoSomething() is also 1 to show that only one external class is being used no matter how much internal code we have that uses it.

     

    Next, let’s create another new class. I’ll call my class Blah and create some properties inside it:

    image

     

    Now consume the class in our DoSomething() method within the PersonStuff class and calculate code metrics again:

    image

     

    As you can see, the class coupling for the PersonStuff class goes up to 2 and, if we drill into the class, we can see that the DoSomething() method has the most coupling in it but the constructor still only consumes 1 class.  Using these metrics we can see the overall max number for a given class and drill down into the details on a per-member basis.

     

     

    The Magic Number

    As I mentioned with cyclomatic complexity (see vstipTool0131, “Code Metrics - Cyclomatic Complexity”), there is no limit that fits all organizations. However, [S2010] does indicate that a limit of 9 is optimal:

    “Therefore, we consider the threshold values […] as the most effective. These threshold values [for a single member] are CBO = 9[…].” (emphasis added)

     

     

    Code Analysis

    When using code analysis, the Extended Design Guideline rule set contains a maintainability area:

    image

     

    Inside the maintainability area is a rule for class coupling:

    image

     

    This rule issues a warning when the class coupling is excessive. You can learn more about the rule here:

    http://msdn.microsoft.com/en-us/library/bb397994.aspx

     

    Unfortunately, the documentation doesn’t talk about the thresholds set for this rule but I did find a description on the Code Analysis Team Blog (http://blogs.msdn.com/b/codeanalysis/archive/2007/11/15/code-metrics-as-check-in-policy.aspx): “Warning at above 80 for class and above 30 for a method”.  These seem abnormally high but at least provide an extreme upper limit. If you hit this warning then something is almost certainly wrong.

     

     

    Citations

    [CK94]

    Chidamber, S. R. & Kemerer, C. F. (1994). A Metrics Suite for Object Oriented Design (IEEE Transactions on Software Engineering, Vol. 20, No. 6). Retrieved May 14, 2011, from the University of Pittsburgh web site: http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricForOOD_ChidamberKemerer94.pdf

     

    [KKLS2000]

    Kabaili, H., Keller, R., Lustman, F., and Saint-Denis, G. (2000). Class Cohesion Revisited: An Empirical Study on Industrial Systems (Proceedings of the Workshop on Quantitative Approaches in Object-Oriented Software Engineering). Retrieved May 20, 2011, from Université de Montréal web site http://www.iro.umontreal.ca/~sahraouh/qaoose/papers/Kabaili.pdf

     

    [SK2003]

    Subramanyam, R. & Krishnan, M. S. (2003). Empirical Analysis of CK Metrics for Object-Oriented Design Complexity: Implications for Software Defects (IEEE Transactions on Software Engineering, Vol. 29, No. 4). Retrieved May 14, 2011, from University of Massachusetts Dartmouth web site http://moosehead.cis.umassd.edu/cis580/readings/OO_Design_Complexity_Metrics.pdf

     

    [S2010]

    Shatnawi, R. (2010). A Quantitative Investigation of the Acceptable Risk Levels of Object-Oriented Metrics in Open-Source Systems (IEEE Transactions on Software Engineering, Vol. 36, No. 2).

     

    [YC79]

    Edward Yourdon and Larry L. Constantine. Structured Design. Prentice Hall, Englewood Cliffs, N.J., 1979.

  • The Ultimate Visual Studio Tips and Tricks Blog

    VMDK(VMWare) to VHD Converter

    • 1 Comments

     

    Several people have asked me how to convert from VMWare to VHD format.  Here are the steps to get you going:

     

    1) Download VMDK to VHD converter free tool from http://vmtoolkit.com/files/folders/converters/entry8.aspx   I had successfully converted disks 29Gb in size

     

    2) “Prepare” your VMWare image by following steps in  http://searchservervirtualization.techtarget.com/tip/0,289483,sid94_gci1239063,00.html or  http://www.jaylee.org/post/2008/10/How-to-convert-a-big-VMWare-VMDK-into-an-Hyper-V-VHD.aspx

    3) Install Virtual Server 2005 (Std/Ent, R2 or not – but if R2, select Enterprise and install the one with SP1 – it’s all free and on the web…)

     

    4) Make sure your VMWare image contains at least one IDE drive before final shutdown (VS2005 will need it). Take note of drives inside VM (C,D,E…)

     

    5) Convert each one VMW files into VHD

     

    6) Attach “system” disk as a main disk in new Virtual Server image

     

     

     

    NOTE:  You could roll out Virtual Machine Manager and use the “conversion” feature in one step instead of six.

     

    Thanks to Oleg Kofman from MS who provided me this info...

  • The Ultimate Visual Studio Tips and Tricks Blog

    Vista Activation

    • 1 Comments

    If you haven't come across this yet you will at some point.  There is a known issue with Vista and activation.  You can get the details for common errors at this KB article, but the steps are pretty straightforward:

    1) Go to Control Panel...System and Maintainence...System

    2) Scroll to the bottom of the screen

    3) Click on Change Product Key

    4) Type in your key

    5) Click Next and follow the rest of the steps in the wizard

     

    That's it!   Soon you'll be enjoying Vista and be activated :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Start Debugging vs. Start Without Debugging

    • 7 Comments

    Keyboard:  F5; CTRL + F5
    Menu:  Debug -> Start Debugging; Debug -> Start Without Debugging
    Command:  Debug.Start; Debug.StartWithoutDebugging
    Versions:  2008,2010
    Published:  11/1/2010
    Code:  vstipDebug0037

     

    While researching this one I came across a LOT of misinformation concerning what is actually happening here.  There seems to be a great deal of confusion as to what is actually happening when you use Start Debugging (F5) versus Start Without Debugging (CTRL + F5):

    image

     

     

     

    Starting With Debugging

    Let's start with the basics:  When you press F5 (Start Debugging) in Visual Studio it launches your application, attaches the Debugger, and let's you do all the "normal" things you would expect: 

    image

     

    According to the documentation (http://msdn.microsoft.com/en-us/library/k0k771bt(v=VS.100).aspx) here is what the Debugger does:

    "The Visual Studio debugger is a powerful tool that allows you to observe the run-time behavior of your program and locate logic errors. The debugger works with all Visual Studio programming languages and their associated libraries. With the debugger, you can break, or suspend, execution of your program to examine your code, evaluate and edit variables in your program, view registers, see the instructions created from your source code, and view the memory space used by your application."

     

    The Debugger:  Release Builds

    One popular misconception is the Debugger doesn't come into play for Release builds.  This isn't true.  Set a Breakpoint in some code for a Release build and then press F5 to see if is stops there:

    image

     

     

    Of course it does!  The Debugger is attached!  That is what is happening.  Now, there are some things that aren't happening as well.  For example, you can't use the System.Diagnostics.Debug class methods to send messages to the Output window since the compiler strips them out for Release builds:

    image

     

     

     

    Start Without Debugging

    This is exactly what it sounds like.  It starts the application WITHOUT THE DEBUGGER ATTACHED.  That's it!  Nothing else.  It just doesn't attach the Debugger.  Otherwise everything else is the same.  So, the practical implications of this are obvious:  Without the Debugger attached when the application runs it will not hit Breakpoints, emit Debug messages, etc.  So now let's deal with the biggest myth about Start Without Debugging.

     

    Myth:  Start Without Debugging Creates a Release Build

    Nope.  It uses the build you are currently on.  So if you are using a Debug build and you press CTRL + F5 then it will run that Debug build.  The easiest way to test this is to use conditional compilation to see if you are using a Debug build:

    image

     

    In this example, the Console statement will run but the Debug statement will NOT run because the Debugger is not attached.  So I will get this output:

    image

     

    And, if I attach the debugger after pressing CTRL + F5, to this process:

    image

     

    Then this is what I get:

    image

    image

     

    The Debug messages haven't been stripped out because I'm using a Debug build of the application.

     

     

     

    Finally

    Okay, so the obvious question is "Why?".  I mean, why would they give us this option?  Well the most obvious answer is so we can run the application without having to hassle with disabling breakpoints, etc. to do a quick "Smoke Test" and see if it runs.  There may be other reasons you have for wanting to run without the Debugger attached as well.  So now you have a better idea of the difference between Start With and Start Without Debugging.  Go forth and debug away!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Go To a Line Number

    • 10 Comments

    Keyboard:  CTRL + G
    Menu:  Edit -> Go To
    Command:  Edit.GoTo
    Versions:  2008,2010
    Published:  3/8/2010
    Code:  vstipEdit0026

     

    You can go to any line number in your code by simply pressing CTRL + G.  You will get this dialog:

    image

     

    Just type in your desired line number and click OK.  The Cursor will move to the line number you typed.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Using Solution Folders

    • 15 Comments

    Menu:  Project -> Add New Solution Folder; [Right-Click Solution] -> Add -> New Solution Folder
    Command:  Project.AddNewSolutionFolder
    Versions:  2008,2010
    Published:  3/27/2010
    Code:  vstipProj0009

     

    Did you know there are special folders to help you organize large solutions?  There is!  They are called, appropriately enough, Solution Folders.  To create one just Right-Click on your solution (or go to Project -> Add New Solution Folder) and you will see this in Solution Explorer:

    image

     

    Simply give the folder a name and you are good to go.  But so what?  I mean, what can you actually DO with these things?  Here is a list of stuff you can do:

    • Move or add projects to them. Solution Folders can be nested to create greater organizational structure.

    • Add, delete, or rename Solution Folders at any time, if the organizational requirements of the solution change.

    • Unload all projects in a Solution Folder to make them temporarily unavailable for building.

    • Collapse or hide entire Solution Folders so that you can work more easily in Solution Explorer. Hidden projects are built when you build the solution. 

    • Build or rebuild all the projects. The projects are built in the order specified by the project dependencies.

    SPECIAL NOTE: 

    Solution Folders are an organizational tool in Solution Explorer; corresponding Windows folders are not created.  Microsoft recommends that you organize your projects on disk in the same way that you organize them in the solution.  But that is your call :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Calculating Mean, Median and Mode with SQL Server

    • 2 Comments

     

     

    I LOVE statistics and was recently asked about calculating the mean, median, and mode using SQL Server.  I found this great article by George Mastros that shows you how:

    http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/calculating-mean-median-and-mode-with-sq

  • The Ultimate Visual Studio Tips and Tricks Blog

    Death and Repudiation License

    • 0 Comments

    I ran into this the other day (http://github.com/indeyets/syck/blob/master/COPYING) and thought I would share

    ==============================================================================================================

    Copyright (c) 2003 why the lucky stiff

     

    [BSD license text deleted to save space]

     

    D&R (Death and Repudiation) License

    ===================================

    This software may not be used directly by any living being. ANY use of this

    software (even perfectly legitimate and non-commercial uses) until after death

    is explicitly restricted. Any living being using (or attempting to use) this software

    will be punished to the fullest extent of the law.

    For your protection, corpses will not be punished. We respectfully request

    that you submit your uses (revisions, uses, distributions, uses, etc.) to

    your children, who may vicariously perform these uses on your behalf. If

    you use this software and you are found to be not dead, you will be punished

    to the fullest extent of the law.

    If you are found to be a ghost or angel, you will be punished to the fullest

    extent of the law.

    After your following the terms of this license, the author has vowed to repudiate

    your claim, meaning that the validity of this contract will no longer be recognized.

    This license will be unexpectedly revoked (at a time which is designated to be

    most inconvenient) and involved heirs will be punished to the fullest extent

    of the law.

    Furthermore, if any parties (related or non-related) escape the punishments

    outlined herein, they will be severely punished to the fullest extent of a new

    revised law that (1) expands the statement "fullest extent of the law" to encompass

    an infinite duration of infinite punishments and (2) exacts said punishments

    upon all parties (related or non-related).

    ==============================================================================================================

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013: Turn Off the Uppercase Menu

    • 27 Comments

    NOTE: This is an older feature. I’ve updated the information for VS2013.

     

    This is one change to Visual Studio that I’m not a fan of and I still continue to see a ton of posts on this change so thought I would share here as well. 

     

    I always try to give credit where credit is due and I believe the earliest mention of this fix is by Richard Banks in his post 6\1\2012 here:  http://www.richard-banks.org/2012/06/how-to-prevent-visual-studio-2012-all.html 

     

     

     

    Mixed Case is Your Friend

    Okay so you really, really don’t like the Uppercase menu in VS2012 because you feel like it is shouting at you:

    5-16-2012 7-50-41 PM

     

     

    You would rather go back to mixed case for your menu:

    5-16-2012 7-43-08 PM

     

    Not a problem! Below are ways you can fix this feature in VS2013.

     

     

     

    Manual Registry Change

    WARNING:  Making changes to the registry can cause unexpected results so do any changes at your own risk!

    1. Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\General\
      (For Windows 8 Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWinExpress\12.0\General)
      (For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\12.0\General)

    2. Create a new DWORD value called SuppressUppercaseConversion set to 1
      image

    3. Restart Visual Studio and you should see the change

    NOTE: Watch your spelling if you are typing this manually.

     

     

    PowerShell

    If you like to “simplify” this a bit you can use PowerShell to run a nice script to make this happen.  However, if you haven’t used PowerShell before this may not be faster for you.

    1. Go to the Start button or (Start Screen in Windows 8) and type powershell then select the Windows PowerShell Entry:
      image

      image

    2. In the PowerShell window copy the script below and paste it in then press Enter:

      Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\12.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

      image 

    3. Restart Visual Studio and you are good to go.
  • The Ultimate Visual Studio Tips and Tricks Blog

    Automatically Check for Updates to Visual Studio 11

    • 2 Comments

    There is an update to Visual Studio 11 that came out in early April that is available.  You can find the details here:

    http://support.microsoft.com/kb/2677574

     

    If you haven’t been playing with Visual Studio 11 yet, I strongly encourage you to get it today.  You can download it from here:

    http://www.microsoft.com/visualstudio/11/en-us/downloads

     

    When you DO have it one of the first things you should do is turn on automatic checking for updates to extensions found at Tools | Options | Environment | Extension Manager:

    image

     

    Not only will this make sure you are notified about the latest and greatest version of your favorite extensions but it will also enable notification of updates to Visual Studio!  We are now pushing updates to the IDE as extension-like elements. When you enable this feature, every time you start Visual Studio you will see a message whenever there is an update to Visual Studio that looks like this:

    image

     

    You can click on the bubble or, to get to updates manually, go to Tools | Options | Extension Manager | Updates | Product Updates:

    image

     

    You will see the update(s) available and can then click on the Update button for the items you want. In this case, when I clicked on update for the April 2012 fix for VS11, I received the download dialog:

    image

     

    Selecting Run began the installation process:

    image

     

    It finished smoothly and Visual Studio was updated easily.

     

    Go out there and update your version of Visual Studio 11 if you haven’t done it already so you can get the most up-to-date goodies!

Page 4 of 135 (1,345 items) «23456»