Hacker News new | ask | show | jobs
by dima_vm 1261 days 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.

4 comments

What exactly do you mean by "damned" here?
I too am confused by the unique use of this word
I am assuming the author is using it as one would use "wicked" (with a positive conotation)?
I 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.

That's so sick.
That's right, forgot the word (not a native speaker unfortunately).
All of these were copied from Groovy, in case you didn't know it.
It 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.)
Almost 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).

Kotlin'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.
Isn'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.

> 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… ;-)