The Purpose of Single Assignment

前端 未结 3 1853
误落风尘
误落风尘 2021-01-02 12:21

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 sing

3条回答
  •  温柔的废话
    2021-01-02 13:03

    Because of Single Assignment, Side effects are so minimal. Infact, its so hard to write code with race conditions or any side effects in Erlang. This is because, the Compiler easilly tells un-used variables, created terms which are not used, shadowed variables (especially inside funs ) e.t.c.

    Another advantage that Erlang gained in this is Referential Transparency. A function in Erlang will depend only on the variables passed to it and NOT on global variables, except MACROS (and macros cannot be changed at run-time, they are constants.).

    Lastly, if you watched the Erlang Movie, the Sophisticated Error Detection Mechanism which was built into Erlang depends so much on the fact that in Erlang, variables are assigned Once.

提交回复
热议问题