This topic is important to me because I want to create programs that aren’t prone to errors, and build applications that are well formated.
Functional Programming Concepts. Node.Js Tutorial (Modules and require()).
Functional Programming is a programming style that views computation as the evaluation of mathematical functions and avoids using mutable data or changing the program’s state.
The first concept is pure functions.
To define what a pure function is, you have to see if its:
If our function reads external files, its not pure. (the files can be changed)
If a function relies on a random number gen, it cannot be pure.
Another concept is Immutability.
Its when its unchanging over time or unable to be changed.
When data is immutable, its ate cannot change after it’s created. If you want to change an immutable object, you don’t. You just create a new object with the new value.
Another concept is Referential Transparency.
This is a property of a function that consistently produces the same output for the same input and has no side effects.
When we write a Node.js App, we split our code in different modules.
Then we call on these modules when we need them.
We would make other ‘modules’ so we can require them to other JS, or code files, so we can keep our code clean and organized.
You would make a file and make it as a function, then we would require the function into our other file.
I want to know how to use pure functions in my own code, and the best practices.
I want to learn how to get better with making code that is reusable, and concise.