Safe Programming with Kotlin
With chapters selected by Pierre-Yves Saumont
  • August 2019
  • ISBN 9781617297199
  • 92 pages
With automated cars, medical diagnostic tools, and natural disaster prediction and response, programming errors can cost not only money but lives. Let Kotlin put your mind at ease! This modern, elegant, JVM language was designed for safe programming. With features that improve efficiency and reduce mind-numbing boilerplate code and null pointer exceptions, Kotlin makes it more fun than ever to write programs that are reliable and easy to maintain!

About the book

Safe Programming with Kotlin features the first three chapters of the book, The Joy of Kotlin by Pierre-Yves Saumont. In it, you’ll learn how to spot programming traps, handle effects safely, and use abstraction to prevent bugs. You’ll also explore Kotlin’s classes and interfaces, handling nulls, functional programming in Kotlin, advanced function features, and much more. With this free ebook, your flexible, concise, and safe Kotlin programs will be a joy to write and maintain!
Table of Contents detailed table of contents


1. Making programs safer

1.1 Programming traps

1.1.1 Safely handling effects

1.1.2 Making programs safer with referential transparency

1.2 The benefits of safe programming

1.2.1 Using the substitution model to reason about programs

1.2.2 Applying safe principles to a simple example

1.2.3 Pushing abstraction to the limit


2. Functional programming in Kotlin: An overview

2.1 Fields and variables in Kotlin

2.1.1 Omitting the type to simplify

2.1.2 Using mutable fields

2.1.3 Understanding lazy initialization

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.7.1 Declaring functions

2.7.2 Using local functions

2.7.3 Overriding functions

2.7.4 Using extension functions

2.7.5 Using lambdas

2.8 Nulls in Kotlin

2.8.1 Dealing with nullable types

2.8.2 Elvis and the default value

2.9 Program flow and control structures

2.9.1 Using conditional selectors

2.9.2 Using multi-conditional selectors

2.9.3 Using loops

2.10 Kotlin’s unchecked exceptions

2.11 Automatic resource closure

2.12 Kotlin’s smart casts

2.13 Equality versus identity

2.14 String interpolation

2.15 Multi-line strings

2.16 Variance: parameterized types and subtyping

2.16.1 Why is variance a potential problem?

2.16.2 When to use covariance and when to use contravariance

2.16.3 Declaration-site variance versus use-site variance


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

3.2.1 Understanding functions as data

3.2.2 Understanding data as functions

3.2.3 Using object constructors as functions

3.2.4 Using Kotlin’s fun functions

3.2.5 Using object notation versus functional notation

3.2.6 Using value functions

3.2.7 Using function references

3.2.8 Composing functions

3.2.9 Reusing functions

3.3 Advanced function features

3.3.1 What about functions of several arguments?

3.3.2 Applying curried functions

3.3.3 Implementing higher-order functions

3.3.4 Creating polymorphic HOFs

3.3.5 Using anonymous functions

3.3.6 Defining local functions

3.3.7 Implementing closures

3.3.8 Applying functions partially and automatic currying

3.3.9 Switching arguments of partially-applied functions

3.3.10 Declaring the identity function


What's inside

  • Applying safe programming principles
  • Pushing abstraction to the limit
  • Advanced function features

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) and The Joy of Kotlin (Manning, 2019).

placing your order...

Don't refresh or navigate away from the page.
eBook $0.00 PDF only
Safe Programming with Kotlin (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks