Jump to ratings and reviews
Rate this book

Functional Programming in C++

Rate this book
Summary

Functional Programming in C++ teaches developers the practical side of functional programming and the tools that C++ provides to develop software in the functional style. This in-depth guide is full of useful diagrams that help you understand FP concepts and begin to think functionally.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Technology

Well-written code is easier to test and reuse, simpler to parallelize, and less error prone. Mastering the functional style of programming can help you tackle the demands of modern apps and will lead to simpler expression of complex program logic, graceful error handling, and elegant concurrency. C++ supports FP with templates, lambdas, and other core language features, along with many parts of the STL.

About the Book

Functional Programming in C++ helps you unleash the functional side of your brain, as you gain a powerful new perspective on C++ coding. You'll discover dozens of examples, diagrams, and illustrations that break down the functional concepts you can apply in C++, including lazy evaluation, function objects and invokables, algebraic data types, and more. As you read, you'll match FP techniques with practical scenarios where they offer the most benefit.

What's inside


Writing safer code with no performance penalties
Explicitly handling errors through the type system
Extending C++ with new control structures
Composing tasks with DSLs

About the Reader

Written for developers with two or more years of experience coding in C++.

About the Author

Ivan Čukić is a core developer at KDE and has been coding in C++ since 1998. He teaches modern C++ and functional programming at the Faculty of Mathematics at the University of Belgrade.

Table of Contents


Introduction to functional programming
Getting started with functional programming
Function objects
Creating new functions from the old ones
Purity: Avoiding mutable state
Lazy evaluation
Ranges
Functional data structures
Algebraic data types and pattern matching
Monads
Template metaprogramming
Functional design for concurrent systems
Testing and debugging

320 pages, Kindle Edition

Published November 19, 2018

17 people are currently reading
119 people want to read

About the author

Ivan Čukić

3 books1 follower

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
26 (36%)
4 stars
38 (53%)
3 stars
6 (8%)
2 stars
1 (1%)
1 star
0 (0%)
Displaying 1 - 13 of 13 reviews
Profile Image for Jeff.
196 reviews10 followers
July 30, 2023
Interesting book, but I don't think it'll change the way I write software very much. Some of the suggestions amount to using the library well; some suggestions seem like they're best sitting on (for open source software) until ranges are totally ubiquitous; and some suggestions I didn't find compelling---whether that's because they required lots of boiler plate, or the existing solutions seem to handle 99% of my use cases (e.g., enums vs other algebraic data types).

That said, I loved the book, and it forced me to think about C++ in ways that I haven't before
Profile Image for Rene Stein.
228 reviews36 followers
November 8, 2018
Poslední hodnocení je pro MEAP V11 - opraveny kritické chyby. Velmi solidní kniha. Bohužel příklad s aktory je zjednodušený příliš (jeden thread) a pro čtenáře, který nezná knihovnu Boost ASIO, asi i dost nepřehledný. Moje C++ knihovna pro aktory/agenty sice neumí skládat dataflow pomocí operátoru |, ale pro projekty, kde v knize popisované explicitní dataflow není snadno rozpoznatelné, se s ní aktoři vytvářejí podle mě mnohem lépe. Dataflow je podle mě také konstrukce, který s aktory úzce souvisí, protože jeden uzel v dataflow je z hlediska implementace aktorem (resp. spíš in-process agentem), ale aktoři/agenti se snadno používají i mimo explicitně vytvářené dataflow a výklad v knize, který v jednom odstavci současně mluví o aktorech, dataflow a monadických operátorech (map, bind, join) je matoucí. Kdybych dataflow a monadické operátory neznal, ve výkladu bych se špatně orientoval i přes to, že jsem přečetl předchozí kapitolu o monádách.

Kapitola o monádách je napsána totiž tak, že nevím, kdo má být cílovou skupinou. Vývojář, který o monádách ještě neslyšel? Pak pochybuju, že z autorova výkladu monády pochopí a zorientuje se v tom, proč pro monády musí platit nějaké zákony (right identity, left identity, associativity) a proč ho nakonec autor uzemní popisem Kleisliho (?) kompozice. Ten, kdo monády zná a používá, i ten, kdo se trochu orientuje v teorii kategorií, bude zase trochu poděšen nesnesitelnou lehkostí autorova výkladu.

