Functional Programming in C++: How to improve your C++ programs using functional techniques
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

  1. Introduction to functional programming
  2. Getting started with functional programming
  3. Function objects
  4. Creating new functions from the old ones
  5. Purity: Avoiding mutable state
  6. Lazy evaluation
  7. Ranges
  8. Functional data structures
  9. Algebraic data types and pattern matching
  10. Monads
  11. Template metaprogramming
  12. Functional design for concurrent systems
  13. Testing and debugging
1126488253
Functional Programming in C++: How to improve your C++ programs using functional techniques
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

  1. Introduction to functional programming
  2. Getting started with functional programming
  3. Function objects
  4. Creating new functions from the old ones
  5. Purity: Avoiding mutable state
  6. Lazy evaluation
  7. Ranges
  8. Functional data structures
  9. Algebraic data types and pattern matching
  10. Monads
  11. Template metaprogramming
  12. Functional design for concurrent systems
  13. Testing and debugging
49.99 In Stock
Functional Programming in C++: How to improve your C++ programs using functional techniques

Functional Programming in C++: How to improve your C++ programs using functional techniques

by Ivan Cukic
Functional Programming in C++: How to improve your C++ programs using functional techniques

Functional Programming in C++: How to improve your C++ programs using functional techniques

by Ivan Cukic

Paperback(1st Edition)

$49.99 
  • SHIP THIS ITEM
    In stock. Ships in 1-2 days.
  • PICK UP IN STORE

    Your local store may have stock of this item.

Related collections and offers


Overview

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

  1. Introduction to functional programming
  2. Getting started with functional programming
  3. Function objects
  4. Creating new functions from the old ones
  5. Purity: Avoiding mutable state
  6. Lazy evaluation
  7. Ranges
  8. Functional data structures
  9. Algebraic data types and pattern matching
  10. Monads
  11. Template metaprogramming
  12. Functional design for concurrent systems
  13. Testing and debugging

Product Details

ISBN-13: 9781617293818
Publisher: Manning
Publication date: 11/19/2018
Edition description: 1st Edition
Pages: 320
Product dimensions: 7.30(w) x 9.10(h) x 0.60(d)

About the Author

Ivan Cukic 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

Preface xiii

Acknowledgments xv

About this book xvii

About the author xxi

1 Introduction to functional programming 1

1.1 What is functional programming? 2

Relationship with object-oriented programming 3

A concrete example of imperative vs. declarative programming 3

1.2 Pure functions 8

Avoiding mutable state 10

1.3 Thinking functionally 12

1.4 Benefits of functional programming 14

Code brevity and readability 15

Concurrency and synchronization 16

Continuous optimization 17

1.5 Evolution of C++ as a functional programming language 17

1.6 What you'll learn in this book 19

2 Getting started with functional programming 21

2.1 Functions taking functions? 22

2.2 Examples from the STL 24

Calculating averages 24

Folding 27

String trimming 31

Partitioning collections based on a predicate 32

Filtering and transforming 34

2.3 Composability problems of STL algorithms 36

2.4 Writing your own higher-order functions 38

Receiving functions as arguments 38

Implementing with loops 38

Recursion and tail-call optimization 40

Implementing using folds 43

3 Function objects 45

3.1 Functions and function objects 46

Automatic return-type deduction 46

Function pointers 49

Overloading call operators 50

Creating generic function objects 52

3.2 Lambdas and closures 54

Lambda syntax 55

Under the hood of lambdas 56

Creating arbitrary member variables in lambdas 59

Generic lambdas 60

3.3 Writing function objects that are even terser than lambdas 61

Operator function objects in STL 64

Operator function objects in other libraries 65

3.4 Wrapping function objects with std::function 68

4 Creating new functions from the old ones 71

4.1 Partial function application 72

A generic way to convert binary functions into unary ones 74

Using stdr::bind to bind values to specific function arguments 77

Reversing the arguments of a binary function 79

Using std::bind on functions with more arguments 80

Using lambdas as an alternative for stdr::bind 83

