First look at NDepend

Last night, I spent a good amount of time with NDepend on one of my largest projects. I have seen NDepend before, but never used it myself. These are my thoughts on using it, and hopefully the first of many posts about how it has made my projects better. How to get started? The first step was selecting all the assemblies to analyze. This actually wasn’t as easy as I thought, but it was really due to my project setup and not NDepend. »

Find All References to a DLL, in Powershell

Visual Studio confuses me, and it is slow. I wanted to find all the assemblies/projects that contained references to System.Web.Mvc. Instead of loading up Visual Studio, I just did this. gci -recurse -filter "*.csproj" | ?{ select-string "System.Web.Mvc" -path $_ } Faster than loading Visual Studio, I promise. »

NHibernate CodeCamp Talk - Source Code

I have published the source of my Code Camp talk here. Check it out and post any questions. Thanks to everyone who showed up for the NHibernate talk. It went really well and everyone had tons of great questions. Feel free to post feedback here, both positive and negative, so the next time I give this talk, it will be even better. For those of you that just want a little more guidance on NHibernate, here are some good links: NH Forge NHibernate Documentation Fluent NHibernate S#arp Architecture NHibernate best practices Also, thanks to the coordinators of Richmond CC. »

Interesting SQL Server Mirroring Problem

I have been trying to narrow down a SQL Server connection timeout problem, that only occurs when a database is mirrored. I have yet to be able to really figure out the cause, but here is the code that describes the problem. [TestFixture] public class SqlMirroringTests { const string connectionString = "Data Source=some_server;Initial Catalog=some_db; User ID=*****;Password=*****;"; private static Random rand = new Random(); private ArrayList times = ArrayList.Synchronized(new ArrayList()); private ArrayList erroredTimes = ArrayList.Synchronized(new ArrayList()); private void DbScenario(int identifier) { var sleepTime = Random(); WriteInfo(identifier, "Sleeping " + sleepTime + "ms"); Thread.Sleep(sleepTime); using (var conn = new SqlConnection(connectionString)) { var stopWatch = new Stopwatch(); stopWatch.Start(); bool isErrored = false; try { conn.Open(); } catch(Exception e) { Console.WriteLine(e); isErrored = true; throw e; } finally { var timespan = stopWatch.Elapsed; WriteInfo(identifier, "Open time: " + timespan); times.Add(timespan); if (isErrored) { erroredTimes.Add(timespan); } } //We have to actually query for something to get the error, and it needs to be a decent chunk of data var command = conn.CreateCommand(); command.CommandText = "select * from your_table_name"; command.ExecuteReader(); conn.Close(); } WriteInfo(identifier, "DONE"); } [Test] public void SlamDatabase() { var exceptions = new List<exception>(); var action = new Action<int>(DbScenario); var results = Enumerable.Range(0, 250) .Select(i => action.BeginInvoke(i, null, null)) .ToList(); results.ForEach(ar => { try { action.EndInvoke(ar); } catch (Exception e) { exceptions.Add(e); } }); Console.WriteLine("Number of Exceptions: " + exceptions.Count); WriteTimeResults("All times - ", times); WriteTimeResults("Error times - ", erroredTimes); } private void WriteTimeResults(string prefix, ArrayList results) { Console.WriteLine(prefix + "Max Open time: " + results.Cast<timespan>().Max()); Console.WriteLine(prefix + "Avg Open time: " + results.Cast<timespan>().Average(t => t.TotalSeconds)); } private int Random() { return rand.Next(1000); } private void WriteInfo(object state, string message) { Console.WriteLine("Thread " + state.ToString() + " - " + message); } } It throws two possible errors: System.Data.SqlClient.SqlException: Timeout expired. »

Shipping Software - A response to Joel Spolsky

Joel recently posted The Duct Tape Programmer which has received an enormous amount of buzz, both positive and negative. At work, I received emails telling me that the article is a must read, while receiving different emails flaming Joel. If you haven’t read it, I highly encourage you to do so. In short, it is about shipping software above all else. I have spent the evening catching up on blogs, many of which are just responses to Joel’s, so I felt I should jump on the bandwagon. »

Why you should use NHibernate.Linq, not Criteria or HQL

What’s wrong with the following? return s.CreateQuery("from CodeCamp c where c.Name = :name order by c.Name") .SetParameter("name", "test") .List<codecamp>(); return s.CreateCriteria<codecamp>() .Add(Expression.Eq("Name", "test")) .AddOrder(Order.Asc("Name")) .List<codecamp>(); There are string references to .NET properties. That is a no-no. If there is a typo, you get runtime errors and not compile time errors. Now, good tests would catch it, but if you want the absolute fastest way to catch typos, NHibernate.Linq is the way to go. »

Powershell script to Register Visual Studio Schemas

I always have to Google how to add an XML schema to Visual Studio because I forget the directory (even though it is super easy). Never again will I forget. function register-vsschemas() { begin { $schema_folders = gci $env:ProgramFiles -Filter "Microsoft Visual Studio*" | gci -Filter "Xml" | gci -Filter "Schemas" } process { if(!$_ -or !(Test-Path $_)) { Write-Error "File '$_' not found" break; } if((gi $_).Extension -ine ".xsd") { Write-Warning "File $_ does not end in an .xsd extension" } foreach($folder in $schema_folders){ #It is very interesting I had to use .FullName... »

Visual Studio Tip: Show All Files

I discovered a Visual Studio feature that I probably should have noticed years ago. It is pretty awesome, and right in front of your face. Show All Files Just click the icon in the Solution Window highlighted in the above screenshot. Bam, all files in the directories get shown, even if they aren’t part of the project. Pretty awesome, especially because of the Include in Project functionality. Much quicker to add items to a project than Add Existing Items. »

Scrum Tip: Granularity of Tasks

One interesting observation I have seen regarding Scrum at Rackspace Apps deals with task breakdowns. Breaking down a story from the product backlog is an important step to create the sprint backlog#Sprint_backlog). Breaking things down into smaller pieces is going to increase estimation accuracy, as well as help the team understand all the different parts of a story. But tasks don’t mean anything. The story is the functional piece of software the product owner requires, not any individual task. »

Brian Hartsock on #Scrum,

Defining outcomes not steps

One of the hardest tasks I have as a manager is empowering developers to make their own decisions. I like to think I do it pretty well, but I know way too much about a lot of applications. Sometimes I find myself defining how something should be done instead of just what should be done. For developers turned managers, I imagine you might feel the same way. What it really boils down to is understanding when to step in and when not to. »