Junior — Middle
What criteria can be used to determine code quality and distinguish between bad and good code?
sobes.tech AI
Answer from AI
Code quality can be assessed based on several criteria:
- Readability: the code should be understandable by other developers, with meaningful variable and function names.
- Maintainability: it should be easy to make changes and fix bugs without risking breaking other parts.
- Simplicity: avoid unnecessary complexity, use clear constructs.
- Reusability: the code should be modular and reusable.
- Testability: the code should be easy to cover with tests.
- Performance: the code should work efficiently, but not at the expense of readability.
Poor code often:
- contains duplication,
- is poorly structured,
- uses unclear names,
- is undocumented,
- is difficult to understand and modify.
An example of good practice in Python:
def calculate_area(radius):
"""Calculates the area of a circle given the radius."""
import math
return math.pi * radius ** 2
Here, the function is short, with a clear name and documentation.