The Joy of Kotlin
Pierre-Yves Saumont
  • MEAP began January 2018
  • Publication in Fall 2018 (estimated)
  • ISBN 9781617295362
  • 475 pages (estimated)
  • printed in black & white
Drudgery like 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, design and write comprehensible code, and build maintainable bug-free applications.
Table of Contents detailed table of contents

1. Making programs safer

1.1. Identifying programming traps

1.2. Safely handling effects

1.3. How referential transparency makes programs safer

1.4. The benefits of "safe" programming

1.5. Using the substitution model to reason about programs

1.6. Applying "safe" principles to a simple example

1.7. Pushing abstraction to the limit

1.8. Summary

2. An Overview of Kotlin

2.1. Fields and variables

2.1.1. Omitting the type

2.1.2. Mutable fields

2.2. Classes and interfaces

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 constructors

2.2.5. Private constructors

2.2.6. Using accessors

2.2.7. Creating equals and hashcode

2.2.8. Destructuring data objects

2.2.9. Static members

2.2.10. Singletons

2.2.11. Preventing utility class instantiation

2.3. Primitives

2.4. Collections

2.5. Packages

2.6. Visibility

2.6.1. Classes and interfaces

2.7. Functions

2.7.1. Local functions

2.7.2. Overriding functions

2.7.3. Extension functions

2.7.4. Lambdas

2.7.5. Specifying parameter types

2.7.6. Lambdas with multi-line implementation

2.7.7. Using it

2.7.8. Closures

2.8. Handling nulls

2.8.1. Operators for dealing with nullable types

2.8.2. Elvis and the default value

2.9. Control structures

2.9.1. Conditional selectors

2.9.2. Multi conditional selectors

2.9.3. Loops

2.10. Exceptions

2.10.1. Try with resources

2.11. Castings

2.12. Equality vs identity

2.13. String interpolation

2.13.1. Multi-line strings

2.14. Variance

2.14.1. Why is variance a potential problem?

2.14.2. When to use covariance and when to use contravariance

2.14.3. Declaration-site variance vs. use-site variance

2.15. Summary

3. Programming with functions

3.1. What is a function?

3.1.1. What makes a relation between two sets a function

3.1.2. Inverse functions

3.1.3. Partial functions

3.1.4. Function composition

3.1.5. Functions of several arguments

3.1.6. Function currying

3.1.7. Partially applied functions

3.1.8. Functions have no effects

3.2. Functions in Kotlin

3.2.1. Functions as data

3.2.2. Data as functions

3.2.3. Object constructors as functions

3.3. Using fun functions

3.3.1. Object notation versus functional notation

3.4. Value functions

3.5. Using function references

3.6. Composing functions

3.6.1. Exercise 3.1

3.7. Polymorphic functions

3.7.1. Exercise 3.2

3.8. Advanced function features

3.9. What about functions of several arguments?

3.9.1. Exercise 3.3

3.10. Applying curried functions

3.11. Higher-order functions

3.11.1. Exercise 3.4

3.12. Polymorphic higher-order functions

3.12.1. Exercise 3.5 (hard)

3.12.2. Exercise 3.6 (easy now!)

3.13. Using anonymous functions

3.13.1. When to use anonymous and when to use named functions

3.13.2. Type inference

3.14. Local functions

3.15. Closures

3.16. Partial function application and automatic currying

3.16.1. Exercise 3.7 (very easy)

3.16.2. Exercise 3.8

3.16.3. Exercise 3.9 (very easy)

3.16.4. Exercise 3.10

3.16.5. Switching arguments of partially applied functions

3.16.6. Exercise 3.11

3.17. The identity function

3.18. Using the right types

3.18.1. Problems with standard types

3.18.2. Defining value types

3.19. Summary

4. Recursion, corecursion, and memoization

4.1. Understanding corecursion and recursion

4.1.1. Implementing corecursion

4.1.2. Implementing recursion

4.2. How to differentiate recursive and corecursive functions

4.3. Should you chose recursion or corecursion?

4.4. Tail Call Elimination

4.4.1. Using Tail Call Elimination

4.4.2. How to switch from loop to corecursion

4.4.3. Exercise 4.1

4.5. Creating recursive value functions

4.5.1. Exercise 4.2 (hard!)

4.6. Using recursive functions on lists

4.7. Doubly recursive functions

4.7.1. Exercise 4.3

4.8. Abstracting recursion on lists

4.8.1. Exercise 4.4

4.8.2. Exercise 4.5

4.8.3. Exercise 4.6

4.9. Reversing a list

4.9.1. Exercise 4.7

4.9.2. Exercise 4.8

4.10. Building corecursive lists

4.10.1. Exercise 4.9

4.10.2. Exercise 4.10

4.10.3. Exercise 4.11

4.10.4. Exercise 4.12

4.10.5. Exercise 4.13

