Read the code carefully before you run it.
fun calc(a: Double, b: Double): Double {
val d = a * b / 100.0
return a - d
}
fun main() {
// The caller meant: a 15 percent discount on a price of 200.0.
println(calc(15.0, 200.0))
}
The caller meant a 15 percent discount on a price of 200.0. What does this print, and what in the code could have warned them?
1. A pull request contains val activeUsers = users.filter { !it.isActive }. What is the most serious problem with this line?
2. Which of these names is a problem?
3. Your team lead proposes prefixing every variable with its type, as in strName and iCount, so readers always see the type. What is the strongest objection?
4. The line val ok = customer.age >= 18 && customer.idVerified decides whether an order with age-restricted items may go through. Which rename follows the rule "name the purpose, not the mechanics"?
5. fun checkPassword(user: User, password: String): Boolean verifies the password and, when it matches, also starts a session for the user. What is the naming problem?