Nejvíc se mi líbily kapitoly o šablonovém metaprogramování (template metaprogramming) a dalších konstrukcích v C++ 17. Asi i proto, že na toto téma zatím moc literatury není.

Poslední kapitola o testování je odbytá, nebo není hotová.

MEAP V8
Podkapitola 8.1.4 MemoryManagement je přímo děsivá (použití shared_ptr). Původní hodnocení **
Profile Image for Austin Gilbert.
9 reviews
February 19, 2020
This book does an excellent job of presenting functional programming techniques and terminology to the reader. I didn't feel I had time to go learn a new language, so bringing the concepts alive in a language I already know well was huge.

There are some chapters I plan on rereading to deepen my understanding. I highly recommend this book to anyone working as a C++ developer.
204 reviews
May 2, 2019
Good but...pales in comparison to 'Functional Programming in JavaScript' from the same publisher.

That sold the idea of FP and monads by way of example that this didn't quite rise to. Nevertheless a worthwhile read and there are some C++1x language tips & tricks to be picked up.
9 reviews
March 13, 2019
A nice intro on functional programming ideas in C++. However, before reading this one, I would recommend familiarizing yourself with FP ideas using some other language that was designed ab initio according to the functional paradigm, such as Haskell. Learn You a Haskell for Great Good! might be a good start of that journey. After that it should be much more clear what this book is trying to achieve and that there is much more unexplored area that needs to be addressed. I hope that author will continue writing (new books) with more in-depth treatment of the topic.
One this that bothered me were inconsistencies between code in the book and accompanying code samples. It would be much better if author kept versions for C++14 and C++17 in separate files.
Profile Image for Carter.
597 reviews
April 29, 2019
This book attempts to explain on the one hand notions in functional programming(FP) and on the other hand how to utilize these techniques(with some compromises) in C++ with a number of interesting examples. I however feel that one would be better served by reading about those concepts in an FP text for the former since some of the explanations here don't really address this facet that well. The book probably could be better if the author were more willing to dive into more lambda calculus style notation before expressing the ideas in C++ or discussing possible ways of implementing these ideas in C++ and what the tradeoffs are.
Profile Image for Moritz.
46 reviews2 followers
October 24, 2019
One cant shake the feeling the author is fighting the programming language in this one. It feels like C++ is not (yet) the best choice for programming in the functional paradigm. But this is not the books fault. Its a great book to get to know the functional parts of C++ and to become a better C++ developer overall.

This book is not for people who want to get into functional programming (because C++ is not (yet) the right language for that). But it is a great read for people who are interested in the paradigm and want to improve their C++ skills.
4 reviews2 followers
May 27, 2020
The author explores several aspects and features of the C++ language that can be used to adopt a more functional paradigm as alternative to traditional OO and imperative programming. The book is friendly even for programmers who aren't familiar with functional programming at all, as the author makes a great introduction on the concepts of functors, monads, algebraic data types and other important functional concepts. The ranges chapter is especially recommended.
Profile Image for Antoine Savine.
Author 2 books16 followers
November 13, 2018
A courageous effort and many interesting insights, unfortunately made very hard by limited support in standard C++ 11/14/17 for functional programming, forcing the author to recourse to non standard third party libraries.
Profile Image for Joe.
108 reviews1 follower
June 21, 2021
Great content, however numerous formatting issues detract from the book’s readability. An updated version to address the source code formatting and page layout would help keep the reader engaged while following along with the examples.
Profile Image for Dayton Outar.
113 reviews5 followers
November 29, 2021
Excellent material that demonstrates the ingenious use of making the most from templates and function overloading.
Profile Image for Parisa.
41 reviews7 followers
April 27, 2022
A really nice intro on functional programming in C++. You’d better be familiar with C++ before reading this, otherwise it would be more challenging to understand the contents.
Displaying 1 - 13 of 13 reviews

Can't find what you're looking for?

Get help and learn more about the design.