3 ms·
I happen to disagree with you both that syntax is irrelevant and that receiver scopes are "just syntax". I think whether you care strongly about syntax is just
by iudqnolq 6y ago
I happen to disagree with you both that syntax is irrelevant and that receiver scopes are "just syntax".
I think whether you care strongly about syntax is just personal preference. For example, I prefer Elixir to Erlang, TypeScript to JavaScript, and Kotlin to Java even though they could be/are implemented by transforming source code to source code.
On receiver scopes specifically, they make simple DSLs very easy to implement. Arguably needing a DSl is a symptom of design flaws, but Android has a lot of those so receiver scopes makes Android programming a lot nicer.
Edit: I would call this more than syntactic sugar:
interface MyScope {
fun frob()
}
fun foobar(content: MyScope.() -> Unit) {
let scope = MyScopeImpl()
scope.apply(content)
scope.getResultInternal()
}
fun user() {
foobar {
frob()
}
}