This article share basic idea of functional programming for beiginner.
- Design policy to minimize ‘side effects’
- Thinking of functional programming is “To add some processing to data” like mathmatic function.
- It is important not to handle state.
Function is a mechanism that “converts” from input to output.
function: input =(converter)=> output
- It is changing some data except input one.
- It is not good to return different output when calling same function with same argument.
- Devide data and behavior. Decompose behavior into some functions without side effects
- Determine input / output of function so as not to depend on outside condition
- Use recursion and iteration methods like map, reduce to eliminate side effects
- A cause and a result is easy to understand.
- It is easy to write unit test.
- As a function type trick, it manipulates data indirectly by passing it to Runtime
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!