Pure Functions Identification
Which function is considered 'pure' in functional programming?
- A function that returns output only based on input and has no side effects.
- A function that modifies a global variable as it runs.
- A function that logs values to the console every time it executes.
- A function that randomly generates different results for the same input.
- A function that pauses execution for a specified amount of time.
Immutability Concept
Why does functional programming emphasize immutability when handling data in backend development?
- It prevents accidental changes and makes code more predictable.
- It increases the frequency of syntax errors.
- It allows data structures to be modified directly.
- It encourages the use of mutable variables everywhere.
- It disables all program modifications at runtime.
First-Class Functions
What does it mean when functions are described as 'first-class citizens' in a programming language?
- Functions can be assigned to variables and passed as arguments.
- Functions must always be global in scope.
- Functions can only return numeric values.
- Functions are not allowed as arguments to other functions.
- Functions can only be executed directly, not assigned.
Higher-Order Functions Usage
Which statement best describes a higher-order function in backend development?
- A function that accepts another function as an argument or returns a function.
- A function that always returns null.
- A function only used for mathematical operations.
- A function defined as a constant and never changed.
- A function that cannot be called recursively.
Side Effects Explanation
In functional programming, which of the following is an example of a side effect?
- Updating a database record inside a function.
- Calculating the square of a number without modifying anything else.
- Returning a sum of two parameters.
- Calling a function that only reads its inputs.
- Sorting an array without altering the original data.
Referential Transparency
What property is satisfied if a function always produces the same output for the same input?
- Referential transparency
- Iterative consistency
- Contextual flexibility
- Mutability invariance
- Reflected constancy
Currying Recognition
When a function transforms a function with multiple arguments into a sequence of functions each with one argument, what is this technique called?
- Currying
- Boiling
- Stirring
- Churning
- Concretizing
Recursion in Functional Programming
Why is recursion commonly used over traditional loops in functional programming languages for backend development?
- Because recursion avoids mutable state and is compatible with immutability.
- Because traditional loops run much faster.
- Because recursion requires global variables to manage state.
- Because recursion cannot be implemented with pure functions.
- Because recursion inherently produces side effects.
Function Composition Explanation
What does function composition allow you to do in functional programming?
- Combine small functions into more complex functions by chaining them together.
- Alter the syntax of a function dynamically.
- Convert functions into classes during runtime.
- Force a function to execute multiple times automatically.
- Replace all variables inside functions automatically.
Functional Approach Advantages
Which is a primary advantage of using the functional programming paradigm in backend development?
- Improved code readability and ease of testing due to pure functions.
- The necessity to rely on global mutable states.
- Automatic conversion of all data to binary.
- Mandatory use of infinite loops.
- Increased use of side effects within business logic.