简体   繁体   English

Erlang 中的进程/消息和 Smalltalk 中的对象/消息有什么区别?

[英]What is the difference between processes/messages in Erlang and objects/messages in Smalltalk?

I'm trying to understand difference between objects/messages in Smalltalk and processes/messages in Erlang .我试图了解Smalltalk中的对象/消息和Erlang中的进程/消息之间的区别。 I read the following post on the topic .阅读了有关该主题的以下帖子

As far as I understand, in Smalltalk, everything is an object , and everything has the same "object/message" abstraction - even the number 1 is an object that can only be reached with message passing.据我了解,在 Smalltalk 中,一切都是object ,并且一切都具有相同的“对象/消息”抽象——即使数字1也是 object ,只能通过消息传递来实现。 Is 1 a process in Erlang/Elixir? 1是 Erlang/Elixir 中的一个进程吗? Is everything in Erlang a response to message/program paradigm? Erlang 中的所有内容都是对消息/程序范例的响应吗? Can you send a message to a number in Erlang?可以发短信到Erlang中的号码吗?

Thanks a lot.非常感谢。

Processes in Erlang and Objects in Smalltalk are indeed the same thing. Erlang 中的进程和 Smalltalk 中的 Objects 确实是一回事。

At first glance, this is not terribly surprising: Erlang is an Actor Model language.乍一看,这并不奇怪:Erlang 是一个Actor Model语言。 The Actor Model was invented by Carl Hewitt, who based the message-driven evaluation model on Smalltalk's message-driven evaluation model. Actor Model 由 Carl Hewitt 发明,他基于 Smalltalk 的消息驱动评估 model 的消息驱动评估 model。 (Really, Actors and Objects are the same thing; they only differ in some details.) Alan Kay, in turn, was influenced by Carl Hewitt's PLANNER, when he designed Smalltalk. (实际上,Actor 和 Objects 是一回事;它们只是在某些细节上有所不同。)反过来,Alan Kay 在设计 Smalltalk 时受到了 Carl Hewitt 的 PLANNER 的影响。

So, there is a close relationship between Actors and Objects, and therefore, it should not be surprising that Erlang's Processes and Smalltalk's Objects are so similar.因此,Actor 和 Objects 之间有着密切的关系,因此 Erlang 的 Processes 和 Smalltalk 的 Objects 如此相似也就不足为奇了。

Except for one thing: the designers of Erlang didn't know about the Actor Model ,.!除了一件事:Erlang 的设计者不知道演员 Model ,.! They only learned about it later, particularly when Joe Armstrong wrote his PhD Thesis under Seif Haridi (co-author of the definitive book on Programming Paradigms) in the late 1990s.他们是后来才知道的,尤其是在 1990 年代后期,乔·阿姆斯特朗在 Seif Haridi(关于编程范式的权威书籍的合著者)的指导下撰写了他的博士论文。

Joe Armstrong wrote an article in which he strongly advocated against OO ( Why OO Sucks ), but he later changed his mind when he realized that Erlang is actually very object-oriented. Joe Armstrong 曾写过一篇文章,强烈反对 OO( Why OO Sucks ),但后来他意识到 Erlang 实际上非常面向对象时改变了主意。 In fact, he even went so far as to claim that Erlang is the only object-oriented language in this interview with Joe Armstrong and Ralph Johnson .事实上,在这次采访 Joe Armstrong 和 Ralph Johnson 时,他甚至声称 Erlang 是唯一的面向对象语言。

This is an interesting case of what evolutionary biologists would call convergent evolution , ie two unrelated species evolving to be similar in response to similar external pressures.这是进化生物学家所说的趋同进化的一个有趣案例,即两个不相关的物种在相似的外部压力下进化为相似的。

There are still a lot of relationships between Erlang and Smalltalk, though: Erlang和Smalltalk之间还是有很多关系的,不过:

