Functional Programming Flashcards
Define functional programming
Functional programming is a programming paradigm that binds all data to pure mathematical functions. Rather than storing and transforming data within a program, a functional program will instead display the result of a computation applied to the input values given to the function.
What are some benefits of functional programming?
- Data represented by functional programming is immutable
- Functional programs do not need to account for shared state
- Prevents side effects within a program
What is a pure function?
Pure functions are simply functions that are immutable. Given the same input they will always return the same output.
They will also never produce side effects because they do not change any other data inside of a program.
Define Recursion.
Recursive functions are functions that will continually call themselves until a base case is reached.
Explain Referential Transparency
Referential Transparency is the idea that any value or expression can be replaced by any other value or expression that results in the same value.
This concept is important to functional programming because pure functions should only represent a data value within a program without modifying other parts of the program.
Explain the statement: Functions are First-Class
This means that functions can behave as variables and can be used in a similar way.
This is possible because of the fact that given acceptable parameters, pure functions will return some sort of data that can be used within the program
Why are functions considered to be immutable data?
Data returned by a function is not being stored anywhere, rather it is simply what was returned after a defined computation was preformed on one or more inputs. Due to this fact, the data being returned cannot be changed manually.
In order to receive a different result, the programmer would have to change the inputs, or modify the function.
What is the Declarative Programming Model
A programming paradigm that expresses the logic of a computation without describing its control flow.