Skip to content
0:00 / 0:00

#clojure#component#stuartsierra

Stuart Sierra - Components Just Enough Structure

ClojureTV

111K subscribers • 158 videos on Hallway

YouTube
  • Recommended by 4 people: 2 on Hacker News and 2 in engineering communities.
  • A classic. People kept recommending it from 2014 to 2024.
  • Presented by Stuart Sierra, Clojure developer
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

35K views12 years ago4 recommendations

Software designProgramming languagesSoftware architectureLisp and ClojureFunctional programming

Stuart Sierra introduces the Component pattern and library for Clojure to manage lifecycle and dependencies of stateful services without global state.

Functional programming with immutable values is wonderful, but sooner or later every program has to deal with mutable, stateful, imperative tasks. A large program may need to manage dozens of stateful services: database connections, thread pools, network services, scheduled tasks, and caches. How do we do this in a functional programming model? All too often we fall back, almost by accident, into global mutable state, promiscuous sharing, and imperative spaghetti code. To escape this quagmire, we need to recall some basic principles of both functional and object-oriented programming: referential transparency, immutable values, message-passing, encapsulation, and interface contracts. The Component pattern and its library implementation offer a minimal way to structure the stateful dependencies of a functional program. This talk will cover the motivation for the Component pattern, its benefits and downsides, comparisons with other approaches, and how to use it in Clojure programs. This talk builds on the concepts in last year's "Clojure in the Large" but does not assume viewers have seen that talk first.

Why it's here

4 people recommend this

What people say. Recommended as a foundational talk on structuring large Clojure applications and managing stateful dependencies.

Moments people linked to

u/ringbuffer__in r/Clojure • Recommends

This guy's talks are always clear and easy to understand

u/jknin r/Clojure • Recommends

Components Just Enough Structure

nilliamson Hacker News • Recommends

On “Spider Programming Language”

Can't agree with your implication that 'real JS stuff' won't get done and 'JS people' won't get on board due to its 'focus on OOP'. I've yet to see a large JS app written in a 'functional style'. Most large client-side apps I've come across are written in Backbone, Angular, Ember etc. which are all frameworks/libraries that embrace OOP. You shouldn't mistake JavaScript's 'prototypal' nature for it being a non-OOP language. JavaScript and OOP are a very good fit. > The people who will appreciate the trappings of OOP are more than likely the typical classically trained programmers, who will write 300 lines of Spider on the frontend of their Python hobby project, and not touch it again. If you'…

nowprovisionon Hacker News • Recommends

On “Your DI framework is killing your code”

This talk might be of interest Stuart Sierra - Components Just Enough Structure link to this video - it is a tiny clojure framework but the ideas should be thought provoking, although granted with OO aligned type system not completely adaptable. In this example Customer could possibly just be a data-bucket/map/hashtable/Dictionary, Im not entirely sure how I'd handle reporting though as the example has put me back in OO mode, but a customer report (which knows how to organize data about a customer) shouldnt be part of customer entity (used loosely) in my opinion.

u/shivekkhuranain r/Clojure • Mentions

On “What does the component library do?”

It’s a data driven - dependency injection framework. It’s also a work of art, that inspired integrant, mount and a few others.  Stuart Sierra gave a presentation in 2014:  link to this video

u/yogthosin r/Clojure • Mentions

On “New Clojurists: Ask Anything”

I recommend looking at the component approach for structuring apps. There's an intro talk by the author and nice introductory post.

u/joshlehmanin r/Clojure • Mentions

On “Comparison of Clojure Web Libraries for React/Om frontend”

I use Om on the front end with a Clojure back end, and as has been echoed here already, the choice of back end stack really doesn't influence the use of Om too greatly. I would encourage you to check out component, as this will help with enforcing a protocol for communication throughout your system. It has tons of great benefits, as explained here. If you agree with the rationale behind the library, definitely embrace it from the get-go. It's a pain to retrofit an existing application to this approach.

u/xeqiin r/Clojure • Mentions

On “New Clojurists: Ask Anything”

