On Tuesday, March 31, 2015 at 7:49:52 AM UTC-4, Jeroen van Dijk wrote:
>
> Thanks for sharing James! I'll have a look. 
>
> As a side note, I see in the example code that you are dissoc-ing on the 
> component. This can lead to unexpected behaviour as I have 
> experienced (mostly in repl cases), as this will return a map instead of a 
> record when the field is not part of the record. This is also mentioned in 
> the readme of https://github.com/stuartsierra/component where `(assoc 
> component ::field nil)` is recommended
>

Perhaps there should be an enablable warning for that, the way there 
already is for reflection. When enabled, it would go off if

a) Code was compiled for (dissoc x :foo) where x could be determined by 
static analysis to be an instance of a record type for which :foo is a base 
field, and also if
b) A dissoc on a record returned a plain map,

or at least b).

Enabling the warning could work partly by actually redefining 
clojure.core/dissoc, as with disabling it, so that the overhead of the 
warning code was completely avoided with it disabled. With it enabled, the 
code path in dissoc that produces a non-record from a record would also 
emit a message to stderr with general wording such as "warning: dissocing 
base field :foo from MyRecord, producing hash map, at line 666 of 
evil.clj". (The line and file being obtained by constructing a Throwable 
and then dismantling and examining its StackTraceElements.)

Turning this on and exercising a project (especially, running all the tests 
if it has good test coverage) would then find most potential-bugs of this 
sort.

-- 
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/d/optout.

Reply via email to