A Critical Look at C# 3.0 Extension Methods

0 comments suggest edit

Ian Griffiths takes an in-depth look at C# 3.0 Extension methods and the potential problems with it. Of particular note is his philosophy, which directly follows from the idea that code should be written for humans, which he summarizes whe he say…

I’m a big fan of code that does what it looks like it does.

Amen brother!

As an example, he highlights the ToUpper method on a System.String instance, which often misleads new developers. He would prefer the more honest and less misleading static method on the String class that would be called like so:

String.ToUpper(input);

I agree wholeheartedly that ToUpper (which sort of follows the Java convention I guess) is misnamed, but (and this really is a minor niggle) I probably would prefer that it still be an instance method, but renamed GetUpperCase. I think that would do a good enough job of being honest and being discoverable.

In any case, if you’re interested in C# 3.0, be sure to read Ian’s take on extension methods.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

2 responses

  1. Avatar for Ian Griffiths
    Ian Griffiths October 2nd, 2005

    Actually, yes, on reflection I prefer your solution of a better name for ToUpper, rather than my more violent change.



    Of course it's too late for either solution... But at least we can relax, knowing that a solution exists.

  2. Avatar for Haacked
    Haacked October 3rd, 2005

    Well since you're planning to write a compiler, you could perhaps also write a new language that corrects all the mistakes in C#. Call it C#++. ;)