holgerbrandl
12/15/2021, 7:47 AMfun myIf(condition: Boolean, block: () -> Any) {
block()
}
fun main() {
if (true) {
println("foo")
}
myIf(true) {
println("bar")
}
}
And yes, I know how to change the default. But I'd rather like to see consistency in the formatting, and would love to upvote some kepp/tickeet to change the default.Emil Kantis
12/15/2021, 7:48 AMif(someCondition)
over if (someCondition)
?holgerbrandl
12/15/2021, 7:49 AMephemient
12/15/2021, 11:47 AMif
can chain with else if
which myIf
can't; looping constructs can break;continue
which user code can't, when
can't be replicated at all. basically I'm negative on changing the style, it's fine that different things look different.holgerbrandl
12/16/2021, 8:30 AMfun myIf(condition: Boolean, block: () -> Any) {
block()
}
infix fun Any.myElse(block: () -> Any) {
block()
}
fun main() {
if (true) {
println("foo")
}
myIf(true) {
println("bar")
} myElse {
println("bar")
}
}
break, and continue do not use brackets, so I don't think they relate to my suggestion. Indeed when
is special.
Because we can do so, formatting experience lacks consistency with the current default style.ephemient
12/16/2021, 10:24 AMelse if
, with a space, is impossible to replicateEmil Kantis
12/16/2021, 10:27 AMif (true) println("foo") else println("bar")
as well, I think?holgerbrandl
12/16/2021, 10:40 AMprivate infix fun Any.myElse(println: Unit) {}
private infix fun Any.println(s: String) {}
fun myIf(b: Boolean): Any {}
fun main() {
if (true) println("foo") else println("bar")
myIf (true) println("foo") myElse println("bar")
}
holgerbrandl
12/16/2021, 10:44 AMprivate infix fun Any.myElse(smthg: Boolean) {}
private infix fun Any.println(s: String) {}
fun myIf(b: Boolean): Any = 23
fun main() {
if (true) println("foo") else println("bar")
val myOtherIf = true
myIf(true) println ("foo") myElse myOtherIf println ("bar")
}
Admittedly a nonsense example, but that's not my point. I'd think that the great majority of users will just perceive inconsistency here: Keyword and functional constructs can realize the similar code constructs but are formatted differently.Emil Kantis
12/16/2021, 10:44 AMmyElse
for Any
, should be confined to work with the if..holgerbrandl
12/16/2021, 11:52 AM