InterviewStack.io LogoInterviewStack.io

Clean Code and Best Practices Questions

Covers the principles and hands on practices that produce readable, maintainable, and reliable code. Core elements include intent revealing and consistent naming, small focused functions and classes that follow single responsibility, avoiding duplication through refactoring and appropriate abstractions, clear structure and separation of concerns, following language specific idioms and style guides, consistent formatting, concise comments that explain nonobvious intent, defensive programming and robust error handling, edge case handling and input validation, use of linters and static analysis, incremental refactoring techniques, and pragmatic trade offs between ideal design and delivery constraints. Interviewers will also probe involvement in code reviews, version control hygiene, code metrics, and how candidates advocate for and teach coding standards to peers.

EasyTechnical
71 practiced
Given this pseudocode that duplicates logic across two functions:
python
def transform_and_load_a(rows):
    cleaned = [clean(r) for r in rows if r is not None]
    transformed = [normalize(x) for x in cleaned]
    write_parquet(transformed, '/path/a')

def transform_and_load_b(rows):
    cleaned = [clean(r) for r in rows if r is not None]
    transformed = [normalize(x) for x in cleaned]
    write_parquet(transformed, '/path/b')
Explain a clean refactor to remove duplication, show extracted function signatures, and justify your naming choices.
MediumTechnical
64 practiced
Show a concise Python dataclass for a record with fields: id (str), timestamp (datetime), value (Optional[float]). Then sketch a `parse_record(raw: dict) -> Record` function with type hints that validates and converts raw values, raising clear exceptions on bad input. Explain how dataclasses and type hints improve readability and maintenance.
HardTechnical
92 practiced
Several critical pipeline functions have very high cyclomatic complexity, making them brittle and hard to test. Propose a concrete plan to reduce complexity without substantially increasing code size: include refactoring patterns, when to extract classes or use strategy/dispatch tables, and how to measure improvement and ensure behavior remains unchanged.
MediumTechnical
74 practiced
How would you structure a complex analytical SQL query to maximize readability and maintainability? Describe use of CTEs, descriptive aliases, and modular SQL views. Provide a high-level structure for a query that computes daily active users and retention, and explain trade-offs between readability and raw performance.
HardTechnical
64 practiced
You are the technical lead and management asks you to ship a feature this sprint. The ideal clean design requires significant refactor work; a pragmatic patch would deliver value now but add technical debt. Describe your decision framework: how you assess risk, time-to-value, communication with stakeholders, and what mitigation steps you would take if you choose the fast path (tests, tickets, timeboxed refactor).

Unlock Full Question Bank

Get access to hundreds of Clean Code and Best Practices interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.