Book description
Maintaining poor legacy code, interpreting cryptic comments, and writing the same boilerplate over and over can suck the joy out of your life as a Java developer. Fear not! There's hope! Kotlin is an elegant JVM language with modern features and easy integration with Java. The Joy of Kotlin teaches you practical techniques to improve abstraction and design, to write comprehensible code, and to build maintainable bug-free applications.
About the Technology
Your programming language should be expressive, safe, flexible, and intuitive, and Kotlin checks all the boxes! This elegant JVM language integrates seamlessly with Java, and makes it a breeze to switch between OO and functional styles of programming. It’s also fully supported by Google as a first-class Android language. Master the powerful techniques in this unique book, and you’ll be able to take on new challenges with increased confidence and skill.
About the Book
The Joy of Kotlin teaches you to write comprehensible, easy-to-maintain, safe programs with Kotlin. In this expert guide, seasoned engineer Pierre-Yves Saumont teaches you to approach common programming challenges with a fresh, FP-inspired perspective. As you work through the many examples, you’ll dive deep into handling errors and data properly, managing state, and taking advantage of laziness. The author’s down-to-earth examples and experience-driven insights will make you a better—and more joyful—developer!
What's Inside
- Programming with functions
- Dealing with optional data
- Safe handling of errors and exceptions
- Handling and sharing state mutation
About the Reader
Written for intermediate Java or Kotlin developers.
About the Author
Pierre-Yves Saumont is a senior software engineer at Alcatel-Submarine Networks. He’s the author of Functional Programming in Java (Manning, 2017).
Quotes
A fabulous introduction to the universe of functional programming!
- Aleksei Slaikovskii, Oracle
Excellent, easy-to-understand examples of implementing functional programming in Kotlin.
- Emmanuel Medina, Global HITSS
A great handbook for anyone studying Kotlin or functional programming who isn’t sure where to start. Provides solid problems and explanations that don’t underestimate readers.
- Bridger Howell, SoFi
As a merger of both Kotlin and FP, this book teaches only the theory you need and features lots of solved exercises. Give it a try!
- Jean-François Morin, Laval University
Table of contents
- The Joy of Kotlin
- Copyright
- Brief contents
- contents
-
Front matter
- preface
- acknowledgments
-
about this book
- Who should read this book
- What you’ll learn
- Pushing abstraction further
- Immutability
- Referential transparency
- Encapsulated state mutation sharing
- Abstracting control flow and control structures
- Using the right types
- Laziness
- Audience
- How this book is organized: A roadmap
- Completing the exercises
- Learning the techniques in this book
- About the code
- liveBook discussion
- about the author
- about the cover illustration
- 1 Making programs safer
-
2 Functional programming in Kotlin: An overview
- 2.1 Fields and variables in Kotlin
-
2.2 Classes and interfaces in Kotlin
- 2.2.1 Making the code even more concise
- 2.2.2 Implementing an interface or extending a class
- 2.2.3 Instantiating a class
- 2.2.4 Overloading property constructors
- 2.2.5 Creating equals and hashCode methods
- 2.2.6 Destructuring data objects
- 2.2.7 Implementing static members in Kotlin
- 2.2.8 Using singletons
- 2.2.9 Preventing utility class instantiation
- 2.3 Kotlin doesn’t have primitives
- 2.4 Kotlin’s two types of collections
- 2.5 Kotlin’s packages
- 2.6 Visibility in Kotlin
- 2.7 Functions in Kotlin
- 2.8 Nulls in Kotlin
- 2.9 Program flow and control structures
- Kotlin’s unchecked exceptions
- Automatic resource closure
- Kotlin’s smart casts
- Equality versus identity
- String interpolation
- Multi-line strings
- Variance: parameterized types and subtyping
- Summary
-
3 Programming with functions
-
3.1 What’s a function?
- 3.1.1 Understanding the relationship between two function sets
- 3.1.2 An overview of inverse functions in Kotlin
- 3.1.3 Working with partial functions
- 3.1.4 Understanding function composition
- 3.1.5 Using functions of several arguments
- 3.1.6 Currying functions
- 3.1.7 Using partially-applied functions
- 3.1.8 Functions have no effects
- 3.2 Functions in Kotlin
- Exactness
- 3.3 Advanced function features
- Testing function parameters
- Summary
-
3.1 What’s a function?
- 4 Recursion, corecursion, and memoization
- 5 Data handling with lists
- 6 Dealing with optional data
- 7 Handling errors and exceptions
- 8 Advanced list handling
- 9 Working with laziness
-
10 More data handling with trees
- 10.1 The binary tree
- 10.2 Understanding balanced and unbalanced trees
- 10.3 Looking at size, height, and depth in trees
- 10.4 Empty trees and the recursive definition
- 10.5 Leafy trees
- 10.6 Ordered binary trees or binary search trees
- 10.7 Insertion order and the structure of trees
- 10.8 Recursive and non-recursive tree traversal order
- 10.9 Binary search tree implementation
- About folding trees
- About mapping trees
- About balancing trees
- Summary
- 11 Solving problems with advanced trees
- 12 Functional input/output
- 13 Sharing mutable states with actors
-
14 Solving common problems functionally
- 14.1 Assertions and data validation
- 14.2 Retries for functions and effects
- 14.3 Reading properties from a file
-
14.4 Converting an imperative program: The XML reader
- 14.4.1 Step 1: The imperative solution
- 14.4.2 Step 2: Making an imperative program more functional
- 14.4.3 Step 3: Making the program even more functional
- 14.4.4 Step 4: Fixing the argument type problem
- 14.4.5 Step 5: Making the element-processing function a parameter
- 14.4.6 Step 6: Handling errors on element names
- 14.4.7 Step 7: Additional improvements to the formerly imperative code
- Summary
-
Appendix A. Mixing Kotlin with Java
- Creating and managing mixed projects
-
Java library methods and Kotlin code
- Using Java primitives
- Using Java numerical object types
- Failing fast on null values
- Using Kotlin and Java string types
- Implementing other type conversions
- Using Java varargs
- Specifying nullability in Java
- Calling getters and setters
- Accessing Java properties with reserved names
- Calling checked exceptions
- SAM interfaces
- Kotlin functions and Java code
- Specific problems with mixed Kotlin/Java projects
- Summary
- Appendix B. Property-based testing in Kotlin
- Index
- Lists of Figures, Tables and Listings
Product information
- Title: The Joy of Kotlin
- Author(s):
- Release date: April 2019
- Publisher(s): Manning Publications
- ISBN: 9781617295362
You might also like
book
Functional Kotlin
Learn how to apply Functional Programming with Kotlin to real-life projects with popular libraries like Arrow. …
book
Mastering Kotlin
Explore popular language features, Java to Kotlin interoperability, advanced topics, and practical applications by building a …
book
Kotlin in Action
Kotlin in Action guides experienced Java developers from the language basics of Kotlin all the way …
book
Functional Programming in Kotlin
Master techniques and concepts of functional programming to deliver safer, simpler, and more effective Kotlin code. …