Use of Functional Programming in the industry

What is Functional Programming

Imperative Programming

Functional Programming

int[] nums = {1,2,3,4...100}
int[] modifedNums;
int j = 0;
for(int i = 0; i < 100; i ++) {
    a[i] = a[i] * a[i];
    if(a[i] < 100) {
         modifiedNums[j++] = a[i]
    }
}
nums.map(x * x).filter(x < 100);

Objective: Write a program that squares every element in an array and returns an array that only contains numbers less than 100

From Wikipedia: In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

What is Functional Programming

Side Effects

global int a = 0;
public void increment() {
     a ++;
}
public void multiply() {
   a * a;
}
public void increment(int a) {
     return a ++;
}
public void multiply(int a) {
   return a * a;
}
  • Less buggy code due to no side effects
  • Efficient Concurrency due to no state
  • Nesting of functions

Who uses Functional Programming

Reactive Programming at Netflix

Fin!

https://www.linkedin.com/in/ahmedbhaila/

https://github.com/ahmedbhaila

ahmed.bhaila@gmail.com

Functional Programming

By Ahmed Bhaila

Functional Programming

  • 80