Thank you, I am aware of the alternative ways of writing this (as one might expect in this forum).
Our code is obviously a bit more complex (with multiple variables) than the simple examples above; I’m looking for something more readable than having series of lambdas with let/run/also in which we have to rename the various “it” back to the name of the variable to continue making sense.
Which of the following do you prefer?
(x as? xClass)?.let { x ->
(y as? yClass)?.let { y ->
x.doSomething(y)
}
}
or
if (val x is xClass && val y is yClass)
x.doSomething(y)
Our current code would probably create local copies of the properties:
val x = x
val y = y
if (x is xClass && y is yClass)
x.doSomething(y)
so (simpleton that I am), wouldn’t the compiler just desugar it into the two part statement? so flow control is the same.
I would say, that you shouldn’t adopt the additional syntaxes that swift also allows, with the comma separated and or the no parenthesis. Requiring parenthesis would make it more clear and allow for easier management of the flow control and determining what needs to be desugared.