DEV Community

Adam Crockett πŸŒ€
Adam Crockett πŸŒ€

Posted on

TypeScript developer tries Kotlin again

Im getting there with Kotlin, try something 3 times and it might start to click. Here is my 5 seconds Rosetta stone on Kotlin classes

Comparisons

Image description

Lets break the above down

Kotlin

// this is an annotation 
@MongoEntity
Enter fullscreen mode Exit fullscreen mode

Typescript

// this is a decorator 
@MongoEntity
Enter fullscreen mode Exit fullscreen mode

Kotlin

// This class inherits from ProductBase but the primary constructor must be called, (Kotlin classes have more than 1 constructor) 
class PrivateProduct : ProductBase()
Enter fullscreen mode Exit fullscreen mode

Typescript

class PrivateProduct inherits ProductBase { constructor() {super()}  }
Enter fullscreen mode Exit fullscreen mode

Kotlin

// the property called 'public' is a Boolean and it is initialised but you can prefix `lateinit` which is equal to the `!` in typescript
val public: Boolean = false
Enter fullscreen mode Exit fullscreen mode

Typescript

class PrivateProduct inherits ProductBase {
    public readonly public: boolean = false;  
}
Enter fullscreen mode Exit fullscreen mode

Final thoughts

What I like about Kotlin is most of the nice ES6 features have equivalent or near to concepts, destructuring, promises, reactive programming (alright thats nothing to do with ES6), array methods with predicate all that stuff its here in Kotlin, making the learning curve really nice for an experienced JS developer and even less for Typescript friendly JS developer.

Its very fast too, also I am writing an app using Quarkus - a web framework which has very very very fast hot reload, so I don't even miss this feature.

Top comments (0)