TypeScript developer tries Kotlin again

adam_cyclones

Adam Crockett πŸŒ€

Posted on December 30, 2021

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.

πŸ’– πŸ’ͺ πŸ™… 🚩
adam_cyclones
Adam Crockett πŸŒ€

Posted on December 30, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related