Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Multiplatform - Mobile

Kotlin Multiplatform - Mobile

Fahim Masud Choudhury, Md Aslam Hossin, Golam Shakib Khan, and I had the privilege of presenting at BRAC University in Bangladesh, focusing on KMP. Our participation in the "Kotlin Config Global 23, BD" conference provided an unforgettable experience, leaving each of us, including myself, overflowing with excitement and a renewed sense of inspiration. The core theme of this conference centered on the significant global influence of Kotlin Multiplatform Mobile (KMP). Additionally, during the event, we seized the opportunity to exhibit a mobile app that we collectively developed using Compose Multiplatform.

#KotlinConfigGlobal23 #BDkug #kotlin #KMM #ComposeMultiplatform #inspiration

Avatar for Jahid Hasan

Jahid Hasan

June 14, 2023
Tweet

More Decks by Jahid Hasan

Other Decks in Technology

Transcript

  1. Kotlin: A Modern Programming Language • Kotlin is a statically-typed

    programming language that runs on the Java Virtual Machine (JVM). • JetBrains started the development of Kotlin in 2010, and the language was officially announced to the public in 2011. • Kotlin is interoperable with Java, meaning that developers can use Kotlin and Java code in the same project. • The latest Kotlin version is 1.8.20 and the latest compiler version is 1.8.22.
  2. 01 02 03 04 Concise syntax, reduces boilerplate code and

    making code easier to read and write. Null safety, reduces the likelihood of NullPointerExceptions. Extension functions, allows developers to add functionality to existing classes without having to inherit from them. Coroutines, simplifies the process of writing asynchronous code. Benefits of using Kotlin
  3. Concise syntax The data class declaration in Kotlin automatically generates

    getters, setters, and common methods like toString(), reducing the amount of boilerplate code
  4. Extension functions ➢ To add a new function to an

    existing class in Java, you would typically create a utility class with a static method. ➢ In Kotlin, you can use extension functions to achieve the same result.
  5. Functional Programming in Kotlin Lambda expressions: A lambda expression is

    a simplified anonymous function that can be used as a value. Higher-order functions: A higher-order function is a function that takes another function as a parameter or returns a function as its result. By using higher-order functions, lambda expressions, and immutability, developers can write expressive and concise code that is easier to read and maintain.
  6. Kotlin vs Java Kotlin Java till JDK 20 Java in

    JDK 21 • Kotlin code makes development much more efficient • Code written in Kotlin is usually about 20% shorter than code written for the same application in Java • Java is embracing Kotlin’s influence
  7. According to recent Statista research, after Go, Kotlin and TypeScript

    are the two programming languages the most programmers plan to switch to learning and using.
  8. Kotlin for Android Write better Android apps faster with Kotlin.

    Kotlin is a modern statically typed programming language used by over 60% of professional Android developers that helps boost productivity, developer satisfaction, and code safety. • Officially supported language for Android app development • Write concise and expressive code using Kotlin's modern features • Leverage Kotlin Android Extensions and Jetpack libraries for enhanced productivity
  9. Kotlin for Server-Side • Use Kotlin with frameworks like Spring

    Boot, Ktor, and Vert.x • Build robust and scalable server applications • Benefit from Kotlin's conciseness, null safety, and coroutines for asynchronous programming
  10. Kotlin WASM (WebAssembly) • Compile Kotlin code to run on

    WebAssembly virtual machine • Build high-performance web applications with near-native speed • Interoperate with JavaScript and leverage existing web technologies
  11. Kotlin Native • Compile Kotlin code to native machine code

    for various platforms (iOS, macOS, Windows, Linux) • Develop platform-specific applications with direct access to system resources • Achieve high performance and efficiency through low-level optimizations
  12. Kotlin for JavaScript • Write Kotlin code that transpiles to

    JavaScript • Develop frontend web applications and interact with existing JavaScript libraries • Benefit from Kotlin's type safety and language features in JavaScript projects
  13. Kotlin for Data Science • Utilize Kotlin libraries like KotlinDL

    and Kotlin Statistics for data analysis and machine learning • Leverage Kotlin's interoperability with popular data science libraries like Apache Spark and TensorFlow • Combine data science capabilities with Kotlin's language benefits for streamlined development
  14. Kotlin for Competitive Programming • Solve algorithmic problems efficiently using

    Kotlin's concise syntax and standard library functions • Leverage Kotlin's advanced language features for clean and readable code • Participate in coding competitions and challenges with Kotlin as a competitive programming language
  15. Kotlin for DSL • Gradle: The Gradle build system utilizes

    a Kotlin DSL for configuring build scripts. This DSL provides a more concise and readable syntax for defining tasks, dependencies, and build configurations. • Kotlinx.html: Kotlinx.html is a library that allows developers to generate HTML markup using a DSL syntax. This makes it easier to write HTML code in a type-safe and readable manner. • Arrow: Arrow is a functional programming library in Kotlin that provides a DSL for working with functional data types such as Option, Either, and Try. The DSL allows developers to compose functional operations in a more intuitive and concise way. • Spek
  16. Kotlin Multiplatform • Develop shared code for multiple platforms (Android,

    iOS, web, desktop) • Share business logic, models, and utilities across platforms • Reduce code duplication and increase development efficiency
  17. Kotlin Multiplatform The Kotlin Multiplatform technology is made to make

    cross-platform project development easier. It keeps the flexibility and advantages of native programming while cutting down on the effort spent writing and maintaining the same code for several platforms. Applications written in Kotlin will run on a variety of OS, including iOS, Android, macOS, Windows, Linux, watchOS, and others.
  18. Code Sharing When starting a new project, use Kotlin Multiplatform

    to implement data, business, and even presentation layers just once. Kotlin Multiplatform can also simplify the development of existing projects. Choose a piece of logic that is frequently changing and typically out of sync (such as data validation, filtering, or sorting), make it cross-platform, and connect it to your project as a micro-library. Additionally, Kotlin Multiplatform doesn’t force you to share any specific part of your codebase. You are free to share your codebase as you see fit.
  19. Code Sharing You can now go beyond sharing app logic

    and reuse the whole app code. Sharing the UI is possible with Compose Multiplatform – you can already experiment with sharing the UI between Android and iOS.
  20. Platform Dependency When we’re talking about multiplatform development, sharing everything

    is not that easy. Some part of your codebase will always be platform dependent. Kotlin Multiplatform offers a solution to that as well. You can write different implementations for the same function, if that function is platform dependent. In this way, you can keep all the code in a single place which will help you to maintain the codebase with minimal effort in the long run.
  21. Kotlin Multiplatform Mobile (KMM) One of the major Kotlin Multiplatform

    use cases is sharing code between mobile platforms. You can share application logic between iOS and Android apps and write platform-specific code only when you need to implement a native UI or work with platform APIs. Compose Multiplatform, a JetBrains' declarative UI framework based on Kotlin and Jetpack Compose, gives you the option to push the sharing capabilities of Kotlin Multiplatform beyond application logic. It allows you to implement your user interface once and then use it for both the platforms. Compose Multiplatform for iOS is currently in Alpha stage. Going forward, we’ll be talking about KMM only.
  22. KMM vs Flutter In order to compare KMM with Flutter,

    first we need to know “What is Flutter?” Released in 2017, Flutter is an open-source UI software development kit (SDK) that allows for building cross-platform solutions for mobile and web devices. With Flutter, it is possible to create an application with a single codebase that will work on iOS, Android, Windows, Linux, and other operating systems. Launched and maintained by Google, Flutter is also supported by the growing community. Unlike other cross-platform frameworks, Flutter does not rely on widgets or web browser technology. Written in the Dart object-oriented language, this UI toolkit employs its own rendering engine for designing widgets.
  23. KMM vs Flutter However, Flutter is mainly popular for mobile

    application development and as you can see, KMM and Flutter, both solve the same problem. But, there are some advantages to KMM over Flutter and that’s why KMM has a very high potential. KMM enables software developers to make apps that offer high performance across both operating systems. Flutter also allows for ensuring great stable performance, but if you want to deliver a comprehensive product to serve a large audience, handle heavy loads, and provide an amazing customer experience, Kotlin Multiplatform is the best choice.
  24. KMM vs Flutter Native solutions written with KMM generally offer

    simpler access to smartphone functions such as a camera, microphone, and offline mode. As a rule, delivering this functionality in a cross-platform application demands more time and effort. To be more specific, Flutter is a hybrid framework. It uses the same codebase and ports it for different platforms. On the other hand, KMM exposes the shared code base as a library to the individual platforms and the application is always built natively. As a result, KMM offers easier integration to platform specific APIs and optimized performance.
  25. Resources • A Basic KMM Repository - https://github.com/jhnaiem/ComposeMultiplatform_KMMPlayGround • A

    More Advanced KMM Repository - https://github.com/ShaQib07/TheMovieApp-KMM • Kotlin Multiplatform • From zero to 10 million lines of Kotlin • Netflix Android and iOS Studio Apps — now powered by Kotlin Multiplatform Bangladesh Kotlin User Group