>
> The problem with using type hints for doc is, that they actually alter
>> runtime behavior, non - locally:
>> - They replace expensive reflective method call sites with casts to a
>> known type
>> - Hence they effectively narrow the accepted type at the call site
>>
> But the above would only apply in case of interop calls, right? Putting a
> Protocol as a return type hint of an fn, we're always calling clojure fns
> on such result types. We should then not suffer from any of the two
> limitations.
>

Right, but due to type inferencing, it can constrain an interop call
anywhere in client code using your lib.


>  - They change the exception thrown in error cases to ClassCastException
>>
> That's something that might be quite a deal breaker. Again, would this
> happen in any situation other than interop calls?
>

Only interop calls, true. But I myself find it grossly distasteful to use
anything for doc that can change runtime behavior in unforseen ways.


> Also for real documentation, type hints lack expressivenes (unions?
>> parameters? function types?).
>>
> Indeed, they would not alone provide all the needed documentation. I guess
> the idea would be to have some quick hints (no pun intended) for the
> developer looking at the sources.
>

Well, any combination of docstrings, contracts, pre- and post conditions
and real type annotations are better suited for that task, IMO.

 
https://github.com/frenchy64/**typed-clojure<https://github.com/frenchy64/typed-clojure>
>>
> That's probably a bit too far already. While I might go for the type hints
> as documentation, I'm not quite interested in full type safety yet.
>

What this gives you isn't type safety in the classical sense. These type
annotations are no-ops and primarily give you a documentation syntax. Then
there are external tools, that can give you warnings about type
inconsistencies in your program. For another example of this principle,
have a look at Google Dart, where it's made very explicit, that type
annotations can never alter runtime behavior; i.e. no casts based on
annotations.

So type annotations, when understood in this sense, effectively become
machine-checkable doc strings.

If you feel you really have to use that nifty metadata syntax for
documenting types (been there, done that ;), use (defn ^:Node user-home
[..] ..).
That's a no-op, at least until some code looks at the Metadata and decides
to use that :Node key for something ...

kind regards

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to