Leanpub Header

Skip to main content

Material for Composing Software

An Exploration of Functional Programming and Object Composition in JavaScript

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
About

About

About the Book

Price

Pick Your Price...

Minimum price

$19.00

$29.00

You pay

$29.00

Author earns

$23.20
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 2)

2
The author will earn $24.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Eric Elliott

Eric Elliott is a Webby-nominated software engineering expert, author, and creator of SudoLang, an AI programming language. With over 10 years of experience deploying AI models at scale to millions of users, he built and trained production AI models, and was an early pioneer of prompt engineering and AI Driven Development (AIDD). He has served as an engineering manager working on Generative AI for Adobe Firefly, tech lead on a social video AI app spun out of Stanford Research Institute, and a JavaScript expert and consultant on software development productivity and AIDD.

Leanpub Podcast

Episode 301

An Interview with Eric Elliott

Contents

Table of Contents

Introduction

  1. Thank You
  2. Composing Software: An Introduction
  3. You Compose Software Every Day
  4. Composing Functions
  5. Working Memory
  6. Signal to Noise Ratio
  7. Surface Area for Bugs
  8. Composing Objects
  9. Conclusion
  10. Exercise 1
  11. The Dao of Immutability (The Way of the Functional Programmer)
  12. Forward
  13. Exercise 2
  14. Quiz 1

The Rise and Fall and Rise of Functional Programming (Composable Software)

  1. The Rise of Functional Programming
  2. Exercise 3
  3. The Fall of Functional Programming
  4. The Rise of Functional Programming
  5. Functional Programming Has Always Been Alive and Well
  6. Quiz 2

Why Learn Functional Programming in JavaScript?

  1. What JavaScript is Missing
  2. What JavaScript Has that Pure Functional Languages Lack
  3. Quiz 3

Pure Functions

  1. What is a Function?
  2. Exercise 4
  3. Mapping
  4. Exercise 5
  5. Pure Functions
  6. Exercise 6
  7. The Trouble with Shared State
  8. Exercise 7
  9. Same Input, Same Output
  10. Exercise 8
  11. No Side Effects
  12. Immutability
  13. Exercise 9
  14. Conclusion
  15. Exercise 10
  16. Quiz 4

What is Functional Programming?

  1. Pure Functions
  2. Exercise 11
  3. Function Composition
  4. Shared State
  5. Exercise 12
  6. Immutability
  7. Exercise 13
  8. Side Effects
  9. Exercise 14
  10. Reusability Through Higher Order Functions
  11. Exercise 15
  12. Containers, Functors, Lists, and Streams
  13. Exercise 16
  14. Declarative vs Imperative
  15. Conclusion
  16. Exercise 17
  17. Quiz 5

A Functional Programmer’s Introduction to JavaScript

  1. Expressions and Values
  2. var, let, and const
  3. Types
  4. Exercise 18
  5. Destructuring
  6. Comparisons and Ternaries
  7. Exercise 19
  8. Functions
  9. Signatures
  10. Default Parameter Values
  11. Named Arguments
  12. Rest and Spread
  13. Exercise 20
  14. Currying
  15. Exercise 21
  16. Function Composition
  17. Exercise 22
  18. Arrays
  19. Exercise 23
  20. Method Chaining
  21. Exercise 24
  22. Conclusion
  23. Quiz 6

Higher Order Functions

  1. Exercise 25
  2. Quiz 7

Curry and Function Composition

  1. What is a curried function?
  2. Exercise 26
  3. What is a partial application?
  4. What’s the Difference?
  5. Exercise 27
  6. What is point-free style?
  7. Exercise 28
  8. Why do we curry?
  9. Exercise 29
  10. Trace
  11. Exercise 30
  12. Curry and Function Composition, Together
  13. Exercise 31
  14. Conclusion
  15. Exercise 32
  16. Quiz 8

Abstraction & Composition

  1. Exercise 33
  2. Abstraction is simplification.
  3. Exercise 34
  4. Abstraction in Software
  5. Exercise 35
  6. Abstraction through composition
  7. Exercise 36
  8. How to Do More with Less Code
  9. Exercise 37
  10. Conclusion
  11. Exercise 38
  12. Reduce
  13. Exercise 39
  14. Reduce is Versatile
  15. A Word on Redux
  16. Exercise 40
  17. Conclusion
  18. Quiz 9

Abstract Data Types and the Software Crisis

  1. Common ADT Examples
  2. Exercise 41
  3. Why ADTs?
  4. History of ADTs
  5. Exercise 42
  6. Specifications for ADTs
  7. Exercise 43
  8. Stack ADT Example
  9. Definitions
  10. Abstract Signatures
  11. Construction
  12. Stack Operations (operations which return a stack)
  13. Axioms
  14. Identity
  15. Sequence
  16. Empty
  17. Exercise 44
  18. Concrete Implementations
  19. Exercise 45
  20. Conclusion
  21. Exercise 46
  22. Glossary
  23. Quiz 10

Functors & Categories

  1. Exercise 47
  2. Why Functors?
  3. Exercise 48
  4. Functor Laws
  5. Identity
  6. Composition
  7. Exercise 49
  8. Category Theory
  9. Exercise 50
  10. Build Your Own Functor
  11. Exercise 51
  12. Curried Map
  13. Exercise 52
  14. Conclusion
  15. Exercise 53
  16. Quiz 11

