Shared UI vs Shared Logic: Kotlin Multiplatform's Approach

Shared UI is a history of failure. Shared logic is the history of computing. Truth or oversimplification?

Shared UI vs Shared Logic: Kotlin Multiplatform's Approach
Shared UI vs Shared Logic: Kotlin Multiplatform's Approach

In the world of cross-platform development, the debate between Shared UI and Shared Logic has been ongoing for years.

You have probably heard this before:

Shared UI is a history of failure. Shared logic is the history of computing.

While this quote may resonate with some developers, it oversimplifies the nuanced reality of cross-platform development.

In this article, we will explore the advantages of Kotlin Multiplatform (KMP), its unique approach of optionally sharing code, and how it addresses the challenges of Shared UI while using Shared Logic.

The Rise of Shared Logic in Computing

Shared logic, the practice of reusing code for the core functionalities across platforms, has been a foundational principle in computing.

It has enabled developers to maximize efficiency and maintain consistency between different applications.

Shared logic serves as the backbone of numerous successful applications and has proven its reliability time and again.

However, it is essential to recognize that Shared Logic is not without its challenges.

Different platforms have distinct UI paradigms, which often leads to the need for platform-specific UI implementations.

The tension arises when trying to combine Shared Logic with platform-specific UI, resulting in compromises and suboptimal user experiences.

The Shared UI Predicament: Striking a Balance

Shared UI, on the other hand, has had a history filled with mixed results.

Attempts to create one-size-fits-all UI components have often led to clunky, non-native experiences that fail to meet user expectations. Nevertheless, some platforms, like the web, have managed to succeed with Shared UI.

Native development on platforms like iOS has proven its resilience despite the increasing popularity of cross-platform frameworks.

KMP’s Approach: Optionally Shared Code

Kotlin Multiplatform (KMP) offers a refreshing perspective on the Shared UI vs. Shared Logic debate.

One of the defining characteristics of KMP is its design to be optionally included.

By default, KMP focuses on sharing logic, ensuring a lower risk of adoption by any development team, regardless of its size.

This approach encourages efficiency while discouraging the creation of non-native experiences.

The Beauty of Not-Necessarily UI Logic

KMP’s philosophy lies in the concept of “not-necessarily UI logic.”

Unlike most cross-platform frameworks that enforce an all-or-nothing approach, KMP allows developers to build UI and logic independently and mix native and cross-platform elements more seamlessly.

This level of interop, though challenging, pays off in the long run.

The KMP Approach in Practice

Imagine an app with multiple settings and data display screens, of which only a few are frequently used.

With KMP, developers can have these main screens fully native on iOS, communicating with a shared Kotlin architecture underneath.

This means that most of the app’s UI can be shared, while crucial parts can still take advantage of the native platform capabilities.

Comparing KMP with Other Portable UI Frameworks

Some portable UI frameworks attempt to enable similar functionalities, but they often come with compromises that negatively impact user experience.

For instance, transparent overlays and click event pass-throughs may be technically possible, but they often result in subpar user interactions.

KMP, on the other hand, incorporates a more comprehensive approach to optionally shared code, making it a superior choice for core use cases.

Conclusion

In conclusion, the Shared UI vs. Shared Logic debate requires a more nuanced understanding of the challenges and benefits of each approach.

While Shared Logic has long been the cornerstone of computing, combining it with Shared UI has often resulted in suboptimal user experiences.

Kotlin Multiplatform (KMP) offers an innovative solution by emphasizing optionally shared code, giving developers the flexibility to mix native and cross-platform elements effectively.

By doing so, KMP encourages efficient development practices and opens up new possibilities for creating exceptional user experiences on various platforms.

As the world of cross-platform development continues to evolve, KMP’s approach may prove to be the key to unlocking the full potential of Shared Logic while gracefully handling the complexities of Shared UI.