Request and response map keyword namespacing

232 kyke
Slaan oor na eerste ongeleesde boodskap

Mark McGranaghan

ongelees,
03 Mrt. 2010 10:37:102010-03-03
aan Ring
Hi All,

The recent clj-oauth thread [1] prompted me to rethink namespacing of
keys in Ring request and response maps.

The Ring 0.1 spec [2] states:

If a component invokes another component with a request map
containing
additional keys, these keys must be namespaced using the Clojure
:name.space/key-name convention. The ring.* namespaces are reserved.
...
As with request maps, keys in response maps other than those listed
above should
be appropriately namespaced.

But we're already adding non-namespaced keys to the request and
response maps in the Ring libraries themselves, for example from the
params, cookies, and session middlewares.

My thinking at the time was that 0.2 would allow components in the
main Ring distribution to use non-namespaced keys, but that externally-
maintained components would still be required to use namespaced keys.

I'm now leaning towards not requiring namespacing at all. My reasons
are:

- As mentioned above, we're not namespacing our own keys.
- I don't see key conflicts as actually being a problem. This might
change as the Ring ecosystem grows, but I can't think of any specific
names for which I anticipate conflicts.
- It's inconvenient to use namespaced keys as functions:
(:some.deep.ns/key-name req) vs (:key-name req)
- It might actually create a naming problem as component
implementations move across repositories. For example, say a user
creates a "ring-utils" library with a "wrap-json-params" middleware
that adds the :ring-utils/json-params key to the request map. If we
eventually pull that component into ring-core or a ring-contrib, what
would the new key be? It would either have to change or be
inconsistent with the new enclosing library name, both of which would
be problematic. But if the original key was just :json-params we
wouldn't have this problem.

Does anyone feel strongly either way about the namespacing issue?

- Mark

[1] http://groups.google.com/group/ring-clojure/browse_thread/thread/6dc4fa43ff616432
[2] http://github.com/mmcgrana/ring/raw/5e7610920ee7df4e490eb9ae63bd26cf2593a146/SPEC

James Reeves

ongelees,
05 Mrt. 2010 08:00:022010-03-05
aan Ring
Namespaced keywords are a little clunky to use in Clojure, because you
can't require or use them. If you want to use a keyword from a library
namespace, you have to type out its namespace in full each time.

I'd imagine that if you wanted to add application specific data to the
request or response map, then namespacing the keyword might be a good
idea. But if you're developing a library (like wrap-json-params), then
you likely want generic keywords (:json-params and :params).

So I'm in favour of lifting this restriction.

- James

> [1]http://groups.google.com/group/ring-clojure/browse_thread/thread/6dc4...
> [2]http://github.com/mmcgrana/ring/raw/5e7610920ee7df4e490eb9ae63bd26cf2...

Antwoord almal
Antwoord skrywer
Stuur aan
0 nuwe boodskappe