Once things move into the realm of an application or service, many OOP principles still apply. These services are basically objects. You can see some of this mentioned in: * Rich Hickey - language of the system * Anthony Marcar - clojure at scale * Stuart Sierra - Components: Just enough structure As an example of how OOP principles might look, lets start with a generally accepted one of **Avoid Global State**. Many usage examples for libraries will def a global state to act with. An example is defining a database spec in a namespace for jdbc. It is an anti-pattern. It limits your ability to swap implementations or configuration data. It also limits the ability to have multiple…

u/tolitiusin r/Clojure • Mentions

On “Contrasting Component and Mount”

> This assertion appears near the top, and seems to be the most damning critique of Component, but I see nothing to back it up. All the examples of Component would seem to be explicitly trying to avoid that. Writing an application like that would certainly make a big mess. (defrecord Customers db email) (defn notify customers name message (let {:keys [db email} customers address (query db ... name)] (send email address message))) backing it up While this could work for a given application / problem, I don't think this Hibernate like approach is something worth to be encouraged in Clojure. It does work rather well in Spring/Hibernate apps in Java,…
4View on Reddit

u/yogthosin r/Clojure • Mentions

On “Edge: A complete Clojure project you can leap from”

>Just to make sure we're on the same page, you're talking about changes to defrecord not affecting existing records of that type? Right, the problem is with the object instances that have already been initiated lingering around after a protocol definition changes. >you're reloading via (reset) anyway I find that I rarely do a full system reset when I develop. Vast majority of the time I'm just reloading individual functions that I'm working on. I only tend to restart the system as a sanity check before doing a commit. However, with Component you do need to `(reset)` the whole system as part of the regular workflow, and that means that the whole app has to be designed around that. >Then t…
4View on Reddit

u/Platzin r/haskell • Mentions

On “Edward Kmett - Encapsulation vs. Code Reuse”

They've had to somewhat refine the naive approach to this, see Stuart Sierra's talk on the challenges they faced wit that they're currently considering as a way to go forward... link to this video

u/freshhawkin r/Clojure • Mentions

On “How would you structure this many-external service Clojure program?”

At a high level I would probably use this type of thing as a chance to try out Stuart Sierra's component approach to organizing code because it's a great approach and sounds like it fits this case well. That might only be because I just watched that talk recently and see a lot of promise in it, I haven't actually tried it yet. As for the concurrency I would use core.async channels because I really like them personally, and using a channel per domain (among what would probably be many other channels at different layers) to do your throttling seems like a nice, cheap way to handle it. This is also clearly going to be a network bound bunch of tasks so it's seems like a good fit from that per…

u/lambdacurryin r/Clojure • Mentions

On “New Clojurians: Ask Anything”

My Clojure Workflow, Reloaded by Stuart Sierra might help. Videos * The joys and perils of interactive development * Components Just Enough Structure Tools * Ring Reload * Integrant-repl

u/blazinglambdain r/Clojure • Mentions

On “New Clojurians: Ask Anything - March 31, 2025”

…enting Electric :) \- Rama (next generation backend data platform) \- XTDB - immutable database with special temporal support \- Datomic - immutable database Background on the component lifecycle approach (which also supports interactive development - restart the entire system): Alessandra Sierra's original talk on component lifecycle [video…

jared314on Hacker News • Mentions

On “Introducing .NET Core”

> but once you need to go for something bigger, with big teams, the thing start to melt down. The people in the Clojure community have already started exploring this issue. Component 1 2, Jig 3, and others are trying to add just enough OOP back for the reasons you mentioned. 1 link 2 link to this video 3 link

nilliamson Hacker News • Mentions

On “React’s diff algorithm (2013)”

…jure community has been very frustrating, I find very few answers on how to actually compose large apps, and the answers I do find basically point back to OOP (but implemented in a syntax-less, ad-hoc manner 1). If I've got this wrong, please tell me, I'm dying for better answers. 0 link 1 Stuart Sierra - Components Just Enough Structure - link to this video…