The Joy of Clojure
Thinking the Clojure Way
A book by Michael Fogus and Chris Houser
We’re really enjoying Clojure, and we’d like to share our knowledge and experience with you. The Joy of Clojure can now be pre-ordered, which gives you access to the first four chapters now, plus more as we write them. If you're not quite ready to buy, you can read the first chapter for free. For updates on the book itself and Clojure in general, check back here or subscribe at any of our news links listed below.
The table of contents is very much subject to change, but here are our current plans for the book:
TABLE OF CONTENTS
- Clojure
- A Book for the Adventurous
- Useful Examples
- Use Available Libraries
- A Word About Notation
- Getting Clojure
- Building Clojure
- Running Clojure
- Clojure -- A Lisp for the Java Virtual Machine
- Perhaps you've heard of Clojure?
- Why Learn About Clojure?
- Roadmap
- Summary
FOUNDATIONS
- Clojure Philosophy
- The Clojure Way
- Concurrency-oriented Programming
- Why Clojure is Not Especially Object-Oriented
- Functional Programming
- Why a(nother) Lisp?
- Java.next
- Understanding Variable Scope, Free Variables, and Closures
- Use the REPL to Experiment
- Summary
- Dipping Our Toes Into the Pool
- Take a Moment to Breathe
- Observe Basic Clojure Style
- Embrace Doc-strings
- Deploying your code: Compiling and Packaging
- Using Clojure As a Scripting Language
- Truthiness
- nil Pun With Care
- Using Destructuring
- Summary
DATA TYPES
- On Scalars
- What Makes Clojure Scalars So Special?
- Understanding Precision
- Try To Be Rational
- When To Use Keywords
- Symbolic Resolution
- Regular Expressions - The "Second Problem"
- Summary
- Composite Data Types
- "I do not think it means what you think it means"
- Always Work Against the Sequence Abstraction
- When To Use Vectors
- When To Use Lists
- When To Use Queues
- When To Use Sets
- When To Use Maps
- EXAMPLE: Universal Design Pattern
- Thinking In Maps
- Case Study: Finding the Position of Items in a Sequence
- Prefer Higher-order Functions For Sequence Processing
- Using Metadata
- Summary
FUNCTIONAL PROGRAMMING
- Being Lazy and Set in Your Ways
- On Immutability
- On Laziness
- Summary
- Functional Programming Idioms
- Functions
- Closures
- Recursion
- Summary
- Macros
- Macros Are Different
- Using Macros To Provide Control Flow
- Using Macros When Combining Forms
- Using Macros When Changing Forms
- Using Macros To Control Evaluation Time
- When Not To Use Macros
- Always Qualify Macro Vars
- Understanding the
->and->>Macros - EXAMPLE: Pattern Matching
- Summary
LARGE-SCALE DESIGN
- Combining Data and Code
- Namespaces
- Multimethods
- Types, Protocols, and Reify
- Interoperability
- Embracing Java
- Using Clojure In Your Java Programs
- Generating Java On the Fly
- Understand Clojure's Relationship to Java Arrays
- All Clojure Functions Implement...
- Simplify Your Singletons
- Using Clojure Functions As Strategies
- Be Aware of null
- Be Wary of Exceptions
- How To Extend Clojure
- Summary
CONCURRENCY
- Concurrency / Mutation Idioms
- What STM and Agents Make Easy
- When To Use Refs
- When To Use Agents
- When To Use Atoms
- When To Use Primitive Locking
- When To Use Futures
- When To Use Promise and Deliver
- When To Use pmap
- Understanding let
- Understanding binding
- EXAMPLE: Cells
- Summary
TANGENTIAL CONSIDERATIONS
- Performance
- Type Hints
- Transients
- Chunked Sequences
- Memoization
- Primitives and Coersion
- Avoiding Boxed Args with Macros or definline
- Hotspot Inlining and Escape Analysis
- Summary
- Clojure Will Change the Way You Program
- DSLs
- Testing
- Refactoring
- Summary
- Appendix A: Clojure's Bare Necessities
- Appendix B: Tool Support
