1 Introduction to functional programming

 

This chapter covers

  • Understanding functional programming
  • Thinking about intent instead of algorithm steps
  • Understanding pure functions
  • Benefits of functional programming
  • C++’s evolution into a functional programming language

As programmers, we’re required to learn more than a few programming languages during our lifetime, and we usually end up focusing on two or three that we’re most comfortable with. It’s common to hear somebody say that learning a new programming language is easy—that the differences between languages are mainly in the syntax, and that most languages provide roughly the same features. If we know C++, it should be easy to learn Java or C#, and vice versa.

This claim does have some merit. But when learning a new language, we usually end up trying to simulate the style of programming we used in the previous language. When I first worked with a functional programming language at my university, I began by learning how to use its features to simulate for and while loops and if-then-else branching. That was the approach most of us took, just to be able to pass the exam and never look back.

1.1 What is functional programming?

1.1.1 Relationship with object-oriented programming

1.1.2 A concrete example of imperative vs. declarative programming

1.2 Pure functions

1.2.1 Avoiding mutable state

1.3 Thinking functionally

1.4 Benefits of functional programming

1.4.1 Code brevity and readability

1.4.2 Concurrency and synchronization

1.4.3 Continuous optimization

1.5 Evolution of C++ as a functional programming language

1.6 What you’ll learn in this book

Summary

sitemap