哪些语言是动态类型和编译的(哪些语言是静态类型和解释的)?

发布于 2024-08-23 08:33:34 字数 135 浏览 9 评论 0原文

在我对动态和静态类型的阅读中,我不断遇到这样的假设:静态类型语言是编译的,而动态类型语言是解释的。我知道一般来说这是正确的,但我对例外情况感兴趣。

我真的希望有人不仅给出这些例外的一些例子,而且尝试解释为什么决定这些语言应该以这种方式工作。

In my reading on dynamic and static typing, I keep coming up against the assumption that statically typed languages are compiled, while dynamically typed languages are interpreted. I know that in general this is true, but I'm interested in the exceptions.

I'd really like someone to not only give some examples of these exceptions, but try to explain why it was decided that these languages should work in this way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

渡你暖光 2024-08-30 08:33:34

这里列出了一些有趣的系统。它并不详尽!

动态类型化和编译

  1. Gambit计划编译器,Chez计划,Will Clinger的Larceny计划编译器,Bigloo 方案编译器,可能还有许多其他编译器。

    <块引用>

    为什么?

    很多人真的很喜欢Scheme。程序即数据,良好的宏观体系,35年的发展,大社区。但他们想要的是性能。因此,出现了许多优秀的本机代码编译器——ChezScheme 甚至是一个成功的商业产品(解释的字节码是免费的;本机代码需要付费)。

  2. Lua 的 LuaJIT 即时编译器。

    <块引用>

    为什么?

    证明这是可以做到的。然后,人们开始喜欢将他们的 Lua 程序加速 3 倍。 Lua 存在于许多性能至关重要的游戏中,而且它也正在渗透到其他产品中。 Adobe Lightroom 中 70% 的代码是 Lua。

  3. icon 图标-to-C 编译器。< /p>

    <块引用>

    为什么?

    使用它的 50 个人都喜欢 Icon。完全不寻常的评估模型,有史以来设计的最具创新性(在我看来是最好的)字符串处理系统。但该评估模型确实非常昂贵,尤其是在 20 世纪 80 年代末的计算机上。通过将 Icon 编译为 C,Icon 项目使大型 Icon 程序在更短的时间内运行成为可能。

结论:人们首先对动态类型语言产生依恋,并且可能是一个重要的代码库。最终,社区推出了本机代码编译器,以便您可以获得更好的性能并解决更大的问题。

静态类型和解释

此类别不太常见,但是...

  1. Objective Caml。机器学习的方言,是语言设计中大量创新实验的工具。

    <块引用>

    为什么?

    非常便携的系统和非常快的编译时间。人们喜欢这两个属性,因此新的语言设计思想得到了广泛传播。

  2. 莫斯科ML。标准机器学习,带有模块系统的一些额外功能。

    <块引用>

    为什么?

    可移植、编译速度快、易于进行交互式读取/评估/打印循环。成为流行的教学编译器。

  3. C-三萜。一个老产品,我想可能来自 Gimpel Software。 Saber C——我认为你再也买不到的产品了。

    <块引用>

    为什么?

    调试。特别是在 MS-DOS 下对 20 世纪 80 年代的硬件进行调试。只需很少的资源,您就可以在非常有限的硬件上调试 C 代码,从而获得非常好的帮助(例如:具有 8 位总线的 4.77MHz 处理器、满载的 640K RAM)。几乎不可能为本机编译的代码获得一个好的可视化调试器,但是使用解释器,相当容易。

  4. UCSD Pascal——这个系统让“P 代码”成为家喻户晓的词。

    <块引用>

    为什么?

    老师们喜欢 Niklaus Wirth 的语言设计,而且编译器可以在非常小的机器上运行。 Wirth 简洁的设计和 UCSD P 系统形成了无与伦比的组合,Pascal 成为 20 世纪 70 年代的标准教学语言。年轻人可能很难理解,在 20 世纪 70 年代,对于第一门课程教什么语言没有争论。今天我知道使用 C、C++、Haskell、Java、ML 和 Scheme 的程序。在 20 世纪 70 年代,人们总是使用 Pascal,而 UCSD P 系统是一个重要原因。

    如果您想知道,P 代表便携式

总结:解释静态类型语言是将实现快速交付到每个人手中的好方法。 (它对于在青铜时代硬件上进行调试也具有优势。)

Here's a list of a few interesting systems. It is not exhaustive!

