A separate DSL type question. One thing I've frequ...
# announcements
A separate DSL type question. One thing I've frequently encountered with DSL's that's a bit annoying is that infix functions generally cannot start a line. So if you are writing something that emulates an
or other control flow, as above, then I'd like to be able to write:
Copy code
something {
my_else {
but this will never compile, you need to put the
after the brace. Does it seem reasonable at all that the compiler could consider allowing this to compile, specifically when you have an infix function starting a line like that
Probably not, due to the fact that it considers newlines equivalent to semicolons. The newline after
something { }
completes the statement, and it is sufficient on its own, and there’s no syntactic marker to indicate that the next line is related to it However, the official convention is actually to put the “else” on the same line as the previous bracket. So the more “conventional” solution is probably to adopt
} else {
so that
} my_else {
doesn’t look so strange, rather than make the infix function able to stand on the next line. Or else just use
.my_else { }
on the next line, which does give that syntactic marker of a continued statement https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
💯 1
That makes sense, I didn't realize somehow that there was really a single official kotlin style guide