umar
04/10/2017, 12:51 PMkevinmost
04/10/2017, 1:19 PMinfix
is because you have to opt into it. My coworkers all thought to
was a keyword at first, but it's just the stdlib infix method to make a Pair. I don't want more functions that look like keywords, especially if we do it like Groovy where all parens can be omitted for one-arg functions. Maybe it'd be clearer if you can at least opt into it with a keyword somehowbenleggiero
04/10/2017, 5:15 PMbenleggiero
04/10/2017, 5:17 PMval log = Logger.global
log "Hello log"
Is that the log
variable I just made? Is it a function taking in a String
? Is it a prefix extension function on the String?umar
04/10/2017, 8:40 PMfun log(str:String) = println("$str in fun")
val log = { str: String -> println("$str in lambda") }
log("hello")
What will be output?
And what is the difference if we omit parens:
log "hello"
?
Logger functions is not very good example. Look at await
, yield
. Suspending call isn't ordinary and dropping parens so they would look like keywords (with IDE colored highlighting) would be a good ideavoddan
04/10/2017, 8:53 PMcbruegg
04/10/2017, 9:05 PMawait()
in call chains without wrapping the expression in paranthesis.
x.foo()
.await()
.bar()
.baz()
vs.
(await x.foo())
.bar()
.baz()
kevinmost
04/10/2017, 11:16 PMtell application "TextEdit"
activate
make new document
set text of front document to "hello world"
end tell
umar
04/11/2017, 4:26 AMsuspend parenless fun await(...) = ...
suspend parenless fun yield(...) = ...
usage :
val backgroundImage = await loadImage(...)
val image = await loadImage(...)
yield 1
yield longComputation()
but cannot use in nested call or with more than 1 argument without parenthesis :
saveImage await loadImage()
yield result1, result2
because it is not clear and creates puzzlers
Also, IDE highlighting can help in recognizing this callsdean
04/11/2017, 4:28 AMparenless
is kinda lengthy and hard to read if you don't know what it means. Perhaps follow the infix
notation and call it prefix
dean
04/11/2017, 4:28 AMdean
04/11/2017, 4:30 AMsynchronized
)orangy
make
is a top-level property, new
is infix function, document
is a property.dmitry.petrov
04/11/2017, 8:35 AMkevinmost
04/11/2017, 1:40 PMsubject.verb(object)
, it would be easier for me to read it than if I had to parse out what each part was individually because there were no symbols to give me contextkevinmost
04/11/2017, 2:51 PMcompile group: "foo", name: "bar", version: "1.0"
, I was very confused. It took me months to even realize compile
was a function and that's how you use 1-arg functions in Groovy, and you could easily also do it with parens. Granted, maybe that's because Groovy has terrible IDE support, but it still reduces visibility for absolutely no readability gains. If we're not allowing these for nested calls, I'm wondering where this would seriously benefit anyone. Just use the parenscodeslubber
04/11/2017, 3:03 PMcodeslubber
04/11/2017, 3:04 PMdmitry.petrov
04/11/2017, 3:05 PMkevinmost
04/11/2017, 3:18 PMsreich
04/11/2017, 3:21 PMkevinmost
04/11/2017, 3:26 PMPaul Woitaschek
04/11/2017, 4:32 PMPaul Woitaschek
04/11/2017, 4:33 PMmasted
04/11/2017, 5:44 PMcbruegg
04/11/2017, 6:16 PMinterface EventHandler {
fun handle(event: Event)
}
class EventHandlerImpl(val ctx: Context) {
override fun handle(event: Event) {
doSomethingWith(event, ctx)
}
}
class SomeActivity: Activity(), EventHandler by eventHandler {
private val eventHandler = EventHandlerImpl(this)
}
voddan
04/12/2017, 5:37 AMclass Foo: Bar by &baz
Paul Woitaschek
04/12/2017, 6:57 AMcbruegg
04/12/2017, 7:25 AM