Geeks With Blogs
Chris Falter .NET Design and Best Practices Coding Practices and Design Patterns To write good code, you need to have a good approach.
When Is Code Good Enough? (A Rule of Thumb for the Perplexed)

We software engineers and architects sometimes feel like the rope in a tug-of-war. Pulling from one side is the short-term goal of delivering functionality, preferably yesterday. Indeed, our customers cannot justify paying for our services unless we deliver a working product, better and faster than our competitors. Pulling from the other side, however, is the long-term goal of quality. If our code becomes too disorganized or hard to understand, we cannot long remain in business, because we w

Posted On Wednesday, June 23, 2010 12:55 AM

How to Use Extension Methods and Lambda Expressions to Write Elegant Unit Tests

Some combinations go together well: New York, Yankees, and pinstripes; Oscar Peterson, Ray Brown, and Ed Thigpen; a loaf of bread, a jug of wine, and thou. To this list you may now add: unit tests, extension methods, and lambda expressions. Read on if you're interested in writing elegant unit tests.

Posted On Wednesday, December 30, 2009 3:23 PM

How to Reuse Code Without Creating an Implicit API

If you're writing a reusable framework, you might want to avoid declaring a class or method as public if you don't want to support it as part of the interface. At the same time, you might want to use it from a different internal assembly--especially if you're writing tests. Believe it or not, there is a way to achieve both seemingly contradictory ends in one codebase. Read on to find out how you can have your cake and eat it, too!

Posted On Sunday, March 29, 2009 2:44 PM

Want to Write Great Business Software? Create a Great Domain Model!

When you are coding in a hurry, it is very tempting to write business logic in the first place that comes to mind, such as a button click handler. However, for all but the simplest systems, such a practice leads very quickly to a chaotic system whose business logic is scattered like the ash from an erupting volcano. Create a great domain model, though, and you will be able to nimbly align your software with your emerging business needs.

Posted On Tuesday, March 25, 2008 9:01 AM

