4 ms·
> Kotlin has a lot useless syntax sugar, for example @decorators are less powerful than the @decorators in python. I think you're comparing two different thing
by matsemann 3y ago
> Kotlin has a lot useless syntax sugar, for example @decorators are less powerful than the @decorators in python.
I think you're comparing two different things. Kotlin has "annotations", not decorators. It's because of it's java inheritance, where that is the way it's done. It's two different concepts. With a decorator, your code is replaced with a function call with the function itself as a parameter. With an annotation, you're just adding metadata and an annotation processor or static analysis tool etc can do whatever it wants with it. Like aspect oriented programming. You mark your code as having certain properties, and then other code can find it and react to those.
I don't know of much other useless syntactic sugar in Kotlin? I think most of it is quite nice, for instance how you can put the lambda outside parenthesis or create infix operator for more readable code. I also like the implicit `it` parameter in lambdas, better than what this article shows. Doesn't support multiple arguments, though.
- TrianguloY 3y agoDoesn't support multiple arguments by itself, because "it" will always refer to the "group". But with destructing you can name yourself as many arguments as you want: listOf(1,2,3).let { (a, b, c) -> a * b + c } Which I think it's a good compromise