动态语言与静态语言(这两者可以放在同一个地方吗)
编程语言分为 2 个主要类别“动态”和“动态”。 “静止的”。 - 编程语言是否总是存在于其中一种而不是两者中的情况,我的意思是一种语言可以同时是动态和静态的吗?
programming languages are grouped it 2 main classes "Dynamic" & "Static".
- Is this always the case a programming language is in one of them and not in both, I mean can a language be dynamic and static at the same time ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
静态和动态语言之间的区别非常模糊,因为它可以引用许多不同的(或多或少合适的)标准。我将尝试回答每种情况:
解释/编译
这不取决于语言本身,而仅取决于所使用的实现。因此,语言可以通过解释器和编译器来执行。示例
一些编译语言还可以在运行时编译其代码 (.NET)。
静态/动态类型
静态和动态类型(鸭子类型)可以组合在一种语言中。请参阅 C# 的
动态
、VB 以及Option Explicit/Strict off 或Boo。结构类型可用于在没有显式类型层次结构的情况下制定严格类型。多态基类型 (System.Object
) 也支持某种动态行为,尽管类型是静态给出的。元构造(例如反射、运行时类型生成)
在 Java 和 .NET 中也可用。
函数式技术(例如高阶函数、延续)
也可以在静态类型语言中复制。请参阅 Haskell 或 Scala。
The distinction static and dynamic language is quite ambiguous since it can refer to many different (more or less suitable) criteria. I'll try to answer for each case:
Interpretation/Compilation
This doesn't depend on the language itself but just on the implementation used. Therefore languages can be executed through both an interpreter and a compiler. Examples
Some compiled languages also have the possibility to compile their code at runtime (.NET).
Static/Dynamic typing
Static and dynamic typing (duck typing) can be combined in one language. See C#'s
dynamic
, VB with Option Explicit/Strict off or Boo. Structural typing can be used to formulate strict typing without explicit type hierarchies. Polymorphic base types (System.Object
) support some kind of dynamic behaviour as well, though the type is given statically.Meta constructs (e.g. Reflection, Runtime type generation)
Are available in Java and .NET too.
Functional techniques(eg. Higher-order functions, continuations)
Can be replicated in statically-typed languages as well. See Haskell or Scala.
C# 4.0 是一种静态类型语言,支持动态解析 也是如此。
dynamic
关键字基本上告诉编译器:现在不用担心这个。如果它无法在运行时解析类型,则会引发异常。C# 4.0 is a statically typed language that supports dynamic resolution as well. The
dynamic
keyword basically tells the compiler: don't worry about this for now. If it can't resolved the type at runtime an exception is thrown.Objective-C 是另一个例子。它是 C 的严格超集,并且 C 是静态类型的。但“客观”的东西可以是完全动态的(所有对象都声明为
id
类型)。编译器对 Objective-C 对象进行一些静态类型检查,尽管它是有限的,因为许多标准方法返回 id。例如,NSArray
集合返回id
类型的对象,因此编译器无法捕获:尽管它可以标记,
NSNumber *n = @"I am一个字符串”
,在编译时。Objective-C is another example. It's a strict superset of C, and C is statically typed. But the "objective" stuff can be totally dynamic (all objects declared as type
id
). The compiler does some static type checking of Objective-C objects, although it is limited since many standard methods returnid
. For example, theNSArray
collection returns objects of typeid
, so the compiler can't catch:although it could flag,
NSNumber *n = @"I am a string"
, at compile time.是的。静态和动态可以同时存在。
如果使用 C#,那么我们就处于静态轨道上,而移动我们在 VS 2010 (.NET 4.0) 中使用新的 System.linq.Expression 树 API。我们的代码目标是 CLR 之上的 DLR(动态语言运行时)框架。
即使我们由
表达式类
创建的代码也可以被其他动态语言使用,如IronPython等。类似地,我们可以在CLR上使用iron python代码。我们需要确保它们发出表达式树并针对 DLR。
Yes. It's possible to have both static and dynamic together.
If one uses C#, then we are on static track and the movement we use a new
System.linq.Expression tree API
in VS 2010 (.NET 4.0). We are targeting our code towards the framework called DLR (Dynamic Language Runtime) a layer above CLR.Even our code created by
expression class
can also be use by other Dynamic languages like IronPython etc..Similarly, we can use the iron python code over CLR. All we need to make sure they emit expression tree and are targeted towards the DLR.
动态和静态以相当模糊的方式指代许多不同的事物。特别是,语言可以是静态或动态类型的,这意味着类型检查要么在编译时在某种程度上强制执行,要么完全推迟到运行时。但人们经常将语言称为“动态”语言,因为它具有 REPL,因此可以交互式地评估定义和表达式。事实上,F# 是一种静态类型语言,在一项调查中被评为最佳动态语言。动态也可以指内省/反思的能力。
所以我认为一种语言可以同时是动态的和静态的。特别是,通过静态类型检查和支持交互式评估。
Dynamic and static refer to many different things in quite a vague way. In particular, languages can be statically or dynamically typed meaning the type checking is either enforced to some extent at compilation or it is entirely deferred to run time. But people often refer to a language as "dynamic" because it has a REPL so definitions and expressions can be evaluated interactively. Indeed, F# is a statically typed language that was voted best dynamic language in a survey. Dynamic can also refer to the ability to do introspection/reflection.
So I suppose a language can be both dynamic and static at the same time. In particular, by being both statically type checked and supporting interactive evaluation.