Fullstack Kotlin, founder of @KtDotAcademy, JetBrains partner, GDE in Kotlin, author of Effective Kotlin and Kotlin Coroutines. Workshops: https://xitter.cf/t.co/xUZVd4J4Jl

Warsaw / Poland
Joined January 2025
Marcin Moskala Android retweeted
Reflection is a powerful tool that allows us to inspect classes and use their methods. To transform an object into a string, we can use reflection to get all properties and their values.
1
4
11
1,034
Marcin Moskala Android retweeted
If you still struggle to understand how the IO dispatcher should be used, here is a pill that explains everything you need to know 👇 IO dispatcher is used when we need to make a blocking call, like reading a file or using a blocking API. This sometimes happens, as some libraries still only offer blocking APIs. You don't need to use IO dispatcher if you use suspending functions. Those should never be blocked, so a lib with suspending API does not need IO. IO dispatcher is by default limited to 64 threads (or the number of cores, whatever number is greater). This limit protects our resources. Imagine that you need to send newsletter using blocking API, and you send elements asynchoniously. Without limit, you would start as many threads as many emails you have to send, what would likely cause OutOfMemoryException, as each thread required 1 MB or RAM. Limit makes sending take longer, but it protects our memory. The biggest problem with IO dispatcher is that is has one limit for the whole application. Imagine that our newsletter service uses all its threads for a couple of minutes. If other services want to use Dispatchers. IO as well, they need to wait in queue until newsletter process is finished. To avoid such interdependencies, we prefer to have dispatchers with custom limits in each service. We create such dispatchers using Dispatchers. IO.limitedParallelism(limit). Dispatchers created this way share a pool with Dispatchers. IO and Dispatchers.Default, but this underlying pool is inlimited, and each dispatcher has its own limit, so it is safe and efficient. How do we set the limit? If we do not care much about execution time, we can set it to a smaller number. For our newsletter it can be 5. If we care more about not having one coroutines wait for enother, even in cost of more resources being spent, we set it to a greater number, like 50. That is all you need to know about IO disatcher! If you like my teaching style, check our my book Kotlin Coroutines: Deep Dive and my workshops, especially Kotlin Coroutines.
1
4
17
1,370
Marcin Moskala Android retweeted
In Compose, parameter providers not only help us preview a component with different values, but also allow switching between those values when we run the preview! Defining a parameter provider is simple. You need a class that implements PreviewParameterProvider<T>, which should specify the values property with different values. Once defined, you can use it in preview with @PreviewParameter(YouProviderClass::class). The biggest limitation is that you can define only one parameter provider per preview.
4
14
1,287
Marcin Moskala Android retweeted
I am especially proud of this final project. I am sure it already offered a lot of value to the author, and it is likely it will offer great value to our community. kmp-resilient by Santiago Mattiauda is a complete solution for setting up resilience patterns in Kotlin Multiplatform (KMM), coroutines-native and with solid tests. It also offers a really nice DSL-based idiomatic API. Congratulations! Code 👉 github.com/santimattius/kmp-… #coroutinesmasteryproject Thread 👇
5
9
438
Marcin Moskala Android retweeted
Do you lack default error handler in viewModelScope? This library by Luka Velimirovic might be what you look for! It offers configurable multiplatform vmScope, as a replacement for viewModelScope. This library was made as a final project on Coroutines Mastery, great congratulations to Luka for creating it ❤ Code 👉 github.com/VelkosX/vmscope #coroutinesmasteryproject
4
11
1,136
Marcin Moskala Android retweeted
Today I am proud to present this Weather application made by Piotr Kanarek as a final project on Coroutines Mastery. It is a nice showcase of how to correctly design an Android application. It implements search with multiple triggers, error handling, uiState pattern, simple yet correct architecture. Kudos for Piotr! 👉 github.com/piotrkanarek-emr/… #coroutinesmasteryproject Useful topic? We go much deeper in our cohort course. Coroutines Mastery: coroutinesmastery.com
1
3
4
267
Marcin Moskala Android retweeted
Time for another amazing final project from Coroutines Mastery 2025: StrayCat is a beautiful Android application for location simulation and GPS tracking. Perfect for testing location-based features and route simulations. Created by Marko Lainovic from TomTom. Code 👉 github.com/lainovic/StrayCat… #coroutinesmasteryproject Thread 👇
3
3
262
Marcin Moskala Android retweeted
Have you ever wondered how libraries like Arrow Lenses actually work? The answer is quite simple, just follow me.
1
5
11
793
Marcin Moskala Android retweeted
1
3
4
420
Marcin Moskala Android retweeted
1️⃣ The first one relates to memory consumption. In early days of programming, we much more respected our memory, and wherever possible we used as small number types as possible. So we used short or byte if that was enough, and we used unsigned type if we needed no negative numbers. We still do that in some applications, but in the past it was an industry standard, because memory was much more expensive. Getting back to indexes, since we have no way to represent positive numbers without 0, starting from 1 would mean wasting one possible value. For instance, if you use unsigned byte and start indexing from 0, you have 256 possible indices, but if you started from 1 you had only 255, which can make a difference.
1
3
4
354
Marcin Moskala Android retweeted
padding, background, border, clip, offset, align… Most Compose developers know these modifiers individually. The hard part is understanding how they behave when combined. That is why I made a Modifier Guessing Game: you read the chain, predict the UI, and verify whether your mental model is correct. A fun way to sharpen Compose intuition. Play here: game.kt.academy/?game=modifi…
3
5
256
Marcin Moskala Android retweeted
What is the best way to turn suspending function into Flow, or Fliw into a suspending function? Learn about it in this new article by Marcin Moskała. kt.academy/article/interop-s…
3
5
267
Marcin Moskala Android retweeted
One of the biggest differences between “I know Flow” and “I use Flow well” is this: Can you predict the result before running the code? This Flow game will help you practice that skill. A short challenge, but a very practical one. Play here: game.kt.academy/?game=flow&u…
3
6
139
Marcin Moskala Android retweeted
One of the most important decisions you need to make when defining custom composables is wrather you want to store mutable state locally or hoist it. When state is local: 👉 Logic can be reused. 👉 Component has simpler API. When we hoist it: 😨 There are more (or more complex) parameters. 👉 Logic can be more easily customised. 👉 Caller can decide how state is stored and how persistent is it. 👍 We can easily preview all different states. I would say, that local state is more React-like, but hoisting this state it much more Compose-like. It is a popular approach hoist all state up to view models.
1
5
1
16
2,669
Marcin Moskala Android retweeted
Being a youngster programmer, I was always told that reflection is slow and should be avoided, but I just couldn't observe this slowness in any real measures. That is why I decided to make some benchmarks to see how reflection really performs and write it all down in this article
3
4
212
Marcin Moskala Android retweeted
Remember to always preview your Compose components in your application theme. Without it, it will look different because it will use default values such as colors, fonts, sizes, etc. If you have multiple theme variants, it is best to preview each universal component in each of them. I wish we had a simpler way to automatically apply the application theme to all our previews, or, even better, to all defined themes.
4
11
1,315
Marcin Moskala Android retweeted
Boost your Kotlin performance with Project Loom's virtual threads! Say goodbye to Dispatchers.IO and run blocking code like it's non-blocking. Faster, simpler, smarter. ⚡ 🔗 Dive in now: kt.academy/article/dispatche…
3
6
147
Marcin Moskala Android retweeted
Did you know that Compose provides out-of-the-box class for providing Lorem ipsum 🤯 It can also be used as a parameter provides. It is super useful for making previews❗
1
3
8
303
Marcin Moskala Android retweeted
A good Compose foundation starts with understanding the essentials well. Our free Compose Essentials Cheat Sheet made by Marcin Moskala and Jov Mit is a compact reference covering core concepts like state hoisting, side effects, layouts, and common UI components. Register with your email, and we’ll send it your way. 👇 cheat-sheet.kt.academy/compo…
3
3
220
Marcin Moskala Android retweeted
✅ 𝗋𝖾𝗆𝖾𝗆𝖻𝖾𝗋 block calculates the value during first initialization, and then caches it for later. This value will be recalculated only if one of its keys changes. If it has no keys, the same value will be used for as long as this composable exists.
1
5
18
1,393