- Prototypal Inheritance
- Functional Programming
What is functional programming?
Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data. Some Examples of functional languages: Lisp, ML, Haskell, Erlang, Clojure, Elm, F Sharp, OCaml, etc…
What is Prototypal Inheritance?
There is more than one type of prototypal inheritance:
· Delegation (i.e., the prototype chain).
· Concatenative (i.e. mixins, `Object.assign()`).
· Functional (Not to be confused with functional programming. A function used to create a closure for private state/encapsulation).
Functional programming vs Prototypal Inheritance (object-oriented programming)?
· OOP Pros:
— Objects and methods are very readable and understandable.
— OOP utilizes an imperative style, in which code reads like a straight-forward set of instructions as a computer would read it
· OOP Cons:
— OOP commonly depends upon shareable state. Objects and behaviors are typically tacked together on the same entity.The unfortunate result of so many objects and methods existing within the same state and being accessed in an entirely undetermined order can lead the pre-discussed concept of “race conditions”.
— Utilizing pure functions, leads to reliable functions with no side effects that accomplish and return exactly what you expect them to.
— Using the functional paradigm, programmers avoid any shared state, which eliminates bugs caused by multiple functions competing for the same resources.
— FP utilizes a more declarative style, which focuses more on what to do and less about how it’s being done. This places the emphasis on performance and optimization, leaving the door to refactor without completely reworking your code.
— Functional programming is a newer paradigm. More people are familiar with OO and imperative programming than functional programming, so even common idioms in functional programming can be confusing to new team members.
— Similar to one of OOP’s strengths, functional programming can lack readability at times. FP concepts are frequently written about using idioms and notations from lambda calculus, algebras, and category theory, all of which requires a prior knowledge foundation in those domains to be understood.