Don’t Program by Fear, Question Everything

Perusing some code base I’ve recently came across with a code comment that I would like to share. It was something like this:

class Animal
    public Animal() { this.Id = Guid.NewGuid(); }

    public Guid Id { get; private set; }

class Cat : Animal
    public Cat()
        : base() // Always call base since it's not always done automatically
    { }

Note: All class names were changed to protect the innocent.

To clear any possible doubts the C# specification explicitly states that:

If an instance constructor has no constructor initializer, a constructor initializer of the form base() is implicitly provided. Thus, an instance constructor declaration of the form
C(...) {...}
is exactly equivalent to
C(...): base() {...}

So in conclusion it’s clearly an incorrect comment but what I find alarming is how a comment like that gets into a code base and survives the test of time. Not to forget what it can do to someone who is making a jump from other technologies to C# and reads stuff like that.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s