4.10.6. Exercise 4.14

4.11. The danger of strictness

4.12. Using memoization

4.12.1. Memoization in loop based programming

4.12.2. Memoization in recursive functions

4.12.3. Exercise 4.15

4.12.4. Implicit memoization

4.12.5. Exercise 4.16

4.12.6. Exercise 4.17

4.12.7. Exercise 4.18

4.12.8. Automatic memoization

4.12.9. Memoization of “multi-argument” functions

4.12.10. Are memoized functions pure?

4.13. Summary

5. Data handling with lists

5.1. How to classify data collections

5.1.1. Different types of lists

5.1.2. Relative expected list performance

5.1.3. Trading time against memory space, and time against complexity

5.1.4. Why in-place mutation should be avoided

5.2. What kinds of lists are available in Kotlin?

5.3. Persistent data structures

5.4. An immutable, persistent, singly linked list implementation

5.5. Data sharing in list operations

5.5.1. Exercise 5.1

5.5.2. Exercise 5.2

5.6. More list operations

5.6.1. Exercise 5.3

5.7. Benefits of object notation

5.7.1. Exercise 5.4

5.8. Concatenating lists

5.9. Dropping from the end of a list

5.9.1. Exercise 5.5

5.10. Using recursion to fold lists with higher-order functions

5.10.1. Exercise 5.6

5.11. Using Variance

5.11.1. Understanding variance

5.11.2. How to get away with variance abuse

5.11.3. Exercise 5.7

5.11.4. Exercise 5.8

5.11.5. Exercise 5.9

5.11.6. Exercise 5.10

5.11.7. Exercise 5.11

5.11.8. Exercise 5.12

5.12. Stack safe recursive version of foldRight

5.12.1. Exercise 5.13

5.12.2. Exercise 5.14

5.12.3. Exercise 5.15

5.13. Mapping and filtering lists

5.13.1. Exercise 5.16

5.13.2. Exercise 5.17

5.13.3. Exercise 5.18

5.13.4. Exercise 5.19

5.13.5. Exercise 5.20

5.13.6. Exercise 5.21

5.14. Summary

6. Dealing with optional data

6.1. Problems with the null pointer

6.2. How Kotlin handles null references

6.3. Alternatives to null references

6.4. The Option type

6.4.1. Getting a value from an Option

6.4.2. Exercise 6.1

6.4.3. Exercise 6.2

6.4.4. Applying functions to optional values

6.4.5. Exercise 6.3

6.4.6. Dealing with Option composition

6.4.7. Exercise 6.4

6.4.8. Exercise 6.5

6.4.9. Exercise 6.6

6.4.10. Option use cases

6.4.11. Exercise 6.7

6.4.12. Other ways to combine options

6.4.13. Exercise 6.8

6.4.14. Exercise 6.9

6.4.15. Exercise 6.10

6.4.16. Composing List with Option

6.4.17. Exercise 6.11

6.4.18. Exercise 6.12

6.5. How and when to use Option

6.6. Summary

7. Safe handling of errors and exceptions

8. Advanced list handling

9. Working with laziness

10. More data handling with trees

11. Solving real problems with advanced trees

12. Safely handling effects

13. Handling and sharing state mutation

14. Solving common problems with safe programming

Appendixes

Appendix A: Property based testing

Appendix B: Mixing Kotlin with Java

About the Technology

The Kotlin programming language offers an expressive syntax, an intuitive type system, and support for a host of tools for you to use. Kotlin runs on the JVM, so it seamlessly integrates with the Java libraries you're already using. Now officially supported by Google as a first-class Android language, there's never been a better time to see what Kotlin can do for you!

About the book

The Joy of Kotlin teaches you the right way to code in Kotlin. In this insight-rich book, you'll master the Kotlin language while exploring coding techniques that will make you a better developer no matter what language you use. Kotlin natively supports a functional style of programming, so seasoned author Pierre-Yves Saumont begins by reviewing the FP principles of immutability, referential transparency, and the separation between functions and effects. Then, you'll move deeper into using Kotlin in the real world, as you learn to handle errors and data properly, encapsulate shared state mutations, and work with laziness. This book will change the way you code—and give you back some of the joy you had when you first started.

What's inside

  • Programming with functions
  • Dealing with optional data
  • Safe handling of errors and exceptions
  • Working with laziness
  • Handling and sharing state mutation

About the reader

Written for intermediate Java or Kotlin developers.

About the author

Pierre-Yves Saumont is an R&D software engineer at Alcatel-Submarine Networks, where he has overseen the previous switch from C to Java, and now to Kotlin too. He has developed several fully functional libraries that are used by business developers. Pierre-Yves is the author of Functional Programming in Java.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
buy
The Joy of Kotlin (combo) added to cart
continue shopping
go to cart

MEAP combo $44.99 pBook + eBook + liveBook
MEAP eBook $35.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks