是否“无类型”?也意味着“动态类型”在学术 CS 世界中?

发布于 2025-01-02 12:43:44 字数 702 浏览 2 评论 0原文

我正在阅读一个幻灯片,上面写着“JavaScript 是无类型的”。这与我的想法相矛盾,因此我开始挖掘并尝试了解更多信息。

JavaScript 是一种无类型语言吗? 的每个答案都说 JavaScript 不是< /em> 无类型,并提供了我熟悉且满意的各种形式的静态、动态、强类型和弱类型的示例..所以这不是正确的选择。

所以我问了 JavaScript 的创造者 Brendan Eich,他说:

学术类型使用“无类型”来表示“无静态类型”。他们足够聪明,能够看到值有类型(废话!)。上下文很重要。

以学术为中心的计算机科学人士是否使用“无类型”作为“动态类型”的同义词(这是有效的吗?)还是我遗漏了更深层次的东西?我同意布伦丹的观点,即背景很重要,但任何解释的引用都会很棒,因为我目前的“入门”书籍并没有在这个主题上发挥作用。

我想确定这一点,这样我就可以提高我的理解,因为即使维基百科也没有提到这种替代用法(无论如何,我可以找到)。如果我错了,我不想搞乱使用这个术语或质疑这个术语的使用:-)

(我也看到顶级 Smalltalker 说 Smalltalk 也是“无类型的”,所以它不是一次性的,这就是我开始这个任务的原因:-))

I'm reading a slide deck that states "JavaScript is untyped." This contradicted what I thought to be true so I started digging to try and learn more.

Every answer to Is JavaScript an untyped language? says that JavaScript is not untyped and offered examples of various forms of static, dynamic, strong, and weak typing that I'm familiar and happy with.. so that wasn't the way to go.

So I asked Brendan Eich, the creator of JavaScript, and he said:

academic types use "untyped" to mean "no static types". they are smart enough to see that values have types (duh!). context matters.

Do academically-focused computer science folks use "untyped" as a synonym of "dynamically typed" (and is this valid?) or is there something deeper to this that I am missing? I agree with Brendan that context is important but any citations of explanations would be great as my current "go to" books are not playing ball on this topic.

I want to nail this down so I can improve my understanding and because even Wikipedia doesn't refer to this alternative usage (that I can find, anyway). I don't want to mess up with either using the term or questioning the use of the term in future if I'm wrong :-)

(I've also seen a top Smalltalker say Smalltalk is "untyped" too, so it's not a one-off which is what set me off on this quest! :-))

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

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

发布评论

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

评论(9

终陌 2025-01-09 12:43:44

是的,这是学术文献中的标准做法。要理解它,需要知道“类型”的概念是在 20 世纪 30 年代在 lambda 演算的背景下发明的(事实上,甚至更早,在集合论的背景下)。从那时起,计算逻辑的一个完整分支出现了,被称为“类型理论”。编程语言理论就是建立在这些基础之上的。在所有这些数学背景中,“类型”具有特定的、既定的含义。

术语“动态类型”是很晚才发明的——与“类型”一词的常见数学用法相比,这是一个术语上的矛盾。

例如,以下是 Benjamin Pierce 在他的标准教科书中使用的“类型系统”的定义 类型和编程语言

类型系统是一种易于处理的语法方法,用于证明不存在
通过根据以下方式对短语进行分类来控制某些程序行为
他们计算的各种值。

他还评论道:

“静态”这个词有时会被明确地添加——我们说的是一个
例如,“静态类型编程语言”——以区分
我们在这里考虑的各种编译时分析
在诸如Scheme(Sussman)等语言中发现的动态或潜在类型
和斯蒂尔,1975;凯尔西、克林格和里斯,1998;戴布维格,1996),
其中运行时类型标签用于区分不同类型的
堆中的结构。像“动态类型”这样的术语可以说是
用词不当,可能应该用“动态检查”来代替,
但用法是标准的。

大多数在该领域工作的人似乎都同意这一观点。

请注意,这并不意味着“无类型”和“动态类型”是同义词。相反,后者是前者特定情况的一个(技术上误导性的)名称。

PS:FWIW,我碰巧既是类型系统的学术研究员,又是 JavaScript 的非学术实现者,所以我必须忍受这种分裂。 :)

Yes, this is standard practice in academic literature. To understand it, it helps to know that the notion of "type" was invented in the 1930s, in the context of lambda calculus (in fact, even earlier, in the context of set theory). Since then, a whole branch of computational logic has emerged that is known as "type theory". Programming language theory is based on these foundations. And in all these mathematical contexts, "type" has a particular, well-established meaning.

The terminology "dynamic typing" was invented much later -- and it is a contradiction in terms in the face of the common mathematical use of the word "type".

For example, here is the definition of "type system" that Benjamin Pierce uses in his standard text book Types and Programming Languages:

A type system is a tractable syntactic method for proving the absence
of certain program behaviors by classifying phrases according to the
kinds of values they compute.

He also remarks:

The word “static” is sometimes added explicitly--we speak of a
“statically typed programming language,” for example--to distinguish the
sorts of compile-time analyses we are considering here from the
dynamic or latent typing found in languages such as Scheme (Sussman
and Steele, 1975; Kelsey, Clinger, and Rees, 1998; Dybvig, 1996),
where run-time type tags are used to distinguish different kinds of
structures in the heap. Terms like “dynamically typed” are arguably
misnomers and should probably be replaced by “dynamically checked,”
but the usage is standard.

Most people working in the field seem to be sharing this point of view.

Note that this does not mean that "untyped" and "dynamically typed" are synonyms. Rather, that the latter is a (technically misleading) name for a particular case of the former.

PS: And FWIW, I happen to be both an academic researcher in type systems, and a non-academic implementer of JavaScript, so I have to live with the schisma. :)

以可爱出名 2025-01-09 12:43:44

我是一位专门研究编程语言的学术计算机科学家,是的,“无类型”这个词经常以这种方式(错误)使用。最好保留这个词用于不带有动态类型标签的语言,例如 Forth 和汇编代码,但这些语言很少使用,甚至更很少研究,而且说“无类型”要容易得多比“动态类型”。

Bob Harper 喜欢说像Scheme、Javascript 等语言应该被视为只有单一类型的类型语言:值。我倾向于这种观点,因为它使得仅使用一种形式主义就可以构建一致的世界观。

PS 在纯 lambda 演算中,唯一的“值”是范式中的项,而范式中唯一的项是函数。但是大多数使用 lambda 演算的科学家都会添加基本类型和常量,然后您要么包含 lambda 的静态类型系统,要么就回到动态类型标记。

PPS 致原发者:当涉及到编程语言,尤其是类型系统时,维基百科上的信息质量很差。不要相信它。

I am an academic computer scientist specializing in programming languages, and yes, the word "untyped" is frequently (mis)-used in this way. It would be nice to reserve the word for use with languages that don't carry dynamic type tags, such as Forth and assembly code, but these languages are rarely used and even more rarely studied, and it's a lot easier to say "untyped" than "dynamically typed".

Bob Harper is fond of saying that languages like Scheme, Javascript, and so on should be considered typed languages with just a single type: value. I lean to this view, as it makes it possible to construct a consistent worldview using just one type formalism.

P.S. In pure lambda calculus, the only "values" are terms in normal form, and the only closed terms in normal form are functions. But most scientists who use the lambda calculus add base types and constants, and then you either include a static type system for lambda or you are right back to dynamic type tags.

P.P.S. To original poster: when it comes to programming languages, and especially type systems, the information on Wikipedia is of poor quality. Don't trust it.

来日方长 2025-01-09 12:43:44

我研究了一下,发现你的问题的答案很简单,而且令人惊讶的是“是”:学术 CS 类型,或者至少其中一些,确实使用“非类型化”来表示“动态类型化”。例如,编程语言:原理与实践,第三版(Kenneth C. Louden 和 Kenneth A. Lambert,2012 年出版)说道:

