Creative

Elfquest short story

(Originally posted this on the Elfquest Father Tree Holt at Forumotion. Decided to grab it from there and repost it here.) I’ve been a long time fan of Strongbow, but mostly I guess because of […]

Read More

Painting: Weather balloon

I finished this painting a while back, but didn’t put it up yet. Forgot to sign it too.. Oh well.. I’m pretty pleased with the end result anyway 🙂 Again, it’s based off real live […]

Are you joking “It compiles, ship it!”? You might actually be doing just that…

A while back, I talked with someone about using the Singleton Design Pattern vs. using an IoC container and registering your class as singleton.

Response:

IoC containers are regularly bootstrapped wrongly, resulting in your product not working as it should. And you don’t discover that until you startup the product. I’d rather use the Singleton Pattern. That way, the compiler will protect against errors.

A composite validator pattern

Have you ever encountered something like this?
(Note: #r denotes a collapsed region of code)

public class MyBulkyClassThatDoesALot
{
    #r Private fields
    #r Constructor
    #r Another constructor
    #r Public properties
    #r Public methods
    #r Private methods

    #region Validation

    // meanwhile, somewhere on line 20485
    public ValidationResult Validate()
    {
        ValidationResult result;
        CheckThatSomethingHolds(result);
        CheckThatSomethingElseHolds(result);

        if (this.somesituation)
        {
            CheckSituationDependentCondition(result);
            CheckSituationDependentOtherCondition(result);
        }

        ...
        // Somewhere on line 20585
        CheckLastThing(result);
        return result;
    }

    private void CheckThatSomethingHolds(ValidationResult result)
    {
        if (this.somecondition)
        {
            result.AddError(new ValidationError("Condition X failed"));
        }
    }

    private void CheckThatSomethingElseHolds(ValidationResult result)
    {
        if (this.somecondition)
        {
            result.AddError(new ValidationError("Condition Y failed"));
        }
    }

    private void CheckSituationDependentCondition(result)
    {
        if (this.somecondition)
        {
            result.AddError(new ValidationError("Condition SituationDependent1 failed"));
        }
    }

    // Are you tired of scrolling yet? Good, because this is how whomever reads this code shall feel in real life ;)

    private void CheckSituationDependentOtherCondition(result) { ... snip }

    // A sigh of relief when you reach the last one
    private void CheckLastThing(ValidationResult result)
    {
        if (this.somecondition)
        {
            result.AddError(new ValidationError("Condition Z failed"));
        }
    }

    #endregion Validation

    // And then, of course, there is a lot of code after this. If you're unlucky, there wasn't even a #region around all the Validation methods and you have to hunt them down one by one because they are scattered through the code.
}

Don’t worry, you’re not the first one to end up with this. Often, it started as a single validation rule that was just implemented directly in the class to be validated. However, there are some things to look out for.

Test test test 

A fellow software engineer today: “I don’t know what the TreeTestHelperTest *falters*… tests.” 

Read More

Painting: Gift for my friend’s sister

Painting of a photograph of my friend and her sister when they were kids. Had fun creating it and my friend’s sister was really happy with it when she received it for her birthday 🙂 […]

Read More

On rediscovering painting

When I was a child, I was once asked to create a painting for a church. I don’t remember exactly what the event was, but I ended up creating a painting of a huge colorful mosque. After secondary school, I followed an art class and during my studies in Computer Science and Engineering, I also once took up a painting class. Although painting hasn’t been a constant hobby of mine, I do return to it from time to time. In the past year, I did quite a few paintings from photographs, as gifts for friends or friends of friends.