Hi Wes,

I'd be on the "don't do that" side of the fence. I did something similar when I 
first moved from Java to a dynamically typed language (I suspect that most 
people do) and it hinders at least as much as it helps.

For me, the thing that I needed to internalise is that Clojure isn't lacking 
types, dynamic typing isn't a deficiency. Both static and dynamic typing are 
features with pros and cons. Clojure has chosen to take advantage of the 
features of dynamic typing. Trying to superimpose a pseudo-static type system 
on top of it leaves you in a worst case scenario - none of the benefits of 
dynamicity and no real type-safety.

Turning on *warn-on-reflection* and using type-hints, where appropriate, isn't 
unreasonable and might help to give you some comfort whilst your instincts 
attune themselves.


R.



On 23 Jul 2014, at 03:59, Wesley Hall <wesley.h...@gmail.com> wrote:

> 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.

-- 
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