Hey all, I have a question regarding the safe call...
# codingconventions
k
Hey all, I have a question regarding the safe call operator and convention on "where to place it". Kotlin coding convention documentation recommends to put it on a new line, when chaining, like this:
Copy code
val anchor = owner
    ?.firstChild!!
    .siblings(forward = true)
    .dropWhile { it is PsiComment || it is PsiWhiteSpace }
What is the general convention, in case you don't chain? In my opinion it is more clear when you put the safe call operator in the same line as the object you apply the safe call to, like:
getSth?.let {
h
Yep, if you don't need a new line, one line is definitely more readable
👍 1
t
I'd say this suggestion really just refers to chaining, meaning you should do
Copy code
val anchor = owner
    ?.firstChild
    ...
rather than
Copy code
val anchor = owner?.
    firstChild
    ...
When you're not chaining/wrapping, you can just keep
?.xyz
in the same line. That's also how the examples in the Kotlin docs are formatted
👍 3