Junior — Middle
Can you provide examples of well-written and readable code?
sobes.tech AI
Answer from AI
Well-written and readable code has the following characteristics:
- Clear and understandable structure.
- Use of meaningful names for variables and methods.
- Minimal nesting and redundancy.
- Comments where they are truly necessary.
Example in Kotlin for Android:
// Function to check if a number is even
fun isEven(number: Int): Boolean {
return number % 2 == 0
}
// Using the function
val number = 10
if (isEven(number)) {
println("Number $number is even")
} else {
println("Number $number is odd")
}
In this example, the function has a clear name, and the code is simple and easy to read.