Book Image

Mastering Kotlin

By : Nate Ebel
Book Image

Mastering Kotlin

By: Nate Ebel

Overview of this book

Using Kotlin without taking advantage of its power and interoperability is like owning a sports car and never taking it out of the garage. While documentation and introductory resources can help you learn the basics of Kotlin, the fact that it’s a new language means that there are limited learning resources and code bases available in comparison to Java and other established languages. This Kotlin book will show you how to leverage software designs and concepts that have made Java the most dominant enterprise programming language. You’ll understand how Kotlin is a modern approach to object-oriented programming (OOP). This book will take you through the vast array of features that Kotlin provides over other languages. These features include seamless interoperability with Java, efficient syntax, built-in functional programming constructs, and support for creating your own DSL. Finally, you will gain an understanding of implementing practical design patterns and best practices to help you master the Kotlin language. By the end of the book, you'll have obtained an advanced understanding of Kotlin in order to be able to build production-grade applications.
Table of Contents (25 chapters)
Free Chapter
1
Section 1: Kotlin – A Modern Solution to Application Development
4
Section 2: Putting the Pieces Together – Modeling Data, Managing State, and Application Architecture
8
Section 3: Play Nice – Integrating Kotlin With Existing Code
13
Section 4: Go Beyond – Exploring Advanced and Experimental Language Features
17
Section 5: The Wide World of Kotlin – Using Kotlin across the Entire Development Stack

What this book covers

Chapter 1, A New Challenger Approaches, provides context for what Kotlin is, how it came about, and why it is gaining popularity. It provides a high-level overview of where the book is headed and lays the foundation for the following chapters' focus on language features, patterns, best practices, and the ability to target multiple domains and platforms.

Chapter 2, Programmers' Multi-Tool – Flexible, Expressive, and Concise, dives into the basic details of the Kotlin language. It highlights some of the most popular language features, such as first-class functions, non-null types, and multiple programming paradigms. For each of these features, you will begin to understand how to take advantage of the feature, and what impact it can have on the overall application architecture.

Chapter 3, Understanding Programming Paradigms in Kotlin, provides an overview of different programming paradigms that Kotlin supports, including imperative, functional, and reactive programming. The chapter describes these paradigms, and details how Kotlin supports, but does not enforce, all three.

Chapter 4, First-Class Functions, introduces you to Kotlin's support for first-class functions. It describes, in detail, how Kotlin functions are flexible, concise, and powerful. You will learn how to leverage Kotlin features such as default parameter values, infix functions, extension functions, and higher-order functions.

Chapter 5, Modeling Real-World Data, exposes you to the fundamentals of inheritance and composition in Kotlin. This chapter details the differences between enums, data classes, sealed classes, and type classes, and aims to illustrate when and why you should choose one over another.

Chapter 6, Interoperability as a Design Goal, provides background into the design goals behind interoperability in Kotlin, why interoperability is so important to Kotlin, and teaches you how to quickly add Kotlin to an existing project.

Chapter 7, Crossing Over – Working across Java and Kotlin, explores the practical ramifications of adding Kotlin to an existing Java code base. It details how to work with both the language within the same project, and about some of the challenges associated with adding a second language to a project.

Chapter 8, Controlling the Story, details how Kotlin code can be modified to provide a better interoperability experience with Java. It highlights how to apply annotations, and how to design Kotlin APIs to make working with Kotlin from Java more idiomatic and enjoyable.

Chapter 9, Baby Steps – Integration through Testing, explores how to integrate Kotlin into an existing project through testing, and demonstrates how the testing experience can be improved using Kotlin and Kotlin-specific features such as DSLs.

Chapter 10, Practical Concurrency, introduces you to advanced threading concepts. It does so by starting from basic threads and working up to Kotlin coroutines as an idiomatic solution for writing asynchronous, non-blocking code.

Chapter 11, Building Your Own Tools – Domain-Specific Languages (DSLs), introduces the concept of custom Domain-Specific Languages (DSLs) written in Kotlin and how they can be used as a powerful tool to solve a variety of challenges.

Chapter 12, Fully Functional – Embracing Functional Programming, provides a deep dive into achieving functional programming with Kotlin. It focuses on how to effectively use the Kotlin Standard Library to write more functional code, and it also takes a look at the Arrow library for writing truly functional code with Kotlin.

Chapter 13, Kotlin on Android, explores the use of Kotlin for Android development. It details why Kotlin is so popular for Android development, how it makes a developer's life easier, and what Kotlin tooling is available for building Android applications.

Chapter 14, Kotlin and Web Development, introduces the use of Kotlin for frontend web development. This chapter will help you to understand where Kotlin can be used for web development, how to get started by building a simple project, and what the limitations of Kotlin for frontend web development are.

Chapter 15, Introducing Multiplatform Kotlin, explores the use of Kotlin for multiplatform projects. It describes how the Kotlin multiplatform approach is different from other cross-platform solutions, how to package and write code that targets multiple platforms, and where the current limitations exist. In this chapter, you will learn how to set up a multiplatform project that targets iOS, Android, and the web using common Kotlin code.

Chapter 16, Taming the Monolith with Microservices, introduces the use of Kotlin for backend services that can be used within a microservices architecture. It will describe how and where Kotlin can be used to write backend services and how those can interoperate with other services.

Chapter 17, Practical Design Patterns, revisits familiar Java design patterns and demonstrates how to reimagine those patterns using Kotlin features that have been explored throughout this book.