Nivaldo H Bondança
08/07/2025, 9:06 PMtrimIndent()
/ trimMargin()
and wanted to hear your thoughts about it.
We'll use the poll results to guide our approach.
Feel free to suggest alternatives as well, but do keep in mind this has to work with all the different use cases, which the represented code here for sure does not cover.
Option 1
val a =
"""
a multiline
string
"""
.trimIndent()
.nextMethod()
val b =
"""
|a multiline
| string
|"""
.trimMargin()
.nextMethod()
Option 2
val a =
"""
a multiline
string
"""
.trimIndent()
.nextMethod()
val b =
"""
|a multiline
| string
|"""
.trimMargin()
.nextMethod()
Option 3
val a =
"""
a multiline
string
"""
.trimIndent()
.nextMethod()
val b =
"""
|a multiline
| string
|"""
.trimMargin()
.nextMethod()
Option 4
val a =
"""
a multiline
string
""".trimIndent()
.nextMethod()
val b =
"""
|a multiline
| string
|""".trimMargin()
.nextMethod()
phldavies
08/07/2025, 9:58 PM.trimIndent()
and .trimMargin()
are processed at compile time, so I've always seen them as "part" of the terminating """
and prefer them attached for that reasonseb
08/08/2025, 8:12 AMiircI don't think so, since they prevent the string from being a constant IIRCand.trimIndent()
are processed at compile time.trimMargin()
phldavies
08/08/2025, 8:16 AMNivaldo H Bondança
08/08/2025, 12:38 PMval a = """
|this is processed
|at compile time
|""".trimMargin()
val b = """
|this is processed
|at runtime because of this $variableHere
|""".trimMargin()
Nivaldo H Bondança
08/08/2025, 4:57 PMseb
08/08/2025, 5:26 PMphldavies
08/08/2025, 5:32 PMval option4 =
myCall(
"""
a multiline
string
""".trimIndent())
val option2 =
myCall(
"""
a multiline
string
"""
.trimIndent())
Nivaldo H Bondança
08/08/2025, 5:34 PMNivaldo H Bondança
08/08/2025, 5:35 PMphldavies
08/08/2025, 5:39 PMNivaldo H Bondança
08/08/2025, 5:41 PMseb
08/08/2025, 5:43 PMseb
08/08/2025, 5:44 PM