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.

MediumTechnical
0 practiced
Implement a thread-safe memoization decorator in Python that caches function results based on arguments, supports a max size (LRU eviction), and is safe to use in multi-threaded data pipelines. Focus on clarity and correctness rather than extreme optimization.
EasyTechnical
0 practiced
As a data scientist working primarily in Python, explain the principles of intent-revealing and consistent naming. Given this short example notebook cell, describe concrete renaming and structural changes to make intent clear and maintainable:
python
df = pd.read_csv('data.csv')
x = df[['a','b','c']]
res = model.predict(x)
Include rules for variable names, function names, constants, and when to introduce small helper functions or classes.
HardTechnical
0 practiced
Implement a custom scikit-learn transformer SafeImputer that: (a) on fit computes per-column strategies (median for numeric, most-frequent for categorical), (b) on transform fills missing values and returns an ndarray or DataFrame matching input columns, (c) is compatible with sklearn Pipeline (get_params/set_params), and (d) validates inputs and raises descriptive errors. Include a short unit test example.
HardTechnical
0 practiced
Design an automated system that scans PRs for code smells specific to data-science code (e.g., heavy loops over dataframes, new dependencies without justification, dangling random seeds, use of print instead of logging). Describe heuristics vs ML approaches, integration points (hooks/CI), and how to present recommendations in PR comments without overwhelming developers.
EasyTechnical
0 practiced
Write a Python function signature with type hints and a detailed docstring for a function that normalizes numeric columns of a pandas DataFrame in-place or returns a copy based on a parameter. Include parameter types, return type, exceptions raised, and an example usage in the docstring.

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.