Simplify Your Code

DependenciesThe rise of package managers like nuget and npm have made taking on external dependencies into your project easier.  Because of this ease, it seems more developers are often adding external dependencies to their project without much thought on the complexity they may be adding.  I suggest you can simplify your code by limiting external dependencies.


Some frameworks are going to be the foundation to parts of your application.  ASP.NET MVC for example, could be the base framework for your UI.   However, it should not be the foundation of your application.  You should view it as the HTTP interface to your application.  Robert “Uncle Bob” Martin has a talk Architecture: The Lost Years which addresses this point.    Developers have been using MVC frameworks as top level architecture which represent the entire application rather than the delivery mechanism.


In recent years and the rise of pushing more to the client side, the front-end development space is full of SomeLibrary.js.

Take Durandal as an example for developing SPA applications.  It is built on top of jQuery, Knockout, RequireJS.  In order to developer a SPA app with Durandal, you are at a minimum taking on 4 dependencies.  Odds are very good you will be adding more dependencies such as Bootstrap, Breeze, Moment, etc.   I’m a fan of Durandal and Rob Eisenberg, which is why I’m really excited to see Aurelia.

You may be saying to yourself: “Who cares!  These are all popular and mature open source libraries!”.  Yes they are, but that doesn’t mean they are bug-free and simple.  They may also move at a pace that is quicker than your own release cycle which can lead to you constantly trying to stay current.

Any external dependency you rely on is now your code and your problem.

How do you explain to a customer or boss of a when you discover a bug that is causing an issue your application?  Do you think they care that you didn’t write it?  It’s your problem.

What Smells?

Code SmellAutomapper is a good example of a popular dependency that can hide a code smell.  If you have a lot of DTO’s that you are mapping through different layers, I can see why you would want to use automapper.  It would be really annoying to have to write all the simple mapping code from one DTO to another.  Hiding smells by using automapper isn’t necessairly the answer.  I would rather the question be asked “Why are we mapping X -> Y -> Z?  Do we really need 3 DTO’s before getting serialized to the client?”

Limiting your external dependencies can simplify your code.  I’m not saying to ditch all your dependencies and to never use anything external.  What I’m saying is be very diligent and understand the dependency, how it works and the problem it solves.

Do you really have the problem that dependency solves?  If so, why do you have that problem?

Code Reviews with Visual Studio

Code Reviews with Visual Studio


Code reviews are one of the most important development practices to improves quality, reduces bugs, and knowledge sharing.   Here is how to perform Code Reviews with Visual Studio.

In order to use code reviews with Visual Studio, you must be using TFVS (Team Foundation Version Control) within Visual Studio Online or Team Foundation

Request Code Review

Before you commit your changes, in the team explorer go to the My Work section.  Create your code review request by specifying the reviewer (who you want to perform the code review), title, area path, and description.

Code Reviews with Visual Studio


Code Reviews with Visual Studio


After submitting the code review request, you can suspend your current work while you wait for feedback from the code reviewer.  This allows you to begin work on another product backlog item.

Code Reviews with Visual Studio


Perform Code Review

Once a code review request has been sent to you, you can see it from the My Work section.

Code Reviews with Visual Studio


Opening the code review will show you the files modified so you can review with the standard diff view.  You can add comments to each file change to let the author know of any suggested changes.

Code Reviews with Visual Studio


Resume Work and Review Feedback

Once your code has been reviewed, you can resume your suspended work and view the feedback from the code reviewer.

Code Reviews with Visual Studio


Code Reviews with Visual Studio


Get Notified!

Once you start using the above workflow, you may want to get notified via email when someone sends you a code review request.  To do so from Visual Studio, in the Team Explorer access the Settings section.

Code Reviews with Visual Studio


This will open up Visual Studio online in your browser where you can manage your basic alerts.

Code Reviews with Visual Studio




Add a build number to your Assembly Version


Including the build number in your assembly version number can be a very useful feature.  Using reflection you can retrieve you assembly version number and display it appropriately in your app. Here is how to add a build number to your Assembly Version using TeamCity continuous integration server.

AssemblyInfo Patcher

TeamCity is a continuous integration server developed by JetBrains.  If you are looking at trying a new build server, I highly recommend giving it a try.   It should take no longer than a hour or two to install, configure, and build your project.

There is a built-in build feature that allows you to modify the AssemblyInfo.cs during the build process.  This feature works by scanning for all AssemblyInfo files (.cs, .vb, .cpp, .fs) in their usual file locations and replaces the AssemblyVersion, AssemblyFileVersion and AssemblyInformationVersion attributes with the values you define.

 Add Build Feature

Under your build configuration settings, add a new Build Feature.


Select the AssemblyInfo patcher.  Here you will be able to specify the version format by using parameters or static text.  In my example below, I’m including the %build.counter% parameter in the version format.



That’s it!  After the build is complete, the assembly outputted now contains the file version with build number.