When is functional programming used?

Programming Paradigm Concepts

Eleanor Thomas

Senior Data Analytics Engineer

Applications of functional programming

  • Machine learning, deep learning, artificial intelligence
  • Analyzing and processing large datasets
  • Data engineering applications (e.g. in Scala and Clojure)

Data processing

Programming Paradigm Concepts

Example of functional programming

def process_data(raw_data):
    processed_data = raw_data

    ... further processing steps here! ...

    return processed_data
  • Function takes input data stored in raw_data
  • Function creates new variable for output data, called processed_data
  • Function performs some consistent set of steps to further process the data
  • Function returns processed_data
Programming Paradigm Concepts

Pros and cons of functional programming

PROS

  • Easier to read and debug pure functions
  • Easier to test pure functions
  • Fewer unexpected consequences in the code
  • Pure functions are highly reusable from project to project
  • Can run different functions in parallel to make code faster

CONS

  • Tricky to get used to thinking in this paradigm, can feel limiting: "side effects" (writing to files, etc.) are most of what we want to do in programming
  • Fewer experts, tools, frameworks exist for functional programming
  • Steeper learning curve and fewer educational resources
  • Larger memory usage limits applications
Programming Paradigm Concepts

Functional programming and declarative programming

  • Functional programming is a type of declarative programming
  • Declarative programming: tell the computer what to do, not how to do it
  • Functional programming is just one type of declarative programming
  • Programmer tells the computer what functions to execute, not the exact steps to follow

Functional programming is declarative

Programming Paradigm Concepts

Let's practice!

Programming Paradigm Concepts

Preparing Video For Download...