BrainTok
ENESIT

Programming Languages and Compilers: Programming paradigms · Imperative and Declarative Styles

How imperative code spells out steps that change state while declarative code states the result and leaves the how to the system.

Programming Languages and Compilers · 27 questions

Try 3 questions

1. What is the defining trait of imperative programming?

  1. Step-by-step commands that change program state
  2. A description of the result, not the steps
  3. Code organized only around reusable objects
Show the answer

Answer: Step-by-step commands that change program state

Imperative code tells the machine how to proceed: a sequence of statements, each updating variables or memory.

2. A query reads: SELECT name FROM users WHERE age > 30. Which style does it illustrate?

  1. Imperative, because it runs in order
  2. Object-oriented, because it names a table
  3. Declarative, because it states the wanted result
Show the answer

Answer: Declarative, because it states the wanted result

The query says which rows and columns are wanted but never says how to find them; that is the essence of declarative code.

3. When you run a declarative database query, what usually decides whether to use an index or scan the whole table?

  1. The operating system's file cache
  2. The database's query optimizer
  3. The programmer, through the order of conditions
Show the answer

Answer: The database's query optimizer

Because the query only states the result, the engine's optimizer chooses the execution plan, such as using an index.

The rest of the quiz, a few questions at a time

BrainTok asks a few questions from quizzes like these before the apps you choose open, so your screen time turns into learning. For iPhone.

Join the beta

More Computer Science quizzes