The Object-Oriented Programming vs Functional Programming debate, in a beginner-friendly nutshell

class Dog
attr_accessor :name, :favorite_treat

def initialize(name, favorite_treat)
@name = name
@favorite_treat = favorite_treat
end

def change_favorite_treat(treat)
@favorite_treat = treat
end
end
charlie = Dog.new("Charlie", "bacon")
charlie.change_favorite_treat('t-bone')
charlie.favorite_treat >> 't-bone'

Functional programming

Pure functions

function number(num){
num * Math.random()
}
function hello(greeting){
console.log(greeting)
}
var totalPeople = 10
function totalVotes(votes){
return votes * totalPeople
}
function plusTwo(num){
return num + 2
}

OOP vs FP

So, what’s the debate about?

--

--

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