```foo if (condition)``` syntax, like exists in Ru...
# language-proposals
h
Copy code
foo if (condition)
syntax, like exists in Ruby and other languages. It is superior to
Copy code
if (condition) foo
in that it doesn't allow for multiline, and avoids the problem of:
Copy code
if (foo)
    bar
    baz // not in scope
Also maybe drop the condition's enclosing
()
6
l
What’s wrong with
foo.takeIf { condition }
? 🤔
h
i guess I just like the beauty of the syntax
j
- The existing syntax is consistent with normal
if
syntax and is ordered logically. If you're using an auto formatter (which you always should) you'll never run into the grouping issue. If that's the problem we want to solve, I'd be for getting rid of implied curly braces on such statements. - The proposed syntax gives double meaning to
if (condition)
which would make code harder to read. - Dropping the parens introduces vagueness to the following statement:
Copy code
fun someName(action:()->Unit):Boolean{}
val someName = true
if someName {}
h
righto. i think i'd like to have the need for parentheses to be tied to ambiguity, similar to type inferences, but I totally jive with the point about syntax consistency.
r
It is superior ... in that it doesn't allow for multiline
That sounds pretty inferior to me
h
meaning that if you want to do multi-line, you'd "have" to use curly braces
x
I'd like postfix if too, just my opinion that it is sometimes more readable
g
Do you have an example when it's more readable?