Core Definition
Which statement best defines a programming paradigm in the context of writing software?
- A general style or approach to organizing and solving problems in code, such as imperative, declarative, or functional.
- A program that translates source code into machine code at build time.
- A team’s internal naming convention for variables and files.
- A reusable package of functions called a library.
- A diagram that shows the flow of control called a flowchart.
Imperative Emphasis
When using the imperative paradigm to total a list of numbers, which approach fits the paradigm best?
- Write a loop that updates an accumulator variable step by step, changing program state explicitly.
- State that the result should equal the sum of the list without describing any steps.
- Declare facts about numbers and ask a query that returns the total.
- Attach an onSum event handler that runs only when a button is clicked.
- Describe the solution using funcitonal equations only.
Declarative Example
Which example best illustrates declarative programming when filtering data?
- Specify that you want all entries where age u003E 18, letting the system figure out how to retrieve them.
- Manually iterate over a list with an index and remove elements under 18.
- Define a class Person with fields and methods, then call filter() on instances.
- Describe parent-child relations and infer who is an adult via rules.
- Use a procedrual script that modifies a global list in place.
Object-Oriented Encapsulation
In object-oriented programming, how would a simple Car example typically organize data and behavior such as fuelLevel and drive()?
- Bundle related state and methods together inside objects that encapsulate the car’s fuelLevel and drive() behavior.
- Store fuelLevel in a global variable and define drive() as an unrelated free function.
- Represent the car only as a set of inference rules about motion.
- Keep fuelLevel immutable and implement drive() as a pure function with no observable effects.
- Trigger drive() only through event-dreven signals without any encapsulated state.
Functional Characteristics
Which feature is most associated with the functional paradigm when mapping a square function over a list without changing the original list?
- Emphasis on pure functions and immutability to avoid side effects.
- Use of class inheritance hierarchies to reuse code.
- Frequent use of goto statements to control execution flow.
- Encoding knowledge as facts and rules with backtracking.
- Defining processes around interrupts and handlers only.
Procedural Flow
A program that calls readData(), processData(), and writeData() in sequence to transform input into output best exemplifies which paradigm?
- Procedural programming, which structures code as procedures or routines.
- Declaritive programming, which avoids describing steps.
- Object-orientated programming, which models everything as objects only.
- Logic programming, which relies solely on queries and rules.
- Reactive-only programming, which requires continuous streams of events.
Logic and Queries
If you state facts like parent(A, B) and a rule that defines grandparent(X, Z) when parent(X, Y) and parent(Y, Z) are true, which paradigm are you using when you ask a query for grandparents?
- Logic programming, which derives answers from facts and inference rules.
- Imperitive programming, which updates variables in loops.
- Functional programming, which relies on higher-order pure functions.
- Procedural programming, which organizes code into subroutines.
- Event-driven programming, which responds only to GUI clicks.
Event-Driven Behavior
When a user clicks a button and an onClick handler runs to update the display, which paradigm is primarily illustrated?
- Event-driven programming, where control flow is determined by external events or signals.
- Batch processing, where work runs on a fixed schedule without interaction.
- Logic programming, where answers come from rule evaluation alone.
- Imperative-only programming, where no events are allowed.
- Decralative programming, which forbids handlers.
Mixing Paradigms
Which statement about combining programming paradigms in a single codebase is correct?
- Many real-world programs mix paradigms, such as organizing code with objects while writing some functions in a functional style.
- You must choose exactly one paradigm per program, and mixing them is invalid.
- Paradigms only apply to mathematics and have no effect on actual code.
- Using more than one paradigm makes compilation impossible.
- Paradigms are just file formats like .txt or .bin.
Why Paradigms Matter
How does choosing a programming paradigm most directly influence the software you write?
- It shapes how you structure data, organize control flow, and reason about correctness and change.
- It determines the color scheme of your editor and keyboard layout.
- It guarantees your program will be free of bugs regardless of skill.
- It fixes the output file extension your program must produce.
- It decides whether the code can be executed by any computer at all.