In this article, I am going to explain how I had my first A-ha moment trying to create my Sudoku app with Jetpack Compose.
As you may already know, Jetpack Compose is a multi-platform reactive declarative UI framework (and also, not just a UI framework).
Compose is great. Not just because it makes our lives easier, but because it enforces us to write functional and declarative code and makes us think about how we can make our design more composable.
In this article, I will explain how Compose’s features helped me achieve an extensible architecture for building my Sudoku app.
In this article, multiple types of synchronization, locking and thread-safety in Java and Kotlin work are explained through interactive examples.
In a multi-threaded world, we need to access shared objects across threads, and If we do not synchronize our work, unwanted situations can occur.
First let’s see a basic example of why synchronization is needed.
In the example above, we are launching 1000 coroutines (If you don’t know what they are, just think about them as light-weight threads) on 4 threads, and each of them, increment the global value
sharedCounter 1000 times, so the final value…
There’s a great little feature in the Kotlin v1.3 that needs more attention, and that is, Kotlin Contracts!
To use it in your project, update you Kotlin Gradle plugin to version 1.3 (or above):
Contracts (or should we say, Kontracts?)
Kotlin contracts is a great way to tell the compiler about what a function does and help it become more intelligent.
Let’s say we have a function as below.
In this example, we have a function
createOnce that we know, runs the
runFunction exactly once. We use this function…