would anyone be down for kotlin adding the ability...
# announcements
h
would anyone be down for kotlin adding the ability to bound an if condition like this
if foobool then
instead of
if( foobool )
? i would enjoy it for when using
if
and
else
as a ternary operator
🚫 8
s
I’m not down for
then
, but I do like to see braces and parens removed where it makes sense
swift omits parentheses in
if/else
conditions but instead mandates the use of braces even with single-line expressions
of the two I think I prefer how Kotlin does it
h
it's just that other than a newline, how would the compiler know the logic that separates the condition from the blocks?
i guess it would just read the boolean then move on, but that might look confusing for readability
s
it’d be nice if if/else let you omit parentheses when you do use braces though
h
older languages and low level languages like VHDL use if/then
c
if configure { false } { println("configured") } else { println("not configured")}
I think compiler would be even more confused than humans reading this
v
Interesting indeed, why is not possible for smart modern compilers to detect first statement in a branch as branch condition, e.g.
if <first_statement> <second_statement> <third_statement> else <fourth_statement>
adding braces where it's necessary? Where the
<first_statement>
is a condition, and the
<third_statement>
,
<fourth_statement>
are those which are returned as the results from the branch (as we have it)
c
It is a balancing act between compilation performance, language rules complexity, readability and I'm probably missing something else, as well.
h
hmmm, so i'm wondering if it would be at all possible to add infix functionality so that users could create their own if statement syntax?
i love the
when
syntax so much. is it more performance impacting than
if
? what is the drawback to always using it instead of
if
?