Book Image

Hands-On Functional Programming with C++

By : Alexandru Bolboaca
Book Image

Hands-On Functional Programming with C++

By: Alexandru Bolboaca

Overview of this book

Functional programming enables you to divide your software into smaller, reusable components that are easy to write, debug, and maintain. Combined with the power of C++, you can develop scalable and functional applications for modern software requirements. This book will help you discover the functional features in C++ 17 and C++ 20 to build enterprise-level applications. Starting with the fundamental building blocks of functional programming and how to use them in C++, you’ll explore functions, currying, and lambdas. As you advance, you’ll learn how to improve cohesion and delve into test-driven development, which will enable you in designing better software. In addition to this, the book covers architectural patterns such as event sourcing to help you get to grips with the importance of immutability for data storage. You’ll even understand how to “think in functions” and implement design patterns in a functional way. By the end of this book, you’ll be able to write faster and cleaner production code in C++ with the help of functional programming.
Table of Contents (23 chapters)
Free Chapter
1
Section 1: Functional Building Blocks in C++
7
Section 2: Design with Functions
12
Section 3: Reaping the Benefits of Functional Programming
17
Section 4: The Present and Future of Functional Programming in C++

What this book covers

Chapter 1, An Introduction to Functional Programming, introduces you to the fundamental ideas of functional programming.

Chapter 2, Understanding Pure Functions, teaches you the fundamental building blocks of functional programming, functions that focus on immutability, and how to write them in C++.

Chapter 3, Deep Dive into Lambdas, focuses on lambdas and how to write them in C++.

Chapter 4, The Idea of Functional Composition, looks at how to compose functions with a higher order operation.

Chapter 5, Partial Application and Currying, teaches you how to use two fundamental operations on functions—partial application and currying in C++.

Chapter 6, Thinking in Functions – from Data in to Data out, introduces you to another way of organizing your code, enabling function-centric design.

Chapter 7, Removing Duplication with Functional Operations, is an overview of the Don't Repeat Yourself (DRY) principle, the types of code duplication and code similarities, and how to write more DRY code using functional operations such as composition, partial application, and currying.

Chapter 8, Improving Cohesion Using Classes, demonstrates how functions can evolve into classes and how classes can be turned into functions.

Chapter 9, Test-Driven Development for Functional Programming, looks at how to use Test-Driven Development (TDD) with functional programming and at how immutability and pure functions simplify tests.

Chapter 10, Performance Optimization, dives into specific methods of how to optimize the performance of function-centric design, including memoization, tail recursion optimization, and parallel execution.

Chapter 11, Property-Based Testing, looks at how functional programming enables a new paradigm of writing automated tests that enhances example-based testing with data generation.

Chapter 12, Refactoring to and through Pure Functions, explains how any existing code can be refactored to pure functions and then back into classes with minimal risk. It also looks at classic design patterns and a few functional design patterns.

Chapter 13, Immutability and Architecture – Event Sourcing, explains that immutability can move at the data storage level, looks at how to use event sourcing, and discusses its advantages and disadvantages.

Chapter 14, Lazy Evaluation Using the Ranges Library, dives into the awesome ranges library and demonstrates how to use it in C++ 17 and C++ 20.

Chapter 15, STL Support and Proposals, looks at STL functional features in the C++ 17 standard and at a few interesting additions to C++ 20.

Chapter 16, Standard Language Support and Proposals, closes the book with an overview of the fundamental building blocks of functional programming and the various options for using them in the C++ 17 standard.