Monads

  1. Exercise 54
  2. You’re probably already using monads.
  3. Exercise 55
  4. What Monads are Made of
  5. Exercise 56
  6. Building a Kleisli Composition Function
  7. Exercise 57
  8. The Monad Laws
  9. Left and right identity laws
  10. Associativity law
  11. Identity Laws
  12. Associativity
  13. Proving the Monad Laws
  14. Exercise 58
  15. Conclusion
  16. Exercise 59
  17. Quiz 12

The Forgotten History of OOP

  1. Exercise 60
  2. The Big Idea
  3. Exercise 61
  4. The Essence of OOP
  5. Exercise 62
  6. What OOP Doesn’t Mean
  7. Exercise 63
  8. What is an object?
  9. Exercise 64
  10. We’ve lost the plot.
  11. Characteristics of Message Passing
  12. Exercise 65
  13. Quiz 13

Object Composition

  1. Exercise 66
  2. What is Object Composition?
  3. Exercise 67
  4. Three Different Forms of Object Composition
  5. Exercise 68
  6. Notes on Code Examples
  7. Exercise 69
  8. Aggregation
  9. Examples
  10. When to use
  11. Considerations
  12. In Code
  13. Exercise 70
  14. Concatenation
  15. Examples
  16. When to Use
  17. Considerations
  18. In Code
  19. Exercise 71
  20. Delegation
  21. Examples
  22. When to Use
  23. Considerations
  24. In Code
  25. Exercise 72
  26. Conclusion
  27. Exercise 73
  28. Quiz 14

Factory Functions

  1. Exercise 74
  2. Literals for One, Factories for Many
  3. Exercise 75
  4. Returning Objects
  5. Exercise 76
  6. Destructuring
  7. Exercise 77
  8. Computed Property Keys
  9. Default Parameters
  10. Exercise 78
  11. Type Inference
  12. Exercise 79
  13. Factory Functions for Mixin Composition
  14. Exercise 80
  15. Conclusion
  16. Quiz 15

Functional Mixins

  1. Exercise 81
  2. Motivation
  3. Exercise 82
  4. What are mixins?
  5. Exercise 83
  6. What is functional inheritance?
  7. Exercise 84
  8. What is a functional mixin?
  9. Exercise 85
  10. Composing Functional Mixins
  11. Exercise 86
  12. When to Use Functional Mixins
  13. Exercise 87
  14. Caveats
  15. Classes
  16. Class Performance
  17. Implicit Dependencies
  18. Functional Mixins & Functional Programming
  19. Exercise 88
  20. Conclusion
  21. Exercise 89
  22. Quiz 16

Why Composition is Harder with Classes

  1. Exercise 90
  2. The Delegate Prototype
  3. Exercise 91
  4. The .constructor Property
  5. Exercise 92
  6. Class to Factory is a Breaking Change
  7. Code that Requires new Violates the Open/Closed Principle
  8. The class Keyword and extends
  9. Friendly Syntax
  10. Performance and Memory
  11. Type Checking
  12. Class Inheritance with extends
  13. Classes are OK if You’re Careful
  14. Exercise 93
  15. Quiz 17

Composable Custom Data Types

  1. Exercise 94
  2. You can do this with any data type
  3. Composable Currency
  4. Exercise 95
  5. Quiz 18

Lenses

  1. Exercise 96
  2. Why Lenses?
  3. Exercise 97
  4. Background
  5. Lens Laws
  6. Exercise 98
  7. Composing Lenses
  8. Over
  9. Exercise 99
  10. Quiz 19

Transducers

  1. Exercise 100
  2. Why Transducers?
  3. Exercise 101
  4. Background and Etymology
  5. A Musical Analogy for Transducers
  6. Exercise 102
  7. Transducers compose top-to-bottom.
  8. Exercise 103
  9. Transducer Rules
  10. Initialization
  11. Early Termination
  12. Completion
  13. Exercise 104
  14. Transducing
  15. Exercise 105
  16. The Transducer Protocol
  17. Exercise 106
  18. Conclusion
  19. Exercise 107
  20. Quiz 20

Elements of JavaScript Style

  1. Exercise 108
  2. 1. Make the function the unit of composition. One job for each function.
  3. Exercise 109
  4. 2. Omit needless code.
  5. Omit needless variables.
  6. Exercise 110
  7. 3. Use active voice.
  8. Event Handlers
  9. Lifecycle Methods
  10. Exercise 111
  11. 4. Avoid a succession of loose statements.
  12. Exercise 112
  13. 5. Keep related code together.
  14. 6. Put statements and expressions in positive form.
  15. If Statements
  16. Ternaries
  17. Prefer strong negative statements.
  18. Avoid null and undefined arguments in function calls.
  19. Exercise 113
  20. 7. Use parallel code for parallel concepts.
  21. Exercise 114
  22. Conclusion: Code should be simple, not simplistic.
  23. Exercise 115
  24. Quiz 21

Mocking is a Code Smell

  1. Exercise 116
  2. TDD should lead to better design.
  3. Exercise 117
  4. What is a code smell?
  5. Exercise 118
  6. What is a mock?
  7. Exercise 119
  8. What is a unit test?
  9. Exercise 120
  10. What is test coverage?
  11. Exercise 121
  12. What is tight coupling?
  13. Exercise 122
  14. What causes tight coupling?
  15. Exercise 123
  16. What does composition have to do with mocking?
  17. Exercise 124
  18. How do we remove coupling?
  19. Use pure functions
  20. Isolate side-effects from the rest of your program logic
  21. Use pub/sub
  22. Isolate logic from I/O
  23. Use objects that represent future computations
  24. Exercise 125
  25. “Code smells” are warning signs, not laws. Mocks are not evil.
  26. Mocking is great for integration tests
  27. Exercise 126
  28. Quiz 22

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub