Den fredag 10 april 2015 kl. 20:51:09 UTC+2 skrev marc fawzi:
> I just noticed that maps where key and value are keywords are used widely, 
> for example in cljs-ajax and leinnigen configuration
> 
> 
> Ii'm assuming it's because it's easier to work with values that are keywords 
> to build other maps from them or do whatever transformations that result in 
> values becoming keys in the output... and so it's explicit. But maybe I'm 
> missing the real reason? 
> 
> 
> Is there a good nerdy blog about Clojure that gets into the finer details of 
> Clojure for those of us who want to turn every atom?

It's common in Clojure to use keywords where in a language like Java you'd use 
enums.

Perhaps a good way to look at the reason to use keywords rather than strings in 
these situations, is that using strings gives the impression that the actual 
content of the strings matter (for example for presentation), whereas for 
keywords, the only important characteristic is that they only equal themselves 
(and the actual keyword chosen is only important for description, as is 
typically the case with enums as well).

So for example in Leiningen, the fact that the value for :description is a 
string makes sense since it's used for presenting information about the 
project, and the properties of the string (for example that it might contain 
the substring "distributed") may be of interest for other purposes as well. For 
:update, however, we are simply specifying one of a number of allowed values. 
We could have used numbers instead, but just like with enums, using keywords 
make it easier.

Besides that rant, I have some vague memory of there being some performance 
benefit memory-wise to using keywords rather than strings, but I might be 
mistaken.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to