I could not agree more. Things can get confusing easily with many language constructs. Take the following example that uses apply(...)
. Should this function be removed because it might cause confusion?
Good developers know how and take the extra time to write clear code, so they do not waste their fellow developer’s and their own time in the future. So usually you use explicit names when nesting lambdas and you do not nest apply(...)
, but if the code remains clear you sure do not want to be prevented from doing so.
class Person {
var name = ""
var status = "living"
}
class PersonView {
var backgroundColor = Color.WHITE
var status = "enabled"
}
fun setUpPersonView() {
PersonView().apply {
Person().apply {
backgroundColor = Color.RED
name = "E. Xample"
// Oops, disabling a person. What does that mean?
status = "disabled"
}
}
}