没有静态类型系统的语言通常称为无类型语言(或动态类型语言)。此类语言包括Scheme 和Lisp、Smalltalk 的其他方言以及大多数脚本语言(例如Perl、Python 和Ruby)。但请注意,非类型化语言不一定允许程序损坏数据——这只是意味着所有安全检查都是在执行时执行的。 [...]

[链接](注意:原文加粗)和继续以这种方式使用“无类型”。

我觉得这很令人惊讶(与 afrischke 和 Adam Mihalcin 给出的原因大致相同),但你就是这样。 :-)


编辑添加:您可以通过将“非类型化语言”插入 Google 图书搜索来找到更多示例。例如:

[...] 这是许多非类型语言的主要信息隐藏机制。例如,PLT 方案 [4] 使用生成式struct,[...]

— Jacob Matthews 和 Amal Ahmed,2008 [链接]

[...],我们提出了一种非类型化函数语言的绑定时间分析[...]。 […]它已被实现并用于计划的无副作用方言的部分评估器中。然而,该分析足够通用,对于非严格类型函数语言(例如 Haskell)有效。 [...]

— Charles Consel,1990 [链接 ]

顺便说一句,在查看这些搜索结果后,我的印象是,如果研究人员编写“无类型”函数语言,他(她)很可能确实认为它是“无类型”与 Adam Mihalcin 提到的无类型 lambda 演算具有相同的意义。至少,一些研究人员同时提到了Scheme 和 lambda 演算。

当然,搜索没有说的是是否有研究人员拒绝这种识别,并且认为这些语言是“无类型的”。嗯,我确实发现了这个:

然后我意识到实际上不存在循环性,因为动态类型语言不是无类型语言 - 只是类型通常不会从程序文本中立即明显看出。

— 某个人(我不知道是谁),1998 年 [链接]

但显然 <大多数拒绝这种认同的人不会觉得有必要明确地说出来。

I've looked into it, and found that the answer to your question is simply, and surprisingly, "yes": academic CS types, or at least some of them, do use "untyped" to mean "dynamically typed". For example, Programming Languages: Principles and Practices, Third Edition (by Kenneth C. Louden and Kenneth A. Lambert, published 2012) says this:

Languages without static type systems are usually called untyped languages (or dynamically typed languages). Such languages include Scheme and other dialects of Lisp, Smalltalk, and most scripting languages such as Perl, Python, and Ruby. Note, however, that an untyped language does not necessarily allow programs to corrupt data—this just means that all safety checking is performed at execution time. […]

[link] (note: bolding in original) and goes on to use "untyped" in just this way.

I find this surprising (for much the same reasons that afrischke and Adam Mihalcin give), but there you are. :-)


Edited to add: You can find more examples by plugging "untyped languages" into Google Book Search. For example:

[…] This is the primary information-hiding mechanism is many untyped languages. For instance PLT Scheme [4] uses generative structs, […]

— Jacob Matthews and Amal Ahmed, 2008 [link]

[…], we present a binding-time analysis for an untyped functional language […]. […] It has been implemented and is used in a partial evaluator for a side-effect free dialect of Scheme. The analysis is general enough, however, to be valid for non-strict typed functional languages such as Haskell. […]

— Charles Consel, 1990 [link]

By the way, my impression, after looking through these search results, is that if a researcher writes of an "untyped" functional language, (s)he very likely does consider it to be "untyped" in the same sense as the untyped lambda calculus that Adam Mihalcin mentions. At least, several researchers mention Scheme and the lambda calculus in the same breath.

What the search doesn't say, of course, is whether there are researchers who reject this identification, and don't consider these languages to be "untyped". Well, I did find this:

I then realized that there is really no circularity, because dynamically typed languages are not untyped languages — it's just that the types are not usually immediately obvious from the program text.

