在AS3中使用最后的时候有什么好处? [英] Are there any benefits when using final in AS3?

查看:112
本文介绍了在AS3中使用最后的时候有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着使用最后关键字,使习惯最近的地方逻辑,这样的不应该被扩展任何类。

I've tried to make a habit recently of using the final keyword wherever logical, like any classes that should never be extended.

我这样做纯粹是因为我喜欢保持严谨简洁的编码风格。

I've done this purely because I like to maintain a strict and concise coding style.

除了在诸如开发应用程序/游戏基础,为其他缔约方或与他人合作时优势明显,有什么实际的好处,当使用最后?即表现。

Aside from the obvious advantages in cases such as developing application/game foundations for other parties or when working with others, is there any actual benefit when using final? i.e. performance.

推荐答案

根据这种广泛的测试,在最后关键字不会使差异表现明智一点半点。

According to this extensive test, the final keyword does not make the slightest bit of difference performance-wise.

方式最后用在ActionScript中,这并不令人吃惊:只有最后一个关键字标记的类和类的方法,因此它仅影响继承。我看不出有什么合乎逻辑的理由,为什么叫最后的方法应该是比任何调用任何其它方法快:在运行时仍然需要查找一个函数指针和执行调用
这同样适用于方法和类的Java 。然而,在Java中,最后还的 标记引用为永恒不变的。这是一个很大的优势及其在ActionScript中使用,因为它可以让编译器内联值(即其实际值替换字节code到变量的所有引用,从而消除查询程序),其中 - 在其他好处 - 可以表现加速了一点。也许我们会看到一些利用这一在ActionScript的未来版本 - 这将是更好的code清晰度和$ P $副作用pvention一个好主意,以及

The way final is used in ActionScript, this comes as no surprise: The final keyword marks only classes and class methods, and thus it affects only inheritance. I see no logical reason why calling a final method should be any faster than calling any other method: The runtime will still need to lookup a function pointer and execute the call.
The same is true for methods and classes in Java. However, in Java, final also marks references as immutable. And this is a big advantage over its use in ActionScript, because it allows the compiler to "inline" values (i.e. replace all references to the variable in byte code with its actual value, eliminating look-up procedures), which - among other benefits - can speed up performance a bit. Perhaps we will see some use of this in a future version of ActionScript - it would be a good idea for better code clarity and prevention of side-effects, as well.

而对于这些理由,我仍然认为这是很好的做法,使用最后,即使你不工作与其他程序员,在案件的其中预期行为要求的方法或类不允许重写:它明确意图和prevents不良影响。它将,因此,加快发展,这不是一件坏事,要么;)

And for those reasons, I would still consider it good practice to use final, even when you are not working with other programmers, in cases where the intended behavior requires methods or classes to disallow overrides: It clarifies intent and prevents undesired effects. It will, therefore, speed up development, and that's not such a bad thing, either ;)

这篇关于在AS3中使用最后的时候有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