Hacker News new | ask | show | jobs
by dgb23 1221 days ago
> A first element of decision lied in the fact that our product used a great number of data structures and business management rules which aim to evolve very frequently and be adapted to new business contexts over time.

They seem to have a very good use case for Clojure adoption. The article mentions many of the affordances Clojure gives you for data oriented, information processing problems.

But one of the unsung heroes of Clojure is the namespaced keyword:

If you’re already working in a FP, data oriented style but in a language that doesn’t have them, I recommend you have a go with Clojure and explore them.

It’s such a simple construct that gives you a lot of leverage in terms of semantics, code organization, flexibility and validation.

Think of them as having characteristics of uuids, URLs, URNs etc. they stand on their own and have meaning across system boundaries.

It’s very nice and calming to have that in-built as an everyday construct.

4 comments

Never heard a lang-feature describe as "calming" but now that I think about it, you are very much right :D
Several Clojure/Datomic design decisions are directly inspired by RDF.
They are also interned such that there is only one keyword by that name. It is created atomically. You can use it to create synchronized blocks in the rare case you would have to
> But one of the unsung heroes of Clojure is the namespaced keyword:

Sounds intriguing, can you say more?

I'll do my best but there might be better explanations around the web.

I think an illustrative example would be this repo:

https://github.com/cognitect-labs/anomalies

These are basically re-usable, namespaced keywords. You might decide to use them or something similar in your program/system and some people do. Pretty neat: Their semantics are documented in the readme and the little bit of code in the repo defines a spec here https://github.com/cognitect-labs/anomalies/blob/master/src/....

You can read it as: any map that has these keywords as defined in the spec is an "anomaly".

Specs are open, non-exclusive so you can add more stuff to your structure and they still conform. (Note that the double colon before the keywords just mean "the current namespace defined at the top".)

Note that you don't need to define a spec for namespaced keywords. It's just a utility that leverages them. By themselves they already say "I can be used in a global context".

---

These keywords can be used from anywhere and by themselves. You don't need to carry around their context for them to work or have meaning. To contrast: for example a JSON field in a nested context might only make sense in that specific nesting context. Clojure namespaces are by convention globally unique.

Some examples:

- `:my.domain.accounting/refnumber`

- `:my.domain.ui/color` defined as `(or :my.domain.ui/rgb :my.domain.ui/hsl)` etc.

- `:my.domain.person/name` defined as a string if at all

- `:my.domain.event/type`

Thanks!

Very interesting, as something along these lines is a direction I've been meaning to extend Polymorphic Identifiers, both to have partial trailing paths and also to have bundles of paths that can be treated a bit like a data structure, but without actually being one.