02 Quiz: Code Quality in Practice
October 2025 (2777 Words, 16 Minutes)
Instructions
- This quiz tests your understanding of key concepts from Chapter 02 (Code Quality in Practice)
- Each question has 4 options with exactly one correct answer
- Try to answer without referring to the lecture materials
- Focus on understanding concepts, not memorizing details
Question 1: The Reality of Working Code
What is the fundamental difference between “working code” and “professional code”?
A) Professional code runs faster and uses less memory
B) Working code meets user requirements, but professional code also meets quality standards for maintainability, readability, and team collaboration
C) Professional code is always longer and more complex
D) Working code is for students, professional code is for companies
Show Answer
Correct Answer: B
The lecture’s opening scenario demonstrates this perfectly: the Road Profile Viewer works beautifully, but fails automated quality checks. Professional code must meet both functional requirements (it works) and non-functional requirements (it’s maintainable, readable, and follows team standards). Speed (A) and length (C) aren’t the defining factors, and both students and companies can write either type (D is too simplistic).
Question 2: The Purpose of Automated Quality Checks
Why do professional development teams use automated code quality checks before allowing code merges?
A) To make developers’ lives difficult and slow down development
B) To replace human code reviewers entirely
C) To catch style issues, potential bugs, and inconsistencies early, allowing human reviewers to focus on logic and architecture
D) To enforce the use of specific programming languages
Show Answer
Correct Answer: C
Automated checks serve as the first line of defense, catching mechanical issues (style violations, unused imports, type errors) in seconds. This allows human reviewers to focus their valuable time on higher-level concerns like algorithm correctness, architecture decisions, and business logic. Automation complements humans, it doesn’t replace them (B is incorrect), and it speeds up development by catching issues early (A is incorrect).
Question 3: Import Statement Best Practices
Why does PEP 8 recommend putting imports on separate lines?
A) Python runs faster with separate import statements
B) It improves readability and makes it easier to track which modules are actually being used
C) It’s required by the Python interpreter or the code won’t run
D) Separate imports take up more lines, making the code file look more substantial
Show Answer
Correct Answer: B
The lecture demonstrates this with the example import sys,os. Separate imports make it easier to scan what’s being imported, track down unused imports, and understand dependencies at a glance. This is purely about human readability—Python will run the code either way (A and C are false), and artificially inflating line count has no value (D is incorrect).
Question 4: The Cost of Dead Code
What is the PRIMARY problem with keeping unused functions in your codebase?
A) They cause the program to crash at runtime
B) They waste disk space and make files larger
C) They create maintenance burden—someone must update them during refactoring, and they confuse future developers about what’s important
D) They automatically get executed anyway, slowing down the program
Show Answer
Correct Answer: C
The lecture’s “technical debt” section explains this clearly: dead code costs maintenance effort (updating during API changes), cognitive effort (future developers must read and understand it), and creates confusion (“Can I safely delete this?”). Dead code doesn’t execute (D is false), doesn’t crash programs (A is false), and while disk space is a minor concern, the real cost is human time (C captures the essential problem better than B).
Question 5: The 10:1 Rule
According to the lecture, what does the “10:1 Rule” refer to in software development?
A) 10% of code causes 90% of bugs
B) Code is read approximately 10 times more often than it’s written
C) Writing code takes 10 times longer than planning it
D) 10 developers can complete work 10 times faster than 1 developer
Show Answer
Correct Answer: B
The lecture explicitly states: “For every hour spent writing code, approximately 10 hours are spent reading it.” This fundamental insight explains why code quality optimizes for reading, not writing. The code you write once will be read during debugging, code review, feature additions, bug fixes, and onboarding—accumulating far more reading time than writing time.
Question 6: Whitespace and Readability
Why does proper whitespace around operators (e.g., x = 5 instead of x=5) improve code quality?
A) Python requires spaces or it produces syntax errors
B) Spaces make the file size larger, which improves caching
C) Whitespace creates visual boundaries that help the brain parse code into “chunks,” reducing cognitive load by approximately 30%
D) It’s purely aesthetic with no measurable impact
Show Answer
Correct Answer: C
The lecture cites cognitive psychology research showing that whitespace creates natural boundaries between information chunks, making code 30% faster to parse visually. This isn’t just aesthetics (D is incorrect)—it’s about reducing the mental effort required to understand code. Python doesn’t require these spaces syntactically (A is false), and file size is irrelevant (B is nonsensical).
Question 7: Naming Conventions as Shared Language
In Python, what does PascalCase (like HelperFunction) typically indicate?
A) A function that should be used everywhere in the code
B) A class definition
C) A constant value that never changes
D) A variable that stores helper data
Show Answer
Correct Answer: B
Python’s naming conventions form a shared language: PascalCase signals classes, snake_case signals functions/variables, and UPPER_CASE signals constants. When you see HelperFunction, your brain expects a class. Using it for a function creates cognitive dissonance and violates the Principle of Least Astonishment. The lecture demonstrates how breaking these conventions wastes developer time and creates debugging confusion.
Question 8: Line Length Limits
What is the MAIN reason for limiting line length to 79-88 characters?
A) Older monitors can’t display longer lines
B) Python’s interpreter processes shorter lines faster
C) It enables side-by-side code comparison, split-screen development, and improves readability—especially during code reviews and diffs
D) Shorter lines use less disk space
Show Answer
Correct Answer: C
The lecture provides specific scenarios: side-by-side code review, split-screen development, and readable diffs. Long lines force horizontal scrolling and make it difficult to compare versions or work with multiple files simultaneously. Research shows comprehension drops with lines longer than 60-80 characters. This isn’t about hardware limitations (A) or performance (B and D are false).
Question 9: The Cost of Bugs Over Time
According to the lecture’s bug cost analysis, when is it MOST expensive to fix a bug?
A) During initial development when writing the code
B) During code review before merging
C) In production after users encounter it
D) All bugs cost the same to fix regardless of when they’re found
Show Answer
Correct Answer: C
The lecture presents a table showing bug costs grow exponentially: fixing during development takes minutes, code review takes hours, production bugs take days and cause user impact, reputation damage, and potential data loss. Early detection through automated tools prevents these expensive production bugs. Option D contradicts the entire premise of the lecture about early quality checks.
Question 10: Consistency and Cognitive Load
How does code consistency reduce cognitive load for developers?
A) Consistent code executes faster because the CPU recognizes patterns
B) Pattern-matching brains recognize consistent patterns instantly, spot anomalies quickly, and understand intent faster without context-switching
C) Consistency means all code looks exactly the same, so developers can copy-paste freely
D) It doesn’t—inconsistency is better because it makes code more unique
Show Answer
Correct Answer: B
The lecture explains that your brain is a pattern-matching machine. Consistent code allows instant pattern recognition, while inconsistent code forces your brain to parse each line individually and context-switch constantly. This has nothing to do with CPU performance (A is false), isn’t about copy-pasting (C misses the point), and D contradicts the entire principle.
Question 11: What is PEP 8?
What is PEP 8 in the context of Python development?
A) A Python library for formatting code automatically
B) Python’s official style guide that defines community-agreed standards for code formatting and style
C) A type checking tool that validates function signatures
D) The eighth version of the Python programming language
Show Answer
Correct Answer: B
PEP 8 (Python Enhancement Proposal 8) is Python’s official style guide, written by Guido van Rossum (Python’s creator) and others. It’s not a tool (A and C are tools like Ruff and Pyright), and it’s definitely not a Python version (D confuses PEP with version numbers). PEP 8 forms the foundation that tools like Ruff use to enforce quality standards.
Question 12: Automation vs. Manual Review
What is the key advantage of automated quality checks over manual code review?
A) Automated checks completely eliminate the need for human reviewers
B) Automation is consistent, fast, scales effortlessly, and catches mechanical issues instantly—freeing humans to focus on logic and architecture
C) Automated tools are better at understanding business requirements than humans
D) Manual review is outdated and should never be used
Show Answer
Correct Answer: B
The lecture’s “Automation Scales, Humans Don’t” section shows how automated checks save massive amounts of time (16.7 hours/week for a 10-person team) by handling mechanical checks consistently and instantly. This doesn’t eliminate human review (A and D are incorrect)—it makes human review more effective by letting reviewers focus on high-level concerns. Automation excels at mechanical checks, not understanding business logic (C is backwards).
Question 13: Unused Imports Problem
Why do unused imports create problems in production code?
A) They cause immediate runtime errors that crash the program
B) Python refuses to execute files with unused imports
C) They waste memory/startup time, create confusion about dependencies, and accumulate as technical debt over time
D) Unused imports are not actually a problem—all imports should be kept just in case
Show Answer
Correct Answer: C
The lecture explains that unused imports waste resources (though minor in small programs), create confusion (“Why do we need this?”), and accumulate over time as technical debt. They don’t cause crashes (A is false), Python will execute the code fine (B is false), and intentionally keeping unused imports (D) violates the principle of clean code.
Question 14: Early Detection Value
According to the lecture’s type checking example, what is the PRIMARY benefit of catching errors early through automated tools?
A) It makes the code run faster in production
B) It eliminates all possible bugs from the codebase
C) Issues caught in seconds during development don’t become expensive production bugs that take days to debug and fix
D) It allows developers to skip writing tests
Show Answer
Correct Answer: C
The lecture’s find_intersection example shows how a type checker catches a return value mismatch in “2 seconds, not 2 weeks.” Early detection prevents the exponential cost growth of bugs reaching production. This isn’t about runtime performance (A), can’t catch all bugs (B is impossible), and doesn’t replace testing (D is dangerous thinking).
Question 15: Code Review Time Allocation
In a workflow with automated quality checks, what should human code reviewers focus on?
A) Checking for missing spaces around operators
B) Counting line lengths to ensure they’re under 88 characters
C) High-level concerns like algorithm correctness, architecture decisions, business logic, and edge cases
D) Finding unused imports and fixing naming conventions
Show Answer
Correct Answer: C
The lecture’s automation section emphasizes that automated tools handle mechanical checks (A, B, D) instantly, freeing human reviewers to focus on complex concerns that require domain knowledge, experience, and judgment. This is the key value proposition: automation handles what computers do best (pattern matching), humans handle what humans do best (understanding context and intent).
Question 16: The Principle of Least Astonishment
What does the “Principle of Least Astonishment” mean in code quality?
A) Code should contain as many surprises as possible to keep developers interested
B) Code should behave as readers expect based on established conventions—breaking conventions creates confusion and wastes time
C) Developers should be surprised by how elegant the code is
D) Code should use unexpected approaches to solve problems creatively
Show Answer
Correct Answer: B
The lecture introduces this principle when discussing naming conventions: code should behave as readers expect. When DatabaseConnection looks like a class but is actually a function, it violates expectations and causes confusion. This principle argues for predictability and convention-following, not surprises (A and C are opposite), and creativity shouldn’t come at the cost of clarity (D misses the point).
Question 17: Code Comparison and Diffs
Why are short, well-formatted lines especially important for code diffs (comparing versions)?
A) Diff tools only work with short lines
B) Changes buried in long lines are hard to spot, while changes in well-formatted code are immediately obvious
C) Short lines create smaller Git repositories
D) Diff tools automatically reject files with long lines
Show Answer
Correct Answer: B
The lecture demonstrates this with the marker dictionary example: spotting color='red' → color='blue' in a 120-character line is difficult, but when each property is on its own line, the change jumps out immediately. Diff tools work fine with any line length (A and D are false), and repository size isn’t the concern (C is incorrect).
Question 18: Reading vs. Writing Optimization
Why does code quality focus on optimizing for READING rather than WRITING?
A) Because reading code is more difficult than writing code
B) Because code is read many more times than it’s written—during debugging, review, maintenance, and onboarding
C) Because most developers prefer reading to writing
D) Because writing code is already optimized by IDEs
Show Answer
Correct Answer: B
The lecture’s 10:1 rule explains this: every hour of writing code results in approximately 10 hours of reading it across its lifetime (debugging, review, feature additions, bug fixes, onboarding). This mathematical reality drives the focus on readability. Options A, C, and D miss the fundamental time-allocation insight that drives this principle.
Question 19: Technical Debt Metaphor
In the lecture’s discussion of dead code, what does “technical debt” mean?
A) Money owed to developers for writing the code
B) Code that needs to be paid for with a license
C) Shortcuts and quality issues that create future maintenance costs—like financial debt, it accumulates “interest” over time
D) The amount of time spent debugging
Show Answer
Correct Answer: C
Technical debt is a metaphor: just as financial debt accumulates interest, code quality issues accumulate maintenance costs over time. Dead code, poor naming, missing documentation—all create future costs when someone must update, understand, or work around them. This isn’t about literal money (A and B) or just debugging time (D is too narrow).
Question 20: The Purpose of Style Guides
What is the ULTIMATE purpose of following a style guide like PEP 8?
A) To make all Python code look identical so no one knows who wrote it
B) To create a shared language and consistent expectations that reduce cognitive load and improve team collaboration
C) To make Python code look like Java code
D) To slow down development by adding extra rules
Show Answer
Correct Answer: B
The lecture emphasizes that PEP 8 creates a “common language” for Python developers worldwide. Consistency reduces cognitive load, speeds up comprehension, and enables effective collaboration across teams and projects. Anonymity (A) and similarity to other languages (C) aren’t goals, and the rules speed up development by preventing issues (D is backwards).
Scoring Guide
- 18-20 correct: Excellent! You have a strong grasp of code quality principles and understand why they matter beyond just following rules
- 15-17 correct: Good understanding! Review the areas you missed, particularly the business case and cognitive science aspects
- 12-14 correct: Fair understanding. Revisit the lecture sections on why code quality matters and the principles behind specific rules
- Below 12: Please review the lecture carefully. Focus on understanding the reasoning behind quality standards, not just memorizing rules. Reach out if you need clarification!
Key Takeaways to Remember
- Working vs. Professional - Code that works isn’t enough; professional code meets quality standards for maintainability and collaboration
- The 10:1 Rule - Code is read 10x more than it’s written, so optimize for reading, not writing
- Early Detection - Bugs caught in development cost minutes; bugs in production cost days
- Automation Scales - Automated checks handle mechanical issues consistently, freeing humans for high-level review
- Consistency Reduces Load - Pattern-matching brains process consistent code 30% faster than inconsistent code
- PEP 8 Foundation - Python’s official style guide creates a shared language for all Python developers
- Dead Code Costs - Unused code creates maintenance burden, cognitive confusion, and technical debt
- Whitespace Matters - Proper spacing creates visual boundaries that help brains parse code into chunks
- Naming Conventions - PascalCase/snake_case/UPPER_CASE signal different code elements; violations create astonishment
- Line Length Logic - Short lines enable side-by-side comparison, split screens, and readable diffs