I’ve noticed a pattern recently in our codebase at work, where most of our model class have a name such as User, and there is an inheriting type that has extra fields on it called UserEx. I’ve also noticed this in the C# async CTP where they put the additional static methods for Task in a class called TaskEx (due to technical restrictions, since they couldn’t alter the existing library). Talking to someone at work, I learned that -Ex classes exist to optimize network transfers (you can pull only the bare minimum if you need). My question, then, is what does -Ex stand for? The only thing I can think of is possibly “Extra”.
Share
The other answers all got it correct: the
Exsuffix stands for “extended”. It’s a way of introducing a new class or method without obsoleting or removing the old one, a common way of retaining backwards compatibility while introducing new features.The Windows API does this all over the place, as explained here.
Hans hints at the problem with this approach in his explanation: it doesn’t scale. What if you want to extend an “extended” function? Do you call it
FunctionExEx? That looks stupid.So stupid, in fact, that Microsoft’s own coding guidelines for .NET (subjective though they are) specifically recommend against appending
Exto a type. Instead, if you must do this, you should use a number:Blaming this on poor planning as dowhilefor tries to do is a bit premature. When writing real world applications and frameworks, you often need to ship. That means getting out a quick-and-dirty version of the function that works. Later, you decide this is a poor design and something needs to change. Rather than throwing up your hands and completely re-writing (producing giant delays and obsoleting all of the old code), you introduce a new type with a different name. Hindsight is always 20/20.