Book description
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!
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
Modern Software Engineering: Doing What Works to Build Better Software Faster
Improve Your Creativity, Effectiveness, and Ultimately, Your Code In Modern Software Engineering, continuous delivery pioneer David …
book
Clean Architecture: A Craftsman's Guide to Software Structure and Design
Building upon the success of best-sellers The Clean Coder and Clean Code, legendary software craftsman Robert …
book
Effective Java, 3rd Edition
Since this Jolt-award winning classic was last updated in 2008, the Java programming environment has changed …
book
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization …