Book Image

Testing with F#

By : Mikael Lundin
Book Image

Testing with F#

By: Mikael Lundin

Overview of this book

Table of Contents (17 chapters)
Testing with F#
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Expressiveness through functional programming


There is a very important distinction between programming language paradigms. Two kinds of programming styles stand against each other:

  • Imperative programming

  • Declarative programming

The imperative programming style has its origin in Fortran, and the declarative programming paradigm's roots can be followed back to Lisp. The following sections will compare the two styles and explain why we prefer one over the other in testing.

Imperative programming

Imperative programming has become the standard of programming methodology with the rise of languages such as BASIC, Pascal, C, and C#. It means describing to the computer how to calculate a result, in a way that you would describe how to make a cake:

// imperative programming
let double_imperative numbers =
    let doubled = System.Collections.Generic.List<int>()

    for number in numbers do
        let double = number * 2
        doubled.Add(double)

    doubled 

This code example will double all...