Code Review and Best Practices Flashcards
What is code review, and why is it important?
Code review is the process of systematically examining code to identify and fix issues, ensure quality, and share knowledge among team members.
Name some benefits of performing regular code reviews.
Improved code quality, knowledge sharing, catching bugs early, consistent coding standards, and fostering collaboration.
Explain the “Single Responsibility Principle” and why it’s important.
The SRP states that a class or module should have only one reason to change. This promotes maintainability and reduces the impact of changes.
What is the “Don’t Repeat Yourself” (DRY) principle?
DRY emphasizes not duplicating code in a codebase to avoid maintenance challenges and ensure consistency.
How can you ensure consistent coding style within a development team?
By using coding guidelines, style analyzers, and tools like EditorConfig.
Why is it important to handle exceptions appropriately in your code?
Proper exception handling enhances the robustness of your application and improves error reporting
What is the purpose of using version control systems like Git in code development?
Version control enables tracking changes, collaboration, and reverting to previous states.
How do you handle sensitive data like connection strings and API keys in your application?
Store sensitive data in environment variables or configuration files outside the source code.
Explain the concept of “Code Smells.” Provide examples.
Code smells are indicators of poor code quality. Examples include long methods, excessive parameters, and duplicated code.
What is the SOLID principle? Briefly explain each letter.
SOLID is an acronym for Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.
Define refactoring. Why is it important?
Refactoring is the process of restructuring existing code without changing its external behavior. It improves code readability and maintainability.
Give an example of a scenario where refactoring is needed.
An example could be splitting a monolithic method into smaller, more focused methods to enhance readability and reusability.
What is the difference between “Extract Method” and “Extract Class” refactoring?
“Extract Method” involves breaking a portion of code into a new method, while “Extract Class” moves a group of related methods and fields into a new class.
When refactoring, what role do unit tests play?
Unit tests help ensure that code changes made during refactoring do not introduce bugs or break existing functionality.
Explain the concept of “code smell” and how it relates to refactoring.
Code smells are indications of problematic code that might require refactoring to improve its quality and maintainability.