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
Which is the best test for whether a name is good, according to clean-code naming guidance?
What is the best test for whether a function is doing "one thing," per clean-code guidance?
Why does clean-code guidance favor exceptions (or explicit result/error types) over returning error codes or null from a function that can fail?
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?
Why is a boolean "flag parameter" (e.g. `save(user, true)`) considered a code smell?
When is a comment most justified, per clean-code guidance?
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?
What is a key risk of comments that clean-code guidance warns about?
A function has 7 parameters, several of them optional booleans controlling different behavior branches inside it. What does clean-code guidance suggest?
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?
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)`
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?