Functional Proframming Flashcards
1
Q
Describe Functional Programming (FP)
A
Applying pure functions in sequence to solve complex problems. Functions take input value and product output value without being affected by the program.
2
Q
What is a pure function?
A
- The same input of a function will always return the same output.
- Immutable variables. No input to a function is altered, but can be copied, then altered and returned.
- No side-effects… Really though, its minimize side effects - (A) Limit access to global/external scoped variables (B) Attempt to be stateless
- Pure functions are composable (A pure function can be made of other functions if they are pure)
3
Q
What are the Pros and Cons of Functional Programming?
A
Pros
* Easy to understand because not stateful/does not have side effects.
* Testing and debugging is easier, as the function is passed everything it needs and does not rely on state or have side effects.
Cons
* Writing pure functions can reduce readability for complex operations.
* Joining pure functions with the rest of application and IO operations can be difficult.
4
Q
When to use Functional Programming?
A
- Concurrency/parallelism
- Mathematical computational code
- Smaller/less feature rich applications.