5-aspect naming scheme for re-frame

5-aspect naming scheme for re-frame

This could lower your stress, increase the joy of your Clojure life, and save you thousands of your local space credits.

I've been doing re-frame almost non-stop for the past 5 years and I want to share my thoughts on keywords hygiene. I use 5 namespace prefixes db, subs, fx, cofx, evt. So my code looks like:

  • :evt.domain/evt-id for events
  • :subs.domain/sub-id for subs
  • :db.domain/key-id for db keys
  • :fx.domain/fx-id for effects
  • :cofx.domain/cofx-id for coeffects

Another two prefixes for non-re-frame needs:

  • :ui/prop-name for transient properties added into entities
  • :comp/prop-id for view components options
  • spec for specs and malli schemas


This enables:

  • Easy autocomplete. I type :evt. and I get the full list of domains and their events.
  • An order of magnitude fewer things to recall. Instead of remembering a dozen of domains for a dozen of projects, I can use these 5-7 prefixes. In re-frame we have only 5 main tech aspects (db, subs, fx, cofx, evt) and dozens of domain members: modules, logic namespaces, etc.
  • Dynamic domain exploration. If you work in a team and either it's a huge project or you just have a dozen of smaller projects – each time you need something you probably go into docs or your teammate. Each interaction breaks your focus, and sometimes the focus of your colleague. Much better if docs are in-place and on-demand. The 5-scheme allows me to [re-]explore the domain just by using autocompletion and navigation to the definition.


Formal definition

tech-layer . domain (...subdomains) / member-name


Conversion

If you want to try these clean sub names and also give your team and yourself time to adapt – I encourage you to register these first as aliases. Let's say you want to try the 5-aspect-scheme in a particular module in one of your company's projects. If you have a sub named :my-sub-one – I suggest you add an alias like :subs.domain/my-sub-one


Enjoy!