Programming

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.” 

Yay ^.^

Okay, so it took me a while to get to it, but here’s my first approved patch. XD Oh the childish joy…

Mozilla Firefox

As mentioned before I’ve been meaning to do some more software development. I’ve written a small WordPress plugin recently and also decided to find an Open Source C/C++ project to contribute to. I’ve found that the community around Mozilla Firefox is approachable and responds quickly to questions. Their build environment was characterized as convoluted by one of the developers in the #introduction IRC channel, but frankly I had it up and running under both Windows and Linux in under an hour, which is highly encouraging for anyone who is new to the project.

AD Gallery: How to reinitialize the gallery after editing the HTML

At Coffeescripter jQuery AD Gallery, you can find the jQuery plugin called AD Gallery. In the comments, you can read that two people want to know how to destroy the gallery so that they can reset it (search for ‘destroy’ on the page if you’re interested).

I’ve had the issue of wanting to reset the gallery as well, because it doesn’t work well with jQuery’s .hide() and .show() methods, which you’ll encounter if you ever use a tabbed layout for a page with the gallery on one of these tabs. (At my job, AD Gallery has been used for quite a while and we haven’t gotten around to trying out other galleries yet. Since using a tabbed layout is also new, I only encountered this problem recently.)

WordPress plugin updated! :D

I just updated my WordPress plugin to version 0.2 πŸ˜€ It’s now possible to customize it, it’s awesome πŸ˜‰ I’ve tested it thoroughly and just now I added it to the WordPress svn repository where […]

Wrote my first WordPress plugin :)

Sunday, some friends came over to eat some pie (It was fun to see you again! πŸ™‚ ) and while talking about work I mentioned that I haven’t really bothered to learn PHP so far. […]