4.2 Currying: a different way to look at functions 85

Creating curried functions the easier way 87

Using currying with database access 88

Currying and partial function application 90

4.3 Function composition 92

4.4 Function lifting, revisited 95

Reversing a list of pairs 97

5 Purity: Avoiding mutable state 100

5.1 Problems with the mutable state 101

5.2 Pure functions and referential transparency 103

5.3 Programming without side effects 106

5.4 Mutable and immutable state in a concurrent environment 110

5.5 The importance of being const 113

Logical and internal const-ness 115

Optimizing member functions for temporaries 117

Pitfalls with const 119

6 Lazy evaluation 122

6.1 Laziness in C++ 123

6.2 Laziness as an optimization technique 126

Sorting collections lazily 126

Item views in the user interfaces 128

Pruning recursion trees by caching function results 129

Dynamic programming as a form of laziness 131

6.3 Generalized memoization 133

6.4 Expression templates and lazy string concatenation 136

Purity and expression templates 140

7 Ranges 142

7.1 Introducing ranges 144

7.2 Creating read-only views over data 145

Filter function for ranges 145

Transform function for ranges 146

Lazy evaluation of range values 147

7.3 Mutating values through ranges 149

7.4 Using delimited and infinite ranges 151

Using delimited ranges to optimize handling input ranges 151

Creating infinite ranges with sentinels 152

7.5 Using ranges to calculate word frequencies 154

8 Functional data structures 158

8.1 Immutable linked lists 159

Adding elements to and removing them from the start of a list 159

Adding elements to and removing them from the end of a list 161

Adding elements to and removing them from the middle of a list 162

Memory management 163

8.2 Immutable vector-like data structures 165

Element lookup in bitmapped vector tries 167

Appending elements to bitmapped vector tries 168

Updating elements in bitmapped vector tries 171

Removing elements from the end of the bitmapped vector trie 171

Other operations and the overall efficiency of bitmapped vector tries 171

9 Algebraic data types and pattern matching 174

9.1 Algebraic data types 175

Sum types through inheritance 176

Sum types through unions and std::variant 179

Implementing specific states 182

Special sum type: Optional values 184

Sum types for error handling 186

9.2 Domain modeling with algebraic data types 191

The naive approach, and where it falls short 192

A more sophisticated approach: Top-down design 192

9.3 Better handling of algebraic data types with pattern matching 194

9.4 Powerful pattern matching with the Mach7 library 196

10 Monads 199

10.1 Not your father's functors 200

Handling optional values 201

10.2 Monads: More power to the functors 204

10.3 Basic examples 207

10.4 Range and monad comprehensions 209

10.5 Failure handling 212

Std::optional<T> as a monad 212

Expected<T, E> as a monad 214

The Try monad 215

10.6 Handling state with monads 216

10.7 Concurrency and the continuation monad 218

Futures as monads 219

Implementations of futures 221

10.8 Monad composition 223

11 Template metaprogramming 226

11.1 Manipulating types at compile-time 227

Debugging deduced types 229

Pattern matching during compilation 231

Providing metainformation about types 234

11.2 Checking type properties at compile-time 235

11.3 Making curried functions 237

Calling all callables 239

11.4 DSL building blocks 242

12 Functional design-for concurrent systems 248

12.1 The actor model: Thinking in components 249

12.2 Creating a simple message source 252

12.3 Modeling reactive streams as monads 256

Creating a sink to receive messages 257

Transforming reactive streams 260

Creating a stream of given values 262

Joining a stream of streams 263

12.4 Filtering reactive streams 264

12.5 Error handling in reactive streams 265

12.6 Replying to the client 267

12.7 Creating actors with a mutable state 271

12.8 Writing distributed systems with actors 272

13 Testing and debugging 274

13.1 Is the program that compiles correct? 275

13.2 Unit testing and pure functions 276

13.3 Automatically generating tests 278

Generating test cases 278

Property-based testing 280

Comparative testing 281

13.4 Testing monad-based concurrent systems 283

Index 287

From the B&N Reads Blog

Customer Reviews