Code Review and Best Practices Flashcards

1
Q

What is code review, and why is it important?

A

Code review is the process of systematically examining code to identify and fix issues, ensure quality, and share knowledge among team members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name some benefits of performing regular code reviews.

A

Improved code quality, knowledge sharing, catching bugs early, consistent coding standards, and fostering collaboration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the “Single Responsibility Principle” and why it’s important.

A

The SRP states that a class or module should have only one reason to change. This promotes maintainability and reduces the impact of changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the “Don’t Repeat Yourself” (DRY) principle?

A

DRY emphasizes not duplicating code in a codebase to avoid maintenance challenges and ensure consistency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you ensure consistent coding style within a development team?

A

By using coding guidelines, style analyzers, and tools like EditorConfig.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is it important to handle exceptions appropriately in your code?

A

Proper exception handling enhances the robustness of your application and improves error reporting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of using version control systems like Git in code development?

A

Version control enables tracking changes, collaboration, and reverting to previous states.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you handle sensitive data like connection strings and API keys in your application?

A

Store sensitive data in environment variables or configuration files outside the source code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the concept of “Code Smells.” Provide examples.

A

Code smells are indicators of poor code quality. Examples include long methods, excessive parameters, and duplicated code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the SOLID principle? Briefly explain each letter.

A

SOLID is an acronym for Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define refactoring. Why is it important?

A

Refactoring is the process of restructuring existing code without changing its external behavior. It improves code readability and maintainability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Give an example of a scenario where refactoring is needed.

A

An example could be splitting a monolithic method into smaller, more focused methods to enhance readability and reusability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between “Extract Method” and “Extract Class” refactoring?

A

“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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When refactoring, what role do unit tests play?

A

Unit tests help ensure that code changes made during refactoring do not introduce bugs or break existing functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the concept of “code smell” and how it relates to refactoring.

A

Code smells are indications of problematic code that might require refactoring to improve its quality and maintainability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of using design patterns during refactoring?

A

Design patterns provide proven solutions to common design problems and can guide refactoring efforts to achieve cleaner and more maintainable code.

17
Q

Give an example of the “Replace Magic Number with Symbolic Constant” refactoring.

A

Replacing a literal value (magic number) in code with a named constant to improve code readability and maintainability.

18
Q

How can you ensure that refactoring doesn’t introduce new bugs?

A

Thorough testing, including running unit tests and performing manual testing, can help identify issues introduced during refactoring.

19
Q

Explain the “Rename Method” refactoring and why it’s important.

A

Renaming a method to better reflect its purpose improves code readability and can clarify its usage for other developers.

20
Q

What steps would you take before starting a large-scale refactoring of a codebase?

A

Understand the existing code, document the goals of the refactoring, and ensure you have proper tests in place.

21
Q

Why is maintainability important for a software application?

A

Maintainability ensures that the codebase remains easy to understand, modify, and extend as the project evolves.

22
Q

Explain the concept of “Technical Debt” and how it affects maintainability.

A

Technical debt refers to the cost of taking shortcuts or making compromises in code quality, which can lead to difficulties in maintaining or enhancing the codebase over time.

23
Q

What practices can help reduce technical debt in a software project?

A

Regular refactoring, writing clean code, and addressing code smells promptly can help minimize technical debt.

24
Q

Name some tools or techniques that can aid in measuring code maintainability.

A

Static code analysis tools, code metrics, and code review processes can help assess and improve code maintainability.

25
Q

Explain the N+1 query problem in database access. How can you mitigate it?

A

The N+1 query problem occurs when an application issues N+1 queries to retrieve related data. It can be mitigated using techniques like eager loading or using joins.

26
Q

What is lazy loading, and how can it impact application performance?

A

Lazy loading is a technique where data is loaded only when it’s accessed. It can improve performance by reducing initial load times but might introduce additional queries

27
Q

How can caching be used to improve application performance?

A

Caching involves storing frequently used data in memory to avoid repetitive calculations or database queries, leading to faster response times.

28
Q

Explain the importance of indexing in database optimization.

A

Indexes speed up database query performance by allowing the database engine to quickly locate the rows that satisfy a query’s conditions.

29
Q

What is connection pooling, and how does it benefit application performance?

A

Connection pooling reuses database connections, reducing the overhead of creating and closing connections for every database interaction.

30
Q

Describe the differences between synchronous and asynchronous programming in terms of performance.

A

Synchronous programming blocks the execution until a task is completed, potentially causing performance bottlenecks. Asynchronous programming allows tasks to execute concurrently, improving responsiveness.