Hello folks, My question is, "Is it 'idiomatic' to perform type checking of function arguments in :pre conditions"?
Coming to clojure from 15 or so years of Java development has been something of a revelation to me, but I am worried that I am still struggling a bit with some old habits, one of which is to type check my function arguments. I cannot get over this feeling of, "OMG!! What if somebody passes a string to this function that requires a function argument!! The world will surely end!". I am finding myself developing a bit of a habit of introducing type checks in :pre conditions, but I am not sure whether the more 'clojure' thing to do is to allow the exception to occur further down the call stack when the reference is actually used in an inappropriate way (I attempt to call the string as if it were a function). I have found a few cases where the error 'invites me' to implement a protocol to 'teach' the system how to handle the particular type, which tends to suggest to me that it might be better not to type check in a pre condition, since at some later point I could decide to make the argument type valid by defining a protocol implementation to handle the type successfully. I am also aware of the existence of core.typed, which is perhaps something I should look into in more detail. Do people have thoughts on this? How do you handle this in your production clojure code? Thanks Wes -- 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.