Middle
Name specific code quality criteria.
sobes.tech AI
Answer from AI
- Readability: Easy to understand what the code does. Meaningful names are used, formatting conventions are followed.
- Maintainability: The code is easy to modify and fix bugs without introducing new ones. Modular structure, low coupling.
- Testability: The code is easy to cover with automated tests. Functions and classes have clearly defined responsibilities.
- Performance: The code efficiently uses resources (CPU, memory, battery). No "bottlenecks".
- Reliability: The code behaves predictably and is resistant to errors. Exception handling, input validation.
- Reusability: Code components can be used in other parts of the application or in other projects. Adherence to SOLID principles.
- Coding standards compliance: The code conforms to accepted standards within the team or industry.
- Documentation: The code (or API) is adequately described if required.
Examples:
// Readable code:
public void processUserData(User user) {
if (user.isActive()) {
// Processing active user
} else {
// Processing inactive user
}
}
// Less readable code:
public void procUsr(User u) {
if (u.getStat()) { // What is getStat()?
// code
} else {
// code
}
}
// Testable code:
class UserRepository(private val apiService: ApiService) {
fun getUserById(userId: String): User? {
return apiService.fetchUser(userId) // Dependency can be easily mocked for testing
}
}
// Less testable code (direct dependency creation inside the function):
class UserRepository {
fun getUserById(userId: String): User? {
val apiService = ApiService() // Difficult to mock
return apiService.fetchUser(userId)
}
}