动态郎。运行VS思考动态、VS

2023-09-07 10:59:28 作者:為愛轉身

我打算使用动态的关键字为我的新项目。但步进之前,我想知道在使用动态关键字在思考的利弊。

以下命令,其中的利弊,我能找到的关于动态关键字:

在读\维护的code。 在更少的行code。

在使用动态关键字相关联的底片,我来听像:

在影响应用程序的性能。 动态关键字在内部反思的包装。 在动态类型,也许就会变成滋生很难找到的bug。 影响与previous .NET版本的互操作性。

请帮我的优点和缺点,我碰到是否明智与否?

解决方案   

读\维护的code

在我的执政经验肯定是真的。

  

更少线条code。

不显著,但它将帮助。

  

影响应用程序的性能。

中很轻微。但是,即使不靠近反射的方式一样。

  

动态关键字在内部反思的包装。

完全不真实的。动态关键字利用动态库运行。

这似乎是动态语言运行时不使用反射和性能改进只是由于cacheing技术。

  

动态类型,也许就会变成滋生了难以发现的故障。

动态动漫情侣头像一对两张

这可能是真实的;这取决于你如何写你的code。您有效地消除编译器从code检查。如果您的测试覆盖好,这可能并不重要;如果没有,那么我怀疑你会遇到的问题。

  

影响与previous .NET版本的互操作性

事实并非如此。我的意思是,你将无法对旧版本的编译code,但如果你想这样做,那么你应该使用旧的版本为基础,支持多达编译它,而不是周围的其他方式。但是,如果你想使用一个.NET 2库,那么你应该不会遇到太多的问题,只要你有在App.config中/ web.config中的声明。

这是你缺少一个显著Pro与COM / ATL组件的改进互操作性。

I am planning to use dynamic keyword for my new project. But before stepping in, I would like to know about the pros and cons in using dynamic keyword over Reflection.

Following where the pros, I could find in respect to dynamic keyword:

Readable\Maintainable code. Fewer lines of code.

While the negatives associated with using dynamic keyword, I came to hear was like:

Affects application performance. Dynamic keyword is internally a wrapper of Reflection. Dynamic typing might turn into breeding ground for hard to find bugs. Affects interoperability with previous .NET versions.

Please help me on whether the pros and cons I came across are sensible or not?

解决方案

Readable\Maintainable code

Certainly true in my experence.

Fewer lines of code.

Not significantly, but it will help.

Affects application performance.

Very slightly. But not even close to the way reflection does.

Dynamic keyword is internally a wrapper of Reflection.

Completely untrue. The dynamic keyword leverages the Dynamic Library Runtime.

[Edit: correction as per comment below]

It would seem that the Dynamic Language Runtime does use Reflection and the performance improvements are only due to cacheing techniques.

Dynamic typing might turn into breeding ground for hard to find bugs.

This may be true; it depends how you write your code. You are effectively removing compiler checking from your code. If your test coverage is good, this probably won't matter; if not then I suspect you will run into problems.

Affects interoperability with previous .NET versions

Not true. I mean you won't be able to compile your code against older versions, but if you want to do that then you should use the old versions as a base and up-compile it rather than the other way around. But if you want to use a .NET 2 library then you shouldn't run into too many problems, as long as you include the declaration in app.config / web.config.

One significant pro that you're missing is the improved interoperability with COM/ATL components.

 
精彩推荐