Browsed by
Category: Good practices

Fail Fast principle

Fail Fast principle

Recently I received a NullReference-Exception when I called another method from a foreign component. Fortunately I had the source code of this component and I found the following code: [code language=”csharp”] public class AgeValidator { public Dictionary Config { get; set; } public bool Validate(int nAge) { int nMinAge = FindValue(“MinAge”); return nAge > nMinAge; } private int FindValue(string strParameter) { int nValue = -1; if(this.Config.ContainsKey(strParameter)) nValue = this.Config[strParameter]; return nValue; } } [/code] There are several problems with this…

Read More Read More

How to structure code in an unit test

How to structure code in an unit test

When you create your unit tests for a method in the SUT (software under test) you will ask yourself how to structure the code in the test method.I saw two kind of syntaxes which help to structure the code in a unit test method (well, actually there are at least three, but the third syntax is just chaos, so this is definitely not the way how to do it). SEVT-Syntax [code language=”csharp”] [TestFixture] public class ThingTest { [Test] public void…

Read More Read More

When to use stored procedures

When to use stored procedures

Recently I discussed with a colleague when to use stored procedures. As exptected it was quite a religious conversation. A few days later I found the following screencast: The Pros and Cons of Stored Procedures Based on the discussion and the screencast I tried to summarize my Pros and Cons: Pros Layering Low-level-Security Protect queries from changing data-access technologies (jdbc, hibernate, toplink, dbcommands, linq to sql, entity framework, nhibernate, etc…) Ivory-Tower-Feature: changing database during project does nearly never happen Coarse-grained…

Read More Read More

Eat your own dog food

Eat your own dog food

Recently I heard the expression “eat your own dog food” again. For a company which produce software for a customer it is very usefull to use the same technology or product in house. But this expression is also usefull in the daily business of a modern software developer. One big advantage of test driven development (TDD) is, that you change the perspective before you code a class or a method. In the test first approach you create the test before…

Read More Read More

Explicit interface implementation

Explicit interface implementation

In C# you have a feature, which java don’t have. It’s called explicit interface implementation.The main use of this feature is to solve problems when you have to implement for example two interfaces which have both unfortunatly a same method signature: namespace testpw.ExplicitInterfaces{    public interface IA    {        void doAction();    }     public interface IB    {        void doAction();    }} The implementation of both interfaces on the same class look now like this: namespace testpw.ExplicitInterfaces{    public class TestImpl : IA, IB    {       …

Read More Read More