Dynamically typed and compiled

  1. The Gambit Scheme compiler, Chez Scheme, Will Clinger's Larceny Scheme compiler, the Bigloo Scheme compiler, and probably many others.

    Why?

    Lots of people really like Scheme. Programs as data, good macro system, 35 years of development, big community. But they want performance. Hence, a number of good native-code compilers—Chez Scheme is even a successful commercial product (interpreted bytecodes are free; native codes you pay for).

  2. The LuaJIT just-in-time compiler for Lua.

    Why?

    To show it could be done. And then, people started to like getting 3x speedup on their Lua programs. Lua is in a lot of games, where performance matters, plus it's creeping into other products too. 70% of the code in Adobe Lightroom is Lua.

  3. The iconc Icon-to-C compiler.

    Why?

    The fifty people who used it loved Icon. Totally unusual evaluation model, the most innovative (and in my opinion, best) string-processing system ever designed. But that evaluation model was really expensive, especially on late-1980s computers. By compiling Icon to C, the Icon Project made it possible for big Icon programs to run in fewer hours.

Conclusion: people first develop an attachment to a dynamically typed language, and probably a significant code base. Eventually, the community spits out a native-code compiler so that you can get better performance and solve bigger problems.

Statically Typed and Interpreted

This category is less common, but...

  1. Objective Caml. Dialect of ML, vehicle for lots of innovative experiments in language design.

    Why?

    Very portable system and very fast compilation times. People like both properties, so the new language-design ideas are desseminated widely.

  2. Moscow ML. Standard ML with a few extra features of the modules system.

    Why?

    Portable, fast compilation times, easy to make an interactive read/eval/print loop. Became a popular teaching compiler.

  3. C-Terp. An old product, I think maybe from Gimpel Software. Saber C—a product I don't think you can buy any more.

    Why?

    Debugging. Especially, debugging on 1980s hardware under MS-DOS. For very little resources, you could get really good help debugging C code on very limited hardware (think: 4.77MHz processor with an 8-bit bus, 640K of RAM fully loaded). Nearly impossible to get a good visual debugger for native-compiled code, but with the interpreter, fairly easy.

  4. UCSD Pascal—the system that made "P-code" a household word.

    Why?

    Teachers liked Niklaus Wirth's language design, and the compiler could run on very small machines. Wirth's clean design and the UCSD P-system made an unbeatable combination, and Pascal was the standard teaching language of the 1970s. Younger people may find it hard to appreciate that in the 1970s there was no debate over what language to teach in the first course. Today I know of programs using C, C++, Haskell, Java, ML, and Scheme. In the 1970s it was always Pascal, and the UCSD P-system was a big reason way.

    In case you are wondering, P stood for portable.

Summary: Interpreting a statically typed language is a great way to get an implementation into everybody's hands quickly. (It also had advantages for debugging on Bronze Age hardware.)

若水微香 2024-08-30 08:33:34

Objective-C 已编译并支持动态类型(当然,当通过 [target doSomething] 语法调用方法时)。也就是说,您可以向目标发送任何消息(使用普通语言语法,无需针对反射 API 进行编程),在编译时仅收到一条可能无法处理该消息的警告,并且仅在运行时如果目标不处理则收到异常不响应该选择器(这就像方法签名);并且您可以询问任何对象(如果您的代码不知道更好或不关心,则所有对象都可以是静态类型 id)是否 respondsToSelector: 进行探测它的能力。

Objective-C is compiled and supports dynamic typing (certainly when calling methods via [target doSomething] syntax). That is, you can send any message to a target (using ordinary language syntax, without programming against a reflection API), receive only a warning at compile time that it might not be handled, and receive an exception only at runtime if the target doesn't respond to that selector (which is like a method signature); and you can ask any object (which can all be of static type id if your code doesn't know any better or doesn't care) whether it respondsToSelector: to probe its capabilities.

俯瞰星空 2024-08-30 08:33:34

Java(一种静态类型语言)被编译为 JVM 字节码,该字节码在旧版本的 JVM 上进行解释,而现在它使用即时 (JIT) 编译,这意味着机器代码是在运行时生成的。我还相信 ML 及其方言是可以解释的,并且 ML 绝对是静态类型的。

Java (a statically typed language) is compiled to JVM bytecode, which was interpreted on older versions of the JVM, whereas it now uses Just In Time (JIT) compilation, meaning machine code is generated at runtime. I also believe ML and its dialects can be interpreted, and ML is definitely statically typed.

初见终念 2024-08-30 08:33:34

Python 是一种具有编译器的动态语言。

例如,请参阅这个SO问题 - Python - 为什么编译?

一般来说,编译可以使程序运行得更快。

Python is a dynamic language that has compilers.

See this SO question - Python - why compile?, for instance.

In general, compiling makes the program run much faster.

栩栩如生 2024-08-30 08:33:34

Actionscript 具有动态类型并编译为字节码。

如果您想在 iPhone 上发布 Flash 应用程序,它甚至可以直接编译为本机机器代码。

Actionscript has dynamic typing and compiles to bytecode.

And it even compiles right down to native machine code if you want to release a Flash app on the iPhone.

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