rschmitt/dynamic-object

Make ':' optional in @Key string value

mattbishop opened this issue · 3 comments

Any reason we have to specify the colon character? I know it's a map thing in CLJ but it makes @key confusing outside.

There is a reason, actually. It's described here:

Note the convention: an initial colon yields a Clojure keyword, and anything else yields a string.

Originally the initial colon was optional, but this was changed to the current convention when I realized that string keys are extremely useful for a lot of use cases involving interop with JSON (for example).

I'd argue for another annotation instead of a string pattern to differentiate. The user has to know more about clojure than perhaps they should, but I'm coming at this library from the perspective that clojure is an internal detail rather than a feature.

This library is extremely Clojure-centric and doesn't have encapsulation of Clojure as a design goal, except in the sense that you shouldn't have to reference Clojure's own implementation details or internal types. Depending on what you're doing, another library may be a better fit.

Adding another annotation is one way to do it, but it has trade-offs too. It's more explicit (DynamicObject as a rule shies away from convention-over-configuration) and I guess it allows you to set up a string key that begins with a colon, but the presence of two or more annotations makes validation a lot more complicated. What happens if someone specifies both keys? Is it clear what's supposed to happen in that case? Or do you have to throw an exception? And if so, when?