Functional Programming Skills
- 45Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
How can functional programming be understood without relying on a single formal definition?
45 questions
- 1
How can functional programming be understood without relying on a single formal definition?
Model answer
It can be understood as a set of skills that functional programmers use more often than programmers working in other paradigms.
Explanation
This approach avoids disagreements over what does or does not count as functional programming and focuses instead on practical programming abilities.
- 2
Are functional programming skills incompatible with object-oriented programming? Explain.
Model answer
No. Functional programming skills can be mixed with object-oriented skills such as encapsulation and object-oriented modeling.
Explanation
Programming paradigms can be viewed as collections of skills, allowing useful techniques from different paradigms to be combined.
- 3
What five major skills are emphasized in functional programming?
Model answer
They are distinguishing actions, calculations, and data; working with immutable values; using and creating higher-order calculations and actions; data modeling; and functional architecture.
Explanation
These skills range from basic distinctions about code behavior to advanced techniques for modeling data and designing systems.
- 4
Why is distinguishing actions, calculations, and data considered a foundational functional programming skill?
Model answer
It allows programmers to recognize the different behaviors in their code and handle the more predictable parts separately from the parts affected by time or side effects.
Explanation
Functional programming emphasizes identifying which code is data, which code is a calculation, and which code is an action.
- 5
Why are data and calculations generally easier to work with than actions?
Model answer
They are easier to test and reuse because their behavior does not depend on when they are run.
Explanation
Actions can vary depending on timing and execution context, while data and calculations are more predictable.
- 6
How do functional programming skills relate to other programming paradigms?
Model answer
They can be used together with skills from other paradigms rather than replacing or contradicting them.
Explanation
For example, functional techniques can coexist with object-oriented encapsulation and modeling.
- 7
What is a calculation in functional programming?
Model answer
A calculation is a computation from inputs to outputs that produces the same result whenever it receives the same arguments.
Explanation
Calculations are often called pure functions, although a calculation is not necessarily represented as a function in every language.
- 8
What is an action in functional programming?
Model answer
An action is an operation whose result or effect can depend on when it is performed.
Explanation
Actions are often associated with impure functions, but they may also be operators or other constructs rather than functions.
- 9
Why is the distinction between actions and calculations important when organizing code?
Model answer
Calculations are predictable and reusable, whereas actions require careful control of when, how, and how often they are executed.
Explanation
The timing and repetition of actions can affect program behavior, making them more difficult to test and reason about.
- 10
How should code generally be distributed between actions and calculations?
Model answer
Programmers should keep actions small and move as much logic as possible into calculations.
Explanation
Reducing the amount of code in actions limits the difficult, timing-sensitive part of the system and places more logic in predictable calculations.
- 11
Why should programmers spend extra effort verifying actions?
Model answer
Because an action's behavior can depend on when it is called, how it is called, and how many times it is called.
Explanation
Errors in these aspects can change the behavior of the system even when the underlying calculation is correct.
- 12
Classify the arithmetic operators + and ++ according to the action-calculation distinction.
Model answer
+ is a calculation because it produces a predictable result from its inputs, while ++ is an action because it changes a value.
Explanation
The distinction applies to operators as well as functions; calculations do not necessarily have to be implemented as functions.
- 13
What does it mean for a value to be immutable?
Model answer
An immutable value cannot be changed after it has been created; a modification requires creating a new value instead.
Explanation
Immutability preserves records rather than allowing existing data to be overwritten freely.
- 14
Why must software teams deliberately develop practices for working with immutable data?
Model answer
Computer memory is mutable, so software systems need a separate discipline, language feature, or database mechanism to preserve data from arbitrary changes.
Explanation
Unlike physical records that can be protected through archival practices and access rules, memory can normally be overwritten.
- 15
How does working with immutable values typically represent a modification?
Model answer
It generally creates copies of the affected data rather than changing the original value in place.
Explanation
The original record remains preserved while the new version represents the modification.
- 16
Why is nested data especially challenging when using immutable values?
Model answer
Changing a deeply nested item may require deciding which parts of the surrounding data structure must be copied to construct a new complete structure.
Explanation
For example, changing an employee's salary requires working through the company and employee structures without mutating the originals.
- 17
In an immutable company structure, what must be considered when giving one employee a raise?
Model answer
The programmer must determine how to copy the relevant parts of the company and employee structure so the new salary is represented without changing the original data.
Explanation
This problem illustrates the practical skill of updating nested immutable data.
- 18
How would giving every employee a 10% raise illustrate immutable-data programming?
Model answer
The programmer must create a new company structure containing updated salary values while preserving the original company, employee, and salary values.
Explanation
The operation involves traversing nested data and constructing a modified copy rather than updating salaries in place.
- 19
What is the central discipline required when programming with immutable data?
Model answer
The programmer must learn to preserve existing values and represent changes by constructing new values.
Explanation
This discipline may be enforced by the programming team, the language, or the database.
- 20
What makes a calculation or action higher-order?
Model answer
It can be treated like any other value: it can be passed as an argument, returned from a function, or stored in a variable.
Explanation
Higher-order behavior makes functions and actions available for ordinary data-like manipulation.
- 21
What are the four related abilities included under the higher-order programming skill?
Model answer
They are using higher-order calculations, using higher-order actions, creating higher-order calculations, and creating higher-order actions.
Explanation
The skill includes both applying existing higher-order behavior and designing new behavior that operates on calculations or actions.
- 22
How does passing behavior to another function increase programming flexibility?
Model answer
It allows a function to operate on behavior supplied by the caller rather than being hard-coded for one specific operation.
Explanation
This enables general mechanisms to be reused with different calculations or actions.
- 23
How can higher-order programming make an action idempotent or more reliable?
Model answer
A higher-order operation can wrap an action and add behavior such as making it safe to repeat or retrying it three times when it fails.
Explanation
The added behavior can be defined once and applied consistently instead of being rewritten separately for every action.
- 24
Why is a higher-order retry mechanism preferable to writing separate retry code for every action?
Model answer
It centralizes the retry behavior, reduces boilerplate, and allows the same mechanism to work consistently across many actions.
Explanation
Without higher-order abstraction, programmers would need bespoke code to retry each action individually.
- 25
What roles do
map,filter, andreduceplay in functional programming?Model answer
They are higher-order functions that take functions as inputs and help construct data-transformation pipelines.
Explanation
These operations use functions as values to process sequences in a compositional way.
- 26
How can higher-order actions support compositional error handling?
Model answer
They allow sequences of actions, including retry behavior and failure responses, to be defined as reusable compositions rather than as one-off top-down code.
Explanation
The behavior associated with actions can be manipulated and combined at a higher level.
- 27
What does a function that returns the derivative of an unknown function demonstrate?
Model answer
It demonstrates that functions can be passed as values and that a function can construct and return another function based on its input.
Explanation
The input function could be any mathematical function, so the derivative-producing function operates at a higher level of abstraction.
- 28
What is data modeling?
Model answer
Data modeling is the process of structuring measurements and facts about the real world into concrete representations that software can use effectively.
Explanation
It connects real-world situations and processes to usable data structures in a program.
- 29
What is the primary goal of effective data modeling?
Model answer
The goal is to structure available data so that it can be used effectively for the intended operations.
Explanation
A suitable representation makes the relevant information accessible and supports the required computations or processes.
- 30
What is public-facing data modeling?
Model answer
It is the design of data that leaves a library or server as part of an API.
Explanation
Because other developers or systems must consume it, public-facing data has design constraints related to communication and understanding.
- 31
Why should public-facing data be human-readable?
Model answer
Developers on the other side of the API must be able to understand and work with the data, whether they write it directly or generate it through a program.
Explanation
Human readability is an important design constraint for data used across a public interface.
- 32
What is internal data modeling?
Model answer
It is the design of data structures used inside a system to support internal operations efficiently.
Explanation
For example, a search process may require a representation that makes searching efficient and keeps all necessary data available.
- 33
How do the design priorities of public-facing and internal data models differ?
Model answer
Public-facing models prioritize clarity and human readability, while internal models prioritize efficient operations and the availability of needed information.
Explanation
The model's location and users determine its design constraints.
- 34
Why is data modeling considered a more advanced functional programming skill than distinguishing actions, calculations, and data?
Model answer
It involves designing effective representations for complex real-world problems, whereas distinguishing computational categories is an earlier foundational step.
Explanation
The skills build upward from identifying basic code behavior to designing data structures for complete systems.
- 35
Why are architectural principles needed as a software system grows?
Model answer
Without architectural principles, increasing amounts of code can become unmanageable and the system may fail to scale effectively.
Explanation
Small programs may fit in one file, but larger systems require deliberate organization.
- 36
What is the basic idea of reactive data architecture?
Model answer
Events are generated and consumed, changes to centralized state produce a view of the world, and that view is projected onto an interface such as a GUI.
Explanation
The architecture forms a cycle in which reactions to data changes drive the displayed result.
- 37
What drives updates in a reactive architecture?
Model answer
Updates are driven by reactions to events and changes in data or centralized state.
Explanation
The system modifies state in response to events and then generates a new projection of that state.
- 38
What are the three main layers of Onion Architecture?
Model answer
They are the outer interaction layer, the middle business rule layer, and the inner domain layer.
Explanation
Each layer has a distinct responsibility, and additional subdivisions can be added within the three main layers.
- 39
What responsibility belongs to the interaction layer in Onion Architecture?
Model answer
It contains actions that communicate with the outside world and receive external messages.
Explanation
The interaction layer connects the internal system to external APIs, users, and other sources of input.
- 40
What responsibility belongs to the business rule layer in Onion Architecture?
Model answer
It contains calculations representing changing business requirements, such as payroll calculations and vacation policies.
Explanation
This layer is composed of calculations rather than actions and is called by the interaction layer.
- 41
What responsibility belongs to the domain layer in Onion Architecture?
Model answer
It contains the relatively timeless domain model, such as the idea that employees receive salaries and vacation.
Explanation
The domain layer represents stable concepts that business rules use rather than rapidly changing policies.
- 42
How does Onion Architecture separate parts of a system according to how quickly they change?
Model answer
The interaction layer changes most rapidly, business rules change less rapidly, and the domain model changes least frequently.
Explanation
External APIs may change often, business policies may change periodically, and core domain concepts are comparatively stable.
- 43
Why should actions generally be placed in the outer interaction layer of Onion Architecture?
Model answer
Actions interact with changing external systems, so isolating them at the outside limits the effect of API and communication changes on the rest of the system.
Explanation
The inner business and domain layers can remain more stable when external interactions are kept at the boundary.
- 44
How do business rules differ from domain concepts in the Onion Architecture example?
Model answer
A business rule determines details such as how much vacation an employee receives, while the domain model represents the more stable fact that employees receive vacation.
Explanation
Policies are changeable calculations, whereas the domain model captures enduring concepts that remain meaningful even when policy values change.
- 45
Why can unusual business cases still fit within the domain model?
Model answer
Even an unusual value, such as employees receiving zero vacation or zero salary, can still be represented by the model's underlying concepts and data types.
Explanation
The unusual case changes the value or rule but does not necessarily invalidate the domain model itself.

Ask anything
We've read this whole study set, so questions about it get the best answers.