Reconciling OOP vs. FP

animal.move(12, 15)
move(animal, 12, 15)
tony := tiger{}
tony.move(1, 2) // OOP syntax
tiger.move(tony, 1, 2) // FP syntax


type animal interface {
move(int, int)
func moveAnimal(a animal) {
a.move(42, 13)
move(a, 42, 13) // This doesn't work.
fun foo(age: Int, name: String) {
println("${name} is ABOUT ${age} years old.");
fun foo(age: Double, name: String) {
println("${name} is EXACTLY ${age} years old.");
val name = "Alice"
val roundedAge = 42
val exactAge = 42.2

foo(roundedAge, name); // prints "Alice is ABOUT 42 years old."
foo(exactAge, name); // prints "Alice is EXACTLY 42.2 years old."

Composition vs. Inheritance


Unnecessary Conditionals

Law of Demeter

Closures vs. Objects

func foo(age int, name)
println("${name} is ABOUT ${age} years old.")
func foo(age double, name)
println("${name} is EXACTLY ${age} years old.")
type person struct
age int
name string
func foo(someone) # Type "inference" rather than interfaces
func main()
# A constant
name = "Alice"
# May be reassigned due to := initialization
unusedName := "Bob"
# All args passed by reference and immutable outside their
# creation scope.
foo(42, name)
foo(42.2, name)
foo(person{age: 42, name: "Alice"})




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
Clay Shentrup

Clay Shentrup

advocate of score voting and approval voting. software engineer. father. husband. american.