Following up the conversation above about string c...
# codingconventions
d
Following up the conversation above about string concatenation formatting, I tried using
+
on new lines as @gabrielfv suggested:
Copy code
foo("one"
    + "two"
    + "three")
only to find that it doesn’t work with
return
, e.g. the following doesn’t compile because of
+
on new line:
Copy code
fun bar(): String {
    return "one;"
        + "two;"
        + "three"
}
I’d argue this means that
+
and
.plus()
are already different enough to have different formatting 🙂 /cc @kevinmost
g
So Kotlin compiler takes identation as a parameter to parse operations?
k
no, you have to put the
+
at the end of the previous line, not the start of the newline, for it to pick
Foo.plus(Bar)
over
unaryPlus(Bar)
g
Got it, although it kinda doesn't comply with the
?.
scenario. Of course there's a good explanation.
What are the applications of
unaryPlus()
, since
unaryPlus(a) == a
?
k
Yeah, it's a little weird. Maybe just to keep consistency with
unaryMinus()
, since you'd certainly want to do
-50
for example 😆
☝️ 1
it could have potential to be used in a DSL as a sort of alias for "add"
Copy code
dependencies {
  + "org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2"
}
g
Well, the return case is understandable, since
return "one;"
is a closed statement, and so are the
+ "etc"
lines, that cannot be reached and break compilation.
So this constrains that convention