4 ms·
Absolutely damned is combination of Kotlin's several features: 1. Lambda functions can be defined with `{}`. 2.`foo(bar, somefunc)` is the same as `foo(bar) s
by dima_vm 4y ago
Absolutely damned is combination of Kotlin's several features:
1. Lambda functions can be defined with `{}`.
2.`foo(bar, somefunc)` is the same as `foo(bar) somefunc`. In other words, if the last parameter is a function, it can be provided AFTER closing parenthesis.
3. Interfaces that require only one method can be implemented on-side with a lambda function (i.e. `{}` syntax for no-param function).
Combined those three features, the code may look like that:
routing {
static("/statics") {
files("css")
}
get("/foo") {
call.respondText("Hello world!")
}
}
So you can make a config-looking file which is just pure Kotlin, with static type checking, autocomplete, suggestions, "this" etc.
It's so damned, I'm surprised author didn't mention it.
- plucas 4y agoWhat exactly do you mean by "damned" here?
- sirsinsalot 4y agoI too am confused by the unique use of this word
- brabel 4y agoI am assuming the author is using it as one would use "wicked" (with a positive conotation)?
- benj111 4y agoI don't know why teenagers insist on taking a negative work and making it positive, especially when teenagers don't like adding emphasis to words so you have no idea whether they think it's good or bad. Not that I was completely innocent of this at that age. /Rant.
- cpurdy 4y agoThat's so sick.
- dima_vm 4y agoThat's right, forgot the word (not a native speaker unfortunately).
- brabel 4y agoAll of these were copied from Groovy, in case you didn't know it.
- pas 4y agoIt reminds me of Scala too, but I have no idea which started when. And of course both could have come up with this fairly independently. (After all it is the norm in functional style.)
- still_grokking 4y agoAlmost all Kotlin features are Scala rip offs. Kotlin was started even as just a poor Scala clone. (Because JetBrains didn't manage to get a working Scala plugin for their IDE, so they thought it would be simpler to create their own "simpler" version of the language).
- zorr 4y agoKotlin's features are amazing for designing DSLs but I think your code sample uses more than just the 3 points you mentioned. Specifically the `call.respondText(..)` part. I assume that in this example the second argument to the `get` function is actually a "lambda with receiver", which means that the lambda executes with another object as the receiver (and that object is bound to "this" inside the lambda block), which makes the `call` object available.
- still_grokking 4y agoIsn't it cool that you can't know what the code is actually by just looking at it? /s Kotlin's scope injection is one of the most terrible "features" ever invented. It's dynamic scoping on steroids! But dynamic scoping was long ago deemed a horrible bug and never ever made it again into any new language.
- still_grokking 4y ago> 1. Lambda functions can be defined with {}. Directly "stolen" form Scala. > 2.foo(bar, somefunc) is the same as foo(bar) somefunc. In other words, if the last parameter is a function, it can be provided AFTER closing parenthesis. Just a irregular syntax quirk that tries to get around the fact that Kotlin does not support multiple parameter lists, like the language where most Kotlin features come form, Scala. > 3. Interfaces that require only one method can be implemented on-side with a lambda function (i.e. {} syntax for no-param function). That doesn't have anything to do with Kotlin. That's Javas SAM (Single Abstract Method) feature. > I'm surprised author didn't mention it. The author seems not to know any Scala. Otherwise the lists would show mostly only Scala features… ;-)