It’s very strange to defend a guess (and a bonus: yes, static constructors get called when using reflection)

First of all: I fully intend to respond to the questions a couple of readers raised in response to my recent post about agile development. The truth is that when I wrote it, I was fully aware that I was giving a very high-level view of what agile development is without providing a lot of explanation about how it’s actually implemented (hence the common concern, “So is agile really just about not planning anything?”—doesn’t sound right, does it?). But I’m not quite ready to delve into an in-depth response just yet! That will require some time, and I’ve been quite busy at work.

The only thing I have to write about today is that I find it very odd when people defend their positions, when their positions are clearly just guesses.

Here’s an example. This morning on Stack Overflow, a user asked if a type’s static constructor would be called upon field access using reflection. I thought it was a pretty good question, albeit fairly trivial to test (I don’t know why the user didn’t just check and see for himself).

The correct answer is yes, field access using reflection will call a type’s static constructor. This is verifiable, and I included example code in my answer.

Curiously, another user answered with this:

If the value is set in the static constructor, it’s ONLY set when first accessed which won’t include being accessed via reflection. It isn’t initialized at runtime automatically.

This is factually wrong. So apparently the user was just guessing at the correct answer.

OK, that happens. But then another user pointed out that the answer appeared to be incorrect, citing my answer, to which the user responded with another guess:

Actually I am correct. In Dan’s answer he uses typeof(TestClass) which in fact calls the Static Constructor.

Again, factually wrong! We can clearly see this with the following very short code:

class TestClass
    static TestClass()
        Console.WriteLine("I am in TestClass's static constructor.");

class Program
    public static void Main(string[] args)
        Type testClassType = typeof(TestClass);
        Console.WriteLine("OK, we're past the typeof part.");


OK, we're past the typeof part.

So the typeof operator does not cause a type’s static constructor to be invoked. Why would this user (1) state a guess as if it’s a fact, and then: (2) defend that guess with another guess, also wrong?

I would like to believe this is an isolated case, but actually I believe that people do this all the time. In fact I tend to think that a whole lot of the controversial issues that people discuss in our society are actually matters of fact which simply have not been definitively established yet (e.g., will government policy X or Y be more effective at reducing crime?).

The human inclination to vehemently defend guesses is one which I have to believe has served our species well in the past (I should hope so, otherwise I fail to see why we do it so readily). But I still just don’t quite get it.


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

%d bloggers like this: