Chas Emerick's excellent clojure type flowchart[1] is my goto for when to
use a defrecord over deftype / plain 'ol map.

Since the criteria to choose defrecord is basically 'do you need it to
behave like a clojure immutable map, but with enhanced protocols support'
then I'd argue that the idiomatic usage would be to treat it like a map.

For constructor usage, i.e

(Point. 10 10) vs (->Point 10 10)

I'd argue for the latter. The first is painful when used from other
namespaces, because you must import the java class even if you've referred
the whole ns. Particularly confusing when you have packages with dash /
underscores in the package name.


[1]
http://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/

*Neale Swinnerton*
{t: @sw1nn <https://twitter.com/#!/sw1nn>, w: sw1nn.com }


On 25 July 2013 17:18, Sean Corfield <seancorfi...@gmail.com> wrote:

> I tend to use plain ol' maps for data structures but was showing
> someone defrecord the other day and had some questions about idiomatic
> usage:
>
> Given:
>
> (defrecord Point [x y])
>
> Which constructor form is considered more idiomatic:
>
> (Point. 10 10) or (->Point 10 10)
>
> Which accessor form is considered more idiomatic (assume pt is a Point
> record):
>
> (.x pt) or (:x pt)
>
> Are there (other) things regarding records for which idiomatic usage
> would not look just like maps?
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to