What is the Substitution Model in Scala - Replacement Model

Asked

Viewed 78 times

2

Substitution Model - Replacement Model

What is the concept behind?

How It Works? What it affects the way we program in Scala

  • https://www.youtube.com/watch?v=Aai5f5RBq98

1 answer

0

I’m guessing you’re referring directly to what Martin discusses in Coursera’s book or course. Anyway the answer should not affect the context of the question so much.

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

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

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

This in practice affects the way you program (scala), since you have a 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 global state affected by their execution. You can test these functions independently. You can modularize your code more easily, since now the functions only depend on the arguments.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.