我听说过“动态”在运行时改变?那是什么?

发布于 2024-10-20 05:00:02 字数 236 浏览 2 评论 0原文

我听说这些(例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢烬 2024-10-27 05:00:02

三点:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文