All quizzes
Free quiz · 28 questions in the bank

Clean Code quiz

Test your Clean Code knowledge with a free interactive quiz — 28 questions with answers and explanations. No signup needed to play.

Question 1/12Score 0

Which is the best test for whether a name is good, according to clean-code naming guidance?

In this round
  1. Which is the best test for whether a name is good, according to clean-code naming guidance?
  2. What is the best test for whether a function is doing "one thing," per clean-code guidance?
  3. Why does clean-code guidance favor exceptions (or explicit result/error types) over returning error codes or null from a function that can fail?
  4. A block of code has a comment reading `// check if user can edit (admin or owner)` directly above a function named `chk(u, r)`. What is the clean-code critique?
  5. Why is a boolean "flag parameter" (e.g. `save(user, true)`) considered a code smell?
  6. When is a comment most justified, per clean-code guidance?
  7. A `checkout(cart, user)` function validates the cart, computes tax, saves the order, and sends a confirmation email -- all in one function body. What clean-code principle does this violate?
  8. What is a key risk of comments that clean-code guidance warns about?
  9. A function has 7 parameters, several of them optional booleans controlling different behavior branches inside it. What does clean-code guidance suggest?
  10. A function `getUsers(list)` filters a list down to users with `status === 1`. A teammate renames it to `getActiveUsers(users)` and replaces `1` with `UserStatus.ACTIVE`. What is the primary clean-code improvement?
  11. Which version of a magic-number check is the clean-code choice? A) `if (user.orders.length > 10) applyDiscount(0.2)` B) `const VIP_ORDER_THRESHOLD = 10 const VIP_DISCOUNT_RATE = 0.2 if (user.orders.length > VIP_ORDER_THRESHOLD) applyDiscount(VIP_DISCOUNT_RATE)`
  12. A function `calculateTotal(cart)` is extracted out of a larger `checkout()` function so it can be unit tested independently. What is the primary clean-code benefit of this extraction?
Gaps to close?
Read the curated Clean Code notes — core concepts, patterns, interview prep.
Clean Code notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web