I’ve started reading the book Functional Programming In Javascript by Luis Atencio and figured it’d be a good idea to take some notes. Might as well keep them here ^_^

1.1 What is functional programming (FP)?

  • “Abstract control flows and operations on data with functions to avoid side effects and reduce mutation of state”
  • Fundamental concepts
    • Declarative
      • Easy to reason about
      • Improves readability
    • Pure functions
      • Only depends on inputs, not on hidden or external state
      • Does not mutate anything outside of its scope therefore has 0 chance of changing/breaking global state
    • Referential transparency
      • A more formal definition of pure
      • Function consistently yields the same result give the same inputs
    • Immutability
  • Functions with single purposes lead to greater composability, reusability, and testability
  • Reactive programming
    • Abstracts away boilerplate code of async and event-based programs
    • Observable:
    • Functional Reactive Programming (FRP)

1.2 Higher-Order Javascript

  • JS draws inspiration from Scheme and Lisp and share commonalities between other hybrid languages like Scala and F#
  • OOP applications are mostly imperative, rely on encapsulation to protect integrity of mutable state = tight coupling between data and behavior (Not sure I totally agree with this… and author goes on to note that this reference applies more strongly to object-oriented practitioners than to the paradigm itself. Many authorities in the field, including the Gang of Four, prefer object composition over class inheritance, based on LSP.)
  • FP removes need to hide data, everything is immutable therefore you work directly with objects = loose coupling of data and behavior
  • FP === functions are main form of abstraction
  • Data and data relationships (OOP) vs. Behavior/Operations Performed (FP)
  • Value Objects
    • OOP design pattern inspired by FP
    • Immutable: returned object interface has no mutating methods
    • Equality is dependent on value, not reference or identity
    • Object.freeze() is shallow, recurse and “deep freeze”
  • Practical applications of closures: Module Pattern
    • Exposes specific methods/data thus emulating private variables
    • Less pollution of global namespace and less collisions