<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pratik Satani on Medium]]></title>
        <description><![CDATA[Stories by Pratik Satani on Medium]]></description>
        <link>https://medium.com/@pratiksatani?source=rss-d89cd80b3689------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dQjOf-kSAXKRzTF8Jt0tPg.png</url>
            <title>Stories by Pratik Satani on Medium</title>
            <link>https://medium.com/@pratiksatani?source=rss-d89cd80b3689------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:20:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pratiksatani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin Symbol Processing (KSP): The Future of Code Generation in Kotlin]]></title>
            <link>https://medium.com/@pratiksatani/kotlin-symbol-processing-ksp-the-future-of-code-generation-in-kotlin-f7503881a59f?source=rss-d89cd80b3689------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7503881a59f</guid>
            <category><![CDATA[annotation-processing]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[ksp]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Pratik Satani]]></dc:creator>
            <pubDate>Thu, 01 May 2025 04:51:03 GMT</pubDate>
            <atom:updated>2025-05-01T05:15:58.422Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction: The Problem KSP Solves</h3><p>Annotation processing has long been a staple in Android development, used for generating boilerplate code, enforcing coding conventions, and more. Popular libraries like Dagger and Room heavily rely on annotation processing. Traditionally, Java Annotation Processing (JAP) was the only tool available for this purpose.</p><p>However, JAP has limitations when used with Kotlin:</p><ul><li>It doesn’t understand Kotlin-specific constructs like properties, nullability, and sealed classes.</li><li>Generated code often lacks Kotlin idioms, leading to awkward interop.</li></ul><p><strong>Enter Kotlin Symbol Processing (KSP):</strong> A modern API designed by Google specifically for Kotlin. KSP provides access to Kotlin’s syntax tree and symbols, allowing better Kotlin-centric code generation.</p><h3>2. Understanding the Basics of KSP</h3><p>KSP is a Kotlin-first API for analyzing and processing source code to generate additional source files during compilation. Unlike JAP, which is limited to Java source-level elements, KSP gives access to rich Kotlin symbols, making it better suited for Kotlin-based projects.</p><h3>Key Concepts:</h3><ul><li><strong>Symbol:</strong> Represents elements in the Kotlin source code (e.g., classes, functions, properties).</li><li><strong>Processor:</strong> A component that reads these symbols and generates new code.</li><li><strong>Platform Agnostic:</strong> KSP supports Kotlin/JS, Kotlin/Native, and Kotlin/JVM.</li></ul><h3>3. Setting Up a KSP Project</h3><p>Here’s how you can integrate KSP into your project:</p><h3>Step 1: Add KSP Plugin</h3><p>In your root build.gradle.kts:</p><pre>plugins {<br>    id(&quot;com.google.devtools.ksp&quot;) version &quot;&lt;ksp_version&gt;&quot;<br>}</pre><h3>Step 2: Add KSP Dependencies</h3><p>In your module build.gradle.kts:</p><pre>dependencies {<br>    implementation(&quot;androidx.room:room-runtime:&lt;version&gt;&quot;)<br>    ksp(&quot;androidx.room:room-compiler:&lt;version&gt;&quot;)<br>    ksp(&quot;com.google.devtools.ksp:symbol-processing-api:&lt;ksp_version&gt;&quot;)<br>}</pre><h3>Step 3: Create a Processor Module</h3><p>To organize your KSP processor, it’s best to place it in its own module. Here’s how to structure this:</p><h4>1. Create a New Module for KSP processing:</h4><ul><li>In Android Studio, go to <strong>File &gt; New &gt; New Module</strong> and select a <strong>Kotlin Library</strong> or <strong>Java Library</strong> module.</li><li>This module will contain the logic for your KSP processor.</li></ul><h4>2. Add Necessary Dependencies:</h4><p>In the new module’s build.gradle.kts file, add the required KSP dependency:</p><pre>dependencies {<br>    implementation(&quot;com.google.devtools.ksp:symbol-processing-api:&lt;ksp_version&gt;&quot;)<br>    // Additional dependencies if needed<br>}</pre><p>3. <strong>Organize the Processor Files</strong>:</p><p>You will create the KSP processor classes in this module. Here’s the recommended structure:</p><ul><li>src/main/kotlin/com/example/ksp/processor/GenerateRepositoryProcessorProvider.kt<br> This file contains the SymbolProcessorProvider class, which serves as the entry point for the KSP processor.</li><li>src/main/kotlin/com/example/ksp/processor/GenerateRepositoryProcessor.kt<br> This file holds the core logic of the processor, where you’ll define how the processor interacts with symbols, finds annotations, and generates code.</li></ul><h4>Example File Structure:</h4><pre>&lt;project-root&gt;<br>|-- app/                            # Your main app module<br>|-- ksp-processor/                  # KSP Processor Module<br>    |-- src/<br>        |-- main/<br>            |-- kotlin/<br>                |-- com/<br>                    |-- example/<br>                        |-- ksp/<br>                            |-- processor/<br>                                |-- GenerateRepositoryProcessorProvider.kt<br>                                |-- GenerateRepositoryProcessor.kt</pre><h4>4. Define Output Files:</h4><p>Inside the processor logic, use the CodeGenerator API to create and write new code files. You’ll specify the output file’s directory and the generated code within the processor class. This makes it possible to automatically generate repository classes, DAOs, or any other code based on annotations.</p><h3>4. Building a Simple KSP Processor</h3><h3>Core Components:</h3><ul><li>SymbolProcessorProvider: Creates the processor.</li><li>SymbolProcessor: Main class with process() method.</li><li>KSPLogger: Logs messages.</li><li>CodeGenerator: Emits files.</li></ul><h3>Example: Find All Classes with a Custom Annotation</h3><p>You can create a simple processor that finds all classes with @AutoGenerate and generates files.</p><h3>5. Real-Time Example: Generating Repositories from DAO Interfaces</h3><h3>Problem:</h3><p>Room requires repetitive writing of repositories to wrap @Dao interfaces.</p><h3>Goal:</h3><p>Automatically generate Repository classes from @Dao interfaces annotated with @GenerateRepository.</p><h3>Step-by-Step:</h3><h4>1. Define Custom Annotation</h4><pre>@Target(AnnotationTarget.CLASS)<br>@Retention(AnnotationRetention.SOURCE)<br>annotation class GenerateRepository</pre><h4>2. Create Processor Provider</h4><pre>class GenerateRepositoryProcessorProvider : SymbolProcessorProvider {<br>    override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {<br>        return GenerateRepositoryProcessor(environment.codeGenerator, environment.logger)<br>    }<br>}</pre><h4>3. Create SymbolProcessor</h4><pre>class GenerateRepositoryProcessor(<br>    private val codeGenerator: CodeGenerator,<br>    private val logger: KSPLogger<br>) : SymbolProcessor {<br><br>    override fun process(resolver: Resolver): List&lt;KSAnnotated&gt; {<br>        val symbols = resolver<br>            .getSymbolsWithAnnotation(&quot;com.example.annotations.GenerateRepository&quot;)<br>            .filterIsInstance&lt;KSClassDeclaration&gt;()<br><br>        for (symbol in symbols) {<br>            generateRepositoryFor(symbol)<br>        }<br><br>        return emptyList()<br>    }<br><br>    private fun generateRepositoryFor(classDecl: KSClassDeclaration) {<br>        val className = classDecl.simpleName.asString()<br>        val packageName = classDecl.packageName.asString()<br>        val repositoryName = &quot;${className.removeSuffix(&quot;Dao&quot;)}Repository&quot;<br><br>        val file = codeGenerator.createNewFile(<br>            Dependencies(false, classDecl.containingFile!!),<br>            packageName,<br>            repositoryName<br>        )<br><br>        val functions = classDecl.getAllFunctions()<br>            .filter { it.isAbstract }<br><br>        file.bufferedWriter().use { writer -&gt;<br>            writer.write(&quot;package $packageName\n\n&quot;)<br>            writer.write(&quot;class $repositoryName(private val ${className.replaceFirstChar { it.lowercase() }}: $className) {\n&quot;)<br><br>            for (function in functions) {<br>                val fnName = function.simpleName.asString()<br>                val returnType = function.returnType?.resolve()?.declaration?.qualifiedName?.asString() ?: &quot;Unit&quot;<br>                val params = function.parameters.joinToString { &quot;${it.name?.asString()}: ${it.type.resolve().declaration.qualifiedName?.asString()}&quot; }<br>                val args = function.parameters.joinToString { it.name?.asString() ?: &quot;&quot; }<br><br>                writer.write(&quot;    fun $fnName($params): $returnType {\n&quot;)<br>                writer.write(&quot;        return ${className.replaceFirstChar { it.lowercase() }}.$fnName($args)\n&quot;)<br>                writer.write(&quot;    }\n\n&quot;)<br>            }<br><br>            writer.write(&quot;}\n&quot;)<br>        }<br>    }<br>}</pre><h4>4. Example DAO</h4><pre>@GenerateRepository<br>@Dao<br>interface UserDao {<br>    suspend fun insert(user: User)<br>    fun getAllUsers(): Flow&lt;List&lt;User&gt;&gt;<br>}</pre><h4>5. Generated Output</h4><pre>class UserRepository(private val userDao: UserDao) {<br>    fun insert(user: User): Unit {<br>        return userDao.insert(user)<br>    }<br><br>    fun getAllUsers(): Flow&lt;List&lt;User&gt;&gt; {<br>        return userDao.getAllUsers()<br>    }<br>}</pre><h3>6. Advanced KSP Concepts (Brief)</h3><ul><li><strong>Type Resolution:</strong> Resolve generic or complex types.</li><li><strong>Annotation Parameters:</strong> Read and use parameters in logic.</li><li><strong>Incremental Builds:</strong> KSP supports incremental compilation, boosting performance.</li></ul><h3>7. Tips and Best Practices</h3><ul><li><strong>Use </strong><strong>KSPLogger</strong> for warnings/errors.</li><li><strong>Separate Logic and Output</strong> cleanly.</li><li><strong>Write Unit Tests</strong> using sample Kotlin source files and in-memory processing.</li><li><strong>Handle All Cases:</strong> Be defensive in type parsing.</li></ul><h3>8. Conclusion</h3><p>KSP is a game-changer for Kotlin developers. It enables precise, idiomatic Kotlin code generation and integrates well with tools like Room and Dagger. With a bit of setup, you can automate complex, repetitive code, improving maintainability and developer happiness.</p><p>Whether you’re building your own codegen framework or optimizing existing workflows, KSP gives you the power to own your development experience.</p><p><strong>👏 Thanks for reading! If you found this helpful, follow me for more Kotlin and Android deep dives.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7503881a59f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Flow vs LiveData in 2025 — Which One’s the Real Standard Now?]]></title>
            <link>https://medium.com/@pratiksatani/kotlin-flow-vs-livedata-in-2025-which-ones-the-real-standard-now-ff258192744a?source=rss-d89cd80b3689------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff258192744a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[livedata]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin-flow]]></category>
            <dc:creator><![CDATA[Pratik Satani]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 04:45:26 GMT</pubDate>
            <atom:updated>2025-04-22T04:51:31.657Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin Flow vs LiveData in 2025 — Which One’s the Real Standard Now?</h3><p>What Android devs need to know when building modern apps.</p><p><strong>Body:</strong></p><blockquote><em>In 2025, we’re seeing a clear shift in how Android apps are built. One of the most debated topics?<br> </em><strong><em>Kotlin Flow vs LiveData.</em></strong></blockquote><blockquote><em>After working hands-on with both over the years — and leading mobile at my current company — here’s how I see it today.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Q8Epim8qINCuzydVg9hiw.png" /></figure><h3>🔄 LiveData: Still Reliable, But…</h3><p>LiveData has served Android devs well. It’s lifecycle-aware and easy to use with the UI. You don’t need much setup — just observe and update.</p><p>But it has limits:</p><ul><li>Can’t be used outside the UI layer</li><li>Lacks advanced operators like debounce or mapLatest</li><li>Doesn’t fit well with clean or modular architecture</li></ul><p>It’s great for beginners or smaller projects — but starts breaking down in complex apps.</p><h3>🌊 Flow: Reactive, Clean, and Built for the Future</h3><p>Flow is Kotlin’s way of handling async streams — and it’s become the <strong>go-to standard</strong> for scalable app architecture.</p><p>Why devs (including me) love it:</p><ul><li>Works across <em>ViewModel, Repository, UseCase</em> layers</li><li>You get powerful operators like map, debounce, catch</li><li>Plays perfectly with suspend functions and coroutines</li><li>Easy to test in unit tests using runBlockingTest</li></ul><p>It requires a bit more understanding up front — but once you master it, it’s a game changer.</p><h3>🧪 Real Experience from Production</h3><p>At our company, we transitioned from LiveData to Flow — and never looked back.</p><p>Here’s what changed:</p><ul><li>ViewModels became cleaner</li><li>Fewer bugs from lifecycle issues</li><li>Business logic moved out of the UI</li><li>Testing was <em>so much easier</em></li></ul><p>We still convert Flow to LiveData in the ViewModel <em>only when necessary</em>, just for compatibility with some UI frameworks.</p><pre>### ✅ When to Use What<br><br>| Use Case                          | LiveData  | Flow       |<br>|----------------------------------|-----------|------------|<br>| Simple UI Data                   | ✅        | ✅          |<br>| Complex async operations         | ❌        | ✅          |<br>| Clean Architecture (multi-layer) | ❌        | ✅          |<br>| Testing                          | 😐        | ✅          |<br>| Lifecycle awareness              | ✅        | ✅ (with scope) |</pre><p><strong>My recommendation?</strong><br> Use Flow everywhere — and wrap it as LiveData in ViewModel only if your UI demands it.</p><h3>💬 What’s Your Approach in 2025?</h3><ul><li>Still using LiveData?</li><li>Fully moved to Flow?</li><li>Something else?</li></ul><p>Drop your thoughts in the comments or connect — let’s exchange ideas and grow together!</p><p>—</p><p>✍️ <em>Written by Pratik Satani</em><br> Head of Mobile Department | Android &amp; Kotlin Enthusiast<br> Let’s connect on <a href="https://www.linkedin.com/in/pratiksatani-androiddev/">LinkedIn</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff258192744a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>