Functional Programming: A Brief Introduction

Functional Programming Languages provide 2 main features:

  1. First class functions 
    • which means functions are first-class citizens.
      • functions can be assigned to variables
      • functions can be stored in data structures
      • functions can be passed to other functions as arguments
      • functions can be returned from other functions
  2. Pure functions without any side-effect
    • Functions take values as parameters and return values.
    • No global or mutable state.

What do these two features lead to

  • Localized thinking space 
  • Localized testing 
  • Control abstraction with higher order functions
  • More readable & shorter code
    • Higher order Functions leads to less branches and assignments, which in turn leads to readable, shorter code. 
  • Data abstraction with closures
  • Concurrency – immutable data structures
  • Simplifies programming. No need for complicated Object Oriented Design Patterns, which are required to solve problems that Object Orientation introduces.

Concurrent Programming Models

Distinguishing Parallel Programming and Concurrent Programming

Parallel Programming 

Multiple-processor or multi-core programming

Concurrent Programming 

Multi-threaded programming

Concurrent Programming Models

  • Threads and lock-based Synchronization
    • Java
  • Functional programming model 
    • Pure Functions with no side-effects + Immutable Data Structures
  • Actor based message passing
    • Scala
    • Erlang
    • Clojure
  • Channel based message passing
    • Go
    • Unix processes-pipes
  • STM (Software Transactional Memory) 
    • Clojure
  • Non-blocking I/O or asynchronous I/O
    • Callback Functions
      • Node.JS: Event driven programming and Callback Functions.