"A Functional Approach to Java" is finally here!
I’m happy to announce that my book, “A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles” is finally available 🥳
The road was quite longer than expected, but so is the content. Instead of the initially planned ~275 pages, it’s now at ~400!
The digital version is available right now, with the paperback following soon. Click the cover to learn more about the book and where you can get your hands on a copy!
Why I Wrote This Book
To be honest, I started writing articles “by accident”, but enjoyed it quite much. The frequency of me releasing new content might vary, still, I won’t quit. After working on several articles on mostly the same topic, I thought about writing a book, which was something I’d always dreamed of but never dared to do. There was no one pushing me and making sure I finish such an ambitious project like a book, so there came nothing of it, except for maybe a few half-baked chapters
Out of the blue, I got approached by a content acquisition manager from O’Reilly, if I was interested in writing a book on functional Java. Even though I wanted to write a book before, actually writing one for an audience is a completely different beast. But having a publisher like O’Reilly on your side might be the guidance, support, and oversight I needed to not procrastinate too much and never finish. So I said yes, and some paperwork later, I started writing the book.
How did it go?
There were many ups and downs, and some misunderstandings leading to rewrites and content shuffle. The overall process was great, I learned so much. As expected, I also learned what not to do, sometimes the hard way. But I see it as in this quote from Theodore Roosevelt:
Nothing in this world is worth having or worth doing unless it means effort, pain, difficulty.
Working with technical reviewers critiquing my words harshly was another unfamiliar experience. I know I’m not perfect, far from it, but I believe I’m quite good at what I do. At first, any negative feedback felt like a personal attack of my knowledge! However, I soon realized that everyone had only the best intentions: to make the book better. And to be fair, they did! Actual errors aside, seeing my own words and content through the eyes of other people, especially more competent ones, gave me the chance to self-reflect and deepen my understanding of topics I thought I already knew enough about.
Tools of the Trade
Another aspect of writing a book is the tools you use.
I love to talk about bike sheds and shave some yaks, so I gave a perfect writing environment a higher priority than starting to write more content. As usual, you always end up with a compromise, as the real world is more complicated than the ideal one in your head.
O’Reilly, as a technical-oriented publisher, provides quite nice tools to write your book. You can write in Word *shudder* but they also have an AsciiDoc- and Git-based workflow, including SSH support and API access to their CI server.
AsciiDoc is great for writing. However, like Markdown, there are multiple ways to do the same thing. To be consistent throughout the book, I decided to create some helpers in the form of Visual Studio Code snippets for writing, and Shell scripts for validation and additional tasks.
The book contains a lot of figures, which are redrawn during production to have a consistent style. Still, I have to provide an initial drawing first. To make it easier to change, I decided to use Ascii art, like the following for explaining recursion:
The rough figure was created with AsciiFlow, an online editor for “drawing” Ascii. It has some rough edges, but it’s a great tool to start, with some fine-tuning afterward. The book obviously can’t display Ascii art, so I used a shell script to convert any Ascii figure to PNG with the help of ImageMagick.
Managing your book’s content with Git is great, but how do I get a PDF or ePub to see how it actually looks? That’s where the API access comes into play. I’ve used a shell script to trigger the build process, wait for it to finish, and download the result to my local machine.
All the different tools and scripts I used are gathered in my
writing-tools repository on GitHub.
The final part of writing the book, the “production process”, was the most exhausting one due to the unfamiliar tools I had to use. The production process is about proofreading, exterminating errors, validating redrawn figures, fixing page flow/layout etc., so it makes sense to work with the PDF variant instead of “raw” content in Git. That means commenting/editing in Adobe Acrobat, which was less than optimal for me.
PDF is an excellent format for printing, but horrendous from a technical point of view. It’s quite fragile and breaks easily if edited with the wrong tools.
A part of the production process, I was on vacation and had no laptop with me. I love to travel with as little luggage as possible, so I only took my iPad Pro. In my previous article, I’ve already ranted about how idiotic the idea was in hindsight. Still, I saved over 1kg, and, therefore, was able to fly with only cabin-luggage.
Working on an iPad Pro attached to the Magic Keyboard isn’t the most ergonomic option, and combined with the lack of a good chair, I was getting quite uncomfortable quickly. Although, that’s something I can endure for some time if needed. Acrobat crashing and not having saved the last 10-15 minutes of comments I can’t. And it happened multiple times, so I had to track my comments in another app, too, in the case of a crash, so I can recreate them.
To be fair, with a laptop, it would’ve worked better and would have been simpler, so it’s my fault that part of the final process was way harder than it needed to be.
The second and final round of reviews I was on another short trip, but this time, I took my laptop with me. Many of the previous woes were gone, but sitting in an unergonomic chair without an elevated monitor was still a bad thing for my back. Next time, I’d look for a coworking space with day passes.
Enough about me not liking to work on my iPad. It’s time to talk about the book’s content!
What’s in the Box 📦
The book consists of two parts:
PART I: Functional Basics
The first part introduces you to the many aspects of functional programming, and where Java JDK fits in. It gives you an overview of the most relevant functional concepts for Java developers, and what tools the JDK has to offer to get going.
- An Introduction to Functional Programming
- Functional Java
- Functional Interfaces of the JDK
PART II: A Functional Approach
The second part consists of chapter-based deep dives on certain aspects and functional-akin Java features.
- Working with Records
- Data Processing with Streams
- Working with Streams
- Parallel Data Processing with Streams
- Handling null with Optionals
- Functional Exception Handling
- Lazy Evaluation
- Asynchronous Tasks
- Functional Design Patterns
- A Functional Approach to Java
The chapters are mostly standalone, but naturally, are interconnected to a certain degree.
Who Should Read This Book
This book is for you if you are curious about functional programming and want to know what all the fuss is about and apply it to your Java code. As the most important new features for a more functional approach were introduced back in Java 8, you might already be using some functional Java types, maybe even without knowing. But if you desire a more profound knowledge of why and how to apply the benefits of functional programming to your code base, this book is for you.
You don’t need to be an expert on OOP, but the book is not a beginner’s guide to Java or OOP, either. No prior knowledge of functional programming is required, as every concept is introduced with an explanation and examples.
The book covers Java 17 as the latest Long-Term-Support (LTS) version available at publication. Knowing that many developers need to support projects with earlier versions, as do I, the general baseline will be the previous LTS, Java 11. But even if you’re stuck on Java 8, many of the discussed topics are still relevant! However, some chapters will definitely rely on newer features, like Records, which were introduced in Java 14.
This book isn’t for you if you are looking for a compartmentalized, recipe-style book presenting “ready-to-implement” solutions. Its main intention is to introduce functional concepts and idioms and teach you how to incorporate them into your Java code. By the end of this book, you will have a fundamental knowledge of functional programming and its underlying concepts and how to apply this knowledge to your daily work. Every Java functional type will be at your disposal, and you will be able to build anything missing from the JDK by yourself, if necessary.