动态语言与静态语言(这两者可以放在同一个地方吗)

发布于 2024-08-12 03:40:42 字数 89 浏览 6 评论 0原文

编程语言分为 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 技术交流群。

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

发布评论

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

评论(5

﹂绝世的画 2024-08-19 03:40:42

静态动态语言之间的区别非常模糊,因为它可以引用许多不同的(或多或少合适的)标准。我将尝试回答每种情况:

解释/编译

这不取决于语言本身,而仅取决于所使用的实现。因此,语言可以通过解释器和编译器来执行。示例

  • Haskell (GHC / GHCI / Hugs)
  • C++ (G++ / Ch)
  • F#

一些编译语言还可以在运行时编译其代码 (.NET)。

静态/动态类型

静态和动态类型(鸭子类型)可以组合在一种语言中。请参阅 C# 的动态VB 以及Option Explicit/Strict offBoo。结构类型可用于在没有显式类型层次结构的情况下制定严格类型。多态基类型 (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

  • Haskell (GHC / GHCI / Hugs)
  • C++ (G++ / Ch)
  • F#

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.

冰之心 2024-08-19 03:40:42

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.

笑饮青盏花 2024-08-19 03:40:42

Objective-C 是另一个例子。它是 C 的严格超集,并且 C 是静态类型的。但“客观”的东西可以是完全动态的(所有对象都声明为 id 类型)。编译器对 Objective-C 对象进行一些静态类型检查,尽管它是有限的,因为许多标准方法返回 id。例如,NSArray集合返回id类型的对象,因此编译器无法捕获:

NSMutableArray *a = [NSMutableArray arrayWithObject:@"I am a string"];
NSNumber *n = [a objectAtIndex:0]; //assigning a string to a number!

尽管它可以标记,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 return id. For example, the NSArray collection returns objects of type id, so the compiler can't catch:

NSMutableArray *a = [NSMutableArray arrayWithObject:@"I am a string"];
NSNumber *n = [a objectAtIndex:0]; //assigning a string to a number!

although it could flag, NSNumber *n = @"I am a string", at compile time.

默嘫て 2024-08-19 03:40:42

是的。静态和动态可以同时存在。

如果使用 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.

じее 2024-08-19 03:40:42

一种语言可以同时是动态的和静态的吗?

动态和静态以相当模糊的方式指代许多不同的事物。特别是,语言可以是静态或动态类型的,这意味着类型检查要么在编译时在某种程度上强制执行,要么完全推迟到运行时。但人们经常将语言称为“动态”语言,因为它具有 REPL,因此可以交互式地评估定义和表达式。事实上,F# 是一种静态类型语言,在一项调查中被评为最佳动态语言。动态也可以指内省/反思的能力。

所以我认为一种语言可以同时是动态的和静态的。特别是,通过静态类型检查和支持交互式评估。

can a language be dynamic and static at the same time ?

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.

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