开发者

Would aspect oriented programming be a positive addition to the C# language?

I've had some interesting debates with colleagues about the merits if incorporating aspect oriented programming as a native paradigm to the C# language.

The debate seems to be divided into three camps:

  1. Those folks who think that C# is already too complicated as it is, and another major feature like AOP would only muddy the waters further.
  2. Those who think that it would be a great addition because anything that 开发者_运维问答can increase the expressiveness of the language without breaking existing is a good thing.
  3. Those who don't think it's necessary because libraries like PostSharp that perform post-compilation IL weaving already allow it in a language neutral way.

I'm curious what the community of C#/.NET developers out there think.


It would be great if languages would make it easier to develop and use AOP extensions.

For instance:

  • It would be nice if one could give a delegate (or anonymous method, or lambda) as a parameter to a custom attribute. It's not a lot of work to implement this in C#, it's quite easy to implement it in the CLR (since it supports types, why not methods?). And it would allow to express 'pointcuts' in an elegant way.

  • Support for 'fieldof' and 'methodof'. It is somewhat supported by the CLR (with bugs), not by C#. The same for 'eventof' and 'propertyof' (they have currently no support in the CLR).

  • Better debugging symbols could make it easier for an aspect weaver to report error messages and give the location in code.

  • It would be great to have a modular compiler; it would be less expensive to implement some features like source code generation based on aspects (for method and interface introductions).

That said, I don't think that the language should provide AOP extensions. This is too large (I think PostSharp 2.0 is more complex than the C# compiler itself, at least than C# 2.0). Let's face it: AOP is still rather experimental in the sense that we still don't know exactly what we want from it. There is still little experience. But we want the specification of a language to be stable and to address well-understood problems (imagine the Entity Framework were a part of the language).

Additionally, there are different ways to achieve AOP, and build-time is only one of them. There is nothing wrong in using runtime technologies, like JIT-emitted proxies (Spring/Castle); these are just for different use cases and have their own pros and cons.

So my opinion in one sentense: yes for limited and well-defined language extensions that make it easier to develop AOP frameworks; no for a full AOP implementation in the language.


I agree with the first camp. C# is already loaded with features. Leverage the PostSharp library instead.


It would be useful, but many of the uses are being included in various ways as it is. For example, we will have the ability to do post and pre validation in .NET4, which was one use for using around, in aspectJ.

By using extension methods you can inject new methods into objects you may not have source code for.

And, I don't believe it would be used much as C# developers seem to approach problems differently than Java programmers, which is easy to do since the two languages have diverged so much now.

I don't know if the companies that tend to use .NET would want to use something like AOP, and you would need tools to help understand what aspects are being injected where, such as AJDT on Eclipse.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