Why Functional Programming?

 

Functional programs contain no assignment statements, so variables, once given a value, never change. More generally, functional programs contain no side-effects at all. A function call can have no effect other than to compute its result. This eliminates a major source of bugs, and also makes the order of execution irrelevant—since no side-effect can change an expression’s value, it can be evaluated at any time. This relieves the programmer of the burden of prescribing the flow of control. Since expressions can be evaluated at any time, one can freely replace variables by their values and vice versa—that is, programs are “referentially transparent.” This freedom helps make functional programs more tractable mathematically than their conventional counterparts.

John Hughes “Why Functional Programming Matters”

I call it my billion-dollar mistake ... My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

Tony Hoare

Program testing can be a very effective way to show the presence of bugs, but is hopelessly inadequate for showing their absence.

Edsger W. Dijkstra

Preface

Acknowledgments

About this Book

Audience

How to use this book

Setting expectations

Author Online

Chapter 1. What is functional programming?

1.1. What is functional programming?

1.2. Writing useful programs with no side effects

1.3. How referential transparency makes programs safer

1.4. The benefits of functional programming

1.5. Using the substitution model to reason about programs

1.6. Applying functional principles to a simple example

1.7. Pushing abstraction to the limit

1.8. Summary

Chapter 2. Using functions in Java

2.1. What is a function?

2.2. Functions in Java

2.3. Advanced function features

2.4. Java 8 functional interfaces

2.5. Debugging with lambdas

2.6. Summary

sitemap