On Jan 18, 1:17 pm, Lee Spector <lspec...@hampshire.edu> wrote: > On Jan 18, 2011, at 1:02 PM, Ken Wesson wrote: > > I haven't looked at the OP's context for this, but I rather like defstruct > and I want to ask about its status. > > I see some mention on the web of it being deprecated in 1.2 (e.g. > inhttp://stackoverflow.com/questions/4288360/clojures-macro-define-a-bi...). > Is this true? That is, is the removal of defstruct from the language > anticipated?
Deprecated doesn't mean "in future this will stop working" - it means "you shouldn't use this". See eg http://dictionary.reference.com/browse/deprecate. Of course in software deprecated features are often eventually removed, but just because it hasn't been removed doesn't mean it's a good idea to use it. For example, if some rare bug is discovered in defstruct it's unlikely to be fixed. > > Athttp://clojure.org/data_structuresI see only the milder statement that > "Note: Most uses of StructMaps would now be better served by records." > Athttp://clojure.org/datatypesthere's a more directive "Overall, records will > be better than structmaps for all information-bearing purposes, and you > should move such structmaps to defrecord." But I don't see anything about > planned removal from the language at clojure.org. > > Why do I care? I'm sure I could get over it but a couple of months ago I > switched a project from defstruct to defrecord and found that it didn't make > any noticable difference to performance (in that application!) and that I > missed the elegance and flexibility of having all of my data structures be > maps. I don't recall exactly what the issues were, just that they were minor > but nonetheless I preferred the struct-map approach. So I switched back. > Whatever the benefits of records are, I would anticipate preferring > struct-maps and defstruct in some cases. Will that still be supported? Records behave the same as structs: they are maps, which you can assoc, dissoc, and get from. Neither one is actually a clojure.lang.PersistentMap, so there's no "elegance and flexibility" that struct-maps have which is missing from defrecords. My understanding of the differences is: - defrecords are real host-level classes, making interop easier - defrecords are faster and smaller - defstruct fields default to nil if you don't pass a particular key in the constructor - defstructs implement IFn, so you can call (m :a) as well as (:a m) The latter two are convenient features, but if records behaved that way it would be bad for performance. And frankly if you're creating a struct to hold :a and :b but don't feel like specifying :b this time, why do you have a struct at all instead of a plain hash-map? That is, defstructs are a slightly more-performant versions of hashmaps: if you don't care about performance and want the convenience of hashmaps...use hashmaps! If you do care about performance, use records, which are more performant and discourage usage that will detract from performance. -- 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