Skip to main content

Module Quiz

Complete this quiz after the required concept and practice pages.

Current Module Questions​

Question 1: Readability and Change​

Why is readable code mainly about changeability rather than beauty?

Answer: Most software cost comes from later understanding and modification. Readability reduces the time and risk involved in reviewing, testing, and changing behavior.

Question 2: Meaningful Names​

Rewrite this code so its role, condition, and action are explicit:

def proc(d):
for x in d:
if x["s"] == "A":
send(x["e"])

Answer: One reasonable rewrite is:

def send_activation_emails(users):
for user in users:
if user["status"] == "ACTIVE":
send(user["email"])

Question 3: Comments​

When is a comment justified?

Answer: When it explains context the code cannot express well, such as business rationale, an external constraint, or a non-obvious tradeoff. It should add why, not repeat what the next line does.

Question 4: Function Design​

Name two signals that a function may do more than one thing.

Answer: Examples include mixed abstraction levels, boolean control flags, long parameter lists, multiple visible phases, or a name that hides a side effect.

Question 5: Side Effects​

Why is this function misleading?

def get_total(cart):
cart.last_accessed_at = now()
return sum(item.price for item in cart.items)

Answer: Its name promises a query, but it also mutates state. That surprise makes the function harder to reason about and test.

Question 6: Tests​

How can a test make a small refactor safer?

Answer: A behavior-focused test records what must remain true. Running it after each structural step provides evidence that the observable behavior did not change.

Interleaved Review​

  1. Why does binary search require sorted data?
  2. What is the difference between syntax and semantics?
  3. Why does Big-O ignore constants and lower-order terms?

Answers: Binary search relies on order to discard half the candidates; syntax defines valid form while semantics defines meaning; Big-O focuses on dominant growth as input size increases.

Self-Assessment​

  • 90%+ correct: ready for the Semester 0 integration work
  • 70-89% correct: review weak areas and redo one practice page
  • Below 70%: repeat the three exercise lanes on a fresh code sample

Before advancing, confirm that your orientation project uses clear names, honest functions, and behavior-focused tests. Do not use this quiz as evidence that you completed the full Clean Code book; that reading belongs to Stage 3.