我听说过“动态”在运行时改变?那是什么?
我听说这些(例如 Groovy)语言能够在运行时动态更改变量名称或调用方法!你所说的动态语言是什么意思?在运行时更改任何值的真正需要是什么?这不会导致混乱吗,因为在运行时如果您更改任何值(或者您的编程约束更改任何内容),那么需要编译什么(因为它决定并确认将使用这些值,那么就没有意义动态改变它)?而且我知道应该有一些有用的东西,所以只有人们引入了这些概念!
我想我的问题已经很清楚了!我需要一些简短的解释:)
i heard that these(say for example Groovy) languages have the capability of changing the variable name or call methods dynamically in runtime! What you meant by dynamic languages? And what is the real need for changing any values during runtime? Is that doen't lead to confusion, because at runtime if you change any value(or your programming constriants change anything), then whats the need for compilation(because it decides and confirms these values will be used, then there is no meaning of changing it in dynamically)? And i know there should be something useful, so only people have introduced these concepts!
I guess i'm clear about my question! And i need some brief explanation :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
三点:
1)是的,这就是“动态语言”的含义——可以在运行时向类添加方法是动态语言的一个共同特征(例如)。
2)你提出了一个很好的观点,即这种能力可能会导致令人困惑的运行时问题。动态语言的支持者会说该功能的好处超过了缺点。元编程能力非常强大。
3)编译时检查仍然可以帮助动态语言的开发,即使只是语法检查。但是,对于动态语言,您确实会失去一些非动态语言的编译时安全性。请注意,某些动态语言是解释性的(例如 javascript),因此这是一个有争议的问题。
Three points:
1) Yes, that is what is meant by 'dynamic languages' -- that you can add methods to a class at runtime is a common feature of dynamic languages (for example).
2) You bring up a good point that this ability could lead to confusing runtime issues. Proponents of dynamic languages would say the benefits of the feature outway the downsides. Being able to meta program can be very powerful.
3) compile time checks can still help in development with dynamic languages, if nothing more than for syntax checks. However, with dynamic languages, you do lose some of the compile time safety of non-dynamic languages. Note that some dynamic languages are interpreted (e.g. javascript) so its kind of a moot point.