Erlang started out as a concurrency extension to Prolog (and even when Erlang became its own separate language, the first implementations were written in Prolog) and is still to this day heavily rooted in Prolog. Erlang started out as a concurrency extension to Prolog (and even when Erlang became its own separate language, the first implementations were written in Prolog) and is still to this day heavily rooted in Prolog. Prolog is heavily influenced by Carl Hewitt's PLANNER. Prolog 深受 Carl Hewitt 的 PLANNER 的影响。

Smalltalk was also heavily influenced by what would later become the ARPANet (and even later the Internet); Smalltalk 也深受后来的 ARPANet(甚至后来的 Internet)的影响。 Erlang was designed for networked systems. Erlang 专为联网系统而设计。

However, one of the important differences between Erlang and Smalltalk is that not everything is a Process.但是,Erlang 和 Smalltalk 之间的重要区别之一是并非所有事物都是进程。 1 is a number, not a process. 1是一个数字,而不是一个过程。 You can't send a message to a number.您无法向号码发送消息。

There are multiple "layers" of Erlang: Erlang有多个“层”:

  • Functional Erlang : a mostly typical, dynamically-typed functional language with some "oddities" inherited from Prolog, eg unification.函数式 Erlang :一种最典型的动态类型函数式语言,具有从 Prolog 继承的一些“奇怪”,例如统一。
  • Concurrent Erlang : Functional Erlang + Processes and Messages.并发 Erlang :功能 Erlang + 进程和消息。
  • Distributed Erlang : Concurrent Erlang + Remote Processes.分布式 Erlang :并发 Erlang + 远程进程。
  • Fault-Tolerant Erlang : Distributed Erlang + certain Design Patterns codified in the OTP libraries, eg supervisor trees and gen_server .容错 Erlang :分布式 Erlang + 在 OTP 库中编码的某些设计模式,例如主管树和gen_server

A Fault-Tolerant system written in Erlang/OTP will typically look like something we might recognize as "Object-Oriented".用 Erlang/OTP 编写的容错系统通常看起来像我们可以识别为“面向对象”的东西。 But the insides of those objects will often be implemented in a more functional than object-oriented style.但是这些对象的内部通常会以比面向对象的风格更实用的方式实现。

Interestingly, the "evolutionary pressure" that Erlang was under, in other words, the problem Erlang's designers were trying to solve (reliability, replication, redundancy, …) is the same pressure that led to the evolution of cells.有趣的是,Erlang 所承受的“进化压力”,换句话说,Erlang 的设计者试图解决的问题(可靠性、复制、冗余……)与导致细胞进化的压力相同。 Alan Kay minored in microbiology, and explicitly modeled OO on biological cells. Alan Kay 辅修微生物学,并明确地将 OO 建模为生物细胞。 This is another parallel between Erlang and Smalltalk.这是 Erlang 和 Smalltalk 之间的另一个相似之处。

I wrote a little bit about this in another answer of mine .我在我的另一个答案中写了一些关于此的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在两个单独的对象之间发送消息 - Sending messages between two separate objects 在两个 JPanel 对象之间发送消息 - Sending messages between two JPanel objects 这两种方法有什么区别[Smalltalk Best Practice Patterns - Kent Beck]? - What is the difference between those two approaches [Smalltalk Best Practice Patterns - Kent Beck]? 如何在 Java 中的对象之间传递消息 - How can I pass messages between objects in Java 在Python中“向对象发送消息”的好例子是什么? - What would be a good example of “sending messages to objects” within Python? Smalltalk和Java中的OO有哪些主要区别? - What are the key differences between OO in Smalltalk and Java? R对象中的$和attr(,var)有什么区别? - What the difference between $ and attr( , var) in objects of R? 使用var与函数声明javascript对象有什么区别? - What is the difference between declaring javascript objects with var vs. with function? 在用OOP语言命名对象时,“map”和“transform”之间有什么区别? - When naming objects in an OOP language, what is the difference between “map” and “transform”? Self和Smalltalk之间的差异 - Differences between Self and Smalltalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM