Thinking inside the box… four of them to be exact

The past few weeks, I’m observing the appearance of a new ‘discovery’.

The discovery is this: You can describe people’s communication style / personality type with four colors!!!111one

There’s RED, for the strong-willed, fast-paced thinkers.
There’s YELLOW, for the sociable, excitable, “ooh, shiny light”-type persons.
There’s BLUE, for the detail-focused, precise analytics.
And GREEN, for the relationship/feeling-oriented person.

It’s a hype. It’s The New Thing. It’s AMAZING. Aannd… it’s really old :’)

Continue reading

Extension to Category Posts in Custom Menu

The WordPress plugin I wrote, Category Posts in Custom Menu, supports custom extensions. Recently, I wrote an extension for someone who wanted to show all posts from some category, say “category A” that were ALSO in “category B” AND NOT in “category C”. So, I helped out (coding, yay) figuring it would give me an idea of whether the extension possibilities I created make sense.

If you’re interested, you can now find all the source code at GitHub. This extension was aptly (ahem) named “cpcm-and-and-not-extension”.

What do a warning, a comment, a test and your backlog have in common?

#warning This is going to be a nitpicky post.

There was once a developer who marked his code with TODO’s.


// TODO does not handle case X
public void Handle()
{

...
// TODO clean this up
var ugly = ...

...
// TODO re-enable after Y is implemented
// if (bla)
// {
// ...
// }

Another developer used warnings.


#warning still have to write test for this
switch (something)
{
case a: i = 4; break;
case c: i = 1;
default: throw new InvalidOperationException();

I’m writing this blog post to illustrate subtle but significant differences between four mechanisms that can be used for a shared goal: To mark what still needs to be done.

Continue reading

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.

Continue reading

Painting of a friend during an archery workshop

In January of this year, I invited a couple of friends for an archery workshop and dinner.
The goal was to hit the balloons taped to the target and at some point I exclaimed I’d paint a picture of the first person to hit a balloon.

I try to make good on my promises 🙂 though I had to ask her for a photo of said painting, because although I swear I took a photo for my own private collection before I gave the painting to her, I can’t find it anywhere.. whoops..

photo-cropped



Ahh, placed it in a wrong folder somewhere, here it is:

_mg_3179-cr2

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.

Continue reading

If

The difference between an implication and a bi-implication is this:

I am a crazy cat lady. I just don’t have all the cats yet XD