— someone (I can't tell who), 1998 [link]

but obviously most people who reject this identification wouldn't feel a need to explicitly say so.

无言温柔 2025-01-09 12:43:44

无类型和动态类型绝对不是同义词。最常被称为“无类型”的语言是 Lambda Calculus,它实际上是一种统一语言——一切都是函数,因此我们可以静态地证明一切的类型都是函数。动态类型语言具有多种类型,但没有添加编译器静态检查它们的方法,从而迫使编译器插入对变量类型的运行时检查。

然后,JavaScript 是一种动态类型语言:可以用 JavaScript 编写程序,使得某些变量 x 可以是数字、函数、字符串或其他内容(并确定哪个变量需要解决停止问题或一些困难的数学问题),因此您可以将 x 应用于参数,并且浏览器必须在运行时检查 x 是否是一个函数。

Untyped and dynamically typed are absolutely not synonyms. The language that is most often called "untyped" is the Lambda Calculus, which is actually a unityped language - everything is a function, so we can statically prove that the type of everything is the function. A dynamically typed language has multiple types, but does not add a way for the compiler to statically check them, forcing the compiler to insert runtime checks on variable types.

Then, JavaScript is a dynamically typed language: it is possible to write programs in JavaScript such that some variable x could be a number, or a function, or a string, or something else (and determining which one would require solving the Halting Problem or some hard mathematical problem), so you can apply x to an argument and the browser has to check at runtime that x is a function.

诠释孤独 2025-01-09 12:43:44

这两种说法都是正确的,具体取决于您谈论的是值还是变量。 JavaScript 变量是无类型的,JavaScript 值有类型,并且变量可以在运行时覆盖任何值类型(即“动态”)。

在 JavaScript 和许多其他语言中,值而不是变量携​​带类型。所有变量都可以涵盖所有类型的值,并且可以被视为“动态类型”或“无类型”——从类型检查的角度来看,没有/不可知类型的变量和可以采用任何类型的变量在逻辑上和实际上是等效的。当类型理论家谈论语言和类型时,他们通常谈论这个 - 携带类型的变量 - 因为他们对编写类型检查器和编译器等感兴趣,这些检查器和编译器等对程序文本(即变量)而不是内存中运行的程序进行操作(即价值观)。

相比之下,在其他语言(如 C)中,变量带有类型,但值不带有类型。在 Java 等语言中,变量和值都带有类型。在 C++ 中,某些值(具有虚函数的值)带有类型,而其他值则不带有类型。在某些语言中,值甚至可以更改类型,尽管这通常被认为是糟糕的设计。

Both statements are correct, depending on whether you are talking about values or variables. JavaScript variables are untyped, JavaScript values have types, and variables can range over any value type at runtime (i.e. 'dynamically').

In JavaScript and many other languages, values and not variables carry types. All variables can range over all types of values and may be considered "dynamically typed" or "untyped" - from the perspective of type-checking a variable that has no/unknowable type and a variable that can take any type are logically and practically equivalent. When type theorists talk about languages and types, they are usually talking about this - variables carrying types - because they are interested in writing type checkers and compilers and so on, which operate on program text (i.e. variables) and not a running program in memory (i.e. values).

By contrast in other languages, like C, variables carry types but values do not. In languages like Java, variables and values both carry types. In C++, some values (those with virtual functions) carry types and others do not. In some languages it is even possible for values to change types, although this is usually considered bad design.

拿命拼未来 2025-01-09 12:43:44

虽然大多数撰写有关类型的计算机科学研究人员基本上只将具有语法可派生类型的语言视为类型化语言,但我们中还有更多使用动态/潜在类型化语言的人对这种用法感到不满。

我认为语言有 3 种类型 [SIC]:

无类型 - 只有运算符决定值的解释 - 它通常适用于任何东西。示例:汇编器、BCPL

静态类型 - 表达式/变量具有与其关联的类型,并且该类型决定编译时运算符的解释/有效性。示例:C、Java、C++、ML、Haskell

动态类型 - 值具有与其关联的类型,并且该类型决定运行时运算符的解释/有效性。示例:LISP、Scheme、Smalltalk、Ruby、Python、Javascript

据我所知,所有动态类型语言都是类型安全的 - 即只有有效的运算符才能对值进行操作。但对于静态类型语言来说情况并非如此。根据所使用的类型系统的功能,某些运算符可能仅在运行时检查,或者根本不检查。例如,大多数静态类型语言不能正确处理整数溢出(将 2 个正整数相加可以生成一个负整数),并且要么根本不检查越界数组引用(C、C++),要么仅在运行时。此外,某些类型系统非常弱,以至于有用的编程需要转义舱口(C 及其系列中的强制转换)来更改表达式的编译时类型。

所有这些都导致了荒谬的说法,比如 C++ 比 Python 更安全,因为它是(静态类型的),而事实是 Python 本质上是安全的,而你可以用 C++ 打断你的腿。

While it is true that most of the CS researchers that write about types essentially consider only languages with syntactically-derivable types as typed languages, there are lots more of us using dynamically/latently typed languages who take umbrage at that usage.

I consider there to be 3 types [SIC] of languages:

Untyped - only the operator determines the interpretation of the value - and it generally works on anything. Examples: Assembler, BCPL

Statically typed - expressions/variables have types associated with them, and that type determines the interpretation/validity of the operator at compile-time. Examples: C, Java, C++, ML, Haskell

Dynamically typed - values have types associated with them, and that type determines the interpretation/validity of the operator at run-time. Examples: LISP, Scheme, Smalltalk, Ruby, Python, Javascript

To my knowledge, all dynamically-typed languages are type-safe - i.e. only valid operators can operate on values. But the same is not true for statically-typed language. Depending on the power of the type system used, some operators may be checked only at run-time, or not at all. For example, most statically-typed languages do not handle integer overflow properly (adding 2 positive integers can produce a negative integer), and out-of-bound array references are either not checked at all (C, C++) or are checked only at run-time. Further, some type systems are so weak that useful programming requires escape hatches (casts in C and family) to change the compile-time type of expressions.

All of this leads to absurd claims, such as that C++ is safer than Python because it's (statically-typed), whereas the truth is that Python is intrinsically safe while you can shoot your leg off with C++.

拥抱没勇气 2025-01-09 12:43:44

这个问题都是关于语义

如果我给你这个数据:12它的类型是什么?你无法确定。可以是整数 - 可以是浮点数 - 可以是字符串。从这个意义上说,它是非常“无类型”的数据。

如果我给你一种想象的语言,它允许你在这个数据和其他一些任意的数据上使用“加”、“减”和“连接”等运算符,那么“类型”在某种程度上是无关的(与我想象的语言)(示例:也许 add(12, a) 会产生 109,即 12 加上 a 的 ascii 值。

让我们谈谈 C。 C 几乎可以让你对任意数据片段做任何你想做的事情。如果您使用的函数需要两个 uint ,您可以强制转换并传递任何您想要的值 - 并且这些值将简单地被解释为 uint 。从这个意义上说,C 是“无类型的”(如果你以这种方式对待它)。

然而 - 回到 Brendan 的观点 - 如果我告诉你“我的年龄是 12” - 那么 12 有一个类型 - 至少我们知道它是数字。 有了上下文,一切都有类型 - 无论语言如何。

这就是为什么我一开始就说——你的问题是语义问题。 “无类型”是什么意思?我认为布伦丹说的“没有静态类型”一语中的——因为这就是它可能的意思。人类自然地将事物分类。我们凭直觉知道汽车和猴子之间有本质上的不同——但我们从未被教导要做出这些区别。

回到我一开始的例子 - 一种“不关心类型”(本身)的语言可能会让你“添加”一个“年龄”和一个“名字”,而不会产生语法错误......但是并不意味着这是一个逻辑上合理的操作。

JavaScript 可能会让你做各种疯狂的事情而不考虑它们是“错误”。这并不意味着您所做的事情在逻辑上是合理的。这是开发人员要解决的问题。

在编译/构建/解释时不强制执行类型安全的系统/语言是“无类型”还是“动态类型”?

语义学。

编辑

我想在这里添加一些东西,因为有些人似乎陷入了“是的,但 Javascript 确实有一些“类型””。

在我对别人的回答的评论中,我说:

在Javascript中,我可以拥有我构建的“猴子”对象和我构建的“人类”对象,并且某些函数可以设计为仅在“人类”上运行”,其他人只关注“猴子”,还有一些人只关注“有武器的东西”。无论该语言是否曾被告知存在“有手臂的东西”这样的对象类别,与汇编(“无类型”)和 Javascript(“动态”)一样无关。这都是逻辑完整性的问题 - 唯一的错误是使用不具备该方法的武器。

所以,如果你认为 Javascript 内部有一些“类型概念”——因此是“动态类型”——并且认为这在某种程度上“与无类型系统明显不同”——你应该从上面的例子中看到,任何它内部的“类型概念”确实无关紧要。

例如,要使用 C# 执行相同的操作,我需要一个名为 ICreatureWithArms 的接口或类似的接口。在 Javascript 中并非如此 - 在 C 或 ASM 中并非如此。

显然,Javascript 是否理解“类型”根本无关紧要。

This question is all about Semantics

If I give you this data: 12 what is it's type? You have no way of knowing for sure. Could be an integer - could be a float - could be a string. In that sense it's very much "untyped" data.

If I give you an imaginary language which lets you use operators like "add", "subtract", and "concatenate" on this data and some other arbitrary piece of data the "type" is somewhat irrelevant (to my imaginary language) (example: perhaps add(12, a) yields 109 which is 12 plus the ascii value of a).

Let's talk C for a second. C pretty much lets you do whatever you want with any arbitrary piece of data. If you're using a function that takes two uints - you could cast and pass anything you want - and the values will simply be interpreted as uints. In that sense C is "untyped" (if you treat it in such a way).

However - and getting to Brendan's point - if I told you that "My age is 12" - then 12 has a type - at least we know it's numeric. With context everything has a type - regardless of the language.

This is why I said at the beginning - your question is one of semantics. What is the meaning of "untyped"? I think Brendan hit the nail on the head when he said "no static types" - because that's all it can possibly mean. Humans naturally classify things into types. We intuitively know that there is something fundamentally different between a car and a monkey - without ever being taught to make those distinctions.

Getting back to my example in the beginning - a language that "doesn't care about types" (per-se) may let you "add" an "age" and a "name" without producing a syntax error... but that doesn't mean it's a logically sound operation.

Javascript may let you do all sorts of crazy things without considering them "errors". That doesn't mean what you are doing is logically sound. Thats for the developer to work out.

Is a system/language which doesn't enforce type safety at compile/build/interpretation time "untyped" or "dynamically typed"?

Semantics.

EDIT

I wanted to add something here because some people seem to be getting caught up on "yeah, but Javascript does have some "types"".

In my comment on someone else's answer I said:

In Javascript I could have objects I've built up to be "Monkeys" and objects I've built up to be "Humans" and some functions could be designed to operate on only "Humans", others on only "Monkeys", and yet others on only "Things With Arms". Whether or not the language has ever been told there is such a category of objects as "things with arms" is as irrelevant to assembly ("untyped") as it is to Javascript ("dynamic"). It's all a matter of logical integrity - and the only error would be using something that didn't have arms with that method.

So, if you consider Javascript to have some "notion of types" internally - and, hence "dynamic types" - and think this is somehow "distinctly different from an untyped system" - you should see from the above example that any "notion of types" it has internally is really irrelevant.

To perform the same operation with C#, for example, I'd NEED an interface called ICreatureWithArms or something similar. Not so in Javascript - not so in C or ASM.

Clearly, whether or not Javascript has any understanding of "types" at all is irrelevant.

沩ん囻菔务 2025-01-09 12:43:44

我不是计算机科学家,但如果“无类型”真的在计算机科学界(至少在科学出版物中)用作“动态类型”的同义词,我会感到相当惊讶,因为恕我直言,这两个术语描述了不同的概念。动态类型语言具有类型的概念,并且它在运行时强制执行类型约束(例如,在 Lisp 中,您不能将整数除以字符串而不会出现错误),而非类型语言在运行时没有任何类型的概念。所有(例如汇编程序)。甚至维基百科有关编程语言的文章 (http://en.m.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages) 也做出了这种区分。

更新:也许混乱来自这样一个事实,即某些文本在 JavaScript 中说了“变量未键入”的程度(这是事实)。但这并不自动意味着该语言是非类型化的(这将是错误的)。

I am not a computer scientist, but I would be rather surprised if "untyped" were really used as a synonym for "dynamically typed" in the CS community (at least in scientific publications) as imho those two terms describe different concepts. A dynamically typed language has a notion of types and it enforces the type constraints at runtime (you can't for example divide an integer by a string in Lisp without getting an error) while an untyped language doesn't have any notion of types at all (e.g. assembler). Even the Wikipedia article about programming languages (http://en.m.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages) makes this distinction.

Update: Maybe the confusion comes from the fact that some texts say something to the extent that "variables are not typed" in Javascript (which is true). But that doesn't automatically mean that the language is untyped (which would be false).

吹梦到西洲 2025-01-09 12:43:44

同意布伦丹的观点——上下文就是一切。

我的看法:

我记得大约在 2004 年,我很困惑,因为关于 Ruby 是非类型化还是动态类型的争论爆发了。老派的 C/C++ 人员(我就是其中之一)正在考虑编译器并说 Ruby 是无类型的。

请记住,在 C 中,没有运行时类型,只有地址,如果正在执行的代码决定将该地址处的任何内容视为不存在的内容,哎呀。这绝对是非类型化的,与动态类型化有很大不同。

在那个世界里,“打字”全都与编译器有关。 C++ 具有“强类型”,因为编译器的检查更加严格。 Java 和 C 更加“弱类型”(甚至存在关于 Java 是强类型还是弱类型的争论)。在这个连续体中,动态语言是“无类型的”,因为它们没有编译器类型检查。

今天,对于练习程序员来说,我们已经习惯了动态语言,我们显然认为无类型意味着没有编译器或解释器类型检查,这将非常难以调试。但有一段时间,这一点并不明显,而且在更理论化的计算机科学世界中,这甚至可能没有意义。

从某种深刻的意义上来说,没有什么可以是非类型化的(或者几乎没有,无论如何),因为您必须有某种意图来操纵一个值来编写一个有意义的算法。这是理论计算机科学的世界,它不涉及如何为给定语言实现编译器或解释器的细节。因此,“无类型”(可能,我不知道)在这种情况下完全没有意义。

Agree with Brendan - context is everything.

My take:

I remember being confused, circa 2004, because there were arguments breaking out about whether Ruby was untyped or dynamically typed. Old school C/C++ people (of which I was one) were thinking about the compiler and saying Ruby was untyped.

Remember, in C, there are no runtime types, there are just addresses and if the code that's executing decides to treat whatever's at that address as something it isn't, whoops. That's definitely untyped and very different from dynamically typed.

In that world, "typing" is all about the compiler. C++ had "strong typing" because the compiler's checks were more stringent. Java and C were more "weakly typed" (there were even arguments about whether Java was strongly or weakly typed). Dynamic languages were, in that continuum, "untyped" because they had no compiler type checking.

Today, for practicing programmers, we're so used to dynamic languages, we obviously think of untyped to mean no compiler nor interpreter type-checking, which would be insanely hard to debug. But there was a period there where that wasn't obvious and in the more theoretical world of CS is may not even be meaningful.

In some deep sense, nothing can be untyped (or almost nothing, anyway) because you must have some intent in manipulating a value to write a meaningful algorithm. This is the world of theoretical CS, which isn't dealing with the specifics of how a compiler or interpreter is implemented for a given language. So "untyped" is (probably, I don't know) entirely meaningless in that context.

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