|The Joy of Kotlin|
Author: Pierre-Yves Saumont
What would you expect a book called The Joy Of Kotlin to be about? Well I would expect it to focus on Kotlin, the language and how wonderful it is to use. I'm of the opinion that Kotlin is wonderful and a practical demonstration of what a modern language should be. By showing up where Java lets us down, it is a wonderful lesson. But none of this is what the book is about. Instead it is about "hardline" functional programming and Kotlin just happens to be the language used. I for one feel cheated by the title. It would be better and more accurately named "The Joy of Functional Programming Using Kotlin".
OK, it's about functional programming how well does it cover this topic?
Pierre-Yves Saumont starts off with a look at referential transparency and how it can make programs "safer". This is a very pure idea and any reader is bound to be wondering if anything like this can work in the real world. Next we take a look at Kotlin as a functional prgramming language This is where we learn that if you don't know Kotlin you should read another book.
What is provided is an overview of a collection of Kotlin topics and it doesn't really explain why the topic chosen are useful for functional programming. It spends a lot of space on functions, as you might expect, but fails to point out adequately that one of the Joys of Kotlin is that it has functions, and not just methods like Java. This introduction to Kotlin is inadequate for the beginner and fails to explain why Kotlin is a good language for functional programming.
Moving on from Kotlin in general, we next concentrate on the idea of a function. The mathematical idea of a function as a mapping from a domain to a co-domain is introduced, something this is arguably unnecessary for practical programming, but it does give you a clue that we are reading a mathematically-oriented account of functional programming - this is programming as math. Ideas such as higher order functions, currying, partial application and so on are discussed.
The twin ideas of co-recursion and recursion are introduced next and I have to say I've never found this distinction to be particularly useful - interesting and entertaining perhaps, but not useful. The good news is that Kotlin supports tail call elimination which makes it much more suitable for recursion than Java. If you don't like recursion you aren't going to like it any more after reading about it here.
The rest of the book digs ever deeper into functional programming by way of examples - mostly about implementing a better List data type. Inevitably we meet ideas such as monads, but without the deep technical detail. Handling errors, optional data, lazy evaluation, trees, functional I/O and actors all feature. They are all explained at a level that is too theoretical for the practical programmer and too practical for the theoretical programmer. It might just suit some readers who want to occupy the middle ground. The big problem, and it always is with functional programming, is keeping the high-minded objectives to the fore while struggling with practical details.
My acid test is would I use a technique to implement a user interface and for functional programming I have to say no - but you might well disagree. My opinion is that if you want to apply functional programming at this level you might as well bite the bullet and learn Haskill.
This is a book that despite some problems has a lot to offer the right reader, if only an intellectual challenge. If you are looking for a book the celebrates the features that makes Kotlin a good language to learn for general purpose programming then the one I would recommend is the The Programmer's Guide to Kotlin, written by Mike James, editor of I Programmer and a fellow Kotlin enthusiast.
To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.
|Last Updated ( Tuesday, 06 October 2020 )|