This was an interesting read I found today: New “Orcas” Language Feature: Extension Methods. The point of the post is to discuss a new upcoming feature for .NET languages in which developers can add their own methods to objects without touching the class definition. Essentially, at any point you can add a method to any class such that all instances will have it. This is just like JavaScript, and it works for all .NET languages!

The ironic thing is that it allows you to do what I always tell people to avoid: you can’t modify objects you don’t own. While it’s possible in JavaScript, and fun to do as a hobby (most of my hobby scripts modify some object or another), it’s not a good idea to do in production code. There’s already too much stuff going on in a developer’s head to make them figure out whether a method is native or not. I know they’re trying to make .NET as extensible as possible, but whatever happened to creating a subclass or using the behavior pattern? :: sigh ::

Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.

Both comments and pings are currently closed.