Refactoring to Comply with the DRY principle (Don't Repeat Yourself)

Every time I see an example of copy-and-paste programming, I'm like a bull who just spotted a waving red flag. "Don't Repeat Yourself" (DRY) is a principle every programmer should live by, for Turing's sake! Read on for a discussion of why copy-and-paste is egregious, and how to refactor an expansive set of conditional logic branches into a concise and elegant piece of code.

Posted On Friday, March 7, 2008 7:45 AM

A Good Solution for "Magic String" Data
Dealing with vendor data (or your own) in the form of "codes" can pose significant challenges. You must ensure that your source code remains readable, that data are properly validated, and that data can be displayed as user-friendly descriptions. The built-in solutions (named constants and enums) help, but they have some significant shortcomings. If you derive a class of named constants from the MagicStringTranslator class, though, you can vanquish all 3 challenges in one fell swoop! Egghead Cafe ......

Posted On Thursday, March 6, 2008 10:08 AM

Make Magic Strings Easy to Understand and Type Safe
As organizations pass data back and forth, they often use codes to represent the data. For example, a marital status of divorced might be represented as "D", married as "M", and so forth. You have to solve three problems when you are dealing with magic strings: When you write logic to handle the data, things can get chaotic on a hurry if you are not careful; the use of literal magic strings in your source code can make it incomprehensible. You can get into trouble by passing a string that is not ......

Posted On Wednesday, February 27, 2008 1:40 AM

Simplicity vs. Performance

I believe strongly in code clarity, and will reluctantly agree to greater complexity only if there is a clear gain that will clearly benefit the user--e.g., to optimize a bottleneck in a heavily-used code path. I was actually surprised to find that not everyone agrees with my stance. Read further for a friendly but vigorous debate between the two perspectives....

Posted On Thursday, February 5, 2009 5:33 AM

How To Create a Windows Form Singleton

The .NET Framework provides built-in capabilities for creating components and services as singletons. If you want to create a singleton process, though, you're on your own. But not really; if you read on, you will find out how to use a Mutex to do the job.

Posted On Friday, June 6, 2008 9:31 AM

BOOK REVIEW: Don't Make Me Think, 2d Ed. by Steve Krug

Steve Krug's "Common Sense Approach to Web Usability" provides surprising and sometimes counterintuitive principles that every good website must follow. Krug preaches the importance of removing clutter in order to make the purpose and functionality of a site (or page) clear--and happily, he practices what he preaches in this remarkably lucid book. Here are some of Krug's key insights...

Posted On Tuesday, May 13, 2008 3:31 PM

"New" Statement Considered Harmful

Just by calling a class' constructor, you are tying your code to some implementation details of the class. Since good software uses loose coupling, though, you should develop the habit of providing a static construction method and hiding a class constructor. There are exceptions that prove the rule, however, as noted both in this article and in the comments. Read on to learn how to develop the good habit, and when you should consider breaking it....

Posted On Friday, February 15, 2008 2:59 PM

Of Sobriety Tests and Loop Iteration

A skill that is useful during traffic stops can also help you write correct loop iterations.

Posted On Thursday, November 8, 2007 5:44 AM

Test-Driven Design: Make Sure You Fail!

The moral of this tale is simple: in test-driven design, you have to fail before you can succeed. The idea behind test-driven design (TDD) is to incorporate testing into the process of constructing your system, rather than waiting for developers to check in their code and to build a system that someone else tests. TDD has some advantages worth considering...

Posted On Saturday, October 20, 2007 1:39 PM

Saved By Good Design

I have been saved from many a peril during my adventure of a life. When I was instrumenting a large system recently, I realized just how wonderful good design can make your software development life...

Posted On Tuesday, July 24, 2007 11:24 AM

How To: Write a Unit Test for Multi-Dimensioned Output
One of the cool features of Visual Studio 2005 is that it can generate a unit test stub for a class or method. However, I recently discovered that the Unit Test plug-in does not know how to auto-generate an assertion for a method whose output includes a multi-dimensioned out parameter or return value. Here's the relevant stub code that VS 2005 generated for one of my methods whose output includes a multi-dimensioned array: // generated code that creates a class instance called "target", plus other ......

Posted On Friday, May 4, 2007 8:42 AM

Opportunistic SOA (or How to Make Your Cool New Code Survive the Hype Cycle)
Robin Harris just posted a near-heresy on his ZDNet blog: he thinks that SOA (Service-Oriented Architecture) is overhyped, and will die a painful death as businesses discover the difficulties in monetizing it and making it reliable. Come on now--hype, in our industry? Please! Actually...I agree that we are indeed well into a hype cycle regarding web services, and we would do well to make sure that SOA doesn't become the next "Golden Hammer." This is a term coined by Brown, Malveau et al. in their ......

Posted On Tuesday, April 10, 2007 8:55 PM

More on How To Re-throw an Exception
Re-throwing an exception is a little more complex that I had realized. The gotcha, pointed out by helpful reader "Sander", is that when the initial exception is thrown from directly inside the try block, rather than from within a method call inside the try block, you will lose the line number of the faulty line of code, regardless of how you re-throw the exception. Here's some sample code that demonstrates what I mean: using System;namespace RethrowExTest{ class Program { static void Main(string[] ......

Posted On Wednesday, March 28, 2007 4:37 PM

How To: Re-throw an Exception
I've coached many youth baseball teams, and I've always put a lot of focus on developing pitchers. Your left fielder can be chasing butterflies, and the right fielder might have his glove off, and the third baseman can be making faces at his sister in the stands...but if the guy on the mound is mowing 'em down, your odds of winning are pretty good. To the uninitiated, pitching looks easy, but in fact it is one of the most difficult skills in all of sports. To throw a baseball with both force and ......

Posted On Thursday, December 7, 2006 6:31 PM

Why You Might Prefer a DataView to an Array of DataRecord
Before we get too obsessed about the performance advantages of an array of DataRecord over a DataView, let's remember that a DataView behaves differently than an array of DataRecord. No matter how you modify the data in an array of DataRecord, the array bounds will always be the same. However, modifying a field in a DataRecord may cause it to disappear from a DataView, if the modification causes the record to be filtered by the DataView.Filter property. Or if you modify a DataRecord in a DataTable, ......

Posted On Monday, August 7, 2006 7:47 PM

Copyright © Chris Falter | Powered by: