What is Functional Programming? 4 Core Concepts that you must know to get the first class ticket

The 4 pillars of functional programming

  1. Mutability
  2. Mutable State
  3. First-Class and Higher Order Functions
  4. Pure Functions

Mutability

var age = 30
// some code here
age = 40
var age = 30 
// some code here
age = 45
func doSomething() {
print("Hello World")
age = 67
}
print(age) // age is 45
doSomething()
print(age) // age is 67
  • They cannot be changed.
  • They are in an immutable state.

Mutable State

  • Race Conditions
  • Dead Locks
  • You don’t have deadlocks.
  • You don’t have things depending on other things.

First-Class and Higher-Order Functions

Pure Functions

  • The function will always produce the same output when given the same input
  • The function creates zero side effects outside of it

Conclusion

  • In functional programming, every variable is immutable.
  • You don’t face the problems with Concurrency Issues with Race Conditions and DeadLock
  • Higher Order Function is a function that can take and return another function.
  • Pure functions will always produce the same output when given the same input.
  • Pure functions create zero side effects outside of it.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

KD Knowledge Diet

2.4K Followers

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!