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
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
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í **
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.
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.
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.
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.
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.
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.
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.
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.
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.