What is the Substitution Model in Scala - Substitution Model

2

Substitution Model - Replacement Template

What is the concept behind?

How Does It Work? In what it affects the way we program in Scala

    
asked by anonymous 08.06.2015 / 04:13

1 answer

0

I'm guessing you're referring directly to what Martin discusses in the Coursera book or course. Anyway the answer should not affect the context of the question either way.

The main idea is that the construction of expressions is done from other expressions that represent some value independent of any external context, just like it does in mathematics.

For example. In the expression 4 + RaizQuadrada(25) , we can substitute 4 + 5 without any damage to the final value. We can also replace% with%. The RaizQuadrada(16) + RaizQuadrada(25) function does not depend on any external elements. We can say that RaizQuadrada without worrying about any global variable / state.

This means that when constructing our functions with this principle in mind, a function must return only a value that depends only on the arguments passed to it. And that this function can be referenced countless times without changing the result or any state external to it.

This affects in practice the way to program (in scala), since you have the guarantee that you can combine functions the way you want without worrying about the order in which they will be called, since there is no state affected by their execution. You can test these functions independently. You can modularize your code more easily, since functions now depend on the arguments.

    
06.02.2016 / 19:21