Geeks With Blogs
Dave Chestnutt: SparklingCode and CodeGaffes Writing better code; for fun and profit Visual Studio Tips
CodeGaffe: Copy & Paste (and ReSharper to the rescue)
I use a coding tool called ReSharper - and I was pleasantly surprised the other day when it pointed out a copy & paste bug that was waiting to explode. You see, copy and paste programming is so very easy to do - that we all do it. Even the best of us accidentally leave in duplicate code snippets from time to time. Why Cut & Paste is so bad There are two big reasons why this is an anti-pattern: If the code you cut and pasted has a bug in it (and it invariably will), what do you think are the ......

Posted On Monday, December 11, 2006 12:22 PM

Gotcha! Visual Studio Pre/Post-Build Events
Visual Studio has a nifty feature called Pre-Build and Post-Build events. These are used to include extra DOS commands before or after the build. But there's a gotcha! And it will bite you when you least expect it. In Visual Studio, there is NO ERROR CHECKING except at the end of an event. Any errors that happen prior to the final step are lost. Keep reading to see a workaround. Setting Build Events Build Events are accessed by right-clicking on a Project in the solution explorer and choosing "Build ......

Posted On Tuesday, May 30, 2006 11:23 AM

CodeGaffe: Avoid .NET “partial” classes in C# and VB
Microsoft added a new keyword to C# and VB for 2005 (CLR 2.0): partial Don't use it. partial is used to physically break up a class definition into multiple files. When the compiler sees the keyword partial it finds all the related partial files in order to compile the class. This makes it possible to split the code for a single class across multiple files. By and large, though, this is a bad idea. Let’s look at why that is. If you find yourself typing"p-a-r-t-i-a-l" Stop! Reasons Given To Use the ......

Posted On Wednesday, April 5, 2006 6:34 PM

NUnit - support both .NET 1.1 and 2.0 at the same time
How to easily run NUnit tests in both .NET 1.1 and 2.0 environments. I want to run my NUnit tests! But I have a problem -- my code runs under both .NET 1.1 and 2.0 frameworks. It is real easy to run tests from the IDE, which I do, but that means I'm only running the tests under one version of .NET. How can I easily run tests under both .NET frameworks? I'm lazy, so it has to be easy. So, without even resorting to the command line, here's how I do it in 3 steps: 1. Running tests with the .NET 1.1 ......

Posted On Tuesday, March 7, 2006 5:44 PM

Visual Studio and Perforce: Suppress the Open Connection dialog
We've used Perforce source control for a number of years. It's a great tool and it integrates with Visual Studio pretty well. But its Visual Studio integration has one really annoying feature, that fortunately, you can work around. The feature is this: If your solution has 10 projects in it, you can put each of those 10 projects in a separate Perforce Depot. Is that useful? I'll leave that to you. Suffice it to say that we put all our source in one Depot. The problem comes when you reload a solution. ......

Posted On Tuesday, February 28, 2006 2:14 PM

Visual Studio: Macro to automatically collapse the projects in the Solution Explorer
One of the pains of working with Visual Studio is that the Solution Explorer, in a large project, is hard to use. As you open more and more files, it gets harder to navigate in the solution explorer since it opens all the projects for you. Edwin Evans wrote a nice short macro to collapse all the projects. It works with both 2003 and 2005. Assign it to a button your toolbar and give it the smiley face ......

Posted On Tuesday, February 21, 2006 3:02 PM

SparklingCode: Count the cost with Line Numbers
One of the benefits of using modern editors is that it's really easy to navigate your code base. If you're looking at a method call, for example, you can use a keystroke combination to jump to the method definition. But there's a drawback to this. If you're not careful, as you add new code you can end up with monster methods, or monster-sized classes. Let me ask you this - what do you think the maximum size of a class should be? 100 lines? 500 lines? 10,000 lines? While we won't agree on an exact ......

Posted On Monday, January 30, 2006 6:46 PM

Copyright © Dave Chestnutt | Powered by: