|
|
|
|
|
by ozten
4399 days ago
|
|
It is a very different way of thinking about programming, but immutable inputs remove a whole class of bugs that can happen. It is analogous to global variables. We know they are bad, because any other piece of code can change them and break our code. A variable having state is similar. When you think about what a function does or write tests... having the variable be able to have many unknown states increases the complexity. In code we write everyday, a variable might be undefined, null, a valid phone number as a string, etc. But in immutable code, if your input comes from a function that returns either None or a valid phone number as a string and no other code can tweak this... then your code becomes much easier to think about and write tests for. |
|