单一作业的目的 [英] The Purpose of Single Assignment
问题描述
我真的很困惑他们为什么这样做。单一作业的目的是什么?可以从中获得什么好处?
不可变性(你称之为单一作业),简化了很多事情,因为它需要从您的程序中删除时间变量。
例如,在数学中,如果你说
x = y
您可以替换 x
为 y
,无处不在。在操作编程语言中,您无法确保此等式成立:存在与每行代码相关联的时间(状态)。这个时间状态也让门打开了不需要的副作用,这是敌方号码一个模块化和并发性。
有关更多信息,请参阅: http://mitpress.mit.edu/sicp/full-text/book/book-ZH-20.html#%_sec_3.1.1
I'm currently trying to master Erlang. It's the first functional programming language that I look into and I noticed that in Erlang, each assignments that you do is a single assignment. And apparently, not just in Erlang, but in many other functional programming languages, assignments are done through single assignment.
I'm really confused about why they made it like that. What exactly is the purpose of single assignment? What benefits can we get from it?
Immutability (what you call single assignment), simplifies a lot of things because it takes out the "time" variable from your programs.
For example, in mathematics if you say
x = y
You can replace x
for y
, everywhere. In operational programming languages you can't ensure that this equality holds: there is a "time" (state) associated with each line of code. This time state also leaves the door open to undesired side effects which is the enemy number one of modularity and concurrency.
For more information see this: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%_sec_3.1.1
这篇关于单一作业的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!