Out of curiosity, is there a reason why the parent...
# announcements
l
Out of curiosity, is there a reason why the parentheses of a function without parameters are not optional?
s
w/o parens it looks like a property, potentially
Kotlin in general tries to avoid ambiguity
imo function calls should be immediately apparent to the reader
3
r
Also, you could potentially run into ambiguity with the
invoke
operator.
Copy code
fun test(op: Thing.() ->) {
    op  // Does this reference the value, or invoke the lambda?
}
👆 2
s
You can create some confusion by creating this extension function
operator fun Type1.invoke(block: () -> Type2) : Type3
🙂
For
Copy code
fun test(op: Thing.() -> Unit) {
    op  // Does this reference the value, or invoke the lambda?
}
the
op
refers to the lambda value; you don’t invoke it.
someThing.op()
invokes it.
l
No, I didn’t mean when calling the function. Yes the call should absolutely use empty parentheses. I’m referring to the function definition. What if instead of defining
fun foo() {...}
, you could write
fun foo {...}
. I don’t see a confusion or ambiguity here
s
Ah! That would be indeed a little less typing and because of the
fun
keyword, it won't be ambiguous. But somehow it looks odd/off to me....
l
Yeah, I got that feeling too, but it might just be a out of habbit. Like we’re so used to see functions declared with them that removing them feels odd but we could get used to that new way
Anyway, I’m